root / src / gr / grnet / pithos / web / client / othersharedtree / OtherSharedTreeViewModel.java @ 4eaecbac
History | View | Annotate | Download (14.1 kB)
1 | 6d8e0f58 | Christos Stathis | /*
|
---|---|---|---|
2 | cae2a8db | Christos Stathis | * Copyright 2011-2012 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 | 6d8e0f58 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Folder; |
43 | 6d8e0f58 | Christos Stathis | import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeView.Templates; |
44 | 6d8e0f58 | Christos Stathis | import gr.grnet.pithos.web.client.rest.GetRequest; |
45 | 6d8e0f58 | Christos Stathis | import gr.grnet.pithos.web.client.rest.RestException; |
46 | 6d8e0f58 | Christos Stathis | |
47 | 6d8e0f58 | Christos Stathis | import java.util.HashMap; |
48 | 6d8e0f58 | Christos Stathis | import java.util.Iterator; |
49 | 6d8e0f58 | Christos Stathis | import java.util.Map; |
50 | 6d8e0f58 | Christos Stathis | |
51 | 6d8e0f58 | Christos Stathis | import com.google.gwt.cell.client.AbstractCell; |
52 | 6d8e0f58 | Christos Stathis | import com.google.gwt.cell.client.Cell; |
53 | 6d8e0f58 | Christos Stathis | import com.google.gwt.cell.client.TextCell; |
54 | 6d8e0f58 | Christos Stathis | import com.google.gwt.cell.client.ValueUpdater; |
55 | 6d8e0f58 | Christos Stathis | import com.google.gwt.core.client.GWT; |
56 | 6d8e0f58 | Christos Stathis | import com.google.gwt.core.client.Scheduler; |
57 | 6d8e0f58 | Christos Stathis | import com.google.gwt.event.dom.client.ContextMenuEvent; |
58 | 9539e23d | Christos Stathis | import com.google.gwt.http.client.Response; |
59 | f5023f13 | Christos Stathis | import com.google.gwt.http.client.URL; |
60 | 6d8e0f58 | Christos Stathis | import com.google.gwt.safehtml.shared.SafeHtml; |
61 | 6d8e0f58 | Christos Stathis | import com.google.gwt.safehtml.shared.SafeHtmlBuilder; |
62 | 6d8e0f58 | Christos Stathis | import com.google.gwt.text.shared.SafeHtmlRenderer; |
63 | 6d8e0f58 | Christos Stathis | import com.google.gwt.user.client.Command; |
64 | 6d8e0f58 | Christos Stathis | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
65 | 6d8e0f58 | Christos Stathis | import com.google.gwt.view.client.ListDataProvider; |
66 | 6d8e0f58 | Christos Stathis | import com.google.gwt.view.client.SingleSelectionModel; |
67 | 6d8e0f58 | Christos Stathis | import com.google.gwt.view.client.TreeViewModel; |
68 | 6d8e0f58 | Christos Stathis | |
69 | 6d8e0f58 | Christos Stathis | public class OtherSharedTreeViewModel implements TreeViewModel { |
70 | 6d8e0f58 | Christos Stathis | |
71 | 6d8e0f58 | Christos Stathis | protected Pithos app;
|
72 | 6d8e0f58 | Christos Stathis | |
73 | 3f62b626 | Christos Stathis | String dummy = "No shares by others yet"; |
74 | 3f62b626 | Christos Stathis | |
75 | 6d8e0f58 | Christos Stathis | private Cell<Folder> folderCell = new AbstractCell<Folder>(ContextMenuEvent.getType().getName()) { |
76 | 6d8e0f58 | Christos Stathis | |
77 | 6d8e0f58 | Christos Stathis | @Override
|
78 | ebead1b5 | Christos Stathis | public void render(Context context, Folder folder, SafeHtmlBuilder safeHtmlBuilder) { |
79 | 6d8e0f58 | Christos Stathis | String html = AbstractImagePrototype.create(OtherSharedTreeView.images.folderYellow()).getHTML();
|
80 | 3f62b626 | Christos Stathis | safeHtmlBuilder.appendHtmlConstant(html).appendHtmlConstant(" ");
|
81 | 6d8e0f58 | Christos Stathis | safeHtmlBuilder.append(Templates.INSTANCE.nameSpan(folder.getName()));
|
82 | 6d8e0f58 | Christos Stathis | } |
83 | 6d8e0f58 | Christos Stathis | |
84 | 6d8e0f58 | Christos Stathis | @Override
|
85 | a2f617f8 | Christos Stathis | public void onBrowserEvent(Context context, com.google.gwt.dom.client.Element parent, final Folder folder, com.google.gwt.dom.client.NativeEvent event, ValueUpdater<Folder> valueUpdater) { |
86 | 6d8e0f58 | Christos Stathis | if (event.getType().equals(ContextMenuEvent.getType().getName())) {
|
87 | a2f617f8 | Christos Stathis | final int x = event.getClientX(); |
88 | a2f617f8 | Christos Stathis | final int y = event.getClientY(); |
89 | 6d8e0f58 | Christos Stathis | OtherSharedTreeViewModel.this.selectionModel.setSelected(folder, true);
|
90 | a2f617f8 | Christos Stathis | app.scheduleFolderHeadCommand(folder, new Command() {
|
91 | a2f617f8 | Christos Stathis | |
92 | a2f617f8 | Christos Stathis | @Override
|
93 | a2f617f8 | Christos Stathis | public void execute() { |
94 | a2f617f8 | Christos Stathis | FolderContextMenu menu = new FolderContextMenu(app, OtherSharedTreeView.images, app.getSelectedTree(), folder);
|
95 | a2f617f8 | Christos Stathis | menu.setPopupPosition(x, y); |
96 | a2f617f8 | Christos Stathis | menu.show(); |
97 | a2f617f8 | Christos Stathis | } |
98 | a2f617f8 | Christos Stathis | }); |
99 | 6d8e0f58 | Christos Stathis | } |
100 | 6d8e0f58 | Christos Stathis | } |
101 | 6d8e0f58 | Christos Stathis | }; |
102 | 6d8e0f58 | Christos Stathis | |
103 | 220831bd | Christos Stathis | protected ListDataProvider<String> userLevelDataProvider = new ListDataProvider<String>(); |
104 | 6d8e0f58 | Christos Stathis | |
105 | 220831bd | Christos Stathis | protected Map<String, ListDataProvider<Folder>> userDataProviderMap = new HashMap<String, ListDataProvider<Folder>>(); |
106 | 6d8e0f58 | Christos Stathis | private Map<Folder, ListDataProvider<Folder>> dataProviderMap = new HashMap<Folder, ListDataProvider<Folder>>(); |
107 | 220831bd | Christos Stathis | |
108 | 220831bd | Christos Stathis | protected SingleSelectionModel<Folder> selectionModel; |
109 | 6d8e0f58 | Christos Stathis | |
110 | 6d8e0f58 | Christos Stathis | public OtherSharedTreeViewModel(Pithos _app, SingleSelectionModel<Folder> selectionModel) { |
111 | 6d8e0f58 | Christos Stathis | app = _app; |
112 | 6d8e0f58 | Christos Stathis | this.selectionModel = selectionModel;
|
113 | 6d8e0f58 | Christos Stathis | } |
114 | 6d8e0f58 | Christos Stathis | |
115 | 6d8e0f58 | Christos Stathis | @Override
|
116 | 6d8e0f58 | Christos Stathis | public <T> NodeInfo<?> getNodeInfo(T value) {
|
117 | 6d8e0f58 | Christos Stathis | if (value == null) { |
118 | 7e8e9ff0 | Christos Stathis | fetchSharingUsers(null);
|
119 | 7e8e9ff0 | Christos Stathis | return new DefaultNodeInfo<String>(userLevelDataProvider, new TextCell(new SafeHtmlRenderer<String>() { |
120 | 7e8e9ff0 | Christos Stathis | |
121 | 7e8e9ff0 | Christos Stathis | @Override
|
122 | 7e8e9ff0 | Christos Stathis | public SafeHtml render(String object) { |
123 | 6d8e0f58 | Christos Stathis | SafeHtmlBuilder builder = new SafeHtmlBuilder();
|
124 | 6d8e0f58 | Christos Stathis | render(object, builder); |
125 | 6d8e0f58 | Christos Stathis | return builder.toSafeHtml();
|
126 | 7e8e9ff0 | Christos Stathis | } |
127 | 6d8e0f58 | Christos Stathis | |
128 | 7e8e9ff0 | Christos Stathis | @Override
|
129 | 7e8e9ff0 | Christos Stathis | public void render(String object, SafeHtmlBuilder builder) { |
130 | 3f62b626 | Christos Stathis | if (!object.equals(dummy)) {
|
131 | 3f62b626 | Christos Stathis | String html = AbstractImagePrototype.create(OtherSharedTreeView.images.myShared()).getHTML();
|
132 | 3f62b626 | Christos Stathis | builder.appendHtmlConstant(html).appendHtmlConstant(" ");
|
133 | 3f62b626 | Christos Stathis | } |
134 | 6d8e0f58 | Christos Stathis | builder.append(OtherSharedTreeView.Templates.INSTANCE.nameSpan(object)); |
135 | 7e8e9ff0 | Christos Stathis | } |
136 | 7e8e9ff0 | Christos Stathis | }), null, null); |
137 | 6d8e0f58 | Christos Stathis | } |
138 | 6d8e0f58 | Christos Stathis | else if (value instanceof String) { |
139 | 220831bd | Christos Stathis | String username = (String) value; |
140 | 220831bd | Christos Stathis | if (userDataProviderMap.get(username) == null) { |
141 | 220831bd | Christos Stathis | userDataProviderMap.put(username, new ListDataProvider<Folder>());
|
142 | 220831bd | Christos Stathis | } |
143 | 220831bd | Christos Stathis | final ListDataProvider<Folder> dataProvider = userDataProviderMap.get(username);
|
144 | 7c54d867 | Christos Stathis | fetchSharedContainers(username, dataProvider, null);
|
145 | 220831bd | Christos Stathis | return new DefaultNodeInfo<Folder>(dataProvider, folderCell, selectionModel, null); |
146 | 6d8e0f58 | Christos Stathis | } |
147 | 6d8e0f58 | Christos Stathis | else {
|
148 | 6d8e0f58 | Christos Stathis | final Folder f = (Folder) value;
|
149 | 6d8e0f58 | Christos Stathis | if (dataProviderMap.get(f) == null) { |
150 | 6d8e0f58 | Christos Stathis | dataProviderMap.put(f, new ListDataProvider<Folder>());
|
151 | 6d8e0f58 | Christos Stathis | } |
152 | 6d8e0f58 | Christos Stathis | final ListDataProvider<Folder> dataProvider = dataProviderMap.get(f);
|
153 | 3646552f | Christos Stathis | fetchFolder(f, dataProvider, false, null); |
154 | 6d8e0f58 | Christos Stathis | return new DefaultNodeInfo<Folder>(dataProvider, folderCell, selectionModel, null); |
155 | 6d8e0f58 | Christos Stathis | } |
156 | 6d8e0f58 | Christos Stathis | } |
157 | 6d8e0f58 | Christos Stathis | |
158 | 7c54d867 | Christos Stathis | private void fetchSharingUsers(final Command callback) { |
159 | 6d8e0f58 | Christos Stathis | GetRequest<SharingUsers> getSharingUsers = new GetRequest<SharingUsers>(SharingUsers.class, app.getApiPath(), "", "?format=json") { |
160 | 6d8e0f58 | Christos Stathis | @Override
|
161 | 7811b9d1 | Christos Stathis | public void onSuccess(final SharingUsers _result) { |
162 | 220831bd | Christos Stathis | userLevelDataProvider.getList().clear(); |
163 | 7811b9d1 | Christos Stathis | userLevelDataProvider.getList().addAll(_result.getUsers()); |
164 | 3f62b626 | Christos Stathis | if (userLevelDataProvider.getList().isEmpty())
|
165 | 3f62b626 | Christos Stathis | userLevelDataProvider.getList().add(dummy); |
166 | 7c54d867 | Christos Stathis | Iterator<String> iter = _result.getUsers().iterator(); |
167 | 7c54d867 | Christos Stathis | fetchSharedContainers(iter, callback); |
168 | 6d8e0f58 | Christos Stathis | } |
169 | 6d8e0f58 | Christos Stathis | |
170 | 6d8e0f58 | Christos Stathis | @Override
|
171 | 6d8e0f58 | Christos Stathis | public void onError(Throwable t) { |
172 | 6d8e0f58 | Christos Stathis | GWT.log("Error getting folder", t);
|
173 | 3f8622d4 | Christos Stathis | app.setError(t); |
174 | 6d8e0f58 | Christos Stathis | if (t instanceof RestException) |
175 | 6d8e0f58 | Christos Stathis | app.displayError("Error getting folder: " + ((RestException) t).getHttpStatusText());
|
176 | 6d8e0f58 | Christos Stathis | else
|
177 | 6d8e0f58 | Christos Stathis | app.displayError("System error fetching folder: " + t.getMessage());
|
178 | 6d8e0f58 | Christos Stathis | } |
179 | 9539e23d | Christos Stathis | |
180 | 9539e23d | Christos Stathis | @Override
|
181 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
182 | 9539e23d | Christos Stathis | app.sessionExpired(); |
183 | 9539e23d | Christos Stathis | } |
184 | 6d8e0f58 | Christos Stathis | }; |
185 | cc0120ab | Christos KK Loverdos | getSharingUsers.setHeader("X-Auth-Token", app.getUserToken());
|
186 | 6d8e0f58 | Christos Stathis | Scheduler.get().scheduleDeferred(getSharingUsers); |
187 | 6d8e0f58 | Christos Stathis | } |
188 | 6d8e0f58 | Christos Stathis | |
189 | 7c54d867 | Christos Stathis | protected void fetchSharedContainers(final Iterator<String> iter, final Command callback) { |
190 | 7c54d867 | Christos Stathis | if (iter.hasNext()) {
|
191 | 7c54d867 | Christos Stathis | String username = iter.next();
|
192 | 7c54d867 | Christos Stathis | if (userDataProviderMap.get(username) == null) { |
193 | 7c54d867 | Christos Stathis | userDataProviderMap.put(username, new ListDataProvider<Folder>());
|
194 | 7c54d867 | Christos Stathis | } |
195 | 7c54d867 | Christos Stathis | final ListDataProvider<Folder> dataProvider = userDataProviderMap.get(username);
|
196 | 7c54d867 | Christos Stathis | fetchSharedContainers(username, dataProvider, new Command() {
|
197 | 7c54d867 | Christos Stathis | |
198 | 7c54d867 | Christos Stathis | @Override
|
199 | 7c54d867 | Christos Stathis | public void execute() { |
200 | 7c54d867 | Christos Stathis | fetchSharedContainers(iter, callback); |
201 | 7c54d867 | Christos Stathis | |
202 | 7c54d867 | Christos Stathis | } |
203 | 7c54d867 | Christos Stathis | }); |
204 | 7c54d867 | Christos Stathis | } |
205 | 7c54d867 | Christos Stathis | else
|
206 | 7c54d867 | Christos Stathis | if (callback != null) |
207 | 7c54d867 | Christos Stathis | callback.execute(); |
208 | 7c54d867 | Christos Stathis | } |
209 | 7c54d867 | Christos Stathis | |
210 | 6d8e0f58 | Christos Stathis | @Override
|
211 | 6d8e0f58 | Christos Stathis | public boolean isLeaf(Object o) { |
212 | 7c54d867 | Christos Stathis | if (o == null) |
213 | cf027879 | Christos Stathis | return userLevelDataProvider.getList().isEmpty();
|
214 | 7c54d867 | Christos Stathis | else if (o instanceof Folder) { |
215 | 6d8e0f58 | Christos Stathis | Folder f = (Folder) o; |
216 | 6d8e0f58 | Christos Stathis | return f.getSubfolders().isEmpty();
|
217 | 6d8e0f58 | Christos Stathis | } |
218 | 7c54d867 | Christos Stathis | else {
|
219 | 7c54d867 | Christos Stathis | ListDataProvider<Folder> dp = userDataProviderMap.get(o); |
220 | 7c54d867 | Christos Stathis | if (dp != null) |
221 | 7c54d867 | Christos Stathis | return dp.getList().isEmpty();
|
222 | 7c54d867 | Christos Stathis | return true; |
223 | 7c54d867 | Christos Stathis | } |
224 | 6d8e0f58 | Christos Stathis | } |
225 | 6d8e0f58 | Christos Stathis | |
226 | 7c54d867 | Christos Stathis | private void fetchSharedContainers(final String username, final ListDataProvider<Folder> dataProvider, final Command callback) { |
227 | 220831bd | Christos Stathis | GetRequest<AccountResource> getUserSharedContainers = new GetRequest<AccountResource>(AccountResource.class, app.getApiPath(), username, "?format=json") { |
228 | 220831bd | Christos Stathis | |
229 | 220831bd | Christos Stathis | @Override
|
230 | 7811b9d1 | Christos Stathis | public void onSuccess(AccountResource _result) { |
231 | 220831bd | Christos Stathis | final ListDataProvider<Folder> tempProvider = new ListDataProvider<Folder>(); |
232 | 7811b9d1 | Christos Stathis | Iterator<Folder> iter = _result.getContainers().iterator();
|
233 | 220831bd | Christos Stathis | fetchFolder(username, iter, tempProvider, new Command() {
|
234 | 220831bd | Christos Stathis | |
235 | 220831bd | Christos Stathis | @Override
|
236 | 220831bd | Christos Stathis | public void execute() { |
237 | 220831bd | Christos Stathis | dataProvider.getList().clear(); |
238 | 220831bd | Christos Stathis | dataProvider.getList().addAll(tempProvider.getList()); |
239 | 7c54d867 | Christos Stathis | if (callback != null) |
240 | 7c54d867 | Christos Stathis | callback.execute(); |
241 | 220831bd | Christos Stathis | } |
242 | 220831bd | Christos Stathis | }); |
243 | 220831bd | Christos Stathis | } |
244 | 220831bd | Christos Stathis | |
245 | 220831bd | Christos Stathis | @Override
|
246 | 220831bd | Christos Stathis | public void onError(Throwable t) { |
247 | 220831bd | Christos Stathis | GWT.log("Error getting account", t);
|
248 | 3f8622d4 | Christos Stathis | app.setError(t); |
249 | 220831bd | Christos Stathis | if (t instanceof RestException) |
250 | 220831bd | Christos Stathis | app.displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
|
251 | 220831bd | Christos Stathis | else
|
252 | 220831bd | Christos Stathis | app.displayError("System error fetching user data: " + t.getMessage());
|
253 | 220831bd | Christos Stathis | } |
254 | 9539e23d | Christos Stathis | |
255 | 9539e23d | Christos Stathis | @Override
|
256 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
257 | 9539e23d | Christos Stathis | app.sessionExpired(); |
258 | 9539e23d | Christos Stathis | } |
259 | 220831bd | Christos Stathis | }; |
260 | cc0120ab | Christos KK Loverdos | getUserSharedContainers.setHeader("X-Auth-Token", app.getUserToken());
|
261 | 220831bd | Christos Stathis | Scheduler.get().scheduleDeferred(getUserSharedContainers); |
262 | 220831bd | Christos Stathis | } |
263 | 220831bd | Christos Stathis | |
264 | 220831bd | Christos Stathis | protected void fetchFolder(final String username, final Iterator<Folder> iter, final ListDataProvider<Folder> dataProvider, final Command callback) { |
265 | 6d8e0f58 | Christos Stathis | if (iter.hasNext()) {
|
266 | 6d8e0f58 | Christos Stathis | final Folder f = iter.next();
|
267 | 6d8e0f58 | Christos Stathis | |
268 | f5023f13 | Christos Stathis | String path = "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix()); |
269 | 220831bd | Christos Stathis | GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), username, path, f) {
|
270 | 6d8e0f58 | Christos Stathis | @Override
|
271 | 7811b9d1 | Christos Stathis | public void onSuccess(Folder _result) { |
272 | 2d0e60ee | Christos Stathis | dataProvider.getList().add(_result); |
273 | 2d0e60ee | Christos Stathis | fetchFolder(username, iter, dataProvider, callback); |
274 | 6d8e0f58 | Christos Stathis | } |
275 | 6d8e0f58 | Christos Stathis | |
276 | 6d8e0f58 | Christos Stathis | @Override
|
277 | 6d8e0f58 | Christos Stathis | public void onError(Throwable t) { |
278 | 6d8e0f58 | Christos Stathis | GWT.log("Error getting folder", t);
|
279 | 3f8622d4 | Christos Stathis | app.setError(t); |
280 | 6d8e0f58 | Christos Stathis | if (t instanceof RestException) |
281 | 6d8e0f58 | Christos Stathis | app.displayError("Error getting folder: " + ((RestException) t).getHttpStatusText());
|
282 | 6d8e0f58 | Christos Stathis | else
|
283 | 6d8e0f58 | Christos Stathis | app.displayError("System error fetching folder: " + t.getMessage());
|
284 | 6d8e0f58 | Christos Stathis | } |
285 | 9539e23d | Christos Stathis | |
286 | 9539e23d | Christos Stathis | @Override
|
287 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
288 | 9539e23d | Christos Stathis | app.sessionExpired(); |
289 | 9539e23d | Christos Stathis | } |
290 | 6d8e0f58 | Christos Stathis | }; |
291 | cc0120ab | Christos KK Loverdos | getFolder.setHeader("X-Auth-Token", app.getUserToken());
|
292 | 6d8e0f58 | Christos Stathis | Scheduler.get().scheduleDeferred(getFolder); |
293 | 6d8e0f58 | Christos Stathis | } |
294 | 6d8e0f58 | Christos Stathis | else if (callback != null) |
295 | 6d8e0f58 | Christos Stathis | callback.execute(); |
296 | 6d8e0f58 | Christos Stathis | } |
297 | 6d8e0f58 | Christos Stathis | |
298 | 6d8e0f58 | Christos Stathis | public Folder getSelection() {
|
299 | 6d8e0f58 | Christos Stathis | return selectionModel.getSelectedObject();
|
300 | 6d8e0f58 | Christos Stathis | } |
301 | 6d8e0f58 | Christos Stathis | |
302 | 3646552f | Christos Stathis | public void updateFolder(Folder folder, boolean showfiles, Command callback) { |
303 | 6d8e0f58 | Christos Stathis | if (dataProviderMap.get(folder) == null) { |
304 | 6d8e0f58 | Christos Stathis | dataProviderMap.put(folder, new ListDataProvider<Folder>());
|
305 | 6d8e0f58 | Christos Stathis | } |
306 | 6d8e0f58 | Christos Stathis | final ListDataProvider<Folder> dataProvider = dataProviderMap.get(folder);
|
307 | 3646552f | Christos Stathis | fetchFolder(folder, dataProvider, showfiles, callback); |
308 | 6d8e0f58 | Christos Stathis | } |
309 | 6d8e0f58 | Christos Stathis | |
310 | 3646552f | Christos Stathis | public void fetchFolder(final Folder f, final ListDataProvider<Folder> dataProvider, final boolean showfiles, final Command callback) { |
311 | f5023f13 | Christos Stathis | String path = "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix()); |
312 | 4eaecbac | Christos KK Loverdos | GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), f.getOwnerID(), path, f) {
|
313 | 6d8e0f58 | Christos Stathis | @Override
|
314 | 7811b9d1 | Christos Stathis | public void onSuccess(final Folder _result) { |
315 | 6d8e0f58 | Christos Stathis | if (showfiles)
|
316 | 7811b9d1 | Christos Stathis | app.showFiles(_result); |
317 | 7811b9d1 | Christos Stathis | Iterator<Folder> iter = _result.getSubfolders().iterator();
|
318 | 4eaecbac | Christos KK Loverdos | fetchFolder(_result.getOwnerID(), iter, dataProvider, new Command() {
|
319 | 6d8e0f58 | Christos Stathis | @Override
|
320 | 6d8e0f58 | Christos Stathis | public void execute() { |
321 | 6d8e0f58 | Christos Stathis | dataProvider.getList().clear(); |
322 | 7811b9d1 | Christos Stathis | dataProvider.getList().addAll(_result.getSubfolders()); |
323 | 6d8e0f58 | Christos Stathis | app.getOtherSharedTreeView().updateChildren(f); |
324 | 3646552f | Christos Stathis | if (callback != null) |
325 | 3646552f | Christos Stathis | callback.execute(); |
326 | 6d8e0f58 | Christos Stathis | } |
327 | 6d8e0f58 | Christos Stathis | }); |
328 | 6d8e0f58 | Christos Stathis | } |
329 | 6d8e0f58 | Christos Stathis | |
330 | 6d8e0f58 | Christos Stathis | @Override
|
331 | 6d8e0f58 | Christos Stathis | public void onError(Throwable t) { |
332 | 6d8e0f58 | Christos Stathis | GWT.log("Error getting folder", t);
|
333 | 3f8622d4 | Christos Stathis | app.setError(t); |
334 | 6d8e0f58 | Christos Stathis | if (t instanceof RestException) |
335 | 6d8e0f58 | Christos Stathis | app.displayError("Error getting folder: " + ((RestException) t).getHttpStatusText());
|
336 | 6d8e0f58 | Christos Stathis | else
|
337 | 6d8e0f58 | Christos Stathis | app.displayError("System error fetching folder: " + t.getMessage());
|
338 | 6d8e0f58 | Christos Stathis | } |
339 | 9539e23d | Christos Stathis | |
340 | 9539e23d | Christos Stathis | @Override
|
341 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
342 | 9539e23d | Christos Stathis | app.sessionExpired(); |
343 | 9539e23d | Christos Stathis | } |
344 | 6d8e0f58 | Christos Stathis | }; |
345 | cc0120ab | Christos KK Loverdos | getFolder.setHeader("X-Auth-Token", app.getUserToken());
|
346 | 6d8e0f58 | Christos Stathis | Scheduler.get().scheduleDeferred(getFolder); |
347 | 6d8e0f58 | Christos Stathis | } |
348 | 7c54d867 | Christos Stathis | |
349 | 7c54d867 | Christos Stathis | public void initialize(Command callback) { |
350 | 7c54d867 | Christos Stathis | fetchSharingUsers(callback); |
351 | 7c54d867 | Christos Stathis | } |
352 | 6d8e0f58 | Christos Stathis | } |