Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / othersharedtree / OtherSharedTreeViewModel.java @ cf027879

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