root / src / gr / grnet / pithos / web / client / othersharedtree / OtherSharedTreeViewModel.java @ 067bbb04
History | View | Annotate | Download (18.6 kB)
1 | 6d8e0f58 | Christos Stathis | /*
|
---|---|---|---|
2 | 6d8e0f58 | Christos Stathis | * Copyright 2011 GRNET S.A. All rights reserved.
|
3 | 6d8e0f58 | Christos Stathis | *
|
4 | 6d8e0f58 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 6d8e0f58 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 6d8e0f58 | Christos Stathis | * conditions are met:
|
7 | 6d8e0f58 | Christos Stathis | *
|
8 | 6d8e0f58 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 6d8e0f58 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 6d8e0f58 | Christos Stathis | * disclaimer.
|
11 | 6d8e0f58 | Christos Stathis | *
|
12 | 6d8e0f58 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 6d8e0f58 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 6d8e0f58 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 6d8e0f58 | Christos Stathis | * provided with the distribution.
|
16 | 6d8e0f58 | Christos Stathis | *
|
17 | 6d8e0f58 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 6d8e0f58 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 6d8e0f58 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 6d8e0f58 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 6d8e0f58 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 6d8e0f58 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 6d8e0f58 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 6d8e0f58 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 6d8e0f58 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 6d8e0f58 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 6d8e0f58 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 6d8e0f58 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 6d8e0f58 | Christos Stathis | *
|
30 | 6d8e0f58 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 6d8e0f58 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 6d8e0f58 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 6d8e0f58 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | 6d8e0f58 | Christos Stathis | */
|
35 | 6d8e0f58 | Christos Stathis | |
36 | 6d8e0f58 | Christos Stathis | package gr.grnet.pithos.web.client.othersharedtree; |
37 | 6d8e0f58 | Christos Stathis | |
38 | 6d8e0f58 | Christos Stathis | import gr.grnet.pithos.web.client.FolderContextMenu; |
39 | 6d8e0f58 | Christos Stathis | import gr.grnet.pithos.web.client.Pithos; |
40 | 6d8e0f58 | Christos Stathis | import gr.grnet.pithos.web.client.SharingUsers; |
41 | 220831bd | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.AccountResource; |
42 | 220831bd | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.File; |
43 | 6d8e0f58 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Folder; |
44 | 6d8e0f58 | Christos Stathis | import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeView.Templates; |
45 | 6d8e0f58 | Christos Stathis | import gr.grnet.pithos.web.client.rest.GetRequest; |
46 | 6d8e0f58 | Christos Stathis | import gr.grnet.pithos.web.client.rest.RestException; |
47 | 6d8e0f58 | Christos Stathis | |
48 | 6d8e0f58 | Christos Stathis | import java.util.HashMap; |
49 | 220831bd | Christos Stathis | import java.util.HashSet; |
50 | 6d8e0f58 | Christos Stathis | import java.util.Iterator; |
51 | 6d8e0f58 | Christos Stathis | import java.util.Map; |
52 | 220831bd | Christos Stathis | import java.util.Set; |
53 | 6d8e0f58 | Christos Stathis | |
54 | 6d8e0f58 | Christos Stathis | import com.google.gwt.cell.client.AbstractCell; |
55 | 6d8e0f58 | Christos Stathis | import com.google.gwt.cell.client.Cell; |
56 | 6d8e0f58 | Christos Stathis | import com.google.gwt.cell.client.TextCell; |
57 | 6d8e0f58 | Christos Stathis | import com.google.gwt.cell.client.ValueUpdater; |
58 | 6d8e0f58 | Christos Stathis | import com.google.gwt.core.client.GWT; |
59 | 6d8e0f58 | Christos Stathis | import com.google.gwt.core.client.Scheduler; |
60 | 6d8e0f58 | Christos Stathis | import com.google.gwt.event.dom.client.ContextMenuEvent; |
61 | 9539e23d | Christos Stathis | import com.google.gwt.http.client.Response; |
62 | f5023f13 | Christos Stathis | import com.google.gwt.http.client.URL; |
63 | 6d8e0f58 | Christos Stathis | import com.google.gwt.safehtml.shared.SafeHtml; |
64 | 6d8e0f58 | Christos Stathis | import com.google.gwt.safehtml.shared.SafeHtmlBuilder; |
65 | 6d8e0f58 | Christos Stathis | import com.google.gwt.text.shared.SafeHtmlRenderer; |
66 | 6d8e0f58 | Christos Stathis | import com.google.gwt.user.client.Command; |
67 | 6d8e0f58 | Christos Stathis | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
68 | 6d8e0f58 | Christos Stathis | import com.google.gwt.view.client.ListDataProvider; |
69 | 6d8e0f58 | Christos Stathis | import com.google.gwt.view.client.SelectionChangeEvent; |
70 | 6d8e0f58 | Christos Stathis | import com.google.gwt.view.client.SelectionChangeEvent.Handler; |
71 | 6d8e0f58 | Christos Stathis | import com.google.gwt.view.client.SingleSelectionModel; |
72 | 6d8e0f58 | Christos Stathis | import com.google.gwt.view.client.TreeViewModel; |
73 | 6d8e0f58 | Christos Stathis | |
74 | 6d8e0f58 | Christos Stathis | public class OtherSharedTreeViewModel implements TreeViewModel { |
75 | 6d8e0f58 | Christos Stathis | |
76 | 7c54d867 | Christos Stathis | private static final String treeTitle = "Other 's shared"; |
77 | 6d8e0f58 | Christos Stathis | protected Pithos app;
|
78 | 6d8e0f58 | Christos Stathis | |
79 | 6d8e0f58 | Christos Stathis | private Cell<Folder> folderCell = new AbstractCell<Folder>(ContextMenuEvent.getType().getName()) { |
80 | 6d8e0f58 | Christos Stathis | |
81 | 6d8e0f58 | Christos Stathis | @Override
|
82 | 7811b9d1 | Christos Stathis | public void render(@SuppressWarnings("unused") Context context, Folder folder, SafeHtmlBuilder safeHtmlBuilder) { |
83 | 6d8e0f58 | Christos Stathis | String html = AbstractImagePrototype.create(OtherSharedTreeView.images.folderYellow()).getHTML();
|
84 | a7b6e464 | Christos Stathis | safeHtmlBuilder.appendHtmlConstant(html).appendHtmlConstant(" ");
|
85 | 6d8e0f58 | Christos Stathis | safeHtmlBuilder.append(Templates.INSTANCE.nameSpan(folder.getName()));
|
86 | 6d8e0f58 | Christos Stathis | } |
87 | 6d8e0f58 | Christos Stathis | |
88 | 6d8e0f58 | Christos Stathis | @Override
|
89 | 7811b9d1 | Christos Stathis | public void onBrowserEvent(@SuppressWarnings("unused") Context context, @SuppressWarnings("unused") com.google.gwt.dom.client.Element parent, Folder folder, com.google.gwt.dom.client.NativeEvent event, @SuppressWarnings("unused") ValueUpdater<Folder> valueUpdater) { |
90 | 6d8e0f58 | Christos Stathis | if (event.getType().equals(ContextMenuEvent.getType().getName())) {
|
91 | 6d8e0f58 | Christos Stathis | OtherSharedTreeViewModel.this.selectionModel.setSelected(folder, true);
|
92 | 02d3a335 | Christos Stathis | FolderContextMenu menu = new FolderContextMenu(app, OtherSharedTreeView.images, app.getSelectedTree(), folder);
|
93 | 6d8e0f58 | Christos Stathis | menu.setPopupPosition(event.getClientX(), event.getClientY()); |
94 | 6d8e0f58 | Christos Stathis | menu.show(); |
95 | 6d8e0f58 | Christos Stathis | } |
96 | 6d8e0f58 | Christos Stathis | } |
97 | 6d8e0f58 | Christos Stathis | }; |
98 | 6d8e0f58 | Christos Stathis | |
99 | 6d8e0f58 | Christos Stathis | private ListDataProvider<String> rootDataProvider = new ListDataProvider<String>(); |
100 | 220831bd | Christos Stathis | protected ListDataProvider<String> userLevelDataProvider = new ListDataProvider<String>(); |
101 | 6d8e0f58 | Christos Stathis | |
102 | 220831bd | Christos Stathis | protected Map<String, ListDataProvider<Folder>> userDataProviderMap = new HashMap<String, ListDataProvider<Folder>>(); |
103 | 6d8e0f58 | Christos Stathis | private Map<Folder, ListDataProvider<Folder>> dataProviderMap = new HashMap<Folder, ListDataProvider<Folder>>(); |
104 | 220831bd | Christos Stathis | |
105 | 220831bd | Christos Stathis | protected Map<String, Set<File>> sharedFiles = new HashMap<String, Set<File>>(); |
106 | 6d8e0f58 | Christos Stathis | |
107 | 220831bd | Christos Stathis | protected SingleSelectionModel<Folder> selectionModel; |
108 | 6d8e0f58 | Christos Stathis | |
109 | 6d8e0f58 | Christos Stathis | public OtherSharedTreeViewModel(Pithos _app, SingleSelectionModel<Folder> selectionModel) { |
110 | 6d8e0f58 | Christos Stathis | app = _app; |
111 | 6d8e0f58 | Christos Stathis | this.selectionModel = selectionModel;
|
112 | 6d8e0f58 | Christos Stathis | } |
113 | 6d8e0f58 | Christos Stathis | |
114 | 6d8e0f58 | Christos Stathis | @Override
|
115 | 6d8e0f58 | Christos Stathis | public <T> NodeInfo<?> getNodeInfo(T value) {
|
116 | 6d8e0f58 | Christos Stathis | if (value == null) { |
117 | 7c54d867 | Christos Stathis | rootDataProvider.getList().add(treeTitle); |
118 | 6d8e0f58 | Christos Stathis | final SingleSelectionModel<String> selectionModel2 = new SingleSelectionModel<String>(); |
119 | 6d8e0f58 | Christos Stathis | selectionModel2.addSelectionChangeHandler(new Handler() { |
120 | 6d8e0f58 | Christos Stathis | |
121 | 6d8e0f58 | Christos Stathis | @Override
|
122 | 7811b9d1 | Christos Stathis | public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) { |
123 | 6d8e0f58 | Christos Stathis | if (selectionModel2.getSelectedObject() != null) { |
124 | f1b24b82 | Christos Stathis | app.deselectOthers(app.getOtherSharedTreeView(), selectionModel2); |
125 | 3ebb88f4 | Christos Stathis | app.applyPermissions(null);
|
126 | 220831bd | Christos Stathis | app.showFiles(new HashSet<File>()); |
127 | 6d8e0f58 | Christos Stathis | } |
128 | 6d8e0f58 | Christos Stathis | } |
129 | 6d8e0f58 | Christos Stathis | }); |
130 | 6d8e0f58 | Christos Stathis | app.addSelectionModel(selectionModel2); |
131 | 6d8e0f58 | Christos Stathis | return new DefaultNodeInfo<String>(rootDataProvider, new TextCell(new SafeHtmlRenderer<String>() { |
132 | 6d8e0f58 | Christos Stathis | @Override
|
133 | 6d8e0f58 | Christos Stathis | public SafeHtml render(String object) { |
134 | 6d8e0f58 | Christos Stathis | SafeHtmlBuilder builder = new SafeHtmlBuilder();
|
135 | 6d8e0f58 | Christos Stathis | render(object, builder); |
136 | 6d8e0f58 | Christos Stathis | return builder.toSafeHtml();
|
137 | 6d8e0f58 | Christos Stathis | } |
138 | 6d8e0f58 | Christos Stathis | |
139 | 6d8e0f58 | Christos Stathis | @Override
|
140 | 6d8e0f58 | Christos Stathis | public void render(String object, SafeHtmlBuilder builder) { |
141 | 6d8e0f58 | Christos Stathis | String html = AbstractImagePrototype.create(OtherSharedTreeView.images.othersShared()).getHTML();
|
142 | a7b6e464 | Christos Stathis | builder.appendHtmlConstant(html).appendHtmlConstant(" ");
|
143 | 6d8e0f58 | Christos Stathis | builder.append(OtherSharedTreeView.Templates.INSTANCE.nameSpan(object)); |
144 | 6d8e0f58 | Christos Stathis | } |
145 | 6d8e0f58 | Christos Stathis | }), selectionModel2, null);
|
146 | 6d8e0f58 | Christos Stathis | } |
147 | 6d8e0f58 | Christos Stathis | else if (value instanceof String) { |
148 | 7c54d867 | Christos Stathis | if (value.equals(treeTitle)) {
|
149 | 7c54d867 | Christos Stathis | fetchSharingUsers(null);
|
150 | 6d8e0f58 | Christos Stathis | final SingleSelectionModel<String> selectionModel3 = new SingleSelectionModel<String>(); |
151 | 6d8e0f58 | Christos Stathis | selectionModel3.addSelectionChangeHandler(new Handler() { |
152 | 6d8e0f58 | Christos Stathis | |
153 | 6d8e0f58 | Christos Stathis | @Override
|
154 | 7811b9d1 | Christos Stathis | public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) { |
155 | 6d8e0f58 | Christos Stathis | if (selectionModel3.getSelectedObject() != null) { |
156 | f1b24b82 | Christos Stathis | app.deselectOthers(app.getOtherSharedTreeView(), selectionModel3); |
157 | 3ebb88f4 | Christos Stathis | app.applyPermissions(null);
|
158 | 220831bd | Christos Stathis | String username = selectionModel3.getSelectedObject();
|
159 | 63ee965c | Christos Stathis | if (userDataProviderMap.get(username) == null) { |
160 | 63ee965c | Christos Stathis | userDataProviderMap.put(username, new ListDataProvider<Folder>());
|
161 | 63ee965c | Christos Stathis | } |
162 | 220831bd | Christos Stathis | fetchSharedFiles(username, userDataProviderMap.get(username)); |
163 | 6d8e0f58 | Christos Stathis | } |
164 | 6d8e0f58 | Christos Stathis | } |
165 | 6d8e0f58 | Christos Stathis | }); |
166 | 6d8e0f58 | Christos Stathis | app.addSelectionModel(selectionModel3); |
167 | 220831bd | Christos Stathis | return new DefaultNodeInfo<String>(userLevelDataProvider, new TextCell(new SafeHtmlRenderer<String>() { |
168 | 6d8e0f58 | Christos Stathis | |
169 | 6d8e0f58 | Christos Stathis | @Override
|
170 | 6d8e0f58 | Christos Stathis | public SafeHtml render(String object) { |
171 | 6d8e0f58 | Christos Stathis | SafeHtmlBuilder builder = new SafeHtmlBuilder();
|
172 | 6d8e0f58 | Christos Stathis | render(object, builder); |
173 | 6d8e0f58 | Christos Stathis | return builder.toSafeHtml();
|
174 | 6d8e0f58 | Christos Stathis | } |
175 | 6d8e0f58 | Christos Stathis | |
176 | 6d8e0f58 | Christos Stathis | @Override
|
177 | 6d8e0f58 | Christos Stathis | public void render(String object, SafeHtmlBuilder builder) { |
178 | 220831bd | Christos Stathis | String html = AbstractImagePrototype.create(OtherSharedTreeView.images.user()).getHTML();
|
179 | a7b6e464 | Christos Stathis | builder.appendHtmlConstant(html).appendHtmlConstant(" ");
|
180 | 6d8e0f58 | Christos Stathis | builder.append(OtherSharedTreeView.Templates.INSTANCE.nameSpan(object)); |
181 | 6d8e0f58 | Christos Stathis | } |
182 | 6d8e0f58 | Christos Stathis | }), selectionModel3, null);
|
183 | 6d8e0f58 | Christos Stathis | } |
184 | 220831bd | Christos Stathis | String username = (String) value; |
185 | 220831bd | Christos Stathis | if (userDataProviderMap.get(username) == null) { |
186 | 220831bd | Christos Stathis | userDataProviderMap.put(username, new ListDataProvider<Folder>());
|
187 | 220831bd | Christos Stathis | } |
188 | 220831bd | Christos Stathis | final ListDataProvider<Folder> dataProvider = userDataProviderMap.get(username);
|
189 | 7c54d867 | Christos Stathis | fetchSharedContainers(username, dataProvider, null);
|
190 | 220831bd | Christos Stathis | return new DefaultNodeInfo<Folder>(dataProvider, folderCell, selectionModel, null); |
191 | 6d8e0f58 | Christos Stathis | } |
192 | 6d8e0f58 | Christos Stathis | else {
|
193 | 6d8e0f58 | Christos Stathis | final Folder f = (Folder) value;
|
194 | 6d8e0f58 | Christos Stathis | if (dataProviderMap.get(f) == null) { |
195 | 6d8e0f58 | Christos Stathis | dataProviderMap.put(f, new ListDataProvider<Folder>());
|
196 | 6d8e0f58 | Christos Stathis | } |
197 | 6d8e0f58 | Christos Stathis | final ListDataProvider<Folder> dataProvider = dataProviderMap.get(f);
|
198 | 6d8e0f58 | Christos Stathis | fetchFolder(f, dataProvider, false);
|
199 | 6d8e0f58 | Christos Stathis | return new DefaultNodeInfo<Folder>(dataProvider, folderCell, selectionModel, null); |
200 | 6d8e0f58 | Christos Stathis | } |
201 | 6d8e0f58 | Christos Stathis | } |
202 | 6d8e0f58 | Christos Stathis | |
203 | 7c54d867 | Christos Stathis | private void fetchSharingUsers(final Command callback) { |
204 | 6d8e0f58 | Christos Stathis | GetRequest<SharingUsers> getSharingUsers = new GetRequest<SharingUsers>(SharingUsers.class, app.getApiPath(), "", "?format=json") { |
205 | 6d8e0f58 | Christos Stathis | @Override
|
206 | 7811b9d1 | Christos Stathis | public void onSuccess(final SharingUsers _result) { |
207 | 220831bd | Christos Stathis | userLevelDataProvider.getList().clear(); |
208 | 7811b9d1 | Christos Stathis | userLevelDataProvider.getList().addAll(_result.getUsers()); |
209 | 7811b9d1 | Christos Stathis | for (String name : _result.getUsers()) { |
210 | 220831bd | Christos Stathis | sharedFiles.put(name, new HashSet<File>()); |
211 | 220831bd | Christos Stathis | } |
212 | 7c54d867 | Christos Stathis | Iterator<String> iter = _result.getUsers().iterator(); |
213 | 7c54d867 | Christos Stathis | fetchSharedContainers(iter, callback); |
214 | 6d8e0f58 | Christos Stathis | } |
215 | 6d8e0f58 | Christos Stathis | |
216 | 6d8e0f58 | Christos Stathis | @Override
|
217 | 6d8e0f58 | Christos Stathis | public void onError(Throwable t) { |
218 | 6d8e0f58 | Christos Stathis | GWT.log("Error getting folder", t);
|
219 | 6d8e0f58 | Christos Stathis | if (t instanceof RestException) |
220 | 6d8e0f58 | Christos Stathis | app.displayError("Error getting folder: " + ((RestException) t).getHttpStatusText());
|
221 | 6d8e0f58 | Christos Stathis | else
|
222 | 6d8e0f58 | Christos Stathis | app.displayError("System error fetching folder: " + t.getMessage());
|
223 | 6d8e0f58 | Christos Stathis | } |
224 | 9539e23d | Christos Stathis | |
225 | 9539e23d | Christos Stathis | @Override
|
226 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
227 | 9539e23d | Christos Stathis | app.sessionExpired(); |
228 | 9539e23d | Christos Stathis | } |
229 | 6d8e0f58 | Christos Stathis | }; |
230 | 6d8e0f58 | Christos Stathis | getSharingUsers.setHeader("X-Auth-Token", app.getToken());
|
231 | 6d8e0f58 | Christos Stathis | Scheduler.get().scheduleDeferred(getSharingUsers); |
232 | 6d8e0f58 | Christos Stathis | } |
233 | 6d8e0f58 | Christos Stathis | |
234 | 7c54d867 | Christos Stathis | protected void fetchSharedContainers(final Iterator<String> iter, final Command callback) { |
235 | 7c54d867 | Christos Stathis | if (iter.hasNext()) {
|
236 | 7c54d867 | Christos Stathis | String username = iter.next();
|
237 | 7c54d867 | Christos Stathis | if (userDataProviderMap.get(username) == null) { |
238 | 7c54d867 | Christos Stathis | userDataProviderMap.put(username, new ListDataProvider<Folder>());
|
239 | 7c54d867 | Christos Stathis | } |
240 | 7c54d867 | Christos Stathis | final ListDataProvider<Folder> dataProvider = userDataProviderMap.get(username);
|
241 | 7c54d867 | Christos Stathis | fetchSharedContainers(username, dataProvider, new Command() {
|
242 | 7c54d867 | Christos Stathis | |
243 | 7c54d867 | Christos Stathis | @Override
|
244 | 7c54d867 | Christos Stathis | public void execute() { |
245 | 7c54d867 | Christos Stathis | fetchSharedContainers(iter, callback); |
246 | 7c54d867 | Christos Stathis | |
247 | 7c54d867 | Christos Stathis | } |
248 | 7c54d867 | Christos Stathis | }); |
249 | 7c54d867 | Christos Stathis | } |
250 | 7c54d867 | Christos Stathis | else
|
251 | 7c54d867 | Christos Stathis | if (callback != null) |
252 | 7c54d867 | Christos Stathis | callback.execute(); |
253 | 7c54d867 | Christos Stathis | } |
254 | 7c54d867 | Christos Stathis | |
255 | 6d8e0f58 | Christos Stathis | @Override
|
256 | 6d8e0f58 | Christos Stathis | public boolean isLeaf(Object o) { |
257 | 7c54d867 | Christos Stathis | if (o == null) |
258 | 7c54d867 | Christos Stathis | return false; |
259 | 7c54d867 | Christos Stathis | else if (o instanceof Folder) { |
260 | 6d8e0f58 | Christos Stathis | Folder f = (Folder) o; |
261 | 6d8e0f58 | Christos Stathis | return f.getSubfolders().isEmpty();
|
262 | 6d8e0f58 | Christos Stathis | } |
263 | 7c54d867 | Christos Stathis | else {
|
264 | 7c54d867 | Christos Stathis | if (o.equals(treeTitle))
|
265 | 7c54d867 | Christos Stathis | return userLevelDataProvider.getList().isEmpty();
|
266 | 7c54d867 | Christos Stathis | ListDataProvider<Folder> dp = userDataProviderMap.get(o); |
267 | 7c54d867 | Christos Stathis | if (dp != null) |
268 | 7c54d867 | Christos Stathis | return dp.getList().isEmpty();
|
269 | 7c54d867 | Christos Stathis | return true; |
270 | 7c54d867 | Christos Stathis | } |
271 | 6d8e0f58 | Christos Stathis | } |
272 | 6d8e0f58 | Christos Stathis | |
273 | 7c54d867 | Christos Stathis | private void fetchSharedContainers(final String username, final ListDataProvider<Folder> dataProvider, final Command callback) { |
274 | 220831bd | Christos Stathis | GetRequest<AccountResource> getUserSharedContainers = new GetRequest<AccountResource>(AccountResource.class, app.getApiPath(), username, "?format=json") { |
275 | 220831bd | Christos Stathis | |
276 | 220831bd | Christos Stathis | @Override
|
277 | 7811b9d1 | Christos Stathis | public void onSuccess(AccountResource _result) { |
278 | 220831bd | Christos Stathis | final ListDataProvider<Folder> tempProvider = new ListDataProvider<Folder>(); |
279 | 7811b9d1 | Christos Stathis | Iterator<Folder> iter = _result.getContainers().iterator();
|
280 | 220831bd | Christos Stathis | fetchFolder(username, iter, tempProvider, new Command() {
|
281 | 220831bd | Christos Stathis | |
282 | 220831bd | Christos Stathis | @Override
|
283 | 220831bd | Christos Stathis | public void execute() { |
284 | 220831bd | Christos Stathis | dataProvider.getList().clear(); |
285 | 220831bd | Christos Stathis | dataProvider.getList().addAll(tempProvider.getList()); |
286 | 7c54d867 | Christos Stathis | if (callback != null) |
287 | 7c54d867 | Christos Stathis | callback.execute(); |
288 | 220831bd | Christos Stathis | } |
289 | 220831bd | Christos Stathis | }); |
290 | 220831bd | Christos Stathis | } |
291 | 220831bd | Christos Stathis | |
292 | 220831bd | Christos Stathis | @Override
|
293 | 220831bd | Christos Stathis | public void onError(Throwable t) { |
294 | 220831bd | Christos Stathis | GWT.log("Error getting account", t);
|
295 | 220831bd | Christos Stathis | if (t instanceof RestException) |
296 | 220831bd | Christos Stathis | app.displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
|
297 | 220831bd | Christos Stathis | else
|
298 | 220831bd | Christos Stathis | app.displayError("System error fetching user data: " + t.getMessage());
|
299 | 220831bd | Christos Stathis | } |
300 | 9539e23d | Christos Stathis | |
301 | 9539e23d | Christos Stathis | @Override
|
302 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
303 | 9539e23d | Christos Stathis | app.sessionExpired(); |
304 | 9539e23d | Christos Stathis | } |
305 | 220831bd | Christos Stathis | }; |
306 | 220831bd | Christos Stathis | getUserSharedContainers.setHeader("X-Auth-Token", app.getToken());
|
307 | 220831bd | Christos Stathis | Scheduler.get().scheduleDeferred(getUserSharedContainers); |
308 | 220831bd | Christos Stathis | } |
309 | 220831bd | Christos Stathis | |
310 | 220831bd | Christos Stathis | protected void fetchSharedFiles(final String username, final ListDataProvider<Folder> dataProvider) { |
311 | 220831bd | Christos Stathis | GetRequest<AccountResource> getUserSharedContainers = new GetRequest<AccountResource>(AccountResource.class, app.getApiPath(), username, "?format=json") { |
312 | 220831bd | Christos Stathis | |
313 | 220831bd | Christos Stathis | @Override
|
314 | 7811b9d1 | Christos Stathis | public void onSuccess(AccountResource _result) { |
315 | 220831bd | Christos Stathis | final ListDataProvider<Folder> tempProvider = new ListDataProvider<Folder>(); |
316 | 7811b9d1 | Christos Stathis | Iterator<Folder> iter = _result.getContainers().iterator();
|
317 | 220831bd | Christos Stathis | fetchFolder(username, iter, tempProvider, new Command() {
|
318 | 220831bd | Christos Stathis | |
319 | 220831bd | Christos Stathis | @Override
|
320 | 220831bd | Christos Stathis | public void execute() { |
321 | 220831bd | Christos Stathis | dataProvider.getList().clear(); |
322 | 220831bd | Christos Stathis | dataProvider.getList().addAll(tempProvider.getList()); |
323 | 220831bd | Christos Stathis | app.showFiles(sharedFiles.get(username)); |
324 | 220831bd | Christos Stathis | } |
325 | 220831bd | Christos Stathis | }); |
326 | 220831bd | Christos Stathis | } |
327 | 220831bd | Christos Stathis | |
328 | 220831bd | Christos Stathis | @Override
|
329 | 220831bd | Christos Stathis | public void onError(Throwable t) { |
330 | 220831bd | Christos Stathis | GWT.log("Error getting account", t);
|
331 | 220831bd | Christos Stathis | if (t instanceof RestException) |
332 | 220831bd | Christos Stathis | app.displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
|
333 | 220831bd | Christos Stathis | else
|
334 | 220831bd | Christos Stathis | app.displayError("System error fetching user data: " + t.getMessage());
|
335 | 220831bd | Christos Stathis | } |
336 | 9539e23d | Christos Stathis | |
337 | 9539e23d | Christos Stathis | @Override
|
338 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
339 | 9539e23d | Christos Stathis | app.sessionExpired(); |
340 | 9539e23d | Christos Stathis | } |
341 | 220831bd | Christos Stathis | }; |
342 | 220831bd | Christos Stathis | getUserSharedContainers.setHeader("X-Auth-Token", app.getToken());
|
343 | 220831bd | Christos Stathis | Scheduler.get().scheduleDeferred(getUserSharedContainers); |
344 | 220831bd | Christos Stathis | } |
345 | 220831bd | Christos Stathis | |
346 | 220831bd | Christos Stathis | protected void fetchFolder(final String username, final Iterator<Folder> iter, final ListDataProvider<Folder> dataProvider, final Command callback) { |
347 | 6d8e0f58 | Christos Stathis | if (iter.hasNext()) {
|
348 | 6d8e0f58 | Christos Stathis | final Folder f = iter.next();
|
349 | 6d8e0f58 | Christos Stathis | |
350 | f5023f13 | Christos Stathis | String path = "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix()); |
351 | 220831bd | Christos Stathis | GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), username, path, f) {
|
352 | 6d8e0f58 | Christos Stathis | @Override
|
353 | 7811b9d1 | Christos Stathis | public void onSuccess(Folder _result) { |
354 | 7811b9d1 | Christos Stathis | if (!_result.isShared()) {
|
355 | 7811b9d1 | Christos Stathis | for (File file : _result.getFiles()) { |
356 | 220831bd | Christos Stathis | if (file.isShared())
|
357 | 220831bd | Christos Stathis | sharedFiles.get(username).add(file); |
358 | 220831bd | Christos Stathis | } |
359 | 7811b9d1 | Christos Stathis | Iterator<Folder> iter2 = _result.getSubfolders().iterator();
|
360 | 220831bd | Christos Stathis | fetchFolder(username, iter2, dataProvider, new Command() {
|
361 | 220831bd | Christos Stathis | |
362 | 220831bd | Christos Stathis | @Override
|
363 | 220831bd | Christos Stathis | public void execute() { |
364 | 220831bd | Christos Stathis | fetchFolder(username, iter, dataProvider, callback); |
365 | 220831bd | Christos Stathis | } |
366 | 220831bd | Christos Stathis | }); |
367 | 220831bd | Christos Stathis | } |
368 | 220831bd | Christos Stathis | else {
|
369 | 7811b9d1 | Christos Stathis | dataProvider.getList().add(_result); |
370 | 220831bd | Christos Stathis | fetchFolder(username, iter, dataProvider, callback); |
371 | 220831bd | Christos Stathis | } |
372 | 6d8e0f58 | Christos Stathis | } |
373 | 6d8e0f58 | Christos Stathis | |
374 | 6d8e0f58 | Christos Stathis | @Override
|
375 | 6d8e0f58 | Christos Stathis | public void onError(Throwable t) { |
376 | 6d8e0f58 | Christos Stathis | GWT.log("Error getting folder", t);
|
377 | 6d8e0f58 | Christos Stathis | if (t instanceof RestException) |
378 | 6d8e0f58 | Christos Stathis | app.displayError("Error getting folder: " + ((RestException) t).getHttpStatusText());
|
379 | 6d8e0f58 | Christos Stathis | else
|
380 | 6d8e0f58 | Christos Stathis | app.displayError("System error fetching folder: " + t.getMessage());
|
381 | 6d8e0f58 | Christos Stathis | } |
382 | 9539e23d | Christos Stathis | |
383 | 9539e23d | Christos Stathis | @Override
|
384 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
385 | 9539e23d | Christos Stathis | app.sessionExpired(); |
386 | 9539e23d | Christos Stathis | } |
387 | 6d8e0f58 | Christos Stathis | }; |
388 | 6d8e0f58 | Christos Stathis | getFolder.setHeader("X-Auth-Token", app.getToken());
|
389 | 6d8e0f58 | Christos Stathis | Scheduler.get().scheduleDeferred(getFolder); |
390 | 6d8e0f58 | Christos Stathis | } |
391 | 6d8e0f58 | Christos Stathis | else if (callback != null) |
392 | 6d8e0f58 | Christos Stathis | callback.execute(); |
393 | 6d8e0f58 | Christos Stathis | } |
394 | 6d8e0f58 | Christos Stathis | |
395 | 6d8e0f58 | Christos Stathis | public Folder getSelection() {
|
396 | 6d8e0f58 | Christos Stathis | return selectionModel.getSelectedObject();
|
397 | 6d8e0f58 | Christos Stathis | } |
398 | 6d8e0f58 | Christos Stathis | |
399 | 6d8e0f58 | Christos Stathis | public void updateFolder(Folder folder, boolean showfiles) { |
400 | 6d8e0f58 | Christos Stathis | if (dataProviderMap.get(folder) == null) { |
401 | 6d8e0f58 | Christos Stathis | dataProviderMap.put(folder, new ListDataProvider<Folder>());
|
402 | 6d8e0f58 | Christos Stathis | } |
403 | 6d8e0f58 | Christos Stathis | final ListDataProvider<Folder> dataProvider = dataProviderMap.get(folder);
|
404 | 6d8e0f58 | Christos Stathis | fetchFolder(folder, dataProvider, showfiles); |
405 | 6d8e0f58 | Christos Stathis | } |
406 | 6d8e0f58 | Christos Stathis | |
407 | 6d8e0f58 | Christos Stathis | public void fetchFolder(final Folder f, final ListDataProvider<Folder> dataProvider, final boolean showfiles) { |
408 | f5023f13 | Christos Stathis | String path = "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix()); |
409 | 220831bd | Christos Stathis | GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), f.getOwner(), path, f) {
|
410 | 6d8e0f58 | Christos Stathis | @Override
|
411 | 7811b9d1 | Christos Stathis | public void onSuccess(final Folder _result) { |
412 | 6d8e0f58 | Christos Stathis | if (showfiles)
|
413 | 7811b9d1 | Christos Stathis | app.showFiles(_result); |
414 | 7811b9d1 | Christos Stathis | Iterator<Folder> iter = _result.getSubfolders().iterator();
|
415 | 7811b9d1 | Christos Stathis | fetchFolder(_result.getOwner(), iter, dataProvider, new Command() {
|
416 | 6d8e0f58 | Christos Stathis | @Override
|
417 | 6d8e0f58 | Christos Stathis | public void execute() { |
418 | 6d8e0f58 | Christos Stathis | dataProvider.getList().clear(); |
419 | 7811b9d1 | Christos Stathis | dataProvider.getList().addAll(_result.getSubfolders()); |
420 | 6d8e0f58 | Christos Stathis | app.getOtherSharedTreeView().updateChildren(f); |
421 | 6d8e0f58 | Christos Stathis | } |
422 | 6d8e0f58 | Christos Stathis | }); |
423 | 6d8e0f58 | Christos Stathis | } |
424 | 6d8e0f58 | Christos Stathis | |
425 | 6d8e0f58 | Christos Stathis | @Override
|
426 | 6d8e0f58 | Christos Stathis | public void onError(Throwable t) { |
427 | 6d8e0f58 | Christos Stathis | GWT.log("Error getting folder", t);
|
428 | 6d8e0f58 | Christos Stathis | if (t instanceof RestException) |
429 | 6d8e0f58 | Christos Stathis | app.displayError("Error getting folder: " + ((RestException) t).getHttpStatusText());
|
430 | 6d8e0f58 | Christos Stathis | else
|
431 | 6d8e0f58 | Christos Stathis | app.displayError("System error fetching folder: " + t.getMessage());
|
432 | 6d8e0f58 | Christos Stathis | } |
433 | 9539e23d | Christos Stathis | |
434 | 9539e23d | Christos Stathis | @Override
|
435 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
436 | 9539e23d | Christos Stathis | app.sessionExpired(); |
437 | 9539e23d | Christos Stathis | } |
438 | 6d8e0f58 | Christos Stathis | }; |
439 | 6d8e0f58 | Christos Stathis | getFolder.setHeader("X-Auth-Token", app.getToken());
|
440 | 6d8e0f58 | Christos Stathis | Scheduler.get().scheduleDeferred(getFolder); |
441 | 6d8e0f58 | Christos Stathis | } |
442 | 7c54d867 | Christos Stathis | |
443 | 7c54d867 | Christos Stathis | public void initialize(Command callback) { |
444 | 7c54d867 | Christos Stathis | fetchSharingUsers(callback); |
445 | 7c54d867 | Christos Stathis | } |
446 | 6d8e0f58 | Christos Stathis | } |