2 * Copyright 2011-2012 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.resources.client.ImageResource.RepeatStyle;
45 import com.google.gwt.safehtml.client.SafeHtmlTemplates;
46 import com.google.gwt.safehtml.shared.SafeHtml;
47 import com.google.gwt.user.cellview.client.CellTree;
48 import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
49 import com.google.gwt.user.cellview.client.TreeNode;
50 import com.google.gwt.user.client.Command;
51 import com.google.gwt.user.client.ui.Composite;
52 import com.google.gwt.user.client.ui.Tree;
54 public class FolderTreeView extends Composite implements TreeView {
56 public boolean isFolderOpen(Folder folder) {
57 TreeNode root = ((CellTree) getWidget()).getRootTreeNode();
58 return isFolderOpen(root, folder);
61 private boolean isFolderOpen(TreeNode node, Folder folder) {
62 for (int i=0; i<node.getChildCount(); i++) {
63 if (folder.equals(node.getChildValue(i))) {
64 return node.isChildOpen(i);
66 if (node.isChildOpen(i)) {
67 TreeNode n = node.setChildOpen(i, true);
68 return isFolderOpen(n, folder);
74 public void openFolder(Folder folder) {
75 TreeNode root = ((CellTree) getWidget()).getRootTreeNode();
76 openFolder(root, folder);
79 private void openFolder(TreeNode node, Folder folder) {
80 for (int i=0; i<node.getChildCount(); i++) {
81 if (folder.equals(node.getChildValue(i))) {
82 node.setChildOpen(i, false, true);
83 node.setChildOpen(i, true, true);
86 if (node.isChildOpen(i)) {
87 TreeNode n = node.setChildOpen(i, true);
88 openFolder(n, folder);
94 static interface BasicResources extends CellTree.Resources {
97 @ImageOptions(flipRtl = true)
98 @Source("gr/grnet/pithos/web/client/cellTreeClosedItem.png")
99 ImageResource cellTreeClosedItem();
102 @ImageOptions(flipRtl = true)
103 @Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif")
104 ImageResource cellTreeLoading();
107 @ImageOptions(flipRtl = true)
108 @Source("gr/grnet/pithos/web/client/cellTreeOpenItem.png")
109 ImageResource cellTreeOpenItem();
112 @Source({"gr/grnet/pithos/web/client/PithosCellTreeBasic.css"})
113 CellTree.Style cellTreeStyle();
115 @Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif")
116 @ImageOptions(repeatStyle=RepeatStyle.None)
117 ImageResource cellTreeLoadingBasic();
120 public static interface Images extends Tree.Resources, FolderContextMenu.Images {
122 @Source("gr/grnet/pithos/resources/home22.png")
123 ImageResource home();
125 @Source("gr/grnet/pithos/resources/folder22.png")
126 public ImageResource folderYellow();
128 @Source("gr/grnet/pithos/resources/mimetypes/document.png")
129 ImageResource document();
131 @Source("gr/grnet/pithos/resources/othersshared.png")
132 ImageResource othersShared();
134 @Source("gr/grnet/pithos/resources/myshared22.png")
135 ImageResource myShared();
137 @Source("gr/grnet/pithos/resources/folder_user.png")
138 ImageResource sharedFolder();
140 @Source("gr/grnet/pithos/resources/trash.png")
141 ImageResource trash();
144 static Images images = GWT.create(Images.class);
146 static interface Templates extends SafeHtmlTemplates {
147 public Templates INSTANCE = GWT.create(Templates.class);
149 @Template("<span style='vertical-align: middle;'>{0}</span>")
150 public SafeHtml nameSpan(String name);
152 @Template("<span class='pithos-folderLabel'>{0}</span>")
153 public SafeHtml imageSpan(String name);
156 private FolderTreeViewModel model;
158 public FolderTreeView(FolderTreeViewModel viewModel) {
159 this.model = viewModel;
161 * Create the tree using the model. We use <code>null</code> as the default
162 * value of the root node. The default value will be passed to
163 * CustomTreeModel#getNodeInfo();
165 CellTree.Resources res = GWT.create(BasicResources.class);
166 CellTree tree = new CellTree(model, null, res);
167 tree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
174 public Folder getSelection() {
175 return model.getSelection();
178 public void updateFolder(Folder folder, boolean showfiles, Command callback, final boolean openParent) {
179 model.updateFolder(folder, showfiles, callback, openParent);