Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / othersharedtree / OtherSharedTreeView.java @ 430898e5

History | View | Annotate | Download (6.5 kB)

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