root / src / gr / grnet / pithos / web / client / foldertree / FolderTreeView.java @ bb9f7c0d
History | View | Annotate | Download (8.2 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2011-2012 GRNET S.A. All rights reserved.
|
3 |
*
|
4 |
* Redistribution and use in source and binary forms, with or
|
5 |
* without modification, are permitted provided that the following
|
6 |
* conditions are met:
|
7 |
*
|
8 |
* 1. Redistributions of source code must retain the above
|
9 |
* copyright notice, this list of conditions and the following
|
10 |
* disclaimer.
|
11 |
*
|
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.
|
16 |
*
|
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.
|
29 |
*
|
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.
|
34 |
*/
|
35 |
|
36 |
package gr.grnet.pithos.web.client.foldertree; |
37 |
|
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 |
|
42 |
import com.google.gwt.core.client.GWT; |
43 |
import com.google.gwt.i18n.client.NumberFormat; |
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.user.cellview.client.CellTree; |
50 |
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy; |
51 |
import com.google.gwt.user.cellview.client.TreeNode; |
52 |
import com.google.gwt.user.client.Command; |
53 |
import com.google.gwt.user.client.ui.Composite; |
54 |
import com.google.gwt.user.client.ui.HTML; |
55 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
56 |
import com.google.gwt.user.client.ui.HorizontalPanel; |
57 |
import com.google.gwt.user.client.ui.Tree; |
58 |
import com.google.gwt.user.client.ui.VerticalPanel; |
59 |
|
60 |
public class FolderTreeView extends Composite implements TreeView { |
61 |
|
62 |
public boolean isFolderOpen(Folder folder) { |
63 |
TreeNode root = ((CellTree) getWidget()).getRootTreeNode();
|
64 |
return isFolderOpen(root, folder);
|
65 |
} |
66 |
|
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);
|
71 |
} |
72 |
if (node.isChildOpen(i)) {
|
73 |
TreeNode n = node.setChildOpen(i, true); |
74 |
return isFolderOpen(n, folder);
|
75 |
} |
76 |
} |
77 |
return false; |
78 |
} |
79 |
|
80 |
public void openFolder(Folder folder) { |
81 |
TreeNode root = tree.getRootTreeNode();
|
82 |
openFolder(root, folder); |
83 |
} |
84 |
|
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); |
90 |
break;
|
91 |
} |
92 |
if (node.isChildOpen(i)) {
|
93 |
TreeNode n = node.setChildOpen(i, true); |
94 |
openFolder(n, folder); |
95 |
break;
|
96 |
} |
97 |
} |
98 |
} |
99 |
|
100 |
static interface BasicResources extends CellTree.Resources { |
101 |
|
102 |
@Override
|
103 |
@ImageOptions(flipRtl = true) |
104 |
@Source("gr/grnet/pithos/web/client/cellTreeClosedItem.png") |
105 |
ImageResource cellTreeClosedItem(); |
106 |
|
107 |
@Override
|
108 |
@ImageOptions(flipRtl = true) |
109 |
@Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif") |
110 |
ImageResource cellTreeLoading(); |
111 |
|
112 |
@Override
|
113 |
@ImageOptions(flipRtl = true) |
114 |
@Source("gr/grnet/pithos/web/client/cellTreeOpenItem.png") |
115 |
ImageResource cellTreeOpenItem(); |
116 |
|
117 |
@Override
|
118 |
@Source({"gr/grnet/pithos/web/client/PithosCellTreeBasic.css"}) |
119 |
CellTree.Style cellTreeStyle(); |
120 |
|
121 |
@Source("gr/grnet/pithos/web/client/cellTreeLoadingBasic.gif") |
122 |
@ImageOptions(repeatStyle=RepeatStyle.None)
|
123 |
ImageResource cellTreeLoadingBasic(); |
124 |
} |
125 |
|
126 |
public static interface Images extends Tree.Resources, FolderContextMenu.Images { |
127 |
|
128 |
@Source("gr/grnet/pithos/resources/home22.png") |
129 |
ImageResource home(); |
130 |
|
131 |
@Source("gr/grnet/pithos/resources/2folder22.png") |
132 |
public ImageResource folderYellow();
|
133 |
|
134 |
@Source("gr/grnet/pithos/resources/mimetypes/document.png") |
135 |
ImageResource document(); |
136 |
|
137 |
@Source("gr/grnet/pithos/resources/myshared22.png") |
138 |
ImageResource myShared(); |
139 |
|
140 |
@Source("gr/grnet/pithos/resources/folder_user.png") |
141 |
ImageResource sharedFolder(); |
142 |
|
143 |
@Source("gr/grnet/pithos/resources/trash.png") |
144 |
ImageResource trash(); |
145 |
} |
146 |
|
147 |
static Images images = GWT.create(Images.class);
|
148 |
|
149 |
static interface Templates extends SafeHtmlTemplates { |
150 |
public Templates INSTANCE = GWT.create(Templates.class); |
151 |
|
152 |
@Template("<span style='vertical-align: middle;'>{0}</span>") |
153 |
public SafeHtml nameSpan(String name); |
154 |
|
155 |
@Template("<span class='pithos-folderLabel'>{0}</span>") |
156 |
public SafeHtml imageSpan(String name); |
157 |
} |
158 |
|
159 |
interface Resources extends gr.grnet.pithos.web.client.PithosDisclosurePanel.Resources { |
160 |
@Override
|
161 |
@Source("gr/grnet/pithos/resources/home22.png") |
162 |
ImageResource icon(); |
163 |
} |
164 |
|
165 |
private FolderTreeViewModel model;
|
166 |
|
167 |
private CellTree tree;
|
168 |
|
169 |
private HTML usedBytes; |
170 |
|
171 |
private HTML totalBytes; |
172 |
|
173 |
private HTML usedPercent; |
174 |
|
175 |
public FolderTreeView(FolderTreeViewModel viewModel) {
|
176 |
this.model = viewModel;
|
177 |
|
178 |
PithosDisclosurePanel panel = new PithosDisclosurePanel((Resources) GWT.create(Resources.class), "My Files", true); |
179 |
|
180 |
VerticalPanel content = new VerticalPanel();
|
181 |
|
182 |
/*
|
183 |
* Create the tree using the model. We use <code>null</code> as the default
|
184 |
* value of the root node. The default value will be passed to
|
185 |
* CustomTreeModel#getNodeInfo();
|
186 |
*/
|
187 |
CellTree.Resources res = GWT.create(BasicResources.class); |
188 |
tree = new CellTree(model, null, res); |
189 |
tree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); |
190 |
content.add(tree); |
191 |
|
192 |
HorizontalPanel separator = new HorizontalPanel();
|
193 |
separator.addStyleName("pithos-statisticsSeparator");
|
194 |
separator.add(new HTML("")); |
195 |
content.add(separator); |
196 |
|
197 |
HorizontalPanel statistics = new HorizontalPanel();
|
198 |
statistics.addStyleName("pithos-statistics");
|
199 |
statistics.add(new HTML("Used: ")); |
200 |
usedBytes = new HTML(); |
201 |
statistics.add(usedBytes); |
202 |
statistics.add(new HTML(" of ")); |
203 |
totalBytes = new HTML(); |
204 |
statistics.add(totalBytes); |
205 |
statistics.add(new HTML(" (")); |
206 |
usedPercent = new HTML(); |
207 |
statistics.add(usedPercent); |
208 |
statistics.add(new HTML(")")); |
209 |
content.add(statistics); |
210 |
content.setCellHorizontalAlignment(statistics, HasHorizontalAlignment.ALIGN_CENTER); |
211 |
|
212 |
panel.setContent(content); |
213 |
initWidget(panel); |
214 |
} |
215 |
|
216 |
|
217 |
@Override
|
218 |
public Folder getSelection() {
|
219 |
return model.getSelection();
|
220 |
} |
221 |
|
222 |
public void updateFolder(Folder folder, boolean showfiles, Command callback, final boolean openParent) { |
223 |
model.updateFolder(folder, showfiles, callback, openParent); |
224 |
} |
225 |
|
226 |
public void showStatistics(AccountResource account) { |
227 |
usedBytes.setHTML(String.valueOf(account.getFileSizeAsString()));
|
228 |
totalBytes.setHTML(String.valueOf(account.getQuotaAsString()));
|
229 |
NumberFormat nf = NumberFormat.getPercentFormat(); |
230 |
usedPercent.setHTML(nf.format(account.getUsedPercentage())); |
231 |
} |
232 |
} |