Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / mysharedtree / MysharedTreeView.java @ 969a4d94

History | View | Annotate | Download (5.4 kB)

1 105b4e49 Christos Stathis
/*
2 105b4e49 Christos Stathis
 * Copyright 2011 GRNET S.A. All rights reserved.
3 105b4e49 Christos Stathis
 *
4 105b4e49 Christos Stathis
 * Redistribution and use in source and binary forms, with or
5 105b4e49 Christos Stathis
 * without modification, are permitted provided that the following
6 105b4e49 Christos Stathis
 * conditions are met:
7 105b4e49 Christos Stathis
 *
8 105b4e49 Christos Stathis
 *   1. Redistributions of source code must retain the above
9 105b4e49 Christos Stathis
 *      copyright notice, this list of conditions and the following
10 105b4e49 Christos Stathis
 *      disclaimer.
11 105b4e49 Christos Stathis
 *
12 105b4e49 Christos Stathis
 *   2. Redistributions in binary form must reproduce the above
13 105b4e49 Christos Stathis
 *      copyright notice, this list of conditions and the following
14 105b4e49 Christos Stathis
 *      disclaimer in the documentation and/or other materials
15 105b4e49 Christos Stathis
 *      provided with the distribution.
16 105b4e49 Christos Stathis
 *
17 105b4e49 Christos Stathis
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 105b4e49 Christos Stathis
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 105b4e49 Christos Stathis
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 105b4e49 Christos Stathis
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 105b4e49 Christos Stathis
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 105b4e49 Christos Stathis
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 105b4e49 Christos Stathis
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 105b4e49 Christos Stathis
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 105b4e49 Christos Stathis
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 105b4e49 Christos Stathis
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 105b4e49 Christos Stathis
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 105b4e49 Christos Stathis
 * POSSIBILITY OF SUCH DAMAGE.
29 105b4e49 Christos Stathis
 *
30 105b4e49 Christos Stathis
 * The views and conclusions contained in the software and
31 105b4e49 Christos Stathis
 * documentation are those of the authors and should not be
32 105b4e49 Christos Stathis
 * interpreted as representing official policies, either expressed
33 105b4e49 Christos Stathis
 * or implied, of GRNET S.A.
34 105b4e49 Christos Stathis
 */
