root / src / gr / grnet / pithos / web / client / foldertree / FolderTreeView.java @ ba6ffffb
History | View | Annotate | Download (8.2 kB)
1 | 6084aa02 | Christos Stathis | /*
|
---|---|---|---|
2 | cae2a8db | Christos Stathis | * Copyright 2011-2012 GRNET S.A. All rights reserved.
|
3 | 63366925 | Christos Stathis | *
|
4 | 63366925 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 63366925 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 63366925 | Christos Stathis | * conditions are met:
|
7 | 63366925 | Christos Stathis | *
|
8 | 63366925 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 63366925 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 63366925 | Christos Stathis | * disclaimer.
|
11 | 63366925 | Christos Stathis | *
|
12 | 63366925 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 63366925 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 63366925 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 63366925 | Christos Stathis | * provided with the distribution.
|
16 | 63366925 | Christos Stathis | *
|
17 | 63366925 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 63366925 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 63366925 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 63366925 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 63366925 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 63366925 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 63366925 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 63366925 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 63366925 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 63366925 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 63366925 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 63366925 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 63366925 | Christos Stathis | *
|
30 | 63366925 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 63366925 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 63366925 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 63366925 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | 6084aa02 | Christos Stathis | */
|
35 | 6084aa02 | Christos Stathis | |
36 | 6084aa02 | Christos Stathis | package gr.grnet.pithos.web.client.foldertree; |
37 | 6084aa02 | Christos Stathis | |
38 | abd8738f | Christos Stathis | import gr.grnet.pithos.web.client.FolderContextMenu; |
39 | 39f6d7b0 | Christos Stathis | import gr.grnet.pithos.web.client.PithosDisclosurePanel; |
40 | abd8738f | Christos Stathis | import gr.grnet.pithos.web.client.TreeView; |
41 | abd8738f | Christos Stathis | |
42 | 6084aa02 | Christos Stathis | import com.google.gwt.core.client.GWT; |
43 | d18749bc | Christos Stathis | import com.google.gwt.i18n.client.NumberFormat; |
44 | 6084aa02 | Christos Stathis | import com.google.gwt.resources.client.ImageResource; |
45 | 6084aa02 | Christos Stathis | import com.google.gwt.resources.client.ImageResource.ImageOptions; |
46 | 3264607e | Christos Stathis | import com.google.gwt.resources.client.ImageResource.RepeatStyle; |
47 | 6084aa02 | Christos Stathis | import com.google.gwt.safehtml.client.SafeHtmlTemplates; |
48 | 6084aa02 | Christos Stathis | import com.google.gwt.safehtml.shared.SafeHtml; |
49 | 6084aa02 | Christos Stathis | import com.google.gwt.user.cellview.client.CellTree; |
50 | 6084aa02 | Christos Stathis | import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy; |
51 | 5ebc9312 | Christos Stathis | import com.google.gwt.user.cellview.client.TreeNode; |
52 | 16e8478a | Christos Stathis | import com.google.gwt.user.client.Command; |
53 | 6084aa02 | Christos Stathis | import com.google.gwt.user.client.ui.Composite; |
54 | 7e8e9ff0 | Christos Stathis | import com.google.gwt.user.client.ui.HTML; |
55 | 3123a5e7 | Christos Stathis | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
56 | e56be452 | Christos Stathis | import com.google.gwt.user.client.ui.HorizontalPanel; |
57 | 6084aa02 | Christos Stathis | import com.google.gwt.user.client.ui.Tree; |
58 | 7e8e9ff0 | Christos Stathis | import com.google.gwt.user.client.ui.VerticalPanel; |
59 | 6084aa02 | Christos Stathis | |
60 | f1b24b82 | Christos Stathis | public class FolderTreeView extends Composite implements TreeView { |
61 | 6084aa02 | Christos Stathis | |
62 | adb597b8 | Christos Stathis | public boolean isFolderOpen(Folder folder) { |
63 | 5ebc9312 | Christos Stathis | TreeNode root = ((CellTree) getWidget()).getRootTreeNode();
|
64 | adb597b8 | Christos Stathis | return isFolderOpen(root, folder);
|
65 | adb597b8 | Christos Stathis | } |
66 | adb597b8 | Christos Stathis | |
67 | adb597b8 | Christos Stathis | private boolean isFolderOpen(TreeNode node, Folder folder) { |
68 | adb597b8 | Christos Stathis | for (int i=0; i<node.getChildCount(); i++) { |
69 | adb597b8 | Christos Stathis | if (folder.equals(node.getChildValue(i))) {
|
70 | adb597b8 | Christos Stathis | return node.isChildOpen(i);
|
71 | adb597b8 | Christos Stathis | } |
72 | ebead1b5 | Christos Stathis | if (node.isChildOpen(i)) {
|
73 | ebead1b5 | Christos Stathis | TreeNode n = node.setChildOpen(i, true); |
74 | ebead1b5 | Christos Stathis | return isFolderOpen(n, folder);
|
75 | ebead1b5 | Christos Stathis | } |
76 | adb597b8 | Christos Stathis | } |
77 | adb597b8 | Christos Stathis | return false; |
78 | adb597b8 | Christos Stathis | } |
79 | adb597b8 | Christos Stathis | |
80 | adb597b8 | Christos Stathis | public void openFolder(Folder folder) { |
81 | 39f6d7b0 | Christos Stathis | TreeNode root = tree.getRootTreeNode();
|
82 | adb597b8 | Christos Stathis | openFolder(root, folder); |
83 | 5ebc9312 | Christos Stathis | } |
84 | 5ebc9312 | Christos Stathis | |
85 | adb597b8 | Christos Stathis | private void openFolder(TreeNode node, Folder folder) { |
86 | 5ebc9312 | Christos Stathis | for (int i=0; i<node.getChildCount(); i++) { |
87 | 49080dd5 | Christos Stathis | if (folder.equals(node.getChildValue(i))) {
|
88 | adb597b8 | Christos Stathis | node.setChildOpen(i, false, true); |
89 | adb597b8 | Christos Stathis | node.setChildOpen(i, true, true); |
90 | adb597b8 | Christos Stathis | break;
|
91 | 49080dd5 | Christos Stathis | } |
92 | ebead1b5 | Christos Stathis | if (node.isChildOpen(i)) {
|
93 | ebead1b5 | Christos Stathis | TreeNode n = node.setChildOpen(i, true); |
94 | ebead1b5 | Christos Stathis | openFolder(n, folder); |
95 | ebead1b5 | Christos Stathis | break;
|
96 | ebead1b5 | Christos Stathis | } |
97 | 49080dd5 | Christos Stathis | } |
98 | 5ebc9312 | Christos Stathis | } |
99 | 5ebc9312 | Christos Stathis | |
100 | 6084aa02 | Christos Stathis | static interface BasicResources extends CellTree.Resources { |
101 | 6084aa02 | Christos Stathis | |
102 | 7811b9d1 | Christos Stathis | @Override
|
103 | 7811b9d1 | Christos Stathis | @ImageOptions(flipRtl = true) |
104 | 140f0f6d | Christos Stathis | @Source("gr/grnet/pithos/web/client/cellTreeClosedItem.png") |
105 | 6084aa02 | Christos Stathis | ImageResource cellTreeClosedItem(); |
106 | 6084aa02 | Christos Stathis | |
107 | 7811b9d1 | Christos Stathis | @Override
|
108 | 7811b9d1 | Christos Stathis | @ImageOptions(flipRtl = true) |
109 | a6592a15 | Christos Stathis | @Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif") |
110 | 6084aa02 | Christos Stathis | ImageResource cellTreeLoading(); |
111 | 6084aa02 | Christos Stathis | |
112 | 7811b9d1 | Christos Stathis | @Override
|
113 | 7811b9d1 | Christos Stathis | @ImageOptions(flipRtl = true) |
114 | 140f0f6d | Christos Stathis | @Source("gr/grnet/pithos/web/client/cellTreeOpenItem.png") |
115 | 6084aa02 | Christos Stathis | ImageResource cellTreeOpenItem(); |
116 | 6084aa02 | Christos Stathis | |
117 | 7811b9d1 | Christos Stathis | @Override
|
118 | 969a4d94 | Christos Stathis | @Source({"gr/grnet/pithos/web/client/PithosCellTreeBasic.css"}) |
119 | 6084aa02 | Christos Stathis | CellTree.Style cellTreeStyle(); |
120 | 3264607e | Christos Stathis | |
121 | 3264607e | Christos Stathis | @Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif") |
122 | 3264607e | Christos Stathis | @ImageOptions(repeatStyle=RepeatStyle.None)
|
123 | 3264607e | Christos Stathis | ImageResource cellTreeLoadingBasic(); |
124 | 6084aa02 | Christos Stathis | } |
125 | 6084aa02 | Christos Stathis | |
126 | 7811b9d1 | Christos Stathis | public static interface Images extends Tree.Resources, FolderContextMenu.Images { |
127 | 6084aa02 | Christos Stathis | |
128 | 9d8521d7 | Christos Stathis | @Source("gr/grnet/pithos/resources/home22.png") |
129 | 6084aa02 | Christos Stathis | ImageResource home(); |
130 | 6084aa02 | Christos Stathis | |
131 | 7e8e9ff0 | Christos Stathis | @Source("gr/grnet/pithos/resources/2folder22.png") |
132 | 447407c8 | Christos Stathis | public ImageResource folderYellow();
|
133 | f6445935 | Christos Stathis | |
134 | f6445935 | Christos Stathis | @Source("gr/grnet/pithos/resources/mimetypes/document.png") |
135 | f6445935 | Christos Stathis | ImageResource document(); |
136 | f6445935 | Christos Stathis | |
137 | bbdd34ef | Christos Stathis | @Source("gr/grnet/pithos/resources/myshared22.png") |
138 | f6445935 | Christos Stathis | ImageResource myShared(); |
139 | f6445935 | Christos Stathis | |
140 | f6445935 | Christos Stathis | @Source("gr/grnet/pithos/resources/folder_user.png") |
141 | f6445935 | Christos Stathis | ImageResource sharedFolder(); |
142 | f6445935 | Christos Stathis | |
143 | bbdd34ef | Christos Stathis | @Source("gr/grnet/pithos/resources/trash.png") |
144 | f6445935 | Christos Stathis | ImageResource trash(); |
145 | 6084aa02 | Christos Stathis | } |
146 | 6084aa02 | Christos Stathis | |
147 | 447407c8 | Christos Stathis | static Images images = GWT.create(Images.class);
|
148 | 6084aa02 | Christos Stathis | |
149 | 6084aa02 | Christos Stathis | static interface Templates extends SafeHtmlTemplates { |
150 | 447407c8 | Christos Stathis | public Templates INSTANCE = GWT.create(Templates.class); |
151 | 6084aa02 | Christos Stathis | |
152 | 0549e173 | Christos Stathis | @Template("<span style='vertical-align: middle;'>{0}</span>") |
153 | 6084aa02 | Christos Stathis | public SafeHtml nameSpan(String name); |
154 | a7b6e464 | Christos Stathis | |
155 | a7b6e464 | Christos Stathis | @Template("<span class='pithos-folderLabel'>{0}</span>") |
156 | a7b6e464 | Christos Stathis | public SafeHtml imageSpan(String name); |
157 | a7b6e464 | Christos Stathis | } |
158 | 6084aa02 | Christos Stathis | |
159 | 39f6d7b0 | Christos Stathis | interface Resources extends gr.grnet.pithos.web.client.PithosDisclosurePanel.Resources { |
160 | 3f62b626 | Christos Stathis | @Override
|
161 | 39f6d7b0 | Christos Stathis | @Source("gr/grnet/pithos/resources/home22.png") |
162 | 39f6d7b0 | Christos Stathis | ImageResource icon(); |
163 | 39f6d7b0 | Christos Stathis | } |
164 | 39f6d7b0 | Christos Stathis | |
165 | 7c818c14 | Christos Stathis | private FolderTreeViewModel model;
|
166 | 39f6d7b0 | Christos Stathis | |
167 | 39f6d7b0 | Christos Stathis | private CellTree tree;
|
168 | d18749bc | Christos Stathis | |
169 | d18749bc | Christos Stathis | private HTML usedBytes; |
170 | d18749bc | Christos Stathis | |
171 | d18749bc | Christos Stathis | private HTML totalBytes; |
172 | d18749bc | Christos Stathis | |
173 | d18749bc | Christos Stathis | private HTML usedPercent; |
174 | 7c818c14 | Christos Stathis | |
175 | 7c818c14 | Christos Stathis | public FolderTreeView(FolderTreeViewModel viewModel) {
|
176 | 7c818c14 | Christos Stathis | this.model = viewModel;
|
177 | 39f6d7b0 | Christos Stathis | |
178 | bb9f7c0d | Christos Stathis | PithosDisclosurePanel panel = new PithosDisclosurePanel((Resources) GWT.create(Resources.class), "My Files", true); |
179 | 39f6d7b0 | Christos Stathis | |
180 | d18749bc | Christos Stathis | VerticalPanel content = new VerticalPanel();
|
181 | d18749bc | Christos Stathis | |
182 | 6084aa02 | Christos Stathis | /*
|
183 | 6084aa02 | Christos Stathis | * Create the tree using the model. We use <code>null</code> as the default
|
184 | 6084aa02 | Christos Stathis | * value of the root node. The default value will be passed to
|
185 | 6084aa02 | Christos Stathis | * CustomTreeModel#getNodeInfo();
|
186 | 6084aa02 | Christos Stathis | */
|
187 | 6084aa02 | Christos Stathis | CellTree.Resources res = GWT.create(BasicResources.class); |
188 | 39f6d7b0 | Christos Stathis | tree = new CellTree(model, null, res); |
189 | 6084aa02 | Christos Stathis | tree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); |
190 | d18749bc | Christos Stathis | content.add(tree); |
191 | d18749bc | Christos Stathis | |
192 | d18749bc | Christos Stathis | HorizontalPanel separator = new HorizontalPanel();
|
193 | d18749bc | Christos Stathis | separator.addStyleName("pithos-statisticsSeparator");
|
194 | 3f62b626 | Christos Stathis | separator.add(new HTML("")); |
195 | d18749bc | Christos Stathis | content.add(separator); |
196 | d18749bc | Christos Stathis | |
197 | d18749bc | Christos Stathis | HorizontalPanel statistics = new HorizontalPanel();
|
198 | d18749bc | Christos Stathis | statistics.addStyleName("pithos-statistics");
|
199 | d18749bc | Christos Stathis | statistics.add(new HTML("Used: ")); |
200 | d18749bc | Christos Stathis | usedBytes = new HTML(); |
201 | d18749bc | Christos Stathis | statistics.add(usedBytes); |
202 | d18749bc | Christos Stathis | statistics.add(new HTML(" of ")); |
203 | d18749bc | Christos Stathis | totalBytes = new HTML(); |
204 | d18749bc | Christos Stathis | statistics.add(totalBytes); |
205 | d18749bc | Christos Stathis | statistics.add(new HTML(" (")); |
206 | d18749bc | Christos Stathis | usedPercent = new HTML(); |
207 | d18749bc | Christos Stathis | statistics.add(usedPercent); |
208 | d18749bc | Christos Stathis | statistics.add(new HTML(")")); |
209 | d18749bc | Christos Stathis | content.add(statistics); |
210 | 4f08fa4d | Christos Stathis | content.setCellHorizontalAlignment(statistics, HasHorizontalAlignment.ALIGN_CENTER); |
211 | d18749bc | Christos Stathis | |
212 | d18749bc | Christos Stathis | panel.setContent(content); |
213 | 39f6d7b0 | Christos Stathis | initWidget(panel); |
214 | 6084aa02 | Christos Stathis | } |
215 | 875a0179 | Christos Stathis | |
216 | 447407c8 | Christos Stathis | |
217 | abd8738f | Christos Stathis | @Override
|
218 | abd8738f | Christos Stathis | public Folder getSelection() {
|
219 | 875a0179 | Christos Stathis | return model.getSelection();
|
220 | 875a0179 | Christos Stathis | } |
221 | b651e67f | Christos Stathis | |
222 | 6acd4df3 | Christos Stathis | public void updateFolder(Folder folder, boolean showfiles, Command callback, final boolean openParent) { |
223 | 6acd4df3 | Christos Stathis | model.updateFolder(folder, showfiles, callback, openParent); |
224 | b651e67f | Christos Stathis | } |
225 | d18749bc | Christos Stathis | |
226 | d18749bc | Christos Stathis | public void showStatistics(AccountResource account) { |
227 | d18749bc | Christos Stathis | usedBytes.setHTML(String.valueOf(account.getFileSizeAsString()));
|
228 | d18749bc | Christos Stathis | totalBytes.setHTML(String.valueOf(account.getQuotaAsString()));
|
229 | d18749bc | Christos Stathis | NumberFormat nf = NumberFormat.getPercentFormat(); |
230 | d18749bc | Christos Stathis | usedPercent.setHTML(nf.format(account.getUsedPercentage())); |
231 | d18749bc | Christos Stathis | } |
232 | 6084aa02 | Christos Stathis | } |