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.PithosDisclosurePanel;
40 import gr.grnet.pithos.web.client.TreeView;
42 import com.google.gwt.core.client.GWT;
43 import com.google.gwt.resources.client.ImageResource;
44 import com.google.gwt.resources.client.ImageResource.ImageOptions;
45 import com.google.gwt.resources.client.ImageResource.RepeatStyle;
46 import com.google.gwt.safehtml.client.SafeHtmlTemplates;
47 import com.google.gwt.safehtml.shared.SafeHtml;
48 import com.google.gwt.user.cellview.client.CellTree;
49 import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
50 import com.google.gwt.user.cellview.client.TreeNode;
51 import com.google.gwt.user.client.Command;
52 import com.google.gwt.user.client.ui.Composite;
53 import com.google.gwt.user.client.ui.Tree;
55 public class FolderTreeView extends Composite implements TreeView {
57 public boolean isFolderOpen(Folder folder) {
58 TreeNode root = ((CellTree) getWidget()).getRootTreeNode();
59 return isFolderOpen(root, folder);
62 private boolean isFolderOpen(TreeNode node, Folder folder) {
63 for (int i=0; i<node.getChildCount(); i++) {
64 if (folder.equals(node.getChildValue(i))) {
65 return node.isChildOpen(i);
67 if (node.isChildOpen(i)) {
68 TreeNode n = node.setChildOpen(i, true);
69 return isFolderOpen(n, folder);
75 public void openFolder(Folder folder) {
76 TreeNode root = tree.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);
87 if (node.isChildOpen(i)) {
88 TreeNode n = node.setChildOpen(i, true);
89 openFolder(n, folder);
95 static interface BasicResources extends CellTree.Resources {
98 @ImageOptions(flipRtl = true)
99 @Source("gr/grnet/pithos/web/client/cellTreeClosedItem.png")
100 ImageResource cellTreeClosedItem();
103 @ImageOptions(flipRtl = true)
104 @Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif")
105 ImageResource cellTreeLoading();
108 @ImageOptions(flipRtl = true)
109 @Source("gr/grnet/pithos/web/client/cellTreeOpenItem.png")
110 ImageResource cellTreeOpenItem();
113 @Source({"gr/grnet/pithos/web/client/PithosCellTreeBasic.css"})
114 CellTree.Style cellTreeStyle();
116 @Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif")
117 @ImageOptions(repeatStyle=RepeatStyle.None)
118 ImageResource cellTreeLoadingBasic();
121 public static interface Images extends Tree.Resources, FolderContextMenu.Images {
123 @Source("gr/grnet/pithos/resources/home22.png")
124 ImageResource home();
126 @Source("gr/grnet/pithos/resources/folder22.png")
127 public ImageResource folderYellow();
129 @Source("gr/grnet/pithos/resources/mimetypes/document.png")
130 ImageResource document();
132 @Source("gr/grnet/pithos/resources/othersshared.png")
133 ImageResource othersShared();
135 @Source("gr/grnet/pithos/resources/myshared22.png")
136 ImageResource myShared();
138 @Source("gr/grnet/pithos/resources/folder_user.png")
139 ImageResource sharedFolder();
141 @Source("gr/grnet/pithos/resources/trash.png")
142 ImageResource trash();
145 static Images images = GWT.create(Images.class);
147 static interface Templates extends SafeHtmlTemplates {
148 public Templates INSTANCE = GWT.create(Templates.class);
150 @Template("<span style='vertical-align: middle;'>{0}</span>")
151 public SafeHtml nameSpan(String name);
153 @Template("<span class='pithos-folderLabel'>{0}</span>")
154 public SafeHtml imageSpan(String name);
157 interface Resources extends gr.grnet.pithos.web.client.PithosDisclosurePanel.Resources {
159 @Source("gr/grnet/pithos/resources/home22.png")
160 ImageResource icon();
163 private FolderTreeViewModel model;
165 private CellTree tree;
167 public FolderTreeView(FolderTreeViewModel viewModel) {
168 this.model = viewModel;
170 PithosDisclosurePanel panel = new PithosDisclosurePanel((Resources) GWT.create(Resources.class), "My Files", true);
173 * Create the tree using the model. We use <code>null</code> as the default
174 * value of the root node. The default value will be passed to
175 * CustomTreeModel#getNodeInfo();
177 CellTree.Resources res = GWT.create(BasicResources.class);
178 tree = new CellTree(model, null, res);
179 tree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
187 public Folder getSelection() {
188 return model.getSelection();
191 public void updateFolder(Folder folder, boolean showfiles, Command callback, final boolean openParent) {
192 model.updateFolder(folder, showfiles, callback, openParent);