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.FlowPanel;
57 import com.google.gwt.user.client.ui.HTML;
58 import com.google.gwt.user.client.ui.HasVerticalAlignment;
59 import com.google.gwt.user.client.ui.HorizontalPanel;
60 import com.google.gwt.user.client.ui.Image;
61 import com.google.gwt.user.client.ui.Tree;
62 import com.google.gwt.user.client.ui.VerticalPanel;
64 public class FolderTreeView extends Composite implements TreeView {
66 public boolean isFolderOpen(Folder folder) {
67 TreeNode root = ((CellTree) getWidget()).getRootTreeNode();
68 return isFolderOpen(root, folder);
71 private boolean isFolderOpen(TreeNode node, Folder folder) {
72 for (int i=0; i<node.getChildCount(); i++) {
73 if (folder.equals(node.getChildValue(i))) {
74 return node.isChildOpen(i);
76 if (node.isChildOpen(i)) {
77 TreeNode n = node.setChildOpen(i, true);
78 return isFolderOpen(n, folder);
84 public void openFolder(Folder folder) {
85 TreeNode root = tree.getRootTreeNode();
86 openFolder(root, folder);
89 private void openFolder(TreeNode node, Folder folder) {
90 for (int i=0; i<node.getChildCount(); i++) {
91 if (folder.equals(node.getChildValue(i))) {
92 node.setChildOpen(i, false, true);
93 node.setChildOpen(i, true, true);
96 if (node.isChildOpen(i)) {
97 TreeNode n = node.setChildOpen(i, true);
98 openFolder(n, folder);
104 static interface BasicResources extends CellTree.Resources {
107 @ImageOptions(flipRtl = true)
108 @Source("gr/grnet/pithos/web/client/cellTreeClosedItem.png")
109 ImageResource cellTreeClosedItem();
112 @ImageOptions(flipRtl = true)
113 @Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif")
114 ImageResource cellTreeLoading();
117 @ImageOptions(flipRtl = true)
118 @Source("gr/grnet/pithos/web/client/cellTreeOpenItem.png")
119 ImageResource cellTreeOpenItem();
122 @Source({"gr/grnet/pithos/web/client/PithosCellTreeBasic.css"})
123 CellTree.Style cellTreeStyle();
125 @Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif")
126 @ImageOptions(repeatStyle=RepeatStyle.None)
127 ImageResource cellTreeLoadingBasic();
130 public static interface Images extends Tree.Resources, FolderContextMenu.Images {
132 @Source("gr/grnet/pithos/resources/home22.png")
133 ImageResource home();
135 @Source("gr/grnet/pithos/resources/2folder22.png")
136 public ImageResource folderYellow();
138 @Source("gr/grnet/pithos/resources/mimetypes/document.png")
139 ImageResource document();
141 @Source("gr/grnet/pithos/resources/myshared22.png")
142 ImageResource myShared();
144 @Source("gr/grnet/pithos/resources/folder_user.png")
145 ImageResource sharedFolder();
147 @Source("gr/grnet/pithos/resources/trash.png")
148 ImageResource trash();
151 static Images images = GWT.create(Images.class);
153 static interface Templates extends SafeHtmlTemplates {
154 public Templates INSTANCE = GWT.create(Templates.class);
156 @Template("<span style='vertical-align: middle;'>{0}</span>")
157 public SafeHtml nameSpan(String name);
159 @Template("<span class='pithos-folderLabel'>{0}</span>")
160 public SafeHtml imageSpan(String name);
163 interface Resources extends gr.grnet.pithos.web.client.PithosDisclosurePanel.Resources {
165 @Source("gr/grnet/pithos/resources/home22.png")
166 ImageResource icon();
169 private FolderTreeViewModel model;
171 private CellTree tree;
173 public FolderTreeView(FolderTreeViewModel viewModel) {
174 this.model = viewModel;
176 VerticalPanel panel = new VerticalPanel();
177 panel.addStyleName("pithos-folderTreeSection");
178 Resources resources = GWT.create(Resources.class);
180 HorizontalPanel header = new HorizontalPanel();
182 // SafeHtmlBuilder sb = new SafeHtmlBuilder();
183 Image img = new Image(resources.icon());
185 header.setCellVerticalAlignment(img, HasVerticalAlignment.ALIGN_MIDDLE);
186 header.setCellWidth(img, "32px");
187 HTML title = new HTML("My Files");
189 header.setCellVerticalAlignment(title, HasVerticalAlignment.ALIGN_MIDDLE);
191 // sb.appendHtmlConstant(AbstractImagePrototype.create(resources.icon()).getHTML());
192 // sb.append(Templates.INSTANCE.nameSpan("My Files"));
193 // HTML header = new HTML(sb.toSafeHtml());
194 header.addStyleName("pithos-folderTreeSectionHeader");
199 * Create the tree using the model. We use <code>null</code> as the default
200 * value of the root node. The default value will be passed to
201 * CustomTreeModel#getNodeInfo();
203 CellTree.Resources res = GWT.create(BasicResources.class);
204 tree = new CellTree(model, null, res);
205 tree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
206 tree.addStyleName("pithos-folderTreeSectionContent");
214 public Folder getSelection() {
215 return model.getSelection();
218 public void updateFolder(Folder folder, boolean showfiles, Command callback, final boolean openParent) {
219 model.updateFolder(folder, showfiles, callback, openParent);