2 * Copyright 2011-2013 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.grouptree;
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.PithosDisclosurePanel.Style;
42 import gr.grnet.pithos.web.client.foldertree.Folder;
44 import com.google.gwt.core.client.GWT;
45 import com.google.gwt.resources.client.ImageResource;
46 import com.google.gwt.resources.client.ClientBundle.Source;
47 import com.google.gwt.resources.client.ImageResource.ImageOptions;
48 import com.google.gwt.resources.client.ImageResource.RepeatStyle;
49 import com.google.gwt.safehtml.client.SafeHtmlTemplates;
50 import com.google.gwt.safehtml.shared.SafeHtml;
51 import com.google.gwt.user.cellview.client.CellTree;
52 import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
53 import com.google.gwt.user.cellview.client.TreeNode;
54 import com.google.gwt.user.client.ui.Composite;
55 import com.google.gwt.user.client.ui.DisclosurePanel;
56 import com.google.gwt.user.client.ui.HTML;
57 import com.google.gwt.user.client.ui.Tree;
59 public class GroupTreeView extends Composite implements TreeView {
61 public void updateChildren(Group group) {
62 TreeNode root = tree.getRootTreeNode();
64 updateChildren(root, group);
65 else if (root.getChildCount() > 0) {
66 root.setChildOpen(0, false, true);
67 root.setChildOpen(0, true, true);
71 private void updateChildren(TreeNode node, Group group) {
72 for (int i=0; i<node.getChildCount(); i++) {
73 if (group.equals(node.getChildValue(i))) {
74 node.setChildOpen(i, false, true);
75 node.setChildOpen(i, true, true);
78 if (node.isChildOpen(i)) {
79 TreeNode n = node.setChildOpen(i, true);
80 updateChildren(n, group);
86 static interface BasicResources extends CellTree.Resources {
89 @ImageOptions(flipRtl = true)
90 @Source("gr/grnet/pithos/web/client/cellTreeClosedItem.png")
91 ImageResource cellTreeClosedItem();
94 @ImageOptions(flipRtl = true)
95 @Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif")
96 ImageResource cellTreeLoading();
99 @ImageOptions(flipRtl = true)
100 @Source("gr/grnet/pithos/web/client/cellTreeOpenItem.png")
101 ImageResource cellTreeOpenItem();
104 @Source({"gr/grnet/pithos/web/client/PithosCellTreeBasic.css"})
105 CellTree.Style cellTreeStyle();
107 @Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif")
108 @ImageOptions(repeatStyle=RepeatStyle.None)
109 ImageResource cellTreeLoadingBasic();
112 public static interface Images extends Tree.Resources, FolderContextMenu.Images {
114 @Source("gr/grnet/pithos/resources/groups22.png")
115 ImageResource groups();
117 @Source("gr/grnet/pithos/resources/groups22.png")
118 public ImageResource group();
120 @Source("gr/grnet/pithos/resources/edit_user.png")
121 ImageResource user();
124 static Images images = GWT.create(Images.class);
126 interface Style extends gr.grnet.pithos.web.client.PithosDisclosurePanel.Style {
131 interface Resources extends gr.grnet.pithos.web.client.PithosDisclosurePanel.Resources {
133 @Source("PithosGroupDisclosurePanel.css")
134 Style pithosDisclosurePanelCss();
137 @Source("gr/grnet/pithos/resources/groups22.png")
138 ImageResource icon();
141 public static interface Templates extends SafeHtmlTemplates {
142 public Templates INSTANCE = GWT.create(Templates.class);
144 @Template("<span style='margin-left:5px;'>{0}</span>")
145 public SafeHtml nameSpan(String name);
148 private GroupTreeViewModel model;
150 private CellTree tree;
152 public GroupTreeView(GroupTreeViewModel viewModel) {
153 this.model = viewModel;
155 PithosDisclosurePanel panel = new PithosDisclosurePanel((Resources) GWT.create(Resources.class), "Groups", false);
157 * Create the tree using the model. We use <code>null</code> as the default
158 * value of the root node. The default value will be passed to
159 * CustomTreeModel#getNodeInfo();
161 CellTree.Resources res = GWT.create(BasicResources.class);
162 tree = new CellTree(model, null, res);
163 tree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
165 panel.setContent(tree);
170 public void updateGroupNode(Group group) {
171 model.updateGroupNode(group);
172 updateChildren(group);
176 public Folder getSelection() {
180 public Object getSelected() {
181 return model.getSelectedObject();