35 105b4e49 Christos Stathis
36 105b4e49 Christos Stathis
package gr.grnet.pithos.web.client.mysharedtree;
37 105b4e49 Christos Stathis
38 7811b9d1 Christos Stathis
import gr.grnet.pithos.web.client.FolderContextMenu;
39 f1b24b82 Christos Stathis
import gr.grnet.pithos.web.client.TreeView;
40 7811b9d1 Christos Stathis
import gr.grnet.pithos.web.client.foldertree.Folder;
41 7811b9d1 Christos Stathis
42 105b4e49 Christos Stathis
import com.google.gwt.core.client.GWT;
43 105b4e49 Christos Stathis
import com.google.gwt.resources.client.ImageResource;
44 105b4e49 Christos Stathis
import com.google.gwt.resources.client.ImageResource.ImageOptions;
45 105b4e49 Christos Stathis
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
46 105b4e49 Christos Stathis
import com.google.gwt.safehtml.shared.SafeHtml;
47 105b4e49 Christos Stathis
import com.google.gwt.user.cellview.client.CellTree;
48 105b4e49 Christos Stathis
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
49 105b4e49 Christos Stathis
import com.google.gwt.user.cellview.client.TreeNode;
50 105b4e49 Christos Stathis
import com.google.gwt.user.client.ui.Composite;
51 105b4e49 Christos Stathis
import com.google.gwt.user.client.ui.Tree;
52 105b4e49 Christos Stathis
53 f1b24b82 Christos Stathis
public class MysharedTreeView extends Composite implements TreeView {
54 105b4e49 Christos Stathis
55 105b4e49 Christos Stathis
    public void updateChildren(Folder folder) {
56 105b4e49 Christos Stathis
        TreeNode root = ((CellTree) getWidget()).getRootTreeNode();
57 105b4e49 Christos Stathis
        updateChildren(root, folder);
58 105b4e49 Christos Stathis
    }
59 105b4e49 Christos Stathis
60 105b4e49 Christos Stathis
    private void updateChildren(TreeNode node, Folder folder) {
61 105b4e49 Christos Stathis
        for (int i=0; i<node.getChildCount(); i++) {
62 105b4e49 Christos Stathis
            if (node.isChildOpen(i)) {
63 105b4e49 Christos Stathis
                if (folder.equals(node.getChildValue(i))) {
64 105b4e49 Christos Stathis
                    node.setChildOpen(i, false, true);
65 105b4e49 Christos Stathis
                    node.setChildOpen(i, true, true);
66 105b4e49 Christos Stathis
                }
67 105b4e49 Christos Stathis
                else {
68 105b4e49 Christos Stathis
                    TreeNode n = node.setChildOpen(i, true);
69 105b4e49 Christos Stathis
                    updateChildren(n, folder);
70 105b4e49 Christos Stathis
                }
71 105b4e49 Christos Stathis
            }
72 105b4e49 Christos Stathis
        }
73 105b4e49 Christos Stathis
    }
74 105b4e49 Christos Stathis
75 105b4e49 Christos Stathis
    static interface BasicResources extends CellTree.Resources {
76 105b4e49 Christos Stathis
77 7811b9d1 Christos Stathis
        @Override
78 7811b9d1 Christos Stathis
                @ImageOptions(flipRtl = true)
79 105b4e49 Christos Stathis
        @Source("gr/grnet/pithos/web/client/cellTreeClosedItem.gif")
80 105b4e49 Christos Stathis
        ImageResource cellTreeClosedItem();
81 105b4e49 Christos Stathis
82 7811b9d1 Christos Stathis
        @Override
83 7811b9d1 Christos Stathis
                @ImageOptions(flipRtl = true)
84 105b4e49 Christos Stathis
        @Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif")
85 105b4e49 Christos Stathis
        ImageResource cellTreeLoading();
86 105b4e49 Christos Stathis
87 7811b9d1 Christos Stathis
        @Override
88 7811b9d1 Christos Stathis
                @ImageOptions(flipRtl = true)
89 105b4e49 Christos Stathis
        @Source("gr/grnet/pithos/web/client/cellTreeOpenItem.gif")
90 105b4e49 Christos Stathis
        ImageResource cellTreeOpenItem();
91 105b4e49 Christos Stathis
92 7811b9d1 Christos Stathis
        @Override
93 969a4d94 Christos Stathis
                @Source({"gr/grnet/pithos/web/client/PithosCellTreeBasic.css"})
94 105b4e49 Christos Stathis
        CellTree.Style cellTreeStyle();
95 105b4e49 Christos Stathis
    }
96 105b4e49 Christos Stathis
97 7811b9d1 Christos Stathis
    public static interface Images extends Tree.Resources, FolderContextMenu.Images {
98 105b4e49 Christos Stathis
99 9d8521d7 Christos Stathis
        @Source("gr/grnet/pithos/resources/home22.png")
100 105b4e49 Christos Stathis
        ImageResource home();
101 105b4e49 Christos Stathis
102 9d8521d7 Christos Stathis
        @Source("gr/grnet/pithos/resources/folder22.png")
103 105b4e49 Christos Stathis
        public ImageResource folderYellow();
104 105b4e49 Christos Stathis
105 105b4e49 Christos Stathis
        @Source("gr/grnet/pithos/resources/mimetypes/document.png")
106 105b4e49 Christos Stathis
        ImageResource document();
107 105b4e49 Christos Stathis
108 105b4e49 Christos Stathis
        @Source("gr/grnet/pithos/resources/othersshared.png")
109 105b4e49 Christos Stathis
        ImageResource othersShared();
110 105b4e49 Christos Stathis
111 105b4e49 Christos Stathis
        @Source("gr/grnet/pithos/resources/myshared22.png")
112 105b4e49 Christos Stathis
        ImageResource myShared();
113 105b4e49 Christos Stathis
114 105b4e49 Christos Stathis
        @Source("gr/grnet/pithos/resources/folder_user.png")
115 105b4e49 Christos Stathis
        ImageResource sharedFolder();
116 105b4e49 Christos Stathis
    }
117 105b4e49 Christos Stathis
118 105b4e49 Christos Stathis
    static Images images = GWT.create(Images.class);
119 105b4e49 Christos Stathis
120 105b4e49 Christos Stathis
    static interface Templates extends SafeHtmlTemplates {
121 105b4e49 Christos Stathis
        public Templates INSTANCE = GWT.create(Templates.class);
122 105b4e49 Christos Stathis
123 105b4e49 Christos Stathis
        @Template("<span>{0}</span>")
124 105b4e49 Christos Stathis
        public SafeHtml nameSpan(String name);
125 105b4e49 Christos Stathis
      }
126 105b4e49 Christos Stathis
127 105b4e49 Christos Stathis
    private MysharedTreeViewModel model;
128 105b4e49 Christos Stathis
129 105b4e49 Christos Stathis
    public MysharedTreeView(MysharedTreeViewModel viewModel) {
130 105b4e49 Christos Stathis
        this.model = viewModel;
131 105b4e49 Christos Stathis
        /*
132 105b4e49 Christos Stathis
         * Create the tree using the model. We use <code>null</code> as the default
133 105b4e49 Christos Stathis
         * value of the root node. The default value will be passed to
134 105b4e49 Christos Stathis
         * CustomTreeModel#getNodeInfo();
135 105b4e49 Christos Stathis
         */
136 105b4e49 Christos Stathis
        CellTree.Resources res = GWT.create(BasicResources.class);
137 105b4e49 Christos Stathis
        CellTree tree = new CellTree(model, null, res);
138 105b4e49 Christos Stathis
        tree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
139 105b4e49 Christos Stathis
140 105b4e49 Christos Stathis
        initWidget(tree);
141 105b4e49 Christos Stathis
    }
142 105b4e49 Christos Stathis
143 105b4e49 Christos Stathis
144 abd8738f Christos Stathis
    @Override
145 abd8738f Christos Stathis
        public Folder getSelection() {
146 105b4e49 Christos Stathis
       return model.getSelection();
147 105b4e49 Christos Stathis
    }
148 105b4e49 Christos Stathis
149 105b4e49 Christos Stathis
    public void updateFolder(Folder folder, boolean showfiles) {
150 105b4e49 Christos Stathis
        model.updateFolder(folder, showfiles);
151 105b4e49 Christos Stathis
    }
152 105b4e49 Christos Stathis
}