Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (3.1 kB)

1
/*
2
 * Copyright (c) 2011 Greek Research and Technology Network
3
 */
4

    
5
package gr.grnet.pithos.web.client.foldertree;
6

    
7
import com.google.gwt.cell.client.AbstractCell;
8
import com.google.gwt.core.client.GWT;
9
import com.google.gwt.resources.client.ClientBundle;
10
import com.google.gwt.resources.client.ImageResource;
11
import com.google.gwt.resources.client.ImageResource.ImageOptions;
12
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
13
import com.google.gwt.safehtml.shared.SafeHtml;
14
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
15
import com.google.gwt.user.cellview.client.CellTree;
16
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
17
import com.google.gwt.user.client.Event;
18
import com.google.gwt.user.client.ui.AbstractImagePrototype;
19
import com.google.gwt.user.client.ui.Composite;
20
import com.google.gwt.user.client.ui.Tree;
21
import gr.grnet.pithos.web.client.FolderContextMenu;
22

    
23
public class FolderTreeView extends Composite {
24

    
25
    static interface BasicResources extends CellTree.Resources {
26

    
27
        @ImageOptions(flipRtl = true)
28
        @Source("cellTreeClosedItem.gif")
29
        ImageResource cellTreeClosedItem();
30

    
31
        @ImageOptions(flipRtl = true)
32
        @Source("cellTreeLoadingBasic.gif")
33
        ImageResource cellTreeLoading();
34

    
35
        @ImageOptions(flipRtl = true)
36
        @Source("cellTreeOpenItem.gif")
37
        ImageResource cellTreeOpenItem();
38

    
39
        @Source({"GssCellTreeBasic.css"})
40
        CellTree.Style cellTreeStyle();
41
    }
42

    
43
    static interface Images extends ClientBundle,Tree.Resources, FolderContextMenu.Images {
44

    
45
        @Source("gr/grnet/pithos/resources/folder_home.png")
46
        ImageResource home();
47

    
48
        @Source("gr/grnet/pithos/resources/folder_yellow.png")
49
        ImageResource folderYellow();
50
    }
51

    
52
    private static Images images = GWT.create(Images.class);
53

    
54
    static interface Templates extends SafeHtmlTemplates {
55
        Templates INSTANCE = GWT.create(Templates.class);
56

    
57
        @Template("<span>{0}</span>")
58
        public SafeHtml nameSpan(String name);
59
      }
60

    
61
    static class FolderCell extends AbstractCell<Folder> {
62

    
63
        @Override
64
        public void render(Context context, Folder folder, SafeHtmlBuilder safeHtmlBuilder) {
65
            String html = AbstractImagePrototype.create(images.folderYellow()).getHTML();
66
            safeHtmlBuilder.appendHtmlConstant(html);
67
            safeHtmlBuilder.append(Templates.INSTANCE.nameSpan(folder.getName()));
68
        }
69
    }
70

    
71

    
72
    private FolderTreeViewModel model;
73

    
74
    public FolderTreeView(FolderTreeViewModel viewModel) {
75
        this.model = viewModel;
76
        /*
77
         * Create the tree using the model. We use <code>null</code> as the default
78
         * value of the root node. The default value will be passed to
79
         * CustomTreeModel#getNodeInfo();
80
         */
81
        CellTree.Resources res = GWT.create(BasicResources.class);
82
        CellTree tree = new CellTree(model, null, res);
83

    
84
        tree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
85

    
86
        sinkEvents(Event.ONCONTEXTMENU);
87
        sinkEvents(Event.ONMOUSEUP);
88
        initWidget(tree);
89
    }
90
}