Statistics
| Branch: | Tag: | Revision:

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

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