2 * Copyright 2011 GRNET S.A. All rights reserved.
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 * The views and conclusions contained in the software and
31 * documentation are those of the authors and should not be
32 * interpreted as representing official policies, either expressed
33 * or implied, of GRNET S.A.
36 package gr.grnet.pithos.web.client.foldertree;
38 import gr.grnet.pithos.web.client.FolderContextMenu;
39 import gr.grnet.pithos.web.client.TreeView;
41 import com.google.gwt.core.client.GWT;
42 import com.google.gwt.resources.client.ImageResource;
43 import com.google.gwt.resources.client.ImageResource.ImageOptions;
44 import com.google.gwt.safehtml.client.SafeHtmlTemplates;
45 import com.google.gwt.safehtml.shared.SafeHtml;
46 import com.google.gwt.user.cellview.client.CellTree;
47 import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
48 import com.google.gwt.user.cellview.client.TreeNode;
49 import com.google.gwt.user.client.Command;
50 import com.google.gwt.user.client.ui.Composite;
51 import com.google.gwt.user.client.ui.Tree;
53 public class FolderTreeView extends Composite implements TreeView {
55 public boolean isFolderOpen(Folder folder) {
56 TreeNode root = ((CellTree) getWidget()).getRootTreeNode();
57 return isFolderOpen(root, folder);
60 private boolean isFolderOpen(TreeNode node, Folder folder) {
61 for (int i=0; i<node.getChildCount(); i++) {
62 if (folder.equals(node.getChildValue(i))) {
63 return node.isChildOpen(i);
66 if (node.isChildOpen(i)) {
67 TreeNode n = node.setChildOpen(i, true);
68 return isFolderOpen(n, folder);
75 public void openFolder(Folder folder) {
76 TreeNode root = ((CellTree) getWidget()).getRootTreeNode();
77 openFolder(root, folder);
80 private void openFolder(TreeNode node, Folder folder) {
81 for (int i=0; i<node.getChildCount(); i++) {
82 if (folder.equals(node.getChildValue(i))) {
83 node.setChildOpen(i, false, true);
84 node.setChildOpen(i, true, true);
88 if (node.isChildOpen(i)) {
89 TreeNode n = node.setChildOpen(i, true);
90 openFolder(n, folder);
97 static interface BasicResources extends CellTree.Resources {
100 @ImageOptions(flipRtl = true)
101 @Source("gr/grnet/pithos/web/client/cellTreeClosedItem.gif")
102 ImageResource cellTreeClosedItem();
105 @ImageOptions(flipRtl = true)
106 @Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif")
107 ImageResource cellTreeLoading();
110 @ImageOptions(flipRtl = true)
111 @Source("gr/grnet/pithos/web/client/cellTreeOpenItem.gif")
112 ImageResource cellTreeOpenItem();
115 @Source({"gr/grnet/pithos/web/client/PithosCellTreeBasic.css"})
116 CellTree.Style cellTreeStyle();
119 public static interface Images extends Tree.Resources, FolderContextMenu.Images {
121 @Source("gr/grnet/pithos/resources/home22.png")
122 ImageResource home();
124 @Source("gr/grnet/pithos/resources/folder22.png")
125 public ImageResource folderYellow();
127 @Source("gr/grnet/pithos/resources/mimetypes/document.png")
128 ImageResource document();
130 @Source("gr/grnet/pithos/resources/othersshared.png")
131 ImageResource othersShared();
133 @Source("gr/grnet/pithos/resources/myshared22.png")
134 ImageResource myShared();
136 @Source("gr/grnet/pithos/resources/folder_user.png")
137 ImageResource sharedFolder();
139 @Source("gr/grnet/pithos/resources/trash.png")
140 ImageResource trash();
143 static Images images = GWT.create(Images.class);
145 static interface Templates extends SafeHtmlTemplates {
146 public Templates INSTANCE = GWT.create(Templates.class);
148 @Template("<span style='vertical-align: middle;'>{0}</span>")
149 public SafeHtml nameSpan(String name);
151 @Template("<span class='pithos-folderLabel'>{0}</span>")
152 public SafeHtml imageSpan(String name);
155 private FolderTreeViewModel model;
157 public FolderTreeView(FolderTreeViewModel viewModel) {
158 this.model = viewModel;
160 * Create the tree using the model. We use <code>null</code> as the default
161 * value of the root node. The default value will be passed to
162 * CustomTreeModel#getNodeInfo();
164 CellTree.Resources res = GWT.create(BasicResources.class);
165 CellTree tree = new CellTree(model, null, res);
166 tree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
173 public Folder getSelection() {
174 return model.getSelection();
177 public void updateFolder(Folder folder, boolean showfiles, Command callback) {
178 model.updateFolder(folder, showfiles, callback);