Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (6.5 kB)

1 6d8e0f58 Christos Stathis
/*
2 e6e9f6e6 Christos KK Loverdos
 * Copyright 2011-2013 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 0a85a75b Christos KK Loverdos
import gr.grnet.pithos.web.client.Const;
39 6d8e0f58 Christos Stathis
import gr.grnet.pithos.web.client.FolderContextMenu;
40 39f6d7b0 Christos Stathis
import gr.grnet.pithos.web.client.PithosDisclosurePanel;
41 f1b24b82 Christos Stathis
import gr.grnet.pithos.web.client.TreeView;
42 6d8e0f58 Christos Stathis
import gr.grnet.pithos.web.client.foldertree.Folder;
43 6d8e0f58 Christos Stathis
44 6d8e0f58 Christos Stathis
import com.google.gwt.core.client.GWT;
45 6d8e0f58 Christos Stathis
import com.google.gwt.resources.client.ImageResource;
46 6d8e0f58 Christos Stathis
import com.google.gwt.resources.client.ImageResource.ImageOptions;
47 3264607e Christos Stathis
import com.google.gwt.resources.client.ImageResource.RepeatStyle;
48 6d8e0f58 Christos Stathis
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
49 6d8e0f58 Christos Stathis
import com.google.gwt.safehtml.shared.SafeHtml;
50 6d8e0f58 Christos Stathis
import com.google.gwt.user.cellview.client.CellTree;
51 6d8e0f58 Christos Stathis
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
52 6d8e0f58 Christos Stathis
import com.google.gwt.user.cellview.client.TreeNode;
53 3646552f Christos Stathis
import com.google.gwt.user.client.Command;
54 6d8e0f58 Christos Stathis
import com.google.gwt.user.client.ui.Composite;
55 6d8e0f58 Christos Stathis
import com.google.gwt.user.client.ui.Tree;
56 6d8e0f58 Christos Stathis
57 f1b24b82 Christos Stathis
public class OtherSharedTreeView extends Composite implements TreeView {
58 6d8e0f58 Christos Stathis
59 6d8e0f58 Christos Stathis
    public void updateChildren(Folder folder) {
60 7e8e9ff0 Christos Stathis
        TreeNode root = tree.getRootTreeNode();
61 6d8e0f58 Christos Stathis
        updateChildren(root, folder);
62 6d8e0f58 Christos Stathis
    }
63 6d8e0f58 Christos Stathis
64 6d8e0f58 Christos Stathis
    private void updateChildren(TreeNode node, Folder folder) {
65 6d8e0f58 Christos Stathis
        for (int i=0; i<node.getChildCount(); i++) {
66 6d8e0f58 Christos Stathis
            if (node.isChildOpen(i)) {
67 6d8e0f58 Christos Stathis
                if (folder.equals(node.getChildValue(i))) {
68 6d8e0f58 Christos Stathis
                    node.setChildOpen(i, false, true);
69 6d8e0f58 Christos Stathis
                    node.setChildOpen(i, true, true);
70 6d8e0f58 Christos Stathis
                }
71 6d8e0f58 Christos Stathis
                else {
72 6d8e0f58 Christos Stathis
                    TreeNode n = node.setChildOpen(i, true);
73 6d8e0f58 Christos Stathis
                    updateChildren(n, folder);
74 6d8e0f58 Christos Stathis
                }
75 6d8e0f58 Christos Stathis
            }
76 6d8e0f58 Christos Stathis
        }
77 6d8e0f58 Christos Stathis
    }
78 6d8e0f58 Christos Stathis
79 6d8e0f58 Christos Stathis
    static interface BasicResources extends CellTree.Resources {
80 6d8e0f58 Christos Stathis
81 7811b9d1 Christos Stathis
        @Override
82 7811b9d1 Christos Stathis
                @ImageOptions(flipRtl = true)
83 140f0f6d Christos Stathis
        @Source("gr/grnet/pithos/web/client/cellTreeClosedItem.png")
84 6d8e0f58 Christos Stathis
        ImageResource cellTreeClosedItem();
85 6d8e0f58 Christos Stathis
86 7811b9d1 Christos Stathis
        @Override
87 7811b9d1 Christos Stathis
                @ImageOptions(flipRtl = true)
88 6d8e0f58 Christos Stathis
        @Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif")
89 6d8e0f58 Christos Stathis
        ImageResource cellTreeLoading();
90 6d8e0f58 Christos Stathis
91 7811b9d1 Christos Stathis
        @Override
92 7811b9d1 Christos Stathis
                @ImageOptions(flipRtl = true)
93 140f0f6d Christos Stathis
        @Source("gr/grnet/pithos/web/client/cellTreeOpenItem.png")
94 6d8e0f58 Christos Stathis
        ImageResource cellTreeOpenItem();
95 6d8e0f58 Christos Stathis
96 7811b9d1 Christos Stathis
        @Override
97 969a4d94 Christos Stathis
                @Source({"gr/grnet/pithos/web/client/PithosCellTreeBasic.css"})
98 6d8e0f58 Christos Stathis
        CellTree.Style cellTreeStyle();
99 3264607e Christos Stathis
        
100 3264607e Christos Stathis
        @Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif")
101 3264607e Christos Stathis
        @ImageOptions(repeatStyle=RepeatStyle.None)
102 3264607e Christos Stathis
        ImageResource cellTreeLoadingBasic();
103 6d8e0f58 Christos Stathis
    }
104 6d8e0f58 Christos Stathis
105 7811b9d1 Christos Stathis
    public static interface Images extends Tree.Resources, FolderContextMenu.Images {
106 6d8e0f58 Christos Stathis
107 9d8521d7 Christos Stathis
        @Source("gr/grnet/pithos/resources/home22.png")
108 6d8e0f58 Christos Stathis
        ImageResource home();
109 6d8e0f58 Christos Stathis
110 7e8e9ff0 Christos Stathis
        @Source("gr/grnet/pithos/resources/2folder22.png")
111 6d8e0f58 Christos Stathis
        public ImageResource folderYellow();
112 6d8e0f58 Christos Stathis
113 6d8e0f58 Christos Stathis
        @Source("gr/grnet/pithos/resources/mimetypes/document.png")
114 6d8e0f58 Christos Stathis
        ImageResource document();
115 6d8e0f58 Christos Stathis
116 7e8e9ff0 Christos Stathis
        @Source("gr/grnet/pithos/resources/sharedtome22.png")
117 6d8e0f58 Christos Stathis
        ImageResource othersShared();
118 6d8e0f58 Christos Stathis
119 6d8e0f58 Christos Stathis
        @Source("gr/grnet/pithos/resources/myshared22.png")
120 6d8e0f58 Christos Stathis
        ImageResource myShared();
121 6d8e0f58 Christos Stathis
122 6d8e0f58 Christos Stathis
        @Source("gr/grnet/pithos/resources/folder_user.png")
123 6d8e0f58 Christos Stathis
        ImageResource sharedFolder();
124 6d8e0f58 Christos Stathis
125 220831bd Christos Stathis
        @Source("gr/grnet/pithos/resources/edit_user.png")
126 220831bd Christos Stathis
        ImageResource user();
127 6d8e0f58 Christos Stathis
    }
128 6d8e0f58 Christos Stathis
129 6d8e0f58 Christos Stathis
    static Images images = GWT.create(Images.class);
130 6d8e0f58 Christos Stathis
131 6d8e0f58 Christos Stathis
    static interface Templates extends SafeHtmlTemplates {
132 6d8e0f58 Christos Stathis
        public Templates INSTANCE = GWT.create(Templates.class);
133 6d8e0f58 Christos Stathis
134 6d8e0f58 Christos Stathis
        @Template("<span>{0}</span>")
135 6d8e0f58 Christos Stathis
        public SafeHtml nameSpan(String name);
136 6d8e0f58 Christos Stathis
      }
137 6d8e0f58 Christos Stathis
138 3f62b626 Christos Stathis
    interface Style extends gr.grnet.pithos.web.client.PithosDisclosurePanel.Style {
139 39f6d7b0 Christos Stathis
            @Override
140 3f62b626 Christos Stathis
                String disclosurePanel();
141 3f62b626 Christos Stathis
    }
142 3f62b626 Christos Stathis
143 3f62b626 Christos Stathis
    interface Resources extends gr.grnet.pithos.web.client.PithosDisclosurePanel.Resources {
144 3f62b626 Christos Stathis
                @Override
145 3f62b626 Christos Stathis
                @Source("PithosOtherSharedDisclosurePanel.css")
146 3f62b626 Christos Stathis
                Style pithosDisclosurePanelCss();
147 3f62b626 Christos Stathis
148 3f62b626 Christos Stathis
                @Override
149 7e8e9ff0 Christos Stathis
                @Source("gr/grnet/pithos/resources/sharedtome22.png")
150 39f6d7b0 Christos Stathis
            ImageResource icon();
151 39f6d7b0 Christos Stathis
    }
152 39f6d7b0 Christos Stathis
153 6d8e0f58 Christos Stathis
    private OtherSharedTreeViewModel model;
154 6d8e0f58 Christos Stathis
155 7e8e9ff0 Christos Stathis
    private CellTree tree;
156 7e8e9ff0 Christos Stathis
    
157 d4ace10a Christos KK Loverdos
    public OtherSharedTreeView(OtherSharedTreeViewModel viewModel, boolean ajaxLoader) {
158 6d8e0f58 Christos Stathis
        this.model = viewModel;
159 39f6d7b0 Christos Stathis
        
160 d4ace10a Christos KK Loverdos
        PithosDisclosurePanel panel = new PithosDisclosurePanel((Resources) GWT.create(Resources.class), Const.TXT_SHARED_WITH_ME, false, ajaxLoader);
161 6d8e0f58 Christos Stathis
        /*
162 6d8e0f58 Christos Stathis
         * Create the tree using the model. We use <code>null</code> as the default
163 6d8e0f58 Christos Stathis
         * value of the root node. The default value will be passed to
164 6d8e0f58 Christos Stathis
         * CustomTreeModel#getNodeInfo();
165 6d8e0f58 Christos Stathis
         */
166 6d8e0f58 Christos Stathis
        CellTree.Resources res = GWT.create(BasicResources.class);
167 7e8e9ff0 Christos Stathis
        tree = new CellTree(model, null, res);
168 6d8e0f58 Christos Stathis
        tree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
169 6d8e0f58 Christos Stathis
170 db365c2d Christos Stathis
        panel.setContent(tree);
171 39f6d7b0 Christos Stathis
        initWidget(panel);
172 6d8e0f58 Christos Stathis
    }
173 6d8e0f58 Christos Stathis
174 6d8e0f58 Christos Stathis
175 abd8738f Christos Stathis
    @Override
176 abd8738f Christos Stathis
        public Folder getSelection() {
177 6d8e0f58 Christos Stathis
       return model.getSelection();
178 6d8e0f58 Christos Stathis
    }
179 6d8e0f58 Christos Stathis
180 3646552f Christos Stathis
    public void updateFolder(Folder folder, boolean showfiles, Command callback) {
181 3646552f Christos Stathis
        model.updateFolder(folder, showfiles, callback);
182 6d8e0f58 Christos Stathis
    }
183 6d8e0f58 Christos Stathis
}