root / src / gr / grnet / pithos / web / client / grouptree / GroupTreeView.java @ f5c86c34
History | View | Annotate | Download (6.4 kB)
1 | ee9fbc37 | Christos Stathis | /*
|
---|---|---|---|
2 | cae2a8db | Christos Stathis | * Copyright 2011-2012 GRNET S.A. All rights reserved.
|
3 | ee9fbc37 | Christos Stathis | *
|
4 | ee9fbc37 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | ee9fbc37 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | ee9fbc37 | Christos Stathis | * conditions are met:
|
7 | ee9fbc37 | Christos Stathis | *
|
8 | ee9fbc37 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | ee9fbc37 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | ee9fbc37 | Christos Stathis | * disclaimer.
|
11 | ee9fbc37 | Christos Stathis | *
|
12 | ee9fbc37 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | ee9fbc37 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | ee9fbc37 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | ee9fbc37 | Christos Stathis | * provided with the distribution.
|
16 | ee9fbc37 | Christos Stathis | *
|
17 | ee9fbc37 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | ee9fbc37 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | ee9fbc37 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | ee9fbc37 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | ee9fbc37 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | ee9fbc37 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | ee9fbc37 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | ee9fbc37 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | ee9fbc37 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | ee9fbc37 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | ee9fbc37 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | ee9fbc37 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | ee9fbc37 | Christos Stathis | *
|
30 | ee9fbc37 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | ee9fbc37 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | ee9fbc37 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | ee9fbc37 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | ee9fbc37 | Christos Stathis | */
|
35 | ee9fbc37 | Christos Stathis | |
36 | ee9fbc37 | Christos Stathis | package gr.grnet.pithos.web.client.grouptree; |
37 | ee9fbc37 | Christos Stathis | |
38 | ee9fbc37 | Christos Stathis | import gr.grnet.pithos.web.client.FolderContextMenu; |
39 | 39f6d7b0 | Christos Stathis | import gr.grnet.pithos.web.client.PithosDisclosurePanel; |
40 | b162dfaa | Christos Stathis | import gr.grnet.pithos.web.client.TreeView; |
41 | c46c9e31 | Christos Stathis | import gr.grnet.pithos.web.client.PithosDisclosurePanel.Style; |
42 | b162dfaa | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Folder; |
43 | ee9fbc37 | Christos Stathis | |
44 | ee9fbc37 | Christos Stathis | import com.google.gwt.core.client.GWT; |
45 | ee9fbc37 | Christos Stathis | import com.google.gwt.resources.client.ImageResource; |
46 | 3264607e | Christos Stathis | import com.google.gwt.resources.client.ClientBundle.Source; |
47 | ee9fbc37 | Christos Stathis | import com.google.gwt.resources.client.ImageResource.ImageOptions; |
48 | 3264607e | Christos Stathis | import com.google.gwt.resources.client.ImageResource.RepeatStyle; |
49 | ee9fbc37 | Christos Stathis | import com.google.gwt.safehtml.client.SafeHtmlTemplates; |
50 | ee9fbc37 | Christos Stathis | import com.google.gwt.safehtml.shared.SafeHtml; |
51 | ee9fbc37 | Christos Stathis | import com.google.gwt.user.cellview.client.CellTree; |
52 | ee9fbc37 | Christos Stathis | import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy; |
53 | ee9fbc37 | Christos Stathis | import com.google.gwt.user.cellview.client.TreeNode; |
54 | ee9fbc37 | Christos Stathis | import com.google.gwt.user.client.ui.Composite; |
55 | 39f6d7b0 | Christos Stathis | import com.google.gwt.user.client.ui.DisclosurePanel; |
56 | 39f6d7b0 | Christos Stathis | import com.google.gwt.user.client.ui.HTML; |
57 | ee9fbc37 | Christos Stathis | import com.google.gwt.user.client.ui.Tree; |
58 | ee9fbc37 | Christos Stathis | |
59 | b162dfaa | Christos Stathis | public class GroupTreeView extends Composite implements TreeView { |
60 | ee9fbc37 | Christos Stathis | |
61 | 4baffab1 | Christos Stathis | public void updateChildren(Group group) { |
62 | c46c9e31 | Christos Stathis | TreeNode root = tree.getRootTreeNode();
|
63 | 4baffab1 | Christos Stathis | if (group != null) |
64 | 4baffab1 | Christos Stathis | updateChildren(root, group); |
65 | 4baffab1 | Christos Stathis | else {
|
66 | 4baffab1 | Christos Stathis | root.setChildOpen(0, false, true); |
67 | 4baffab1 | Christos Stathis | root.setChildOpen(0, true, true); |
68 | 4baffab1 | Christos Stathis | } |
69 | ee9fbc37 | Christos Stathis | } |
70 | ee9fbc37 | Christos Stathis | |
71 | 4baffab1 | Christos Stathis | private void updateChildren(TreeNode node, Group group) { |
72 | ee9fbc37 | Christos Stathis | for (int i=0; i<node.getChildCount(); i++) { |
73 | 61f8605d | Christos Stathis | if (group.equals(node.getChildValue(i))) {
|
74 | 61f8605d | Christos Stathis | node.setChildOpen(i, false, true); |
75 | 61f8605d | Christos Stathis | node.setChildOpen(i, true, true); |
76 | 61f8605d | Christos Stathis | } |
77 | 61f8605d | Christos Stathis | else {
|
78 | 61f8605d | Christos Stathis | if (node.isChildOpen(i)) {
|
79 | 61f8605d | Christos Stathis | TreeNode n = node.setChildOpen(i, true); |
80 | 61f8605d | Christos Stathis | updateChildren(n, group); |
81 | 61f8605d | Christos Stathis | } |
82 | ee9fbc37 | Christos Stathis | } |
83 | ee9fbc37 | Christos Stathis | } |
84 | ee9fbc37 | Christos Stathis | } |
85 | ee9fbc37 | Christos Stathis | |
86 | ee9fbc37 | Christos Stathis | static interface BasicResources extends CellTree.Resources { |
87 | ee9fbc37 | Christos Stathis | |
88 | ee9fbc37 | Christos Stathis | @Override
|
89 | ee9fbc37 | Christos Stathis | @ImageOptions(flipRtl = true) |
90 | 140f0f6d | Christos Stathis | @Source("gr/grnet/pithos/web/client/cellTreeClosedItem.png") |
91 | ee9fbc37 | Christos Stathis | ImageResource cellTreeClosedItem(); |
92 | ee9fbc37 | Christos Stathis | |
93 | ee9fbc37 | Christos Stathis | @Override
|
94 | ee9fbc37 | Christos Stathis | @ImageOptions(flipRtl = true) |
95 | ee9fbc37 | Christos Stathis | @Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif") |
96 | ee9fbc37 | Christos Stathis | ImageResource cellTreeLoading(); |
97 | ee9fbc37 | Christos Stathis | |
98 | ee9fbc37 | Christos Stathis | @Override
|
99 | ee9fbc37 | Christos Stathis | @ImageOptions(flipRtl = true) |
100 | 140f0f6d | Christos Stathis | @Source("gr/grnet/pithos/web/client/cellTreeOpenItem.png") |
101 | ee9fbc37 | Christos Stathis | ImageResource cellTreeOpenItem(); |
102 | ee9fbc37 | Christos Stathis | |
103 | ee9fbc37 | Christos Stathis | @Override
|
104 | 969a4d94 | Christos Stathis | @Source({"gr/grnet/pithos/web/client/PithosCellTreeBasic.css"}) |
105 | ee9fbc37 | Christos Stathis | CellTree.Style cellTreeStyle(); |
106 | 3264607e | Christos Stathis | |
107 | 3264607e | Christos Stathis | @Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif") |
108 | 3264607e | Christos Stathis | @ImageOptions(repeatStyle=RepeatStyle.None)
|
109 | 3264607e | Christos Stathis | ImageResource cellTreeLoadingBasic(); |
110 | ee9fbc37 | Christos Stathis | } |
111 | ee9fbc37 | Christos Stathis | |
112 | ee9fbc37 | Christos Stathis | public static interface Images extends Tree.Resources, FolderContextMenu.Images { |
113 | ee9fbc37 | Christos Stathis | |
114 | 9d8521d7 | Christos Stathis | @Source("gr/grnet/pithos/resources/groups22.png") |
115 | ee9fbc37 | Christos Stathis | ImageResource groups(); |
116 | ee9fbc37 | Christos Stathis | |
117 | 9d8521d7 | Christos Stathis | @Source("gr/grnet/pithos/resources/groups22.png") |
118 | ee9fbc37 | Christos Stathis | public ImageResource group();
|
119 | ee9fbc37 | Christos Stathis | |
120 | ee9fbc37 | Christos Stathis | @Source("gr/grnet/pithos/resources/edit_user.png") |
121 | ee9fbc37 | Christos Stathis | ImageResource user(); |
122 | ee9fbc37 | Christos Stathis | } |
123 | ee9fbc37 | Christos Stathis | |
124 | ee9fbc37 | Christos Stathis | static Images images = GWT.create(Images.class);
|
125 | 39f6d7b0 | Christos Stathis | |
126 | c46c9e31 | Christos Stathis | interface Style extends gr.grnet.pithos.web.client.PithosDisclosurePanel.Style { |
127 | 39f6d7b0 | Christos Stathis | @Override
|
128 | c46c9e31 | Christos Stathis | String header();
|
129 | c46c9e31 | Christos Stathis | } |
130 | c46c9e31 | Christos Stathis | |
131 | c46c9e31 | Christos Stathis | interface Resources extends gr.grnet.pithos.web.client.PithosDisclosurePanel.Resources { |
132 | c46c9e31 | Christos Stathis | @Override
|
133 | c46c9e31 | Christos Stathis | @Source("PithosGroupDisclosurePanel.css") |
134 | c46c9e31 | Christos Stathis | Style pithosDisclosurePanelCss();
|
135 | c46c9e31 | Christos Stathis | |
136 | c46c9e31 | Christos Stathis | @Override
|
137 | 39f6d7b0 | Christos Stathis | @Source("gr/grnet/pithos/resources/groups22.png") |
138 | 39f6d7b0 | Christos Stathis | ImageResource icon(); |
139 | 39f6d7b0 | Christos Stathis | } |
140 | ee9fbc37 | Christos Stathis | |
141 | 39f6d7b0 | Christos Stathis | public static interface Templates extends SafeHtmlTemplates { |
142 | ee9fbc37 | Christos Stathis | public Templates INSTANCE = GWT.create(Templates.class); |
143 | ee9fbc37 | Christos Stathis | |
144 | 7e8e9ff0 | Christos Stathis | @Template("<span style='margin-left:5px;'>{0}</span>") |
145 | ee9fbc37 | Christos Stathis | public SafeHtml nameSpan(String name); |
146 | ee9fbc37 | Christos Stathis | } |
147 | ee9fbc37 | Christos Stathis | |
148 | ee9fbc37 | Christos Stathis | private GroupTreeViewModel model;
|
149 | c46c9e31 | Christos Stathis | |
150 | c46c9e31 | Christos Stathis | private CellTree tree;
|
151 | ee9fbc37 | Christos Stathis | |
152 | ee9fbc37 | Christos Stathis | public GroupTreeView(GroupTreeViewModel viewModel) {
|
153 | ee9fbc37 | Christos Stathis | this.model = viewModel;
|
154 | 39f6d7b0 | Christos Stathis | |
155 | 39f6d7b0 | Christos Stathis | PithosDisclosurePanel panel = new PithosDisclosurePanel((Resources) GWT.create(Resources.class), "Groups", false); |
156 | ee9fbc37 | Christos Stathis | /*
|
157 | ee9fbc37 | Christos Stathis | * Create the tree using the model. We use <code>null</code> as the default
|
158 | ee9fbc37 | Christos Stathis | * value of the root node. The default value will be passed to
|
159 | ee9fbc37 | Christos Stathis | * CustomTreeModel#getNodeInfo();
|
160 | ee9fbc37 | Christos Stathis | */
|
161 | ee9fbc37 | Christos Stathis | CellTree.Resources res = GWT.create(BasicResources.class); |
162 | c46c9e31 | Christos Stathis | tree = new CellTree(model, null, res); |
163 | ee9fbc37 | Christos Stathis | tree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); |
164 | ee9fbc37 | Christos Stathis | |
165 | 39f6d7b0 | Christos Stathis | panel.add(tree); |
166 | 39f6d7b0 | Christos Stathis | |
167 | 39f6d7b0 | Christos Stathis | initWidget(panel); |
168 | ee9fbc37 | Christos Stathis | } |
169 | ee9fbc37 | Christos Stathis | |
170 | 4baffab1 | Christos Stathis | public void updateGroupNode(Group group) { |
171 | 61f8605d | Christos Stathis | model.updateGroupNode(group); |
172 | 4baffab1 | Christos Stathis | updateChildren(group); |
173 | ee9fbc37 | Christos Stathis | } |
174 | b162dfaa | Christos Stathis | |
175 | b162dfaa | Christos Stathis | @Override
|
176 | b162dfaa | Christos Stathis | public Folder getSelection() {
|
177 | b162dfaa | Christos Stathis | // TODO Auto-generated method stub
|
178 | b162dfaa | Christos Stathis | return null; |
179 | b162dfaa | Christos Stathis | } |
180 | b162dfaa | Christos Stathis | |
181 | b162dfaa | Christos Stathis | public Object getSelected() { |
182 | b162dfaa | Christos Stathis | return model.getSelectedObject();
|
183 | b162dfaa | Christos Stathis | } |
184 | ee9fbc37 | Christos Stathis | } |