root / web_client / src / gr / grnet / pithos / web / client / Pithos.java @ 10791b56
History | View | Annotate | Download (31.5 kB)
1 | ab1eb3f8 | Christos Stathis | /*
|
---|---|---|---|
2 | 58777026 | Christos Stathis | * Copyright 2011 GRNET S.A. All rights reserved.
|
3 | 58777026 | Christos Stathis | *
|
4 | 58777026 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 58777026 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 58777026 | Christos Stathis | * conditions are met:
|
7 | 58777026 | Christos Stathis | *
|
8 | 58777026 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 58777026 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 58777026 | Christos Stathis | * disclaimer.
|
11 | 58777026 | Christos Stathis | *
|
12 | 58777026 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 58777026 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 58777026 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 58777026 | Christos Stathis | * provided with the distribution.
|
16 | 58777026 | Christos Stathis | *
|
17 | 58777026 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 58777026 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 58777026 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 58777026 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 58777026 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 58777026 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 58777026 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 58777026 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 58777026 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 58777026 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 58777026 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 58777026 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 58777026 | Christos Stathis | *
|
30 | 58777026 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 58777026 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 58777026 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 58777026 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | ab1eb3f8 | Christos Stathis | */
|
35 | ab1eb3f8 | Christos Stathis | package gr.grnet.pithos.web.client; |
36 | ab1eb3f8 | Christos Stathis | |
37 | 0ae83d19 | Christos Stathis | import gr.grnet.pithos.web.client.commands.UploadFileCommand; |
38 | 9e8e14e4 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.AccountResource; |
39 | fbff60ff | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.File; |
40 | 1ac430a1 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Folder; |
41 | 9e8e14e4 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.FolderTreeView; |
42 | 1ac430a1 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.FolderTreeViewModel; |
43 | 49df7570 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Resource; |
44 | 3331e8d8 | Christos Stathis | import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeView; |
45 | 3331e8d8 | Christos Stathis | import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeViewModel; |
46 | eee732d5 | Christos Stathis | import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeView; |
47 | eee732d5 | Christos Stathis | import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeViewModel; |
48 | 49df7570 | Christos Stathis | import gr.grnet.pithos.web.client.rest.DeleteRequest; |
49 | 9e8e14e4 | Christos Stathis | import gr.grnet.pithos.web.client.rest.GetRequest; |
50 | 33b61be6 | Christos Stathis | import gr.grnet.pithos.web.client.rest.PutRequest; |
51 | ab1eb3f8 | Christos Stathis | import gr.grnet.pithos.web.client.rest.RestException; |
52 | 860e552b | Christos Stathis | import gr.grnet.pithos.web.client.tagtree.Tag; |
53 | 860e552b | Christos Stathis | import gr.grnet.pithos.web.client.tagtree.TagTreeView; |
54 | 860e552b | Christos Stathis | import gr.grnet.pithos.web.client.tagtree.TagTreeViewModel; |
55 | 10791b56 | Christos Stathis | |
56 | ab1eb3f8 | Christos Stathis | import java.util.ArrayList; |
57 | ab1eb3f8 | Christos Stathis | import java.util.HashMap; |
58 | 1ac430a1 | Christos Stathis | import java.util.Iterator; |
59 | ab1eb3f8 | Christos Stathis | import java.util.List; |
60 | 10791b56 | Christos Stathis | import java.util.Set; |
61 | ab1eb3f8 | Christos Stathis | |
62 | ab1eb3f8 | Christos Stathis | import com.google.gwt.core.client.EntryPoint; |
63 | ab1eb3f8 | Christos Stathis | import com.google.gwt.core.client.GWT; |
64 | 10791b56 | Christos Stathis | import com.google.gwt.core.client.Scheduler; |
65 | 10791b56 | Christos Stathis | import com.google.gwt.core.client.Scheduler.ScheduledCommand; |
66 | 10791b56 | Christos Stathis | import com.google.gwt.event.dom.client.ClickEvent; |
67 | 10791b56 | Christos Stathis | import com.google.gwt.event.dom.client.ClickHandler; |
68 | ab1eb3f8 | Christos Stathis | import com.google.gwt.event.logical.shared.ResizeEvent; |
69 | ab1eb3f8 | Christos Stathis | import com.google.gwt.event.logical.shared.ResizeHandler; |
70 | 10791b56 | Christos Stathis | import com.google.gwt.http.client.Request; |
71 | 10791b56 | Christos Stathis | import com.google.gwt.http.client.RequestBuilder; |
72 | 10791b56 | Christos Stathis | import com.google.gwt.http.client.RequestCallback; |
73 | 10791b56 | Christos Stathis | import com.google.gwt.http.client.RequestException; |
74 | 10791b56 | Christos Stathis | import com.google.gwt.http.client.Response; |
75 | 10791b56 | Christos Stathis | import com.google.gwt.json.client.JSONArray; |
76 | 10791b56 | Christos Stathis | import com.google.gwt.json.client.JSONObject; |
77 | 10791b56 | Christos Stathis | import com.google.gwt.json.client.JSONParser; |
78 | 10791b56 | Christos Stathis | import com.google.gwt.json.client.JSONString; |
79 | 10791b56 | Christos Stathis | import com.google.gwt.json.client.JSONValue; |
80 | ab1eb3f8 | Christos Stathis | import com.google.gwt.resources.client.ImageResource; |
81 | 10791b56 | Christos Stathis | import com.google.gwt.user.client.Command; |
82 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.Cookies; |
83 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.Event; |
84 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.History; |
85 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.Window; |
86 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
87 | 10791b56 | Christos Stathis | import com.google.gwt.user.client.ui.Button; |
88 | 10791b56 | Christos Stathis | import com.google.gwt.user.client.ui.HTML; |
89 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
90 | 10791b56 | Christos Stathis | import com.google.gwt.user.client.ui.HasVerticalAlignment; |
91 | 10791b56 | Christos Stathis | import com.google.gwt.user.client.ui.HorizontalPanel; |
92 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.HorizontalSplitPanel; |
93 | 10791b56 | Christos Stathis | import com.google.gwt.user.client.ui.Image; |
94 | 10791b56 | Christos Stathis | import com.google.gwt.user.client.ui.PushButton; |
95 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.RootPanel; |
96 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.VerticalPanel; |
97 | 10791b56 | Christos Stathis | import com.google.gwt.view.client.SelectionChangeEvent; |
98 | 10791b56 | Christos Stathis | import com.google.gwt.view.client.SelectionChangeEvent.Handler; |
99 | 10791b56 | Christos Stathis | import com.google.gwt.view.client.SingleSelectionModel; |
100 | 9e8e14e4 | Christos Stathis | |
101 | ab1eb3f8 | Christos Stathis | /**
|
102 | ab1eb3f8 | Christos Stathis | * Entry point classes define <code>onModuleLoad()</code>.
|
103 | ab1eb3f8 | Christos Stathis | */
|
104 | f55cf326 | Christos Stathis | public class Pithos implements EntryPoint, ResizeHandler { |
105 | ab1eb3f8 | Christos Stathis | |
106 | 3331e8d8 | Christos Stathis | public static final String HOME_CONTAINER = "pithos"; |
107 | 3331e8d8 | Christos Stathis | |
108 | ab1eb3f8 | Christos Stathis | /**
|
109 | ab1eb3f8 | Christos Stathis | * Instantiate an application-level image bundle. This object will provide
|
110 | ab1eb3f8 | Christos Stathis | * programmatic access to all the images needed by widgets.
|
111 | ab1eb3f8 | Christos Stathis | */
|
112 | ab1eb3f8 | Christos Stathis | private static Images images = (Images) GWT.create(Images.class); |
113 | ab1eb3f8 | Christos Stathis | |
114 | 9e8e14e4 | Christos Stathis | public String getUsername() { |
115 | 9e8e14e4 | Christos Stathis | return username;
|
116 | 9e8e14e4 | Christos Stathis | } |
117 | ab1eb3f8 | Christos Stathis | |
118 | 5cd18037 | Christos Stathis | public void setAccount(AccountResource acct) { |
119 | 5cd18037 | Christos Stathis | account = acct; |
120 | 5cd18037 | Christos Stathis | } |
121 | 5cd18037 | Christos Stathis | |
122 | 5cd18037 | Christos Stathis | public AccountResource getAccount() {
|
123 | 5cd18037 | Christos Stathis | return account;
|
124 | 5cd18037 | Christos Stathis | } |
125 | 5cd18037 | Christos Stathis | |
126 | 19a73342 | Christos Stathis | public void updateFolder(Folder f, boolean showfiles) { |
127 | 19a73342 | Christos Stathis | folderTreeView.updateFolder(f, showfiles); |
128 | fa5600f7 | Christos Stathis | } |
129 | fa5600f7 | Christos Stathis | |
130 | 3331e8d8 | Christos Stathis | public void updateSharedFolder(Folder f, boolean showfiles) { |
131 | 3331e8d8 | Christos Stathis | mysharedTreeView.updateFolder(f, showfiles); |
132 | 3331e8d8 | Christos Stathis | } |
133 | 3331e8d8 | Christos Stathis | |
134 | eee732d5 | Christos Stathis | public void updateOtherSharedFolder(Folder f, boolean showfiles) { |
135 | eee732d5 | Christos Stathis | otherSharedTreeView.updateFolder(f, showfiles); |
136 | eee732d5 | Christos Stathis | } |
137 | eee732d5 | Christos Stathis | |
138 | ba0078a6 | Christos Stathis | public void updateTag(Tag t) { |
139 | ba0078a6 | Christos Stathis | tagTreeView.updateTag(t); |
140 | ba0078a6 | Christos Stathis | } |
141 | ba0078a6 | Christos Stathis | |
142 | ba0078a6 | Christos Stathis | public void updateTags() { |
143 | a39e5b47 | Christos Stathis | tagTreeViewModel.initialize(getAllTags()); |
144 | a39e5b47 | Christos Stathis | } |
145 | a39e5b47 | Christos Stathis | |
146 | a39e5b47 | Christos Stathis | public List<Tag> getAllTags() { |
147 | a39e5b47 | Christos Stathis | List<Tag> tagList = new ArrayList<Tag>(); |
148 | a39e5b47 | Christos Stathis | for (Folder f : account.getContainers()) {
|
149 | a39e5b47 | Christos Stathis | for (String t : f.getTags()) { |
150 | a39e5b47 | Christos Stathis | tagList.add(new Tag(t));
|
151 | a39e5b47 | Christos Stathis | } |
152 | a39e5b47 | Christos Stathis | } |
153 | a39e5b47 | Christos Stathis | return tagList;
|
154 | ba0078a6 | Christos Stathis | } |
155 | ba0078a6 | Christos Stathis | |
156 | 3331e8d8 | Christos Stathis | public MysharedTreeView getMySharedTreeView() {
|
157 | 3331e8d8 | Christos Stathis | return mysharedTreeView;
|
158 | 3331e8d8 | Christos Stathis | } |
159 | 3331e8d8 | Christos Stathis | |
160 | 9e8e14e4 | Christos Stathis | /**
|
161 | ab1eb3f8 | Christos Stathis | * An aggregate image bundle that pulls together all the images for this
|
162 | ab1eb3f8 | Christos Stathis | * application into a single bundle.
|
163 | ab1eb3f8 | Christos Stathis | */
|
164 | 10791b56 | Christos Stathis | public interface Images extends TopPanel.Images, FileList.Images { |
165 | ab1eb3f8 | Christos Stathis | |
166 | ab1eb3f8 | Christos Stathis | @Source("gr/grnet/pithos/resources/document.png") |
167 | ab1eb3f8 | Christos Stathis | ImageResource folders(); |
168 | ab1eb3f8 | Christos Stathis | |
169 | ab1eb3f8 | Christos Stathis | @Source("gr/grnet/pithos/resources/edit_group_22.png") |
170 | ab1eb3f8 | Christos Stathis | ImageResource groups(); |
171 | ab1eb3f8 | Christos Stathis | |
172 | ab1eb3f8 | Christos Stathis | @Source("gr/grnet/pithos/resources/search.png") |
173 | ab1eb3f8 | Christos Stathis | ImageResource search(); |
174 | ab1eb3f8 | Christos Stathis | } |
175 | ab1eb3f8 | Christos Stathis | |
176 | ab1eb3f8 | Christos Stathis | /**
|
177 | ab1eb3f8 | Christos Stathis | * The Application Clipboard implementation;
|
178 | ab1eb3f8 | Christos Stathis | */
|
179 | ab1eb3f8 | Christos Stathis | private Clipboard clipboard = new Clipboard(); |
180 | ab1eb3f8 | Christos Stathis | |
181 | ab1eb3f8 | Christos Stathis | /**
|
182 | ab1eb3f8 | Christos Stathis | * The top panel that contains the menu bar.
|
183 | ab1eb3f8 | Christos Stathis | */
|
184 | ab1eb3f8 | Christos Stathis | private TopPanel topPanel;
|
185 | ab1eb3f8 | Christos Stathis | |
186 | ab1eb3f8 | Christos Stathis | /**
|
187 | ab1eb3f8 | Christos Stathis | * The panel that contains the various system messages.
|
188 | ab1eb3f8 | Christos Stathis | */
|
189 | f55cf326 | Christos Stathis | private MessagePanel messagePanel = new MessagePanel(Pithos.images); |
190 | ab1eb3f8 | Christos Stathis | |
191 | ab1eb3f8 | Christos Stathis | /**
|
192 | ab1eb3f8 | Christos Stathis | * The bottom panel that contains the status bar.
|
193 | ab1eb3f8 | Christos Stathis | */
|
194 | 5cd18037 | Christos Stathis | private StatusPanel statusPanel = null; |
195 | ab1eb3f8 | Christos Stathis | |
196 | ab1eb3f8 | Christos Stathis | /**
|
197 | ab1eb3f8 | Christos Stathis | * The file list widget.
|
198 | ab1eb3f8 | Christos Stathis | */
|
199 | ab1eb3f8 | Christos Stathis | private FileList fileList;
|
200 | ab1eb3f8 | Christos Stathis | |
201 | ab1eb3f8 | Christos Stathis | /**
|
202 | ab1eb3f8 | Christos Stathis | * The tab panel that occupies the right side of the screen.
|
203 | ab1eb3f8 | Christos Stathis | */
|
204 | 0ae83d19 | Christos Stathis | private VerticalPanel inner = new VerticalPanel(); |
205 | ab1eb3f8 | Christos Stathis | |
206 | 58777026 | Christos Stathis | |
207 | ab1eb3f8 | Christos Stathis | /**
|
208 | ab1eb3f8 | Christos Stathis | * The split panel that will contain the left and right panels.
|
209 | ab1eb3f8 | Christos Stathis | */
|
210 | ab1eb3f8 | Christos Stathis | private HorizontalSplitPanel splitPanel = new HorizontalSplitPanel(); |
211 | ab1eb3f8 | Christos Stathis | |
212 | ab1eb3f8 | Christos Stathis | /**
|
213 | ab1eb3f8 | Christos Stathis | * The currently selected item in the application, for use by the Edit menu
|
214 | ab1eb3f8 | Christos Stathis | * commands. Potential types are Folder, File, User and Group.
|
215 | ab1eb3f8 | Christos Stathis | */
|
216 | ab1eb3f8 | Christos Stathis | private Object currentSelection; |
217 | ab1eb3f8 | Christos Stathis | |
218 | ab1eb3f8 | Christos Stathis | |
219 | ab1eb3f8 | Christos Stathis | /**
|
220 | ab1eb3f8 | Christos Stathis | * The WebDAV password of the current user
|
221 | ab1eb3f8 | Christos Stathis | */
|
222 | ab1eb3f8 | Christos Stathis | private String webDAVPassword; |
223 | ab1eb3f8 | Christos Stathis | |
224 | ab1eb3f8 | Christos Stathis | public HashMap<String, String> userFullNameMap = new HashMap<String, String>(); |
225 | ab1eb3f8 | Christos Stathis | |
226 | 9e8e14e4 | Christos Stathis | private String username = null; |
227 | 9e8e14e4 | Christos Stathis | |
228 | 9e8e14e4 | Christos Stathis | /**
|
229 | 9e8e14e4 | Christos Stathis | * The authentication token of the current user.
|
230 | 9e8e14e4 | Christos Stathis | */
|
231 | 9e8e14e4 | Christos Stathis | private String token; |
232 | 9e8e14e4 | Christos Stathis | |
233 | 10791b56 | Christos Stathis | protected SingleSelectionModel<Folder> folderTreeSelectionModel; |
234 | 10791b56 | Christos Stathis | protected FolderTreeViewModel folderTreeViewModel;
|
235 | 10791b56 | Christos Stathis | protected FolderTreeView folderTreeView;
|
236 | 9e8e14e4 | Christos Stathis | |
237 | 10791b56 | Christos Stathis | protected SingleSelectionModel<Folder> mysharedTreeSelectionModel; |
238 | 3331e8d8 | Christos Stathis | private MysharedTreeViewModel mysharedTreeViewModel;
|
239 | 3331e8d8 | Christos Stathis | private MysharedTreeView mysharedTreeView;
|
240 | 3331e8d8 | Christos Stathis | |
241 | 10791b56 | Christos Stathis | protected SingleSelectionModel<Folder> otherSharedTreeSelectionModel; |
242 | eee732d5 | Christos Stathis | private OtherSharedTreeViewModel otherSharedTreeViewModel;
|
243 | eee732d5 | Christos Stathis | private OtherSharedTreeView otherSharedTreeView;
|
244 | eee732d5 | Christos Stathis | |
245 | 10791b56 | Christos Stathis | protected SingleSelectionModel<Tag> tagTreeSelectionModel; |
246 | 860e552b | Christos Stathis | private TagTreeViewModel tagTreeViewModel;
|
247 | 860e552b | Christos Stathis | private TagTreeView tagTreeView;
|
248 | 860e552b | Christos Stathis | |
249 | 10791b56 | Christos Stathis | protected AccountResource account;
|
250 | 5cd18037 | Christos Stathis | |
251 | 10791b56 | Christos Stathis | @SuppressWarnings("rawtypes") |
252 | 10791b56 | Christos Stathis | private List<SingleSelectionModel> selectionModels = new ArrayList<SingleSelectionModel>(); |
253 | 3331e8d8 | Christos Stathis | |
254 | ab1eb3f8 | Christos Stathis | @Override
|
255 | ab1eb3f8 | Christos Stathis | public void onModuleLoad() { |
256 | 9e8e14e4 | Christos Stathis | if (parseUserCredentials())
|
257 | 9e8e14e4 | Christos Stathis | initialize(); |
258 | 9e8e14e4 | Christos Stathis | } |
259 | ab1eb3f8 | Christos Stathis | |
260 | 9e8e14e4 | Christos Stathis | private void initialize() { |
261 | 0ae83d19 | Christos Stathis | VerticalPanel outer = new VerticalPanel();
|
262 | 0ae83d19 | Christos Stathis | outer.setWidth("100%");
|
263 | 0ae83d19 | Christos Stathis | |
264 | e9c9f408 | Christos Stathis | topPanel = new TopPanel(this, Pithos.images); |
265 | 9e8e14e4 | Christos Stathis | topPanel.setWidth("100%");
|
266 | 0ae83d19 | Christos Stathis | outer.add(topPanel); |
267 | 9e8e14e4 | Christos Stathis | |
268 | 9e8e14e4 | Christos Stathis | messagePanel.setWidth("100%");
|
269 | 9e8e14e4 | Christos Stathis | messagePanel.setVisible(false);
|
270 | 0ae83d19 | Christos Stathis | outer.add(messagePanel); |
271 | 0ae83d19 | Christos Stathis | outer.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER); |
272 | ab1eb3f8 | Christos Stathis | |
273 | 9e8e14e4 | Christos Stathis | |
274 | 9e8e14e4 | Christos Stathis | // Inner contains the various lists.
|
275 | 9e8e14e4 | Christos Stathis | inner.sinkEvents(Event.ONCONTEXTMENU);
|
276 | 9e8e14e4 | Christos Stathis | inner.setWidth("100%");
|
277 | 9e8e14e4 | Christos Stathis | |
278 | 0ae83d19 | Christos Stathis | HorizontalPanel rightside = new HorizontalPanel();
|
279 | 0ae83d19 | Christos Stathis | rightside.addStyleName("pithos-rightSide");
|
280 | 0ae83d19 | Christos Stathis | rightside.setSpacing(5);
|
281 | 9e8e14e4 | Christos Stathis | |
282 | 0ae83d19 | Christos Stathis | PushButton parentButton = new PushButton(new Image(images.asc()), new ClickHandler() { |
283 | 9e8e14e4 | Christos Stathis | @Override
|
284 | 10791b56 | Christos Stathis | public void onClick(@SuppressWarnings("unused") ClickEvent event) { |
285 | 0ae83d19 | Christos Stathis | |
286 | 9e8e14e4 | Christos Stathis | } |
287 | 9e8e14e4 | Christos Stathis | }); |
288 | 0ae83d19 | Christos Stathis | parentButton.addStyleName("pithos-parentButton");
|
289 | 0ae83d19 | Christos Stathis | rightside.add(parentButton); |
290 | 0ae83d19 | Christos Stathis | |
291 | 0ae83d19 | Christos Stathis | HTML folderStatistics = new HTML("5 Files (size: 1.1GB)"); |
292 | 0ae83d19 | Christos Stathis | folderStatistics.addStyleName("pithos-folderStatistics");
|
293 | 0ae83d19 | Christos Stathis | rightside.add(folderStatistics); |
294 | 0ae83d19 | Christos Stathis | inner.add(rightside); |
295 | 0ae83d19 | Christos Stathis | inner.setCellHorizontalAlignment(rightside, HasHorizontalAlignment.ALIGN_RIGHT); |
296 | 0ae83d19 | Christos Stathis | inner.setCellVerticalAlignment(rightside, HasVerticalAlignment.ALIGN_MIDDLE); |
297 | 0ae83d19 | Christos Stathis | inner.setCellHeight(rightside, "60px");
|
298 | 9e8e14e4 | Christos Stathis | |
299 | fbff60ff | Christos Stathis | folderTreeSelectionModel = new SingleSelectionModel<Folder>(); |
300 | fbff60ff | Christos Stathis | folderTreeSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
|
301 | fbff60ff | Christos Stathis | @Override
|
302 | 10791b56 | Christos Stathis | public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) { |
303 | 3da18014 | Christos Stathis | if (folderTreeSelectionModel.getSelectedObject() != null) { |
304 | 3331e8d8 | Christos Stathis | deselectOthers(folderTreeSelectionModel); |
305 | 3da18014 | Christos Stathis | Folder f = folderTreeSelectionModel.getSelectedObject(); |
306 | 19a73342 | Christos Stathis | updateFolder(f, true);
|
307 | 3da18014 | Christos Stathis | } |
308 | fbff60ff | Christos Stathis | } |
309 | fbff60ff | Christos Stathis | }); |
310 | 3331e8d8 | Christos Stathis | selectionModels.add(folderTreeSelectionModel); |
311 | fbff60ff | Christos Stathis | |
312 | e9c9f408 | Christos Stathis | folderTreeViewModel = new FolderTreeViewModel(this, folderTreeSelectionModel); |
313 | fbff60ff | Christos Stathis | folderTreeView = new FolderTreeView(folderTreeViewModel);
|
314 | fbff60ff | Christos Stathis | |
315 | e9c9f408 | Christos Stathis | fileList = new FileList(this, images, folderTreeView); |
316 | 0ae83d19 | Christos Stathis | inner.add(fileList); |
317 | fbff60ff | Christos Stathis | |
318 | 3331e8d8 | Christos Stathis | mysharedTreeSelectionModel = new SingleSelectionModel<Folder>(); |
319 | 3331e8d8 | Christos Stathis | mysharedTreeSelectionModel.addSelectionChangeHandler(new Handler() { |
320 | 3331e8d8 | Christos Stathis | @Override
|
321 | 10791b56 | Christos Stathis | public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) { |
322 | 3331e8d8 | Christos Stathis | if (mysharedTreeSelectionModel.getSelectedObject() != null) { |
323 | 3331e8d8 | Christos Stathis | deselectOthers(mysharedTreeSelectionModel); |
324 | 3331e8d8 | Christos Stathis | updateSharedFolder(mysharedTreeSelectionModel.getSelectedObject(), true);
|
325 | 3331e8d8 | Christos Stathis | } |
326 | 3331e8d8 | Christos Stathis | } |
327 | 3331e8d8 | Christos Stathis | }); |
328 | 3331e8d8 | Christos Stathis | selectionModels.add(mysharedTreeSelectionModel); |
329 | 3331e8d8 | Christos Stathis | mysharedTreeViewModel = new MysharedTreeViewModel(this, mysharedTreeSelectionModel); |
330 | 3331e8d8 | Christos Stathis | mysharedTreeView = new MysharedTreeView(mysharedTreeViewModel);
|
331 | 3331e8d8 | Christos Stathis | |
332 | eee732d5 | Christos Stathis | otherSharedTreeSelectionModel = new SingleSelectionModel<Folder>(); |
333 | eee732d5 | Christos Stathis | otherSharedTreeSelectionModel.addSelectionChangeHandler(new Handler() { |
334 | eee732d5 | Christos Stathis | @Override
|
335 | 10791b56 | Christos Stathis | public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) { |
336 | eee732d5 | Christos Stathis | if (otherSharedTreeSelectionModel.getSelectedObject() != null) { |
337 | eee732d5 | Christos Stathis | deselectOthers(otherSharedTreeSelectionModel); |
338 | eee732d5 | Christos Stathis | updateOtherSharedFolder(otherSharedTreeSelectionModel.getSelectedObject(), true);
|
339 | eee732d5 | Christos Stathis | } |
340 | eee732d5 | Christos Stathis | } |
341 | eee732d5 | Christos Stathis | }); |
342 | eee732d5 | Christos Stathis | selectionModels.add(otherSharedTreeSelectionModel); |
343 | eee732d5 | Christos Stathis | otherSharedTreeViewModel = new OtherSharedTreeViewModel(this, otherSharedTreeSelectionModel); |
344 | eee732d5 | Christos Stathis | otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel);
|
345 | eee732d5 | Christos Stathis | |
346 | 860e552b | Christos Stathis | tagTreeSelectionModel = new SingleSelectionModel<Tag>(); |
347 | ba0078a6 | Christos Stathis | tagTreeSelectionModel.addSelectionChangeHandler(new Handler() { |
348 | ba0078a6 | Christos Stathis | @Override
|
349 | 10791b56 | Christos Stathis | public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) { |
350 | 3da18014 | Christos Stathis | if (tagTreeSelectionModel.getSelectedObject() != null) { |
351 | 3331e8d8 | Christos Stathis | deselectOthers(tagTreeSelectionModel); |
352 | 3da18014 | Christos Stathis | Tag t = tagTreeSelectionModel.getSelectedObject(); |
353 | 3da18014 | Christos Stathis | updateTag(t); |
354 | 3da18014 | Christos Stathis | } |
355 | ba0078a6 | Christos Stathis | } |
356 | ba0078a6 | Christos Stathis | }); |
357 | 3331e8d8 | Christos Stathis | selectionModels.add(tagTreeSelectionModel); |
358 | e9c9f408 | Christos Stathis | tagTreeViewModel = new TagTreeViewModel(this, tagTreeSelectionModel); |
359 | 860e552b | Christos Stathis | tagTreeView = new TagTreeView(tagTreeViewModel);
|
360 | ba0078a6 | Christos Stathis | |
361 | 860e552b | Christos Stathis | VerticalPanel trees = new VerticalPanel();
|
362 | 0ae83d19 | Christos Stathis | |
363 | 0ae83d19 | Christos Stathis | Button upload = new Button("Upload File", new ClickHandler() { |
364 | 0ae83d19 | Christos Stathis | @Override
|
365 | 10791b56 | Christos Stathis | public void onClick(@SuppressWarnings("unused") ClickEvent event) { |
366 | 0ae83d19 | Christos Stathis | new UploadFileCommand(Pithos.this, null, folderTreeView.getSelection()).execute(); |
367 | 0ae83d19 | Christos Stathis | } |
368 | 0ae83d19 | Christos Stathis | }); |
369 | 0ae83d19 | Christos Stathis | upload.addStyleName("pithos-uploadButton");
|
370 | 0ae83d19 | Christos Stathis | trees.add(upload); |
371 | 0ae83d19 | Christos Stathis | |
372 | 0ae83d19 | Christos Stathis | HorizontalPanel treeHeader = new HorizontalPanel();
|
373 | 0ae83d19 | Christos Stathis | treeHeader.addStyleName("pithos-treeHeader");
|
374 | 0ae83d19 | Christos Stathis | treeHeader.add(new HTML("Total Files: 6 | Used: 2.1 of 50 GB (4.2%)")); |
375 | 0ae83d19 | Christos Stathis | trees.add(treeHeader); |
376 | 0ae83d19 | Christos Stathis | |
377 | 860e552b | Christos Stathis | trees.add(folderTreeView); |
378 | 3331e8d8 | Christos Stathis | trees.add(mysharedTreeView); |
379 | eee732d5 | Christos Stathis | trees.add(otherSharedTreeView); |
380 | 3331e8d8 | Christos Stathis | // trees.add(tagTreeView);
|
381 | 9e8e14e4 | Christos Stathis | // Add the left and right panels to the split panel.
|
382 | 860e552b | Christos Stathis | splitPanel.setLeftWidget(trees); |
383 | 9e8e14e4 | Christos Stathis | splitPanel.setRightWidget(inner); |
384 | 9e8e14e4 | Christos Stathis | splitPanel.setSplitPosition("25%");
|
385 | 9e8e14e4 | Christos Stathis | splitPanel.setSize("100%", "100%"); |
386 | 9e8e14e4 | Christos Stathis | splitPanel.addStyleName("pithos-splitPanel");
|
387 | 9e8e14e4 | Christos Stathis | outer.add(splitPanel); |
388 | 0ae83d19 | Christos Stathis | |
389 | aff7a7bf | Christos Stathis | statusPanel = new StatusPanel();
|
390 | 9e8e14e4 | Christos Stathis | outer.add(statusPanel); |
391 | 0ae83d19 | Christos Stathis | |
392 | 9e8e14e4 | Christos Stathis | |
393 | 9e8e14e4 | Christos Stathis | // Hook the window resize event, so that we can adjust the UI.
|
394 | 9e8e14e4 | Christos Stathis | Window.addResizeHandler(this); |
395 | 9e8e14e4 | Christos Stathis | // Clear out the window's built-in margin, because we want to take
|
396 | 9e8e14e4 | Christos Stathis | // advantage of the entire client area.
|
397 | 9e8e14e4 | Christos Stathis | Window.setMargin("0px"); |
398 | 9e8e14e4 | Christos Stathis | // Finally, add the outer panel to the RootPanel, so that it will be
|
399 | 9e8e14e4 | Christos Stathis | // displayed.
|
400 | 9e8e14e4 | Christos Stathis | RootPanel.get().add(outer); |
401 | 9e8e14e4 | Christos Stathis | // Call the window resized handler to get the initial sizes setup. Doing
|
402 | 9e8e14e4 | Christos Stathis | // this in a deferred command causes it to occur after all widgets'
|
403 | 9e8e14e4 | Christos Stathis | // sizes have been computed by the browser.
|
404 | 1ac430a1 | Christos Stathis | Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
405 | 9e8e14e4 | Christos Stathis | |
406 | 9e8e14e4 | Christos Stathis | @Override
|
407 | 9e8e14e4 | Christos Stathis | public void execute() { |
408 | 9e8e14e4 | Christos Stathis | onWindowResized(Window.getClientHeight());
|
409 | 9e8e14e4 | Christos Stathis | } |
410 | 9e8e14e4 | Christos Stathis | }); |
411 | 1ac430a1 | Christos Stathis | |
412 | 1ac430a1 | Christos Stathis | Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
413 | 1ac430a1 | Christos Stathis | @Override
|
414 | 1ac430a1 | Christos Stathis | public void execute() { |
415 | 1ac430a1 | Christos Stathis | fetchAccount(); |
416 | 1ac430a1 | Christos Stathis | } |
417 | 1ac430a1 | Christos Stathis | }); |
418 | 9e8e14e4 | Christos Stathis | } |
419 | ab1eb3f8 | Christos Stathis | |
420 | 10791b56 | Christos Stathis | @SuppressWarnings({ "rawtypes", "unchecked" }) |
421 | 10791b56 | Christos Stathis | public void deselectOthers(SingleSelectionModel model) { |
422 | 3331e8d8 | Christos Stathis | for (SingleSelectionModel s : selectionModels) |
423 | 3331e8d8 | Christos Stathis | if (!s.equals(model))
|
424 | 3331e8d8 | Christos Stathis | s.setSelected(s.getSelectedObject(), false);
|
425 | 3331e8d8 | Christos Stathis | } |
426 | 3331e8d8 | Christos Stathis | |
427 | 26cbae7a | Christos Stathis | public void showFiles(Folder f) { |
428 | 0bc032bf | Christos Stathis | Set<File> files = f.getFiles(); |
429 | 3da18014 | Christos Stathis | showFiles(files); |
430 | 3da18014 | Christos Stathis | } |
431 | 3da18014 | Christos Stathis | |
432 | 3da18014 | Christos Stathis | public void showFiles(Set<File> files) { |
433 | 3da18014 | Christos Stathis | //Iterator<File> iter = files.iterator();
|
434 | 3da18014 | Christos Stathis | //fetchFile(iter, files);
|
435 | 3da18014 | Christos Stathis | fileList.setFiles(new ArrayList<File>(files)); |
436 | 0bc032bf | Christos Stathis | } |
437 | 0bc032bf | Christos Stathis | |
438 | 10791b56 | Christos Stathis | protected void fetchFile(final Iterator<File> iter, final Set<File> files) { |
439 | 0bc032bf | Christos Stathis | if (iter.hasNext()) {
|
440 | 0bc032bf | Christos Stathis | File file = iter.next();
|
441 | 12190a0c | Christos Stathis | String path = file.getUri() + "?format=json"; |
442 | 12190a0c | Christos Stathis | GetRequest<File> getFile = new GetRequest<File>(File.class, getApiPath(), username, path, file) { |
443 | 0bc032bf | Christos Stathis | @Override
|
444 | 10791b56 | Christos Stathis | public void onSuccess(@SuppressWarnings("unused") File _result) { |
445 | 0bc032bf | Christos Stathis | fetchFile(iter, files); |
446 | 0bc032bf | Christos Stathis | } |
447 | 0bc032bf | Christos Stathis | |
448 | 0bc032bf | Christos Stathis | @Override
|
449 | 0bc032bf | Christos Stathis | public void onError(Throwable t) { |
450 | 0bc032bf | Christos Stathis | GWT.log("Error getting file", t);
|
451 | 0bc032bf | Christos Stathis | if (t instanceof RestException) |
452 | e9c9f408 | Christos Stathis | displayError("Error getting file: " + ((RestException) t).getHttpStatusText());
|
453 | 0bc032bf | Christos Stathis | else
|
454 | e9c9f408 | Christos Stathis | displayError("System error fetching file: " + t.getMessage());
|
455 | 0bc032bf | Christos Stathis | } |
456 | 0bc032bf | Christos Stathis | }; |
457 | 0bc032bf | Christos Stathis | getFile.setHeader("X-Auth-Token", "0000"); |
458 | 0bc032bf | Christos Stathis | Scheduler.get().scheduleDeferred(getFile); |
459 | 0bc032bf | Christos Stathis | } |
460 | 0bc032bf | Christos Stathis | else
|
461 | 0bc032bf | Christos Stathis | fileList.setFiles(new ArrayList<File>(files)); |
462 | fbff60ff | Christos Stathis | } |
463 | fbff60ff | Christos Stathis | |
464 | fbff60ff | Christos Stathis | /**
|
465 | ab1eb3f8 | Christos Stathis | * Parse and store the user credentials to the appropriate fields.
|
466 | ab1eb3f8 | Christos Stathis | */
|
467 | 9e8e14e4 | Christos Stathis | private boolean parseUserCredentials() { |
468 | aff7a7bf | Christos Stathis | username = Window.Location.getParameter("user"); |
469 | aff7a7bf | Christos Stathis | token = Window.Location.getParameter("token"); |
470 | aff7a7bf | Christos Stathis | Configuration conf = (Configuration) GWT.create(Configuration.class); |
471 | aff7a7bf | Christos Stathis | if (username == null || username.length() == 0 || token == null || token.length() == 0) { |
472 | aff7a7bf | Christos Stathis | String cookie = conf.authCookie();
|
473 | aff7a7bf | Christos Stathis | String auth = Cookies.getCookie(cookie);
|
474 | aff7a7bf | Christos Stathis | if (auth == null) { |
475 | 9e8e14e4 | Christos Stathis | authenticateUser(); |
476 | 9e8e14e4 | Christos Stathis | return false; |
477 | 9e8e14e4 | Christos Stathis | } |
478 | 10791b56 | Christos Stathis | String[] authSplit = auth.split("\\" + conf.cookieSeparator(), 2); |
479 | 10791b56 | Christos Stathis | if (authSplit.length != 2) { |
480 | 10791b56 | Christos Stathis | authenticateUser(); |
481 | 10791b56 | Christos Stathis | return false; |
482 | 10791b56 | Christos Stathis | } |
483 | 10791b56 | Christos Stathis | username = authSplit[0];
|
484 | 10791b56 | Christos Stathis | token = authSplit[1];
|
485 | 10791b56 | Christos Stathis | return true; |
486 | aff7a7bf | Christos Stathis | } |
487 | 10791b56 | Christos Stathis | Cookies.setCookie(conf.authCookie(), username + conf.cookieSeparator() + token); |
488 | 10791b56 | Christos Stathis | return true; |
489 | aff7a7bf | Christos Stathis | } |
490 | ab1eb3f8 | Christos Stathis | |
491 | 9e8e14e4 | Christos Stathis | /**
|
492 | ab1eb3f8 | Christos Stathis | * Redirect the user to the login page for authentication.
|
493 | ab1eb3f8 | Christos Stathis | */
|
494 | ab1eb3f8 | Christos Stathis | protected void authenticateUser() { |
495 | 9e8e14e4 | Christos Stathis | Configuration conf = (Configuration) GWT.create(Configuration.class); |
496 | aff7a7bf | Christos Stathis | Window.Location.assign(Window.Location.getHost() + conf.loginUrl() + "?next=" + Window.Location.getHref()); |
497 | ab1eb3f8 | Christos Stathis | } |
498 | ab1eb3f8 | Christos Stathis | |
499 | 10791b56 | Christos Stathis | protected void fetchAccount() { |
500 | 12190a0c | Christos Stathis | String path = "?format=json"; |
501 | 1ac430a1 | Christos Stathis | |
502 | 12190a0c | Christos Stathis | GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, getApiPath(), username, path) {
|
503 | 1ac430a1 | Christos Stathis | @Override
|
504 | 10791b56 | Christos Stathis | public void onSuccess(AccountResource _result) { |
505 | 10791b56 | Christos Stathis | account = _result; |
506 | 2996f218 | Christos Stathis | if (account.getContainers().isEmpty())
|
507 | 2996f218 | Christos Stathis | createHomeContainers(); |
508 | 3331e8d8 | Christos Stathis | else {
|
509 | 2996f218 | Christos Stathis | folderTreeViewModel.initialize(account); |
510 | 3331e8d8 | Christos Stathis | } |
511 | 1ac430a1 | Christos Stathis | } |
512 | 1ac430a1 | Christos Stathis | |
513 | 1ac430a1 | Christos Stathis | @Override
|
514 | 1ac430a1 | Christos Stathis | public void onError(Throwable t) { |
515 | 1ac430a1 | Christos Stathis | GWT.log("Error getting account", t);
|
516 | 1ac430a1 | Christos Stathis | if (t instanceof RestException) |
517 | e9c9f408 | Christos Stathis | displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
|
518 | 1ac430a1 | Christos Stathis | else
|
519 | e9c9f408 | Christos Stathis | displayError("System error fetching user data: " + t.getMessage());
|
520 | 1ac430a1 | Christos Stathis | } |
521 | 1ac430a1 | Christos Stathis | }; |
522 | fbff60ff | Christos Stathis | getAccount.setHeader("X-Auth-Token", token);
|
523 | 1ac430a1 | Christos Stathis | Scheduler.get().scheduleDeferred(getAccount); |
524 | 1ac430a1 | Christos Stathis | } |
525 | 1ac430a1 | Christos Stathis | |
526 | 10791b56 | Christos Stathis | protected void createHomeContainers() { |
527 | 12190a0c | Christos Stathis | String path = "/pithos"; |
528 | 12190a0c | Christos Stathis | PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) {
|
529 | 2996f218 | Christos Stathis | @Override
|
530 | 10791b56 | Christos Stathis | public void onSuccess(@SuppressWarnings("unused") Resource result) { |
531 | 2996f218 | Christos Stathis | fetchAccount(); |
532 | 2996f218 | Christos Stathis | } |
533 | 2996f218 | Christos Stathis | |
534 | 2996f218 | Christos Stathis | @Override
|
535 | 2996f218 | Christos Stathis | public void onError(Throwable t) { |
536 | 2996f218 | Christos Stathis | GWT.log("Error creating pithos", t);
|
537 | 2996f218 | Christos Stathis | if (t instanceof RestException) |
538 | e9c9f408 | Christos Stathis | displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
|
539 | 2996f218 | Christos Stathis | else
|
540 | e9c9f408 | Christos Stathis | displayError("System error Error creating pithos: " + t.getMessage());
|
541 | 2996f218 | Christos Stathis | } |
542 | 2996f218 | Christos Stathis | }; |
543 | 2996f218 | Christos Stathis | createPithos.setHeader("X-Auth-Token", getToken());
|
544 | 2996f218 | Christos Stathis | Scheduler.get().scheduleDeferred(createPithos); |
545 | 2996f218 | Christos Stathis | } |
546 | 2996f218 | Christos Stathis | |
547 | ab1eb3f8 | Christos Stathis | /**
|
548 | ab1eb3f8 | Christos Stathis | * Creates an HTML fragment that places an image & caption together, for use
|
549 | ab1eb3f8 | Christos Stathis | * in a group header.
|
550 | ab1eb3f8 | Christos Stathis | *
|
551 | ab1eb3f8 | Christos Stathis | * @param imageProto an image prototype for an image
|
552 | ab1eb3f8 | Christos Stathis | * @param caption the group caption
|
553 | ab1eb3f8 | Christos Stathis | * @return the header HTML fragment
|
554 | ab1eb3f8 | Christos Stathis | */
|
555 | ab1eb3f8 | Christos Stathis | private String createHeaderHTML(AbstractImagePrototype imageProto, String caption) { |
556 | ab1eb3f8 | Christos Stathis | String captionHTML = "<table class='caption' cellpadding='0' " |
557 | ab1eb3f8 | Christos Stathis | + "cellspacing='0'>" + "<tr><td class='lcaption'>" + imageProto.getHTML() |
558 | ab1eb3f8 | Christos Stathis | + "</td><td id =" + caption +" class='rcaption'><b style='white-space:nowrap'> " |
559 | ab1eb3f8 | Christos Stathis | + caption + "</b></td></tr></table>";
|
560 | ab1eb3f8 | Christos Stathis | return captionHTML;
|
561 | ab1eb3f8 | Christos Stathis | } |
562 | ab1eb3f8 | Christos Stathis | |
563 | 10791b56 | Christos Stathis | protected void onWindowResized(int height) { |
564 | ab1eb3f8 | Christos Stathis | // Adjust the split panel to take up the available room in the window.
|
565 | aff7a7bf | Christos Stathis | int newHeight = height - splitPanel.getAbsoluteTop() - 60; |
566 | ab1eb3f8 | Christos Stathis | if (newHeight < 1) |
567 | ab1eb3f8 | Christos Stathis | newHeight = 1;
|
568 | ab1eb3f8 | Christos Stathis | splitPanel.setHeight("" + newHeight);
|
569 | ab1eb3f8 | Christos Stathis | inner.setHeight("" + newHeight);
|
570 | ab1eb3f8 | Christos Stathis | } |
571 | ab1eb3f8 | Christos Stathis | |
572 | ab1eb3f8 | Christos Stathis | @Override
|
573 | ab1eb3f8 | Christos Stathis | public void onResize(ResizeEvent event) { |
574 | ab1eb3f8 | Christos Stathis | int height = event.getHeight();
|
575 | ab1eb3f8 | Christos Stathis | onWindowResized(height); |
576 | ab1eb3f8 | Christos Stathis | } |
577 | ab1eb3f8 | Christos Stathis | |
578 | ab1eb3f8 | Christos Stathis | /**
|
579 | ab1eb3f8 | Christos Stathis | * Display an error message.
|
580 | ab1eb3f8 | Christos Stathis | *
|
581 | ab1eb3f8 | Christos Stathis | * @param msg the message to display
|
582 | ab1eb3f8 | Christos Stathis | */
|
583 | ab1eb3f8 | Christos Stathis | public void displayError(String msg) { |
584 | ab1eb3f8 | Christos Stathis | messagePanel.displayError(msg); |
585 | ab1eb3f8 | Christos Stathis | } |
586 | ab1eb3f8 | Christos Stathis | |
587 | ab1eb3f8 | Christos Stathis | /**
|
588 | ab1eb3f8 | Christos Stathis | * Display a warning message.
|
589 | ab1eb3f8 | Christos Stathis | *
|
590 | ab1eb3f8 | Christos Stathis | * @param msg the message to display
|
591 | ab1eb3f8 | Christos Stathis | */
|
592 | ab1eb3f8 | Christos Stathis | public void displayWarning(String msg) { |
593 | ab1eb3f8 | Christos Stathis | messagePanel.displayWarning(msg); |
594 | ab1eb3f8 | Christos Stathis | } |
595 | ab1eb3f8 | Christos Stathis | |
596 | ab1eb3f8 | Christos Stathis | /**
|
597 | ab1eb3f8 | Christos Stathis | * Display an informational message.
|
598 | ab1eb3f8 | Christos Stathis | *
|
599 | ab1eb3f8 | Christos Stathis | * @param msg the message to display
|
600 | ab1eb3f8 | Christos Stathis | */
|
601 | ab1eb3f8 | Christos Stathis | public void displayInformation(String msg) { |
602 | ab1eb3f8 | Christos Stathis | messagePanel.displayInformation(msg); |
603 | ab1eb3f8 | Christos Stathis | } |
604 | ab1eb3f8 | Christos Stathis | |
605 | ab1eb3f8 | Christos Stathis | /**
|
606 | ab1eb3f8 | Christos Stathis | * Retrieve the fileList.
|
607 | ab1eb3f8 | Christos Stathis | *
|
608 | ab1eb3f8 | Christos Stathis | * @return the fileList
|
609 | ab1eb3f8 | Christos Stathis | */
|
610 | ab1eb3f8 | Christos Stathis | public FileList getFileList() {
|
611 | ab1eb3f8 | Christos Stathis | return fileList;
|
612 | ab1eb3f8 | Christos Stathis | } |
613 | ab1eb3f8 | Christos Stathis | |
614 | ab1eb3f8 | Christos Stathis | /**
|
615 | ab1eb3f8 | Christos Stathis | * Retrieve the topPanel.
|
616 | ab1eb3f8 | Christos Stathis | *
|
617 | ab1eb3f8 | Christos Stathis | * @return the topPanel
|
618 | ab1eb3f8 | Christos Stathis | */
|
619 | ab1eb3f8 | Christos Stathis | TopPanel getTopPanel() { |
620 | ab1eb3f8 | Christos Stathis | return topPanel;
|
621 | ab1eb3f8 | Christos Stathis | } |
622 | ab1eb3f8 | Christos Stathis | |
623 | ab1eb3f8 | Christos Stathis | /**
|
624 | ab1eb3f8 | Christos Stathis | * Retrieve the clipboard.
|
625 | ab1eb3f8 | Christos Stathis | *
|
626 | ab1eb3f8 | Christos Stathis | * @return the clipboard
|
627 | ab1eb3f8 | Christos Stathis | */
|
628 | ab1eb3f8 | Christos Stathis | public Clipboard getClipboard() { |
629 | ab1eb3f8 | Christos Stathis | return clipboard;
|
630 | ab1eb3f8 | Christos Stathis | } |
631 | ab1eb3f8 | Christos Stathis | |
632 | ab1eb3f8 | Christos Stathis | public StatusPanel getStatusPanel() {
|
633 | ab1eb3f8 | Christos Stathis | return statusPanel;
|
634 | ab1eb3f8 | Christos Stathis | } |
635 | ab1eb3f8 | Christos Stathis | |
636 | ab1eb3f8 | Christos Stathis | public String getToken() { |
637 | ab1eb3f8 | Christos Stathis | return token;
|
638 | ab1eb3f8 | Christos Stathis | } |
639 | ab1eb3f8 | Christos Stathis | |
640 | ab1eb3f8 | Christos Stathis | public String getWebDAVPassword() { |
641 | ab1eb3f8 | Christos Stathis | return webDAVPassword;
|
642 | ab1eb3f8 | Christos Stathis | } |
643 | ab1eb3f8 | Christos Stathis | |
644 | ab1eb3f8 | Christos Stathis | public static native void preventIESelection() /*-{ |
645 | ab1eb3f8 | Christos Stathis | $doc.body.onselectstart = function () { return false; };
|
646 | ab1eb3f8 | Christos Stathis | }-*/;
|
647 | ab1eb3f8 | Christos Stathis | |
648 | ab1eb3f8 | Christos Stathis | public static native void enableIESelection() /*-{ |
649 | ab1eb3f8 | Christos Stathis | if ($doc.body.onselectstart != null)
|
650 | ab1eb3f8 | Christos Stathis | $doc.body.onselectstart = null;
|
651 | ab1eb3f8 | Christos Stathis | }-*/;
|
652 | ab1eb3f8 | Christos Stathis | |
653 | ab1eb3f8 | Christos Stathis | /**
|
654 | ab1eb3f8 | Christos Stathis | * @return the absolute path of the API root URL
|
655 | ab1eb3f8 | Christos Stathis | */
|
656 | ab1eb3f8 | Christos Stathis | public String getApiPath() { |
657 | ab1eb3f8 | Christos Stathis | Configuration conf = (Configuration) GWT.create(Configuration.class); |
658 | 9e8e14e4 | Christos Stathis | return conf.apiPath();
|
659 | ab1eb3f8 | Christos Stathis | } |
660 | ab1eb3f8 | Christos Stathis | |
661 | ab1eb3f8 | Christos Stathis | /**
|
662 | ab1eb3f8 | Christos Stathis | * History support for folder navigation
|
663 | ab1eb3f8 | Christos Stathis | * adds a new browser history entry
|
664 | ab1eb3f8 | Christos Stathis | *
|
665 | ab1eb3f8 | Christos Stathis | * @param key
|
666 | ab1eb3f8 | Christos Stathis | */
|
667 | ab1eb3f8 | Christos Stathis | public void updateHistory(String key){ |
668 | ab1eb3f8 | Christos Stathis | // Replace any whitespace of the initial string to "+"
|
669 | ab1eb3f8 | Christos Stathis | // String result = key.replaceAll("\\s","+");
|
670 | ab1eb3f8 | Christos Stathis | // Add a new browser history entry.
|
671 | ab1eb3f8 | Christos Stathis | // History.newItem(result);
|
672 | ab1eb3f8 | Christos Stathis | History.newItem(key); |
673 | ab1eb3f8 | Christos Stathis | } |
674 | ab1eb3f8 | Christos Stathis | |
675 | 49df7570 | Christos Stathis | public void deleteFolder(final Folder folder) { |
676 | 49df7570 | Christos Stathis | String path = getApiPath() + getUsername() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + folder.getPrefix(); |
677 | 49df7570 | Christos Stathis | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
|
678 | 49df7570 | Christos Stathis | builder.setHeader("If-Modified-Since", "0"); |
679 | 49df7570 | Christos Stathis | builder.setHeader("X-Auth-Token", getToken());
|
680 | 49df7570 | Christos Stathis | try {
|
681 | 49df7570 | Christos Stathis | builder.sendRequest("", new RequestCallback() { |
682 | 49df7570 | Christos Stathis | @Override
|
683 | 10791b56 | Christos Stathis | public void onResponseReceived(@SuppressWarnings("unused") Request request, Response response) { |
684 | 49df7570 | Christos Stathis | if (response.getStatusCode() == Response.SC_OK) {
|
685 | 49df7570 | Christos Stathis | JSONValue json = JSONParser.parseStrict(response.getText()); |
686 | 49df7570 | Christos Stathis | JSONArray array = json.isArray(); |
687 | 49df7570 | Christos Stathis | int i = 0; |
688 | 49df7570 | Christos Stathis | if (array != null) { |
689 | 49df7570 | Christos Stathis | deleteObject(folder, i, array); |
690 | 49df7570 | Christos Stathis | } |
691 | 49df7570 | Christos Stathis | } |
692 | 49df7570 | Christos Stathis | } |
693 | 49df7570 | Christos Stathis | |
694 | 49df7570 | Christos Stathis | @Override
|
695 | 10791b56 | Christos Stathis | public void onError(@SuppressWarnings("unused") Request request, Throwable exception) { |
696 | e9c9f408 | Christos Stathis | displayError("System error unable to delete folder: " + exception.getMessage());
|
697 | 49df7570 | Christos Stathis | } |
698 | 49df7570 | Christos Stathis | }); |
699 | 49df7570 | Christos Stathis | } |
700 | 49df7570 | Christos Stathis | catch (RequestException e) {
|
701 | 49df7570 | Christos Stathis | } |
702 | 49df7570 | Christos Stathis | } |
703 | 49df7570 | Christos Stathis | |
704 | 49df7570 | Christos Stathis | public void deleteObject(final Folder folder, final int i, final JSONArray array) { |
705 | 49df7570 | Christos Stathis | if (i < array.size()) {
|
706 | 49df7570 | Christos Stathis | JSONObject o = array.get(i).isObject(); |
707 | 49df7570 | Christos Stathis | if (o != null && !o.containsKey("subdir")) { |
708 | 49df7570 | Christos Stathis | JSONString name = o.get("name").isString();
|
709 | 12190a0c | Christos Stathis | String path = "/" + folder.getContainer() + "/" + name.stringValue(); |
710 | 12190a0c | Christos Stathis | DeleteRequest delete = new DeleteRequest(getApiPath(), getUsername(), path) {
|
711 | 49df7570 | Christos Stathis | @Override
|
712 | 10791b56 | Christos Stathis | public void onSuccess(@SuppressWarnings("unused") Resource result) { |
713 | 49df7570 | Christos Stathis | deleteObject(folder, i + 1, array);
|
714 | 49df7570 | Christos Stathis | } |
715 | 49df7570 | Christos Stathis | |
716 | 49df7570 | Christos Stathis | @Override
|
717 | 49df7570 | Christos Stathis | public void onError(Throwable t) { |
718 | 49df7570 | Christos Stathis | GWT.log("", t);
|
719 | e9c9f408 | Christos Stathis | displayError("System error unable to delete folder: " + t.getMessage());
|
720 | 49df7570 | Christos Stathis | } |
721 | 49df7570 | Christos Stathis | }; |
722 | 49df7570 | Christos Stathis | delete.setHeader("X-Auth-Token", getToken());
|
723 | 49df7570 | Christos Stathis | Scheduler.get().scheduleDeferred(delete); |
724 | 49df7570 | Christos Stathis | } |
725 | 10791b56 | Christos Stathis | else if (o != null) { |
726 | 49df7570 | Christos Stathis | String subdir = o.get("subdir").isString().stringValue(); |
727 | 49df7570 | Christos Stathis | subdir = subdir.substring(0, subdir.length() - 1); |
728 | 49df7570 | Christos Stathis | String path = getApiPath() + getUsername() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + subdir; |
729 | 49df7570 | Christos Stathis | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
|
730 | 49df7570 | Christos Stathis | builder.setHeader("If-Modified-Since", "0"); |
731 | 49df7570 | Christos Stathis | builder.setHeader("X-Auth-Token", getToken());
|
732 | 49df7570 | Christos Stathis | try {
|
733 | 49df7570 | Christos Stathis | builder.sendRequest("", new RequestCallback() { |
734 | 49df7570 | Christos Stathis | @Override
|
735 | 10791b56 | Christos Stathis | public void onResponseReceived(@SuppressWarnings("unused") Request request, Response response) { |
736 | 49df7570 | Christos Stathis | if (response.getStatusCode() == Response.SC_OK) {
|
737 | 49df7570 | Christos Stathis | JSONValue json = JSONParser.parseStrict(response.getText()); |
738 | 49df7570 | Christos Stathis | JSONArray array2 = json.isArray(); |
739 | 49df7570 | Christos Stathis | if (array2 != null) { |
740 | 49df7570 | Christos Stathis | int l = array.size();
|
741 | 49df7570 | Christos Stathis | for (int j=0; j<array2.size(); j++) { |
742 | 49df7570 | Christos Stathis | array.set(l++, array2.get(j)); |
743 | 49df7570 | Christos Stathis | } |
744 | 49df7570 | Christos Stathis | } |
745 | 49df7570 | Christos Stathis | deleteObject(folder, i + 1, array);
|
746 | 49df7570 | Christos Stathis | } |
747 | 49df7570 | Christos Stathis | } |
748 | 49df7570 | Christos Stathis | |
749 | 49df7570 | Christos Stathis | @Override
|
750 | 10791b56 | Christos Stathis | public void onError(@SuppressWarnings("unused") Request request, Throwable exception) { |
751 | e9c9f408 | Christos Stathis | displayError("System error unable to delete folder: " + exception.getMessage());
|
752 | 49df7570 | Christos Stathis | } |
753 | 49df7570 | Christos Stathis | }); |
754 | 49df7570 | Christos Stathis | } |
755 | 49df7570 | Christos Stathis | catch (RequestException e) {
|
756 | 49df7570 | Christos Stathis | } |
757 | 49df7570 | Christos Stathis | } |
758 | 49df7570 | Christos Stathis | } |
759 | 49df7570 | Christos Stathis | else {
|
760 | 12190a0c | Christos Stathis | String path = folder.getUri();
|
761 | 12190a0c | Christos Stathis | DeleteRequest deleteFolder = new DeleteRequest(getApiPath(), getUsername(), path) {
|
762 | 49df7570 | Christos Stathis | @Override
|
763 | 10791b56 | Christos Stathis | public void onSuccess(@SuppressWarnings("unused") Resource result) { |
764 | 19a73342 | Christos Stathis | updateFolder(folder.getParent(), true);
|
765 | 49df7570 | Christos Stathis | } |
766 | 49df7570 | Christos Stathis | |
767 | 49df7570 | Christos Stathis | @Override
|
768 | 49df7570 | Christos Stathis | public void onError(Throwable t) { |
769 | 49df7570 | Christos Stathis | GWT.log("", t);
|
770 | 49df7570 | Christos Stathis | if (t instanceof RestException) { |
771 | 49df7570 | Christos Stathis | displayError("Unable to delete folder: "+((RestException) t).getHttpStatusText());
|
772 | 49df7570 | Christos Stathis | } |
773 | 49df7570 | Christos Stathis | else
|
774 | e9c9f408 | Christos Stathis | displayError("System error unable to delete folder: " + t.getMessage());
|
775 | 49df7570 | Christos Stathis | } |
776 | 49df7570 | Christos Stathis | }; |
777 | 49df7570 | Christos Stathis | deleteFolder.setHeader("X-Auth-Token", getToken());
|
778 | 49df7570 | Christos Stathis | Scheduler.get().scheduleDeferred(deleteFolder); |
779 | 49df7570 | Christos Stathis | } |
780 | 49df7570 | Christos Stathis | } |
781 | 3d01deba | Christos Stathis | |
782 | 3d01deba | Christos Stathis | public FolderTreeView getFolderTreeView() {
|
783 | 3d01deba | Christos Stathis | return folderTreeView;
|
784 | 3d01deba | Christos Stathis | } |
785 | 33b61be6 | Christos Stathis | |
786 | 33b61be6 | Christos Stathis | public void copyFiles(final Iterator<File> iter, final String targetUri, final Command callback) { |
787 | 33b61be6 | Christos Stathis | if (iter.hasNext()) {
|
788 | 33b61be6 | Christos Stathis | File file = iter.next();
|
789 | 12190a0c | Christos Stathis | String path = targetUri + "/" + file.getName(); |
790 | 12190a0c | Christos Stathis | PutRequest copyFile = new PutRequest(getApiPath(), getUsername(), path) {
|
791 | 33b61be6 | Christos Stathis | @Override
|
792 | 10791b56 | Christos Stathis | public void onSuccess(@SuppressWarnings("unused") Resource result) { |
793 | 33b61be6 | Christos Stathis | copyFiles(iter, targetUri, callback); |
794 | 33b61be6 | Christos Stathis | } |
795 | 33b61be6 | Christos Stathis | |
796 | 33b61be6 | Christos Stathis | @Override
|
797 | 33b61be6 | Christos Stathis | public void onError(Throwable t) { |
798 | 33b61be6 | Christos Stathis | GWT.log("", t);
|
799 | 33b61be6 | Christos Stathis | if (t instanceof RestException) { |
800 | e9c9f408 | Christos Stathis | displayError("Unable to copy file: " + ((RestException) t).getHttpStatusText());
|
801 | 33b61be6 | Christos Stathis | } |
802 | 33b61be6 | Christos Stathis | else
|
803 | e9c9f408 | Christos Stathis | displayError("System error unable to copy file: "+t.getMessage());
|
804 | 33b61be6 | Christos Stathis | } |
805 | 33b61be6 | Christos Stathis | }; |
806 | 33b61be6 | Christos Stathis | copyFile.setHeader("X-Auth-Token", getToken());
|
807 | 33b61be6 | Christos Stathis | copyFile.setHeader("X-Copy-From", file.getUri());
|
808 | 33b61be6 | Christos Stathis | Scheduler.get().scheduleDeferred(copyFile); |
809 | 33b61be6 | Christos Stathis | } |
810 | 33b61be6 | Christos Stathis | else if (callback != null) { |
811 | 33b61be6 | Christos Stathis | callback.execute(); |
812 | 33b61be6 | Christos Stathis | } |
813 | 33b61be6 | Christos Stathis | } |
814 | 33b61be6 | Christos Stathis | |
815 | 33b61be6 | Christos Stathis | public void copySubfolders(final Iterator<Folder> iter, final String targetUri, final Command callback) { |
816 | 33b61be6 | Christos Stathis | if (iter.hasNext()) {
|
817 | 33b61be6 | Christos Stathis | final Folder f = iter.next();
|
818 | 33b61be6 | Christos Stathis | copyFolder(f, targetUri, callback); |
819 | 33b61be6 | Christos Stathis | } |
820 | 33b61be6 | Christos Stathis | else if (callback != null) { |
821 | 33b61be6 | Christos Stathis | callback.execute(); |
822 | 33b61be6 | Christos Stathis | } |
823 | 33b61be6 | Christos Stathis | } |
824 | 33b61be6 | Christos Stathis | |
825 | 33b61be6 | Christos Stathis | public void copyFolder(final Folder f, final String targetUri, final Command callback) { |
826 | 12190a0c | Christos Stathis | String path = targetUri + "/" + f.getName(); |
827 | 12190a0c | Christos Stathis | PutRequest createFolder = new PutRequest(getApiPath(), getUsername(), path) {
|
828 | 33b61be6 | Christos Stathis | @Override
|
829 | 10791b56 | Christos Stathis | public void onSuccess(@SuppressWarnings("unused") Resource result) { |
830 | 33b61be6 | Christos Stathis | Iterator<File> iter = f.getFiles().iterator(); |
831 | 33b61be6 | Christos Stathis | copyFiles(iter, targetUri + "/" + f.getName(), new Command() { |
832 | 33b61be6 | Christos Stathis | @Override
|
833 | 33b61be6 | Christos Stathis | public void execute() { |
834 | 33b61be6 | Christos Stathis | Iterator<Folder> iterf = f.getSubfolders().iterator();
|
835 | 33b61be6 | Christos Stathis | copySubfolders(iterf, targetUri + "/" + f.getName(), new Command() { |
836 | 33b61be6 | Christos Stathis | @Override
|
837 | 33b61be6 | Christos Stathis | public void execute() { |
838 | 33b61be6 | Christos Stathis | callback.execute(); |
839 | 33b61be6 | Christos Stathis | } |
840 | 33b61be6 | Christos Stathis | }); |
841 | 33b61be6 | Christos Stathis | } |
842 | 33b61be6 | Christos Stathis | }); |
843 | 33b61be6 | Christos Stathis | } |
844 | 33b61be6 | Christos Stathis | |
845 | 33b61be6 | Christos Stathis | @Override
|
846 | 33b61be6 | Christos Stathis | public void onError(Throwable t) { |
847 | 33b61be6 | Christos Stathis | GWT.log("", t);
|
848 | 33b61be6 | Christos Stathis | if (t instanceof RestException) { |
849 | 33b61be6 | Christos Stathis | displayError("Unable to create folder:" + ((RestException) t).getHttpStatusText());
|
850 | 33b61be6 | Christos Stathis | } |
851 | 33b61be6 | Christos Stathis | else
|
852 | 33b61be6 | Christos Stathis | displayError("System error creating folder:" + t.getMessage());
|
853 | 33b61be6 | Christos Stathis | } |
854 | 33b61be6 | Christos Stathis | }; |
855 | 33b61be6 | Christos Stathis | createFolder.setHeader("X-Auth-Token", getToken());
|
856 | 33b61be6 | Christos Stathis | createFolder.setHeader("Accept", "*/*"); |
857 | 33b61be6 | Christos Stathis | createFolder.setHeader("Content-Length", "0"); |
858 | 33b61be6 | Christos Stathis | createFolder.setHeader("Content-Type", "application/folder"); |
859 | 33b61be6 | Christos Stathis | Scheduler.get().scheduleDeferred(createFolder); |
860 | 33b61be6 | Christos Stathis | } |
861 | 3331e8d8 | Christos Stathis | |
862 | 10791b56 | Christos Stathis | public void addSelectionModel(@SuppressWarnings("rawtypes") SingleSelectionModel model) { |
863 | 3331e8d8 | Christos Stathis | selectionModels.add(model); |
864 | 3331e8d8 | Christos Stathis | } |
865 | eee732d5 | Christos Stathis | |
866 | eee732d5 | Christos Stathis | public OtherSharedTreeView getOtherSharedTreeView() {
|
867 | eee732d5 | Christos Stathis | return otherSharedTreeView;
|
868 | eee732d5 | Christos Stathis | } |
869 | ab1eb3f8 | Christos Stathis | } |