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;
41 import gr.grnet.pithos.web.client.grouptree.GroupTreeView.Templates;
43 import com.google.gwt.core.client.GWT;
44 import com.google.gwt.resources.client.ImageResource;
45 import com.google.gwt.resources.client.ImageResource.ImageOptions;
46 import com.google.gwt.resources.client.ImageResource.RepeatStyle;
47 import com.google.gwt.safehtml.client.SafeHtmlTemplates;
48 import com.google.gwt.safehtml.shared.SafeHtml;
49 import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
50 import com.google.gwt.user.cellview.client.CellTree;
51 import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
52 import com.google.gwt.user.cellview.client.TreeNode;
53 import com.google.gwt.user.client.Command;
54 import com.google.gwt.user.client.ui.AbstractImagePrototype;
55 import com.google.gwt.user.client.ui.Composite;
56 import com.google.gwt.user.client.ui.HTML;
57 import com.google.gwt.user.client.ui.Tree;
58 import com.google.gwt.user.client.ui.VerticalPanel;
60 public class FolderTreeView extends Composite implements TreeView {
62 public boolean isFolderOpen(Folder folder) {
63 TreeNode root = ((CellTree) getWidget()).getRootTreeNode();
64 return isFolderOpen(root, folder);
67 private boolean isFolderOpen(TreeNode node, Folder folder) {
68 for (int i=0; i<node.getChildCount(); i++) {
69 if (folder.equals(node.getChildValue(i))) {
70 return node.isChildOpen(i);
72 if (node.isChildOpen(i)) {
73 TreeNode n = node.setChildOpen(i, true);
74 return isFolderOpen(n, folder);
80 public void openFolder(Folder folder) {
81 TreeNode root = tree.getRootTreeNode();
82 openFolder(root, folder);
85 private void openFolder(TreeNode node, Folder folder) {
86 for (int i=0; i<node.getChildCount(); i++) {
87 if (folder.equals(node.getChildValue(i))) {
88 node.setChildOpen(i, false, true);
89 node.setChildOpen(i, true, true);
92 if (node.isChildOpen(i)) {
93 TreeNode n = node.setChildOpen(i, true);
94 openFolder(n, folder);
100 static interface BasicResources extends CellTree.Resources {
103 @ImageOptions(flipRtl = true)
104 @Source("gr/grnet/pithos/web/client/cellTreeClosedItem.png")
105 ImageResource cellTreeClosedItem();
108 @ImageOptions(flipRtl = true)
109 @Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif")
110 ImageResource cellTreeLoading();
113 @ImageOptions(flipRtl = true)
114 @Source("gr/grnet/pithos/web/client/cellTreeOpenItem.png")
115 ImageResource cellTreeOpenItem();
118 @Source({"gr/grnet/pithos/web/client/PithosCellTreeBasic.css"})
119 CellTree.Style cellTreeStyle();
121 @Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif")
122 @ImageOptions(repeatStyle=RepeatStyle.None)
123 ImageResource cellTreeLoadingBasic();
126 public static interface Images extends Tree.Resources, FolderContextMenu.Images {
128 @Source("gr/grnet/pithos/resources/home22.png")
129 ImageResource home();
131 @Source("gr/grnet/pithos/resources/2folder22.png")
132 public ImageResource folderYellow();
134 @Source("gr/grnet/pithos/resources/mimetypes/document.png")
135 ImageResource document();
137 @Source("gr/grnet/pithos/resources/myshared22.png")
138 ImageResource myShared();
140 @Source("gr/grnet/pithos/resources/folder_user.png")
141 ImageResource sharedFolder();
143 @Source("gr/grnet/pithos/resources/trash.png")
144 ImageResource trash();
147 static Images images = GWT.create(Images.class);
149 static interface Templates extends SafeHtmlTemplates {
150 public Templates INSTANCE = GWT.create(Templates.class);
152 @Template("<span style='vertical-align: middle;'>{0}</span>")
153 public SafeHtml nameSpan(String name);
155 @Template("<span class='pithos-folderLabel'>{0}</span>")
156 public SafeHtml imageSpan(String name);
159 interface Resources extends gr.grnet.pithos.web.client.PithosDisclosurePanel.Resources {
161 @Source("gr/grnet/pithos/resources/home22.png")
162 ImageResource icon();
165 private FolderTreeViewModel model;
167 private CellTree tree;
169 public FolderTreeView(FolderTreeViewModel viewModel) {
170 this.model = viewModel;
172 VerticalPanel panel = new VerticalPanel();
173 panel.addStyleName("pithos-folderTreeSection");
174 Resources resources = GWT.create(Resources.class);
175 SafeHtmlBuilder sb = new SafeHtmlBuilder();
176 sb.appendHtmlConstant(AbstractImagePrototype.create(resources.icon()).getHTML());
177 sb.append(Templates.INSTANCE.nameSpan("My Files"));
178 panel.add(new HTML(sb.toSafeHtml()));
182 * Create the tree using the model. We use <code>null</code> as the default
183 * value of the root node. The default value will be passed to
184 * CustomTreeModel#getNodeInfo();
186 CellTree.Resources res = GWT.create(BasicResources.class);
187 tree = new CellTree(model, null, res);
188 tree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
189 tree.addStyleName("pithos-folderTreeSectionContent");
197 public Folder getSelection() {
198 return model.getSelection();
201 public void updateFolder(Folder folder, boolean showfiles, Command callback, final boolean openParent) {
202 model.updateFolder(folder, showfiles, callback, openParent);