Statistics
| Branch: | Tag: | Revision:

root / web_client / src / gr / grnet / pithos / web / client / foldertree / FolderTreeView.java @ 1ac430a1

History | View | Annotate | Download (3.5 kB)

1 9e8e14e4 Christos Stathis
/*
2 9e8e14e4 Christos Stathis
 * Copyright (c) 2011 Greek Research and Technology Network
3 9e8e14e4 Christos Stathis
 */
4 9e8e14e4 Christos Stathis
5 9e8e14e4 Christos Stathis
package gr.grnet.pithos.web.client.foldertree;
6 9e8e14e4 Christos Stathis
7 9e8e14e4 Christos Stathis
import com.google.gwt.cell.client.AbstractCell;
8 9e8e14e4 Christos Stathis
import com.google.gwt.core.client.GWT;
9 9e8e14e4 Christos Stathis
import com.google.gwt.resources.client.ClientBundle;
10 9e8e14e4 Christos Stathis
import com.google.gwt.resources.client.ImageResource;
11 9e8e14e4 Christos Stathis
import com.google.gwt.resources.client.ImageResource.ImageOptions;
12 9e8e14e4 Christos Stathis
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
13 9e8e14e4 Christos Stathis
import com.google.gwt.safehtml.shared.SafeHtml;
14 9e8e14e4 Christos Stathis
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
15 9e8e14e4 Christos Stathis
import com.google.gwt.user.cellview.client.CellTree;
16 9e8e14e4 Christos Stathis
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
17 9e8e14e4 Christos Stathis
import com.google.gwt.user.client.Event;
18 9e8e14e4 Christos Stathis
import com.google.gwt.user.client.ui.AbstractImagePrototype;
19 9e8e14e4 Christos Stathis
import com.google.gwt.user.client.ui.Composite;
20 9e8e14e4 Christos Stathis
import com.google.gwt.user.client.ui.Tree;
21 9e8e14e4 Christos Stathis
import com.google.gwt.view.client.SelectionChangeEvent;
22 9e8e14e4 Christos Stathis
import com.google.gwt.view.client.SelectionChangeEvent.Handler;
23 9e8e14e4 Christos Stathis
import com.google.gwt.view.client.SingleSelectionModel;
24 9e8e14e4 Christos Stathis
import com.google.gwt.view.client.TreeViewModel.NodeInfo;
25 9e8e14e4 Christos Stathis
import gr.grnet.pithos.web.client.FolderContextMenu;
26 9e8e14e4 Christos Stathis
import gr.grnet.pithos.web.client.GSS;
27 9e8e14e4 Christos Stathis
import gwtquery.plugins.droppable.client.gwt.DragAndDropCellTree;
28 1ac430a1 Christos Stathis
import java.util.Iterator;
29 9e8e14e4 Christos Stathis
30 9e8e14e4 Christos Stathis
public class FolderTreeView extends Composite {
31 9e8e14e4 Christos Stathis
32 9e8e14e4 Christos Stathis
    static interface BasicResources extends CellTree.Resources {
33 9e8e14e4 Christos Stathis
34 9e8e14e4 Christos Stathis
        @ImageOptions(flipRtl = true)
35 9e8e14e4 Christos Stathis
        @Source("cellTreeClosedItem.gif")
36 9e8e14e4 Christos Stathis
        ImageResource cellTreeClosedItem();
37 9e8e14e4 Christos Stathis
38 9e8e14e4 Christos Stathis
        @ImageOptions(flipRtl = true)
39 9e8e14e4 Christos Stathis
        @Source("cellTreeLoadingBasic.gif")
40 9e8e14e4 Christos Stathis
        ImageResource cellTreeLoading();
41 9e8e14e4 Christos Stathis
42 9e8e14e4 Christos Stathis
        @ImageOptions(flipRtl = true)
43 9e8e14e4 Christos Stathis
        @Source("cellTreeOpenItem.gif")
44 9e8e14e4 Christos Stathis
        ImageResource cellTreeOpenItem();
45 9e8e14e4 Christos Stathis
46 9e8e14e4 Christos Stathis
        @Source({"GssCellTreeBasic.css"})
47 9e8e14e4 Christos Stathis
        CellTree.Style cellTreeStyle();
48 9e8e14e4 Christos Stathis
    }
49 9e8e14e4 Christos Stathis
50 9e8e14e4 Christos Stathis
    static interface Images extends ClientBundle,Tree.Resources, FolderContextMenu.Images {
51 9e8e14e4 Christos Stathis
52 9e8e14e4 Christos Stathis
        @Source("gr/grnet/pithos/resources/folder_home.png")
53 9e8e14e4 Christos Stathis
        ImageResource home();
54 9e8e14e4 Christos Stathis
55 9e8e14e4 Christos Stathis
        @Source("gr/grnet/pithos/resources/folder_yellow.png")
56 9e8e14e4 Christos Stathis
        ImageResource folderYellow();
57 9e8e14e4 Christos Stathis
    }
58 9e8e14e4 Christos Stathis
59 9e8e14e4 Christos Stathis
    private static Images images = GWT.create(Images.class);
60 9e8e14e4 Christos Stathis
61 9e8e14e4 Christos Stathis
    static interface Templates extends SafeHtmlTemplates {
62 9e8e14e4 Christos Stathis
        Templates INSTANCE = GWT.create(Templates.class);
63 9e8e14e4 Christos Stathis
64 9e8e14e4 Christos Stathis
        @Template("<span>{0}</span>")
65 9e8e14e4 Christos Stathis
        public SafeHtml nameSpan(String name);
66 9e8e14e4 Christos Stathis
      }
67 9e8e14e4 Christos Stathis
68 9e8e14e4 Christos Stathis
    static class FolderCell extends AbstractCell<Folder> {
69 9e8e14e4 Christos Stathis
70 9e8e14e4 Christos Stathis
        @Override
71 9e8e14e4 Christos Stathis
        public void render(Context context, Folder folder, SafeHtmlBuilder safeHtmlBuilder) {
72 9e8e14e4 Christos Stathis
            String html = AbstractImagePrototype.create(images.folderYellow()).getHTML();
73 9e8e14e4 Christos Stathis
            safeHtmlBuilder.appendHtmlConstant(html);
74 9e8e14e4 Christos Stathis
            safeHtmlBuilder.append(Templates.INSTANCE.nameSpan(folder.getName()));
75 9e8e14e4 Christos Stathis
        }
76 9e8e14e4 Christos Stathis
    }
77 9e8e14e4 Christos Stathis
78 9e8e14e4 Christos Stathis
79 1ac430a1 Christos Stathis
    private FolderTreeViewModel model;
80 1ac430a1 Christos Stathis
81 1ac430a1 Christos Stathis
    public FolderTreeView(FolderTreeViewModel viewModel) {
82 1ac430a1 Christos Stathis
        this.model = viewModel;
83 9e8e14e4 Christos Stathis
        /*
84 9e8e14e4 Christos Stathis
         * Create the tree using the model. We use <code>null</code> as the default
85 9e8e14e4 Christos Stathis
         * value of the root node. The default value will be passed to
86 9e8e14e4 Christos Stathis
         * CustomTreeModel#getNodeInfo();
87 9e8e14e4 Christos Stathis
         */
88 9e8e14e4 Christos Stathis
        CellTree.Resources res = GWT.create(BasicResources.class);
89 9e8e14e4 Christos Stathis
        DragAndDropCellTree tree = new DragAndDropCellTree(model,null, res);
90 9e8e14e4 Christos Stathis
91 9e8e14e4 Christos Stathis
        tree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
92 9e8e14e4 Christos Stathis
93 9e8e14e4 Christos Stathis
        sinkEvents(Event.ONCONTEXTMENU);
94 9e8e14e4 Christos Stathis
        sinkEvents(Event.ONMOUSEUP);
95 9e8e14e4 Christos Stathis
        initWidget(tree);
96 9e8e14e4 Christos Stathis
    }
97 9e8e14e4 Christos Stathis
}