root / src / gr / grnet / pithos / web / client / Pithos.java @ 1238d28d
History | View | Annotate | Download (48 kB)
1 | a57faaf0 | Christos Stathis | /*
|
---|---|---|---|
2 | cae2a8db | Christos Stathis | * Copyright 2011-2012 GRNET S.A. All rights reserved.
|
3 | 63366925 | Christos Stathis | *
|
4 | 63366925 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 63366925 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 63366925 | Christos Stathis | * conditions are met:
|
7 | 63366925 | Christos Stathis | *
|
8 | 63366925 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 63366925 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 63366925 | Christos Stathis | * disclaimer.
|
11 | 63366925 | Christos Stathis | *
|
12 | 63366925 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 63366925 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 63366925 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 63366925 | Christos Stathis | * provided with the distribution.
|
16 | 63366925 | Christos Stathis | *
|
17 | 63366925 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 63366925 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 63366925 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 63366925 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 63366925 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 63366925 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 63366925 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 63366925 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 63366925 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 63366925 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 63366925 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 63366925 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 63366925 | Christos Stathis | *
|
30 | 63366925 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 63366925 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 63366925 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 63366925 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | a57faaf0 | Christos Stathis | */
|
35 | a57faaf0 | Christos Stathis | package gr.grnet.pithos.web.client; |
36 | a57faaf0 | Christos Stathis | |
37 | bbdd34ef | Christos Stathis | import gr.grnet.pithos.web.client.commands.UploadFileCommand; |
38 | 6084aa02 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.AccountResource; |
39 | 875a0179 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.File; |
40 | 7c818c14 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Folder; |
41 | 6084aa02 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.FolderTreeView; |
42 | 7c818c14 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.FolderTreeViewModel; |
43 | 602ebeb4 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Resource; |
44 | 4baffab1 | Christos Stathis | import gr.grnet.pithos.web.client.grouptree.Group; |
45 | ee9fbc37 | Christos Stathis | import gr.grnet.pithos.web.client.grouptree.GroupTreeView; |
46 | ee9fbc37 | Christos Stathis | import gr.grnet.pithos.web.client.grouptree.GroupTreeViewModel; |
47 | 105b4e49 | Christos Stathis | import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeView; |
48 | 105b4e49 | Christos Stathis | import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeViewModel; |
49 | 6d8e0f58 | Christos Stathis | import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeView; |
50 | 6d8e0f58 | Christos Stathis | import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeViewModel; |
51 | 602ebeb4 | Christos Stathis | import gr.grnet.pithos.web.client.rest.DeleteRequest; |
52 | 6084aa02 | Christos Stathis | import gr.grnet.pithos.web.client.rest.GetRequest; |
53 | 64f42c0b | Christos Stathis | import gr.grnet.pithos.web.client.rest.HeadRequest; |
54 | d6be39da | Christos Stathis | import gr.grnet.pithos.web.client.rest.PutRequest; |
55 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.rest.RestException; |
56 | 7811b9d1 | Christos Stathis | |
57 | a57faaf0 | Christos Stathis | import java.util.ArrayList; |
58 | a57faaf0 | Christos Stathis | import java.util.HashMap; |
59 | 7c818c14 | Christos Stathis | import java.util.Iterator; |
60 | a57faaf0 | Christos Stathis | import java.util.List; |
61 | 7811b9d1 | Christos Stathis | import java.util.Set; |
62 | a57faaf0 | Christos Stathis | |
63 | a57faaf0 | Christos Stathis | import com.google.gwt.core.client.EntryPoint; |
64 | a57faaf0 | Christos Stathis | import com.google.gwt.core.client.GWT; |
65 | 7811b9d1 | Christos Stathis | import com.google.gwt.core.client.Scheduler; |
66 | 983f9ee2 | Christos Stathis | import com.google.gwt.core.client.Scheduler.RepeatingCommand; |
67 | 7811b9d1 | Christos Stathis | import com.google.gwt.core.client.Scheduler.ScheduledCommand; |
68 | 7811b9d1 | Christos Stathis | import com.google.gwt.event.dom.client.ClickEvent; |
69 | 7811b9d1 | Christos Stathis | import com.google.gwt.event.dom.client.ClickHandler; |
70 | a57faaf0 | Christos Stathis | import com.google.gwt.event.logical.shared.ResizeEvent; |
71 | a57faaf0 | Christos Stathis | import com.google.gwt.event.logical.shared.ResizeHandler; |
72 | 7811b9d1 | Christos Stathis | import com.google.gwt.http.client.Request; |
73 | 7811b9d1 | Christos Stathis | import com.google.gwt.http.client.RequestBuilder; |
74 | 7811b9d1 | Christos Stathis | import com.google.gwt.http.client.RequestCallback; |
75 | 7811b9d1 | Christos Stathis | import com.google.gwt.http.client.RequestException; |
76 | 7811b9d1 | Christos Stathis | import com.google.gwt.http.client.Response; |
77 | f5023f13 | Christos Stathis | import com.google.gwt.http.client.URL; |
78 | f0105e9f | Christos Stathis | import com.google.gwt.i18n.client.Dictionary; |
79 | 29b2177c | Christos Stathis | import com.google.gwt.i18n.client.NumberFormat; |
80 | 7811b9d1 | Christos Stathis | import com.google.gwt.json.client.JSONArray; |
81 | 7811b9d1 | Christos Stathis | import com.google.gwt.json.client.JSONObject; |
82 | 7811b9d1 | Christos Stathis | import com.google.gwt.json.client.JSONParser; |
83 | 7811b9d1 | Christos Stathis | import com.google.gwt.json.client.JSONString; |
84 | 7811b9d1 | Christos Stathis | import com.google.gwt.json.client.JSONValue; |
85 | a57faaf0 | Christos Stathis | import com.google.gwt.resources.client.ImageResource; |
86 | 9fbf5596 | Christos Stathis | import com.google.gwt.resources.client.ImageResource.ImageOptions; |
87 | 7811b9d1 | Christos Stathis | import com.google.gwt.user.client.Command; |
88 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.Cookies; |
89 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.Event; |
90 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.History; |
91 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.Window; |
92 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
93 | 7811b9d1 | Christos Stathis | import com.google.gwt.user.client.ui.Button; |
94 | 0549e173 | Christos Stathis | import com.google.gwt.user.client.ui.Composite; |
95 | 1238d28d | Christos Stathis | import com.google.gwt.user.client.ui.FlowPanel; |
96 | 7811b9d1 | Christos Stathis | import com.google.gwt.user.client.ui.HTML; |
97 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
98 | 7811b9d1 | Christos Stathis | import com.google.gwt.user.client.ui.HasVerticalAlignment; |
99 | 7811b9d1 | Christos Stathis | import com.google.gwt.user.client.ui.HorizontalPanel; |
100 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.HorizontalSplitPanel; |
101 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.RootPanel; |
102 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.VerticalPanel; |
103 | 7811b9d1 | Christos Stathis | import com.google.gwt.view.client.SelectionChangeEvent; |
104 | 7811b9d1 | Christos Stathis | import com.google.gwt.view.client.SelectionChangeEvent.Handler; |
105 | 7811b9d1 | Christos Stathis | import com.google.gwt.view.client.SingleSelectionModel; |
106 | 6084aa02 | Christos Stathis | |
107 | a57faaf0 | Christos Stathis | /**
|
108 | a57faaf0 | Christos Stathis | * Entry point classes define <code>onModuleLoad()</code>.
|
109 | a57faaf0 | Christos Stathis | */
|
110 | 749068ba | Christos Stathis | public class Pithos implements EntryPoint, ResizeHandler { |
111 | a57faaf0 | Christos Stathis | |
112 | 105b4e49 | Christos Stathis | public static final String HOME_CONTAINER = "pithos"; |
113 | 7b28ae07 | Christos Stathis | |
114 | 7b28ae07 | Christos Stathis | public static final String TRASH_CONTAINER = "trash"; |
115 | 2dfdda3f | Christos Stathis | |
116 | 2dfdda3f | Christos Stathis | public static final Configuration config = GWT.create(Configuration.class); |
117 | 105b4e49 | Christos Stathis | |
118 | a57faaf0 | Christos Stathis | /**
|
119 | a57faaf0 | Christos Stathis | * Instantiate an application-level image bundle. This object will provide
|
120 | a57faaf0 | Christos Stathis | * programmatic access to all the images needed by widgets.
|
121 | a57faaf0 | Christos Stathis | */
|
122 | a9e497d4 | Christos Stathis | static Images images = (Images) GWT.create(Images.class);
|
123 | a57faaf0 | Christos Stathis | |
124 | 6084aa02 | Christos Stathis | public String getUsername() { |
125 | 6084aa02 | Christos Stathis | return username;
|
126 | 6084aa02 | Christos Stathis | } |
127 | a57faaf0 | Christos Stathis | |
128 | 8e61880b | Christos Stathis | public void setAccount(AccountResource acct) { |
129 | 8e61880b | Christos Stathis | account = acct; |
130 | 8e61880b | Christos Stathis | } |
131 | 8e61880b | Christos Stathis | |
132 | 8e61880b | Christos Stathis | public AccountResource getAccount() {
|
133 | 8e61880b | Christos Stathis | return account;
|
134 | 8e61880b | Christos Stathis | } |
135 | 8e61880b | Christos Stathis | |
136 | 6acd4df3 | Christos Stathis | public void updateFolder(Folder f, boolean showfiles, Command callback, final boolean openParent) { |
137 | 6acd4df3 | Christos Stathis | folderTreeView.updateFolder(f, showfiles, callback, openParent); |
138 | b651e67f | Christos Stathis | } |
139 | b651e67f | Christos Stathis | |
140 | 4baffab1 | Christos Stathis | public void updateGroupNode(Group group) { |
141 | 4baffab1 | Christos Stathis | groupTreeView.updateGroupNode(group); |
142 | 4baffab1 | Christos Stathis | } |
143 | 4baffab1 | Christos Stathis | |
144 | 3601b114 | Christos Stathis | public void updateMySharedRoot() { |
145 | 3601b114 | Christos Stathis | mysharedTreeView.updateRoot(); |
146 | 3601b114 | Christos Stathis | } |
147 | 3601b114 | Christos Stathis | |
148 | 105b4e49 | Christos Stathis | public void updateSharedFolder(Folder f, boolean showfiles) { |
149 | 105b4e49 | Christos Stathis | mysharedTreeView.updateFolder(f, showfiles); |
150 | 105b4e49 | Christos Stathis | } |
151 | 105b4e49 | Christos Stathis | |
152 | 6d8e0f58 | Christos Stathis | public void updateOtherSharedFolder(Folder f, boolean showfiles) { |
153 | 6d8e0f58 | Christos Stathis | otherSharedTreeView.updateFolder(f, showfiles); |
154 | 6d8e0f58 | Christos Stathis | } |
155 | 6d8e0f58 | Christos Stathis | |
156 | 105b4e49 | Christos Stathis | public MysharedTreeView getMySharedTreeView() {
|
157 | 105b4e49 | Christos Stathis | return mysharedTreeView;
|
158 | 105b4e49 | Christos Stathis | } |
159 | 105b4e49 | Christos Stathis | |
160 | 6084aa02 | Christos Stathis | /**
|
161 | a57faaf0 | Christos Stathis | * An aggregate image bundle that pulls together all the images for this
|
162 | a57faaf0 | Christos Stathis | * application into a single bundle.
|
163 | a57faaf0 | Christos Stathis | */
|
164 | a9e497d4 | Christos Stathis | public interface Images extends TopPanel.Images, FileList.Images, ToolsMenu.Images { |
165 | a57faaf0 | Christos Stathis | |
166 | a57faaf0 | Christos Stathis | @Source("gr/grnet/pithos/resources/document.png") |
167 | a57faaf0 | Christos Stathis | ImageResource folders(); |
168 | a57faaf0 | Christos Stathis | |
169 | a9e497d4 | Christos Stathis | @Source("gr/grnet/pithos/resources/advancedsettings.png") |
170 | 9fbf5596 | Christos Stathis | @ImageOptions(width=32, height=32) |
171 | a9e497d4 | Christos Stathis | ImageResource tools(); |
172 | a57faaf0 | Christos Stathis | } |
173 | a57faaf0 | Christos Stathis | |
174 | 3f8622d4 | Christos Stathis | private Throwable error; |
175 | 3f8622d4 | Christos Stathis | |
176 | a57faaf0 | Christos Stathis | /**
|
177 | a57faaf0 | Christos Stathis | * The Application Clipboard implementation;
|
178 | a57faaf0 | Christos Stathis | */
|
179 | a57faaf0 | Christos Stathis | private Clipboard clipboard = new Clipboard(); |
180 | a57faaf0 | Christos Stathis | |
181 | a57faaf0 | Christos Stathis | /**
|
182 | a57faaf0 | Christos Stathis | * The top panel that contains the menu bar.
|
183 | a57faaf0 | Christos Stathis | */
|
184 | a57faaf0 | Christos Stathis | private TopPanel topPanel;
|
185 | a57faaf0 | Christos Stathis | |
186 | a57faaf0 | Christos Stathis | /**
|
187 | a57faaf0 | Christos Stathis | * The panel that contains the various system messages.
|
188 | a57faaf0 | Christos Stathis | */
|
189 | 3f8622d4 | Christos Stathis | private MessagePanel messagePanel = new MessagePanel(this, Pithos.images); |
190 | a57faaf0 | Christos Stathis | |
191 | a57faaf0 | Christos Stathis | /**
|
192 | a57faaf0 | Christos Stathis | * The bottom panel that contains the status bar.
|
193 | a57faaf0 | Christos Stathis | */
|
194 | 8e61880b | Christos Stathis | private StatusPanel statusPanel = null; |
195 | a57faaf0 | Christos Stathis | |
196 | a57faaf0 | Christos Stathis | /**
|
197 | a57faaf0 | Christos Stathis | * The file list widget.
|
198 | a57faaf0 | Christos Stathis | */
|
199 | a57faaf0 | Christos Stathis | private FileList fileList;
|
200 | a57faaf0 | Christos Stathis | |
201 | a57faaf0 | Christos Stathis | /**
|
202 | a57faaf0 | Christos Stathis | * The tab panel that occupies the right side of the screen.
|
203 | a57faaf0 | Christos Stathis | */
|
204 | bbdd34ef | Christos Stathis | private VerticalPanel inner = new VerticalPanel(); |
205 | a57faaf0 | Christos Stathis | |
206 | 63366925 | Christos Stathis | |
207 | a57faaf0 | Christos Stathis | /**
|
208 | a57faaf0 | Christos Stathis | * The split panel that will contain the left and right panels.
|
209 | a57faaf0 | Christos Stathis | */
|
210 | a57faaf0 | Christos Stathis | private HorizontalSplitPanel splitPanel = new HorizontalSplitPanel(); |
211 | a57faaf0 | Christos Stathis | |
212 | a57faaf0 | Christos Stathis | /**
|
213 | a57faaf0 | Christos Stathis | * The currently selected item in the application, for use by the Edit menu
|
214 | a57faaf0 | Christos Stathis | * commands. Potential types are Folder, File, User and Group.
|
215 | a57faaf0 | Christos Stathis | */
|
216 | a57faaf0 | Christos Stathis | private Object currentSelection; |
217 | a57faaf0 | Christos Stathis | |
218 | a57faaf0 | Christos Stathis | public HashMap<String, String> userFullNameMap = new HashMap<String, String>(); |
219 | a57faaf0 | Christos Stathis | |
220 | 6084aa02 | Christos Stathis | private String username = null; |
221 | 6084aa02 | Christos Stathis | |
222 | 6084aa02 | Christos Stathis | /**
|
223 | 6084aa02 | Christos Stathis | * The authentication token of the current user.
|
224 | 6084aa02 | Christos Stathis | */
|
225 | 6084aa02 | Christos Stathis | private String token; |
226 | 6084aa02 | Christos Stathis | |
227 | 7c54d867 | Christos Stathis | VerticalPanel trees; |
228 | 7c54d867 | Christos Stathis | |
229 | f1b24b82 | Christos Stathis | SingleSelectionModel<Folder> folderTreeSelectionModel;
|
230 | f1b24b82 | Christos Stathis | FolderTreeViewModel folderTreeViewModel; |
231 | f1b24b82 | Christos Stathis | FolderTreeView folderTreeView; |
232 | 6084aa02 | Christos Stathis | |
233 | f1b24b82 | Christos Stathis | SingleSelectionModel<Folder> mysharedTreeSelectionModel;
|
234 | 7c54d867 | Christos Stathis | MysharedTreeViewModel mysharedTreeViewModel; |
235 | 7c54d867 | Christos Stathis | MysharedTreeView mysharedTreeView = null;;
|
236 | 105b4e49 | Christos Stathis | |
237 | 7811b9d1 | Christos Stathis | protected SingleSelectionModel<Folder> otherSharedTreeSelectionModel; |
238 | 7c54d867 | Christos Stathis | OtherSharedTreeViewModel otherSharedTreeViewModel; |
239 | 7c54d867 | Christos Stathis | OtherSharedTreeView otherSharedTreeView = null;
|
240 | a6592a15 | Christos Stathis | |
241 | abd8738f | Christos Stathis | GroupTreeViewModel groupTreeViewModel; |
242 | c46c9e31 | Christos Stathis | GroupTreeView groupTreeView; |
243 | ee9fbc37 | Christos Stathis | |
244 | c4b7a6bb | Christos Stathis | TreeView selectedTree; |
245 | 7811b9d1 | Christos Stathis | protected AccountResource account;
|
246 | 16e8478a | Christos Stathis | |
247 | abd8738f | Christos Stathis | Folder trash; |
248 | 0549e173 | Christos Stathis | |
249 | 0549e173 | Christos Stathis | List<Composite> treeViews = new ArrayList<Composite>(); |
250 | 8e61880b | Christos Stathis | |
251 | 7c54d867 | Christos Stathis | @SuppressWarnings("rawtypes") List<SingleSelectionModel> selectionModels = new ArrayList<SingleSelectionModel>(); |
252 | 3ebb88f4 | Christos Stathis | |
253 | 1238d28d | Christos Stathis | public Button upload; |
254 | bf664298 | Christos Stathis | |
255 | a19f758c | Christos Stathis | private HTML numOfFiles; |
256 | b162dfaa | Christos Stathis | |
257 | b75210b5 | Christos Stathis | private Toolbar toolbar;
|
258 | b75210b5 | Christos Stathis | |
259 | 1a0db4f4 | Christos Stathis | private FileUploadDialog fileUploadDialog;
|
260 | 1a0db4f4 | Christos Stathis | |
261 | a57faaf0 | Christos Stathis | @Override
|
262 | a57faaf0 | Christos Stathis | public void onModuleLoad() { |
263 | 6084aa02 | Christos Stathis | if (parseUserCredentials())
|
264 | 6084aa02 | Christos Stathis | initialize(); |
265 | 6084aa02 | Christos Stathis | } |
266 | a57faaf0 | Christos Stathis | |
267 | 6084aa02 | Christos Stathis | private void initialize() { |
268 | a7b6e464 | Christos Stathis | boolean bareContent = Window.Location.getParameter("noframe") != null; |
269 | a7b6e464 | Christos Stathis | String contentWidth = bareContent ? "100%" : "75%"; |
270 | bbdd34ef | Christos Stathis | |
271 | a7b6e464 | Christos Stathis | VerticalPanel outer = new VerticalPanel();
|
272 | a7b6e464 | Christos Stathis | outer.setWidth("100%");
|
273 | a7b6e464 | Christos Stathis | if (!bareContent) {
|
274 | a7b6e464 | Christos Stathis | outer.addStyleName("pithos-outer");
|
275 | a7b6e464 | Christos Stathis | } |
276 | a7b6e464 | Christos Stathis | |
277 | a7b6e464 | Christos Stathis | if (!bareContent) {
|
278 | a7b6e464 | Christos Stathis | topPanel = new TopPanel(this, Pithos.images); |
279 | a7b6e464 | Christos Stathis | topPanel.setWidth("100%");
|
280 | a7b6e464 | Christos Stathis | outer.add(topPanel); |
281 | a7b6e464 | Christos Stathis | outer.setCellHorizontalAlignment(topPanel, HasHorizontalAlignment.ALIGN_CENTER); |
282 | a7b6e464 | Christos Stathis | } |
283 | a76065b6 | Christos Stathis | |
284 | 6cf258b1 | Christos Stathis | messagePanel.setVisible(false);
|
285 | 6cf258b1 | Christos Stathis | outer.add(messagePanel); |
286 | 6cf258b1 | Christos Stathis | outer.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER); |
287 | 6cf258b1 | Christos Stathis | outer.setCellVerticalAlignment(messagePanel, HasVerticalAlignment.ALIGN_MIDDLE); |
288 | 6cf258b1 | Christos Stathis | |
289 | a7b6e464 | Christos Stathis | HorizontalPanel header = new HorizontalPanel();
|
290 | a7b6e464 | Christos Stathis | header.addStyleName("pithos-header");
|
291 | 2d91458a | Christos Stathis | header.setWidth(contentWidth); |
292 | 0549e173 | Christos Stathis | if (bareContent)
|
293 | 0549e173 | Christos Stathis | header.addStyleName("pithos-header-noframe");
|
294 | 1a0db4f4 | Christos Stathis | upload = new Button("Upload", new ClickHandler() { |
295 | a7b6e464 | Christos Stathis | @Override
|
296 | ebead1b5 | Christos Stathis | public void onClick(ClickEvent event) { |
297 | eb2ae14b | Christos Stathis | if (getSelection() != null) |
298 | eb2ae14b | Christos Stathis | new UploadFileCommand(Pithos.this, null, getSelection()).execute(); |
299 | a7b6e464 | Christos Stathis | } |
300 | a7b6e464 | Christos Stathis | }); |
301 | a7b6e464 | Christos Stathis | upload.addStyleName("pithos-uploadButton");
|
302 | 140f0f6d | Christos Stathis | header.add(upload); |
303 | 140f0f6d | Christos Stathis | header.setCellHorizontalAlignment(upload, HasHorizontalAlignment.ALIGN_LEFT); |
304 | 140f0f6d | Christos Stathis | header.setCellVerticalAlignment(upload, HasVerticalAlignment.ALIGN_MIDDLE); |
305 | 6084aa02 | Christos Stathis | |
306 | b75210b5 | Christos Stathis | toolbar = new Toolbar(this); |
307 | bd187dfb | Christos Stathis | header.add(toolbar); |
308 | bd187dfb | Christos Stathis | header.setCellHorizontalAlignment(toolbar, HasHorizontalAlignment.ALIGN_CENTER); |
309 | bd187dfb | Christos Stathis | header.setCellVerticalAlignment(toolbar, HasVerticalAlignment.ALIGN_MIDDLE); |
310 | bd187dfb | Christos Stathis | |
311 | a19f758c | Christos Stathis | HorizontalPanel folderStatistics = new HorizontalPanel();
|
312 | bbdd34ef | Christos Stathis | folderStatistics.addStyleName("pithos-folderStatistics");
|
313 | a19f758c | Christos Stathis | numOfFiles = new HTML(); |
314 | a19f758c | Christos Stathis | folderStatistics.add(numOfFiles); |
315 | a7b6e464 | Christos Stathis | folderStatistics.setCellVerticalAlignment(numOfFiles, HasVerticalAlignment.ALIGN_MIDDLE); |
316 | a19f758c | Christos Stathis | HTML numOfFilesLabel = new HTML(" Files"); |
317 | a19f758c | Christos Stathis | folderStatistics.add(numOfFilesLabel); |
318 | a7b6e464 | Christos Stathis | folderStatistics.setCellVerticalAlignment(numOfFilesLabel, HasVerticalAlignment.ALIGN_MIDDLE); |
319 | 140f0f6d | Christos Stathis | header.add(folderStatistics); |
320 | 140f0f6d | Christos Stathis | header.setCellHorizontalAlignment(folderStatistics, HasHorizontalAlignment.ALIGN_RIGHT); |
321 | 140f0f6d | Christos Stathis | header.setCellVerticalAlignment(folderStatistics, HasVerticalAlignment.ALIGN_MIDDLE); |
322 | 9fbf5596 | Christos Stathis | header.setCellWidth(folderStatistics, "40px");
|
323 | a7b6e464 | Christos Stathis | outer.add(header); |
324 | a7b6e464 | Christos Stathis | outer.setCellHorizontalAlignment(header, HasHorizontalAlignment.ALIGN_CENTER); |
325 | a7b6e464 | Christos Stathis | // Inner contains the various lists.nner
|
326 | a7b6e464 | Christos Stathis | inner.sinkEvents(Event.ONCONTEXTMENU);
|
327 | a7b6e464 | Christos Stathis | inner.setWidth("100%");
|
328 | 6084aa02 | Christos Stathis | |
329 | 875a0179 | Christos Stathis | folderTreeSelectionModel = new SingleSelectionModel<Folder>(); |
330 | 875a0179 | Christos Stathis | folderTreeSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
|
331 | 875a0179 | Christos Stathis | @Override
|
332 | ebead1b5 | Christos Stathis | public void onSelectionChange(SelectionChangeEvent event) { |
333 | a845b044 | Christos Stathis | if (folderTreeSelectionModel.getSelectedObject() != null) { |
334 | f1b24b82 | Christos Stathis | deselectOthers(folderTreeView, folderTreeSelectionModel); |
335 | 3ebb88f4 | Christos Stathis | applyPermissions(folderTreeSelectionModel.getSelectedObject()); |
336 | a845b044 | Christos Stathis | Folder f = folderTreeSelectionModel.getSelectedObject(); |
337 | dddb75e2 | Christos Stathis | updateFolder(f, true, new Command() { |
338 | dddb75e2 | Christos Stathis | |
339 | dddb75e2 | Christos Stathis | @Override
|
340 | dddb75e2 | Christos Stathis | public void execute() { |
341 | dddb75e2 | Christos Stathis | updateStatistics(); |
342 | dddb75e2 | Christos Stathis | } |
343 | 6acd4df3 | Christos Stathis | }, true);
|
344 | 80a65a5f | Christos Stathis | showRelevantToolbarButtons(); |
345 | a845b044 | Christos Stathis | } |
346 | 80a65a5f | Christos Stathis | else {
|
347 | 80a65a5f | Christos Stathis | if (getSelectedTree().equals(folderTreeView))
|
348 | 80a65a5f | Christos Stathis | setSelectedTree(null);
|
349 | 80a65a5f | Christos Stathis | if (getSelectedTree() == null) |
350 | 80a65a5f | Christos Stathis | showRelevantToolbarButtons(); |
351 | 80a65a5f | Christos Stathis | } |
352 | 875a0179 | Christos Stathis | } |
353 | 875a0179 | Christos Stathis | }); |
354 | 105b4e49 | Christos Stathis | selectionModels.add(folderTreeSelectionModel); |
355 | 875a0179 | Christos Stathis | |
356 | a7c43f26 | Christos Stathis | folderTreeViewModel = new FolderTreeViewModel(this, folderTreeSelectionModel); |
357 | 875a0179 | Christos Stathis | folderTreeView = new FolderTreeView(folderTreeViewModel);
|
358 | 0549e173 | Christos Stathis | treeViews.add(folderTreeView); |
359 | 0549e173 | Christos Stathis | |
360 | e2920e8d | Christos Stathis | fileList = new FileList(this, images); |
361 | bbdd34ef | Christos Stathis | inner.add(fileList); |
362 | 875a0179 | Christos Stathis | |
363 | 1238d28d | Christos Stathis | inner.add(createUploadArea()); |
364 | 1238d28d | Christos Stathis | |
365 | 7c54d867 | Christos Stathis | trees = new VerticalPanel();
|
366 | a76065b6 | Christos Stathis | trees.setWidth("100%");
|
367 | bbdd34ef | Christos Stathis | |
368 | 6084aa02 | Christos Stathis | // Add the left and right panels to the split panel.
|
369 | a6592a15 | Christos Stathis | splitPanel.setLeftWidget(trees); |
370 | 6084aa02 | Christos Stathis | splitPanel.setRightWidget(inner); |
371 | e56be452 | Christos Stathis | splitPanel.setSplitPosition("219px");
|
372 | 6084aa02 | Christos Stathis | splitPanel.setSize("100%", "100%"); |
373 | 6084aa02 | Christos Stathis | splitPanel.addStyleName("pithos-splitPanel");
|
374 | a7b6e464 | Christos Stathis | splitPanel.setWidth(contentWidth); |
375 | 6084aa02 | Christos Stathis | outer.add(splitPanel); |
376 | a76065b6 | Christos Stathis | outer.setCellHorizontalAlignment(splitPanel, HasHorizontalAlignment.ALIGN_CENTER); |
377 | bbdd34ef | Christos Stathis | |
378 | a7b6e464 | Christos Stathis | if (!bareContent) {
|
379 | a7b6e464 | Christos Stathis | statusPanel = new StatusPanel();
|
380 | a7b6e464 | Christos Stathis | statusPanel.setWidth("100%");
|
381 | a7b6e464 | Christos Stathis | outer.add(statusPanel); |
382 | a7b6e464 | Christos Stathis | outer.setCellHorizontalAlignment(statusPanel, HasHorizontalAlignment.ALIGN_CENTER); |
383 | a7b6e464 | Christos Stathis | } |
384 | 0549e173 | Christos Stathis | else
|
385 | 0549e173 | Christos Stathis | splitPanel.addStyleName("pithos-splitPanel-noframe");
|
386 | 6084aa02 | Christos Stathis | |
387 | 6084aa02 | Christos Stathis | // Hook the window resize event, so that we can adjust the UI.
|
388 | 6084aa02 | Christos Stathis | Window.addResizeHandler(this); |
389 | 6084aa02 | Christos Stathis | // Clear out the window's built-in margin, because we want to take
|
390 | 6084aa02 | Christos Stathis | // advantage of the entire client area.
|
391 | 6084aa02 | Christos Stathis | Window.setMargin("0px"); |
392 | 6084aa02 | Christos Stathis | // Finally, add the outer panel to the RootPanel, so that it will be
|
393 | 6084aa02 | Christos Stathis | // displayed.
|
394 | 6084aa02 | Christos Stathis | RootPanel.get().add(outer); |
395 | 6084aa02 | Christos Stathis | // Call the window resized handler to get the initial sizes setup. Doing
|
396 | 6084aa02 | Christos Stathis | // this in a deferred command causes it to occur after all widgets'
|
397 | 6084aa02 | Christos Stathis | // sizes have been computed by the browser.
|
398 | 7c818c14 | Christos Stathis | Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
399 | 6084aa02 | Christos Stathis | |
400 | 6084aa02 | Christos Stathis | @Override
|
401 | 6084aa02 | Christos Stathis | public void execute() { |
402 | 6084aa02 | Christos Stathis | onWindowResized(Window.getClientHeight());
|
403 | 6084aa02 | Christos Stathis | } |
404 | 6084aa02 | Christos Stathis | }); |
405 | 7c818c14 | Christos Stathis | |
406 | 7c818c14 | Christos Stathis | Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
407 | 7c818c14 | Christos Stathis | @Override
|
408 | 7c818c14 | Christos Stathis | public void execute() { |
409 | 64f42c0b | Christos Stathis | fetchAccount(new Command() {
|
410 | 64f42c0b | Christos Stathis | |
411 | 64f42c0b | Christos Stathis | @Override
|
412 | 64f42c0b | Christos Stathis | public void execute() { |
413 | 64f42c0b | Christos Stathis | if (!account.hasHomeContainer())
|
414 | 64f42c0b | Christos Stathis | createHomeContainer(account, this);
|
415 | 64f42c0b | Christos Stathis | else if (!account.hasTrashContainer()) |
416 | 64f42c0b | Christos Stathis | createTrashContainer(this);
|
417 | 64f42c0b | Christos Stathis | else {
|
418 | 64f42c0b | Christos Stathis | for (Folder f : account.getContainers())
|
419 | 64f42c0b | Christos Stathis | if (f.getName().equals(Pithos.TRASH_CONTAINER)) {
|
420 | 64f42c0b | Christos Stathis | trash = f; |
421 | 64f42c0b | Christos Stathis | break;
|
422 | 64f42c0b | Christos Stathis | } |
423 | ba6ffffb | Christos Stathis | trees.add(folderTreeView); |
424 | 5fab761b | Christos Stathis | folderTreeViewModel.initialize(account, new Command() {
|
425 | 5fab761b | Christos Stathis | |
426 | 5fab761b | Christos Stathis | @Override
|
427 | 5fab761b | Christos Stathis | public void execute() { |
428 | 5fab761b | Christos Stathis | createMySharedTree(); |
429 | 5fab761b | Christos Stathis | } |
430 | 5fab761b | Christos Stathis | }); |
431 | 3f62b626 | Christos Stathis | |
432 | 3f62b626 | Christos Stathis | HorizontalPanel separator = new HorizontalPanel();
|
433 | 3f62b626 | Christos Stathis | separator.addStyleName("pithos-statisticsSeparator");
|
434 | 3f62b626 | Christos Stathis | separator.add(new HTML("")); |
435 | 3f62b626 | Christos Stathis | trees.add(separator); |
436 | 3f62b626 | Christos Stathis | |
437 | c46c9e31 | Christos Stathis | groupTreeViewModel = new GroupTreeViewModel(Pithos.this);
|
438 | c46c9e31 | Christos Stathis | groupTreeView = new GroupTreeView(groupTreeViewModel);
|
439 | c46c9e31 | Christos Stathis | treeViews.add(groupTreeView); |
440 | c46c9e31 | Christos Stathis | trees.add(groupTreeView); |
441 | d18749bc | Christos Stathis | folderTreeView.showStatistics(account); |
442 | 64f42c0b | Christos Stathis | } |
443 | 64f42c0b | Christos Stathis | } |
444 | 64f42c0b | Christos Stathis | }); |
445 | 7c818c14 | Christos Stathis | } |
446 | 7c818c14 | Christos Stathis | }); |
447 | 140f0f6d | Christos Stathis | |
448 | 7307d16b | Christos Stathis | Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
|
449 | 7307d16b | Christos Stathis | |
450 | 7307d16b | Christos Stathis | @Override
|
451 | 7307d16b | Christos Stathis | public boolean execute() { |
452 | 7307d16b | Christos Stathis | Folder f = getSelection(); |
453 | 7307d16b | Christos Stathis | if (f != null) { |
454 | 7307d16b | Christos Stathis | if (getSelectedTree().equals(folderTreeView))
|
455 | 7307d16b | Christos Stathis | updateFolder(f, true, null, false); |
456 | 7307d16b | Christos Stathis | else if (getSelectedTree().equals(mysharedTreeView)) |
457 | 7307d16b | Christos Stathis | updateSharedFolder(f, true);
|
458 | 7307d16b | Christos Stathis | } |
459 | 7307d16b | Christos Stathis | return true; |
460 | 7307d16b | Christos Stathis | } |
461 | 7307d16b | Christos Stathis | }, 3000);
|
462 | 6084aa02 | Christos Stathis | } |
463 | a57faaf0 | Christos Stathis | |
464 | 3ebb88f4 | Christos Stathis | public void applyPermissions(Folder f) { |
465 | 3ebb88f4 | Christos Stathis | if (f != null) { |
466 | 1238d28d | Christos Stathis | if (f.isInTrash()) {
|
467 | 3ebb88f4 | Christos Stathis | upload.setEnabled(false);
|
468 | 1238d28d | Christos Stathis | hideUploadArea(); |
469 | 1238d28d | Christos Stathis | } |
470 | 3ebb88f4 | Christos Stathis | else {
|
471 | 3ebb88f4 | Christos Stathis | Boolean[] perms = f.getPermissions().get(username); |
472 | 3ebb88f4 | Christos Stathis | if (f.getOwner().equals(username) || (perms != null && perms[1] != null && perms[1])) { |
473 | 3ebb88f4 | Christos Stathis | upload.setEnabled(true);
|
474 | 1238d28d | Christos Stathis | showUploadArea(); |
475 | 3ebb88f4 | Christos Stathis | } |
476 | 1238d28d | Christos Stathis | else {
|
477 | 3ebb88f4 | Christos Stathis | upload.setEnabled(false);
|
478 | 1238d28d | Christos Stathis | hideUploadArea(); |
479 | 1238d28d | Christos Stathis | } |
480 | 3ebb88f4 | Christos Stathis | } |
481 | 3ebb88f4 | Christos Stathis | } |
482 | 1238d28d | Christos Stathis | else {
|
483 | 3ebb88f4 | Christos Stathis | upload.setEnabled(false);
|
484 | 1238d28d | Christos Stathis | hideUploadArea(); |
485 | 1238d28d | Christos Stathis | } |
486 | 3ebb88f4 | Christos Stathis | } |
487 | 3ebb88f4 | Christos Stathis | |
488 | 3ebb88f4 | Christos Stathis | @SuppressWarnings({ "rawtypes", "unchecked" }) |
489 | f1b24b82 | Christos Stathis | public void deselectOthers(TreeView _selectedTree, SingleSelectionModel model) { |
490 | f1b24b82 | Christos Stathis | selectedTree = _selectedTree; |
491 | 0549e173 | Christos Stathis | |
492 | 105b4e49 | Christos Stathis | for (SingleSelectionModel s : selectionModels) |
493 | 80a65a5f | Christos Stathis | if (!s.equals(model) && s.getSelectedObject() != null) |
494 | 105b4e49 | Christos Stathis | s.setSelected(s.getSelectedObject(), false);
|
495 | 105b4e49 | Christos Stathis | } |
496 | 105b4e49 | Christos Stathis | |
497 | dddb75e2 | Christos Stathis | public void showFiles(final Folder f) { |
498 | 07a1b5fe | Christos Stathis | Set<File> files = f.getFiles(); |
499 | a845b044 | Christos Stathis | showFiles(files); |
500 | a845b044 | Christos Stathis | } |
501 | a845b044 | Christos Stathis | |
502 | a845b044 | Christos Stathis | public void showFiles(Set<File> files) { |
503 | a845b044 | Christos Stathis | fileList.setFiles(new ArrayList<File>(files)); |
504 | 07a1b5fe | Christos Stathis | } |
505 | 07a1b5fe | Christos Stathis | |
506 | 875a0179 | Christos Stathis | /**
|
507 | a57faaf0 | Christos Stathis | * Parse and store the user credentials to the appropriate fields.
|
508 | a57faaf0 | Christos Stathis | */
|
509 | 6084aa02 | Christos Stathis | private boolean parseUserCredentials() { |
510 | 36dc8e18 | Christos Stathis | Configuration conf = (Configuration) GWT.create(Configuration.class); |
511 | ff057ec1 | Christos Stathis | Dictionary otherProperties = Dictionary.getDictionary("otherProperties"); |
512 | 4ea3c87b | Christos Stathis | String cookie = otherProperties.get("authCookie"); |
513 | 4ea3c87b | Christos Stathis | String auth = Cookies.getCookie(cookie);
|
514 | 4ea3c87b | Christos Stathis | if (auth == null) { |
515 | 4ea3c87b | Christos Stathis | authenticateUser(); |
516 | 4ea3c87b | Christos Stathis | return false; |
517 | 36dc8e18 | Christos Stathis | } |
518 | 4ea3c87b | Christos Stathis | if (auth.startsWith("\"")) |
519 | 4ea3c87b | Christos Stathis | auth = auth.substring(1);
|
520 | 4ea3c87b | Christos Stathis | if (auth.endsWith("\"")) |
521 | 4ea3c87b | Christos Stathis | auth = auth.substring(0, auth.length() - 1); |
522 | 4ea3c87b | Christos Stathis | String[] authSplit = auth.split("\\" + conf.cookieSeparator(), 2); |
523 | 4ea3c87b | Christos Stathis | if (authSplit.length != 2) { |
524 | 4ea3c87b | Christos Stathis | authenticateUser(); |
525 | 4ea3c87b | Christos Stathis | return false; |
526 | 4ea3c87b | Christos Stathis | } |
527 | 4ea3c87b | Christos Stathis | username = authSplit[0];
|
528 | 4ea3c87b | Christos Stathis | token = authSplit[1];
|
529 | 4d869bf1 | Christos Stathis | |
530 | 4d869bf1 | Christos Stathis | String gotoUrl = Window.Location.getParameter("goto"); |
531 | 4d869bf1 | Christos Stathis | if (gotoUrl != null && gotoUrl.length() > 0) { |
532 | 983f9ee2 | Christos Stathis | Window.Location.assign(gotoUrl);
|
533 | 4d869bf1 | Christos Stathis | return false; |
534 | 4d869bf1 | Christos Stathis | } |
535 | 7811b9d1 | Christos Stathis | return true; |
536 | 36dc8e18 | Christos Stathis | } |
537 | a57faaf0 | Christos Stathis | |
538 | 6084aa02 | Christos Stathis | /**
|
539 | a57faaf0 | Christos Stathis | * Redirect the user to the login page for authentication.
|
540 | a57faaf0 | Christos Stathis | */
|
541 | a57faaf0 | Christos Stathis | protected void authenticateUser() { |
542 | f0105e9f | Christos Stathis | Dictionary otherProperties = Dictionary.getDictionary("otherProperties"); |
543 | 4d869bf1 | Christos Stathis | Window.Location.assign(otherProperties.get("loginUrl") + Window.Location.getHref()); |
544 | a57faaf0 | Christos Stathis | } |
545 | a57faaf0 | Christos Stathis | |
546 | 64f42c0b | Christos Stathis | protected void fetchAccount(final Command callback) { |
547 | b51c628b | Christos Stathis | String path = "?format=json"; |
548 | 7c818c14 | Christos Stathis | |
549 | b51c628b | Christos Stathis | GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, getApiPath(), username, path) {
|
550 | 7c818c14 | Christos Stathis | @Override
|
551 | 7811b9d1 | Christos Stathis | public void onSuccess(AccountResource _result) { |
552 | 7811b9d1 | Christos Stathis | account = _result; |
553 | 64f42c0b | Christos Stathis | if (callback != null) |
554 | 64f42c0b | Christos Stathis | callback.execute(); |
555 | 7c818c14 | Christos Stathis | } |
556 | 7c818c14 | Christos Stathis | |
557 | 7c818c14 | Christos Stathis | @Override
|
558 | 7c818c14 | Christos Stathis | public void onError(Throwable t) { |
559 | 7c818c14 | Christos Stathis | GWT.log("Error getting account", t);
|
560 | 3f8622d4 | Christos Stathis | setError(t); |
561 | 7c818c14 | Christos Stathis | if (t instanceof RestException) |
562 | a7c43f26 | Christos Stathis | displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
|
563 | 7c818c14 | Christos Stathis | else
|
564 | a7c43f26 | Christos Stathis | displayError("System error fetching user data: " + t.getMessage());
|
565 | 7c818c14 | Christos Stathis | } |
566 | 9539e23d | Christos Stathis | |
567 | 9539e23d | Christos Stathis | @Override
|
568 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
569 | 9539e23d | Christos Stathis | sessionExpired(); |
570 | 9539e23d | Christos Stathis | } |
571 | 7c818c14 | Christos Stathis | }; |
572 | 875a0179 | Christos Stathis | getAccount.setHeader("X-Auth-Token", token);
|
573 | 7c818c14 | Christos Stathis | Scheduler.get().scheduleDeferred(getAccount); |
574 | 7c818c14 | Christos Stathis | } |
575 | 7c818c14 | Christos Stathis | |
576 | 64f42c0b | Christos Stathis | public void updateStatistics() { |
577 | 64f42c0b | Christos Stathis | HeadRequest<AccountResource> headAccount = new HeadRequest<AccountResource>(AccountResource.class, getApiPath(), username, "", account) { |
578 | 64f42c0b | Christos Stathis | |
579 | 64f42c0b | Christos Stathis | @Override
|
580 | ebead1b5 | Christos Stathis | public void onSuccess(AccountResource _result) { |
581 | d18749bc | Christos Stathis | folderTreeView.showStatistics(account); |
582 | 64f42c0b | Christos Stathis | } |
583 | 64f42c0b | Christos Stathis | |
584 | 64f42c0b | Christos Stathis | @Override
|
585 | 64f42c0b | Christos Stathis | public void onError(Throwable t) { |
586 | 64f42c0b | Christos Stathis | GWT.log("Error getting account", t);
|
587 | 3f8622d4 | Christos Stathis | setError(t); |
588 | 64f42c0b | Christos Stathis | if (t instanceof RestException) |
589 | 64f42c0b | Christos Stathis | displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
|
590 | 64f42c0b | Christos Stathis | else
|
591 | 64f42c0b | Christos Stathis | displayError("System error fetching user data: " + t.getMessage());
|
592 | 64f42c0b | Christos Stathis | } |
593 | 9539e23d | Christos Stathis | |
594 | 9539e23d | Christos Stathis | @Override
|
595 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
596 | 9539e23d | Christos Stathis | sessionExpired(); |
597 | 9539e23d | Christos Stathis | } |
598 | 64f42c0b | Christos Stathis | }; |
599 | 64f42c0b | Christos Stathis | headAccount.setHeader("X-Auth-Token", token);
|
600 | 64f42c0b | Christos Stathis | Scheduler.get().scheduleDeferred(headAccount); |
601 | 64f42c0b | Christos Stathis | } |
602 | 64f42c0b | Christos Stathis | |
603 | abd8738f | Christos Stathis | protected void createHomeContainer(final AccountResource _account, final Command callback) { |
604 | 7b28ae07 | Christos Stathis | String path = "/" + Pithos.HOME_CONTAINER; |
605 | b51c628b | Christos Stathis | PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) {
|
606 | b8822fe7 | Christos Stathis | @Override
|
607 | ebead1b5 | Christos Stathis | public void onSuccess(Resource result) { |
608 | abd8738f | Christos Stathis | if (!_account.hasTrashContainer())
|
609 | 64f42c0b | Christos Stathis | createTrashContainer(callback); |
610 | 7b28ae07 | Christos Stathis | else
|
611 | 64f42c0b | Christos Stathis | fetchAccount(callback); |
612 | b8822fe7 | Christos Stathis | } |
613 | b8822fe7 | Christos Stathis | |
614 | b8822fe7 | Christos Stathis | @Override
|
615 | b8822fe7 | Christos Stathis | public void onError(Throwable t) { |
616 | b8822fe7 | Christos Stathis | GWT.log("Error creating pithos", t);
|
617 | 3f8622d4 | Christos Stathis | setError(t); |
618 | b8822fe7 | Christos Stathis | if (t instanceof RestException) |
619 | a7c43f26 | Christos Stathis | displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
|
620 | b8822fe7 | Christos Stathis | else
|
621 | a7c43f26 | Christos Stathis | displayError("System error Error creating pithos: " + t.getMessage());
|
622 | b8822fe7 | Christos Stathis | } |
623 | 9539e23d | Christos Stathis | |
624 | 9539e23d | Christos Stathis | @Override
|
625 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
626 | 9539e23d | Christos Stathis | sessionExpired(); |
627 | 9539e23d | Christos Stathis | } |
628 | b8822fe7 | Christos Stathis | }; |
629 | b8822fe7 | Christos Stathis | createPithos.setHeader("X-Auth-Token", getToken());
|
630 | b8822fe7 | Christos Stathis | Scheduler.get().scheduleDeferred(createPithos); |
631 | b8822fe7 | Christos Stathis | } |
632 | b8822fe7 | Christos Stathis | |
633 | 64f42c0b | Christos Stathis | protected void createTrashContainer(final Command callback) { |
634 | 7b28ae07 | Christos Stathis | String path = "/" + Pithos.TRASH_CONTAINER; |
635 | 7b28ae07 | Christos Stathis | PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) {
|
636 | 7b28ae07 | Christos Stathis | @Override
|
637 | ebead1b5 | Christos Stathis | public void onSuccess(Resource result) { |
638 | 64f42c0b | Christos Stathis | fetchAccount(callback); |
639 | 7b28ae07 | Christos Stathis | } |
640 | 7b28ae07 | Christos Stathis | |
641 | 7b28ae07 | Christos Stathis | @Override
|
642 | 7b28ae07 | Christos Stathis | public void onError(Throwable t) { |
643 | 7b28ae07 | Christos Stathis | GWT.log("Error creating pithos", t);
|
644 | 3f8622d4 | Christos Stathis | setError(t); |
645 | 7b28ae07 | Christos Stathis | if (t instanceof RestException) |
646 | 7b28ae07 | Christos Stathis | displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
|
647 | 7b28ae07 | Christos Stathis | else
|
648 | 7b28ae07 | Christos Stathis | displayError("System error Error creating pithos: " + t.getMessage());
|
649 | 7b28ae07 | Christos Stathis | } |
650 | 9539e23d | Christos Stathis | |
651 | 9539e23d | Christos Stathis | @Override
|
652 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
653 | 9539e23d | Christos Stathis | sessionExpired(); |
654 | 9539e23d | Christos Stathis | } |
655 | 7b28ae07 | Christos Stathis | }; |
656 | 7b28ae07 | Christos Stathis | createPithos.setHeader("X-Auth-Token", getToken());
|
657 | 7b28ae07 | Christos Stathis | Scheduler.get().scheduleDeferred(createPithos); |
658 | 7b28ae07 | Christos Stathis | } |
659 | 7b28ae07 | Christos Stathis | |
660 | 7b28ae07 | Christos Stathis | /**
|
661 | a57faaf0 | Christos Stathis | * Creates an HTML fragment that places an image & caption together, for use
|
662 | a57faaf0 | Christos Stathis | * in a group header.
|
663 | a57faaf0 | Christos Stathis | *
|
664 | a57faaf0 | Christos Stathis | * @param imageProto an image prototype for an image
|
665 | a57faaf0 | Christos Stathis | * @param caption the group caption
|
666 | a57faaf0 | Christos Stathis | * @return the header HTML fragment
|
667 | a57faaf0 | Christos Stathis | */
|
668 | a57faaf0 | Christos Stathis | private String createHeaderHTML(AbstractImagePrototype imageProto, String caption) { |
669 | a57faaf0 | Christos Stathis | String captionHTML = "<table class='caption' cellpadding='0' " |
670 | a57faaf0 | Christos Stathis | + "cellspacing='0'>" + "<tr><td class='lcaption'>" + imageProto.getHTML() |
671 | a57faaf0 | Christos Stathis | + "</td><td id =" + caption +" class='rcaption'><b style='white-space:nowrap'> " |
672 | a57faaf0 | Christos Stathis | + caption + "</b></td></tr></table>";
|
673 | a57faaf0 | Christos Stathis | return captionHTML;
|
674 | a57faaf0 | Christos Stathis | } |
675 | a57faaf0 | Christos Stathis | |
676 | d7be6c23 | Christos Stathis | protected void onWindowResized(int height) { |
677 | d7be6c23 | Christos Stathis | // Adjust the split panel to take up the available room in the window.
|
678 | 0549e173 | Christos Stathis | int newHeight = height - splitPanel.getAbsoluteTop();
|
679 | d7be6c23 | Christos Stathis | if (newHeight < 1) |
680 | d7be6c23 | Christos Stathis | newHeight = 1;
|
681 | d7be6c23 | Christos Stathis | splitPanel.setHeight("" + newHeight);
|
682 | d7be6c23 | Christos Stathis | inner.setHeight("" + newHeight);
|
683 | d7be6c23 | Christos Stathis | } |
684 | a57faaf0 | Christos Stathis | |
685 | a57faaf0 | Christos Stathis | @Override
|
686 | a57faaf0 | Christos Stathis | public void onResize(ResizeEvent event) { |
687 | a57faaf0 | Christos Stathis | int height = event.getHeight();
|
688 | d7be6c23 | Christos Stathis | onWindowResized(height); |
689 | a57faaf0 | Christos Stathis | } |
690 | a57faaf0 | Christos Stathis | |
691 | a57faaf0 | Christos Stathis | /**
|
692 | a57faaf0 | Christos Stathis | * Display an error message.
|
693 | a57faaf0 | Christos Stathis | *
|
694 | a57faaf0 | Christos Stathis | * @param msg the message to display
|
695 | a57faaf0 | Christos Stathis | */
|
696 | a57faaf0 | Christos Stathis | public void displayError(String msg) { |
697 | a57faaf0 | Christos Stathis | messagePanel.displayError(msg); |
698 | a57faaf0 | Christos Stathis | } |
699 | a57faaf0 | Christos Stathis | |
700 | a57faaf0 | Christos Stathis | /**
|
701 | a57faaf0 | Christos Stathis | * Display a warning message.
|
702 | a57faaf0 | Christos Stathis | *
|
703 | a57faaf0 | Christos Stathis | * @param msg the message to display
|
704 | a57faaf0 | Christos Stathis | */
|
705 | a57faaf0 | Christos Stathis | public void displayWarning(String msg) { |
706 | a57faaf0 | Christos Stathis | messagePanel.displayWarning(msg); |
707 | a57faaf0 | Christos Stathis | } |
708 | a57faaf0 | Christos Stathis | |
709 | a57faaf0 | Christos Stathis | /**
|
710 | a57faaf0 | Christos Stathis | * Display an informational message.
|
711 | a57faaf0 | Christos Stathis | *
|
712 | a57faaf0 | Christos Stathis | * @param msg the message to display
|
713 | a57faaf0 | Christos Stathis | */
|
714 | a57faaf0 | Christos Stathis | public void displayInformation(String msg) { |
715 | a57faaf0 | Christos Stathis | messagePanel.displayInformation(msg); |
716 | a57faaf0 | Christos Stathis | } |
717 | a57faaf0 | Christos Stathis | |
718 | a57faaf0 | Christos Stathis | /**
|
719 | a57faaf0 | Christos Stathis | * Retrieve the fileList.
|
720 | a57faaf0 | Christos Stathis | *
|
721 | a57faaf0 | Christos Stathis | * @return the fileList
|
722 | a57faaf0 | Christos Stathis | */
|
723 | a57faaf0 | Christos Stathis | public FileList getFileList() {
|
724 | a57faaf0 | Christos Stathis | return fileList;
|
725 | a57faaf0 | Christos Stathis | } |
726 | a57faaf0 | Christos Stathis | |
727 | a57faaf0 | Christos Stathis | /**
|
728 | a57faaf0 | Christos Stathis | * Retrieve the topPanel.
|
729 | a57faaf0 | Christos Stathis | *
|
730 | a57faaf0 | Christos Stathis | * @return the topPanel
|
731 | a57faaf0 | Christos Stathis | */
|
732 | a57faaf0 | Christos Stathis | TopPanel getTopPanel() { |
733 | a57faaf0 | Christos Stathis | return topPanel;
|
734 | a57faaf0 | Christos Stathis | } |
735 | a57faaf0 | Christos Stathis | |
736 | a57faaf0 | Christos Stathis | /**
|
737 | a57faaf0 | Christos Stathis | * Retrieve the clipboard.
|
738 | a57faaf0 | Christos Stathis | *
|
739 | a57faaf0 | Christos Stathis | * @return the clipboard
|
740 | a57faaf0 | Christos Stathis | */
|
741 | a57faaf0 | Christos Stathis | public Clipboard getClipboard() { |
742 | a57faaf0 | Christos Stathis | return clipboard;
|
743 | a57faaf0 | Christos Stathis | } |
744 | a57faaf0 | Christos Stathis | |
745 | a57faaf0 | Christos Stathis | public StatusPanel getStatusPanel() {
|
746 | a57faaf0 | Christos Stathis | return statusPanel;
|
747 | a57faaf0 | Christos Stathis | } |
748 | a57faaf0 | Christos Stathis | |
749 | a57faaf0 | Christos Stathis | public String getToken() { |
750 | a57faaf0 | Christos Stathis | return token;
|
751 | a57faaf0 | Christos Stathis | } |
752 | a57faaf0 | Christos Stathis | |
753 | a57faaf0 | Christos Stathis | public static native void preventIESelection() /*-{ |
754 | a57faaf0 | Christos Stathis | $doc.body.onselectstart = function () { return false; };
|
755 | a57faaf0 | Christos Stathis | }-*/;
|
756 | a57faaf0 | Christos Stathis | |
757 | a57faaf0 | Christos Stathis | public static native void enableIESelection() /*-{ |
758 | a57faaf0 | Christos Stathis | if ($doc.body.onselectstart != null)
|
759 | a57faaf0 | Christos Stathis | $doc.body.onselectstart = null;
|
760 | a57faaf0 | Christos Stathis | }-*/;
|
761 | a57faaf0 | Christos Stathis | |
762 | a57faaf0 | Christos Stathis | /**
|
763 | a57faaf0 | Christos Stathis | * @return the absolute path of the API root URL
|
764 | a57faaf0 | Christos Stathis | */
|
765 | a57faaf0 | Christos Stathis | public String getApiPath() { |
766 | a57faaf0 | Christos Stathis | Configuration conf = (Configuration) GWT.create(Configuration.class); |
767 | 6084aa02 | Christos Stathis | return conf.apiPath();
|
768 | a57faaf0 | Christos Stathis | } |
769 | a57faaf0 | Christos Stathis | |
770 | a57faaf0 | Christos Stathis | /**
|
771 | a57faaf0 | Christos Stathis | * History support for folder navigation
|
772 | a57faaf0 | Christos Stathis | * adds a new browser history entry
|
773 | a57faaf0 | Christos Stathis | *
|
774 | a57faaf0 | Christos Stathis | * @param key
|
775 | a57faaf0 | Christos Stathis | */
|
776 | a57faaf0 | Christos Stathis | public void updateHistory(String key){ |
777 | a57faaf0 | Christos Stathis | // Replace any whitespace of the initial string to "+"
|
778 | a57faaf0 | Christos Stathis | // String result = key.replaceAll("\\s","+");
|
779 | a57faaf0 | Christos Stathis | // Add a new browser history entry.
|
780 | a57faaf0 | Christos Stathis | // History.newItem(result);
|
781 | a57faaf0 | Christos Stathis | History.newItem(key); |
782 | a57faaf0 | Christos Stathis | } |
783 | a57faaf0 | Christos Stathis | |
784 | 2c801ad7 | Christos Stathis | public void deleteFolder(final Folder folder, final Command callback) { |
785 | f5023f13 | Christos Stathis | String path = getApiPath() + folder.getOwner() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(folder.getPrefix()) + "&t=" + System.currentTimeMillis(); |
786 | 602ebeb4 | Christos Stathis | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
|
787 | 602ebeb4 | Christos Stathis | builder.setHeader("X-Auth-Token", getToken());
|
788 | 602ebeb4 | Christos Stathis | try {
|
789 | 602ebeb4 | Christos Stathis | builder.sendRequest("", new RequestCallback() { |
790 | 602ebeb4 | Christos Stathis | @Override
|
791 | ebead1b5 | Christos Stathis | public void onResponseReceived(Request request, Response response) { |
792 | 602ebeb4 | Christos Stathis | if (response.getStatusCode() == Response.SC_OK) {
|
793 | 602ebeb4 | Christos Stathis | JSONValue json = JSONParser.parseStrict(response.getText()); |
794 | 602ebeb4 | Christos Stathis | JSONArray array = json.isArray(); |
795 | 602ebeb4 | Christos Stathis | int i = 0; |
796 | 602ebeb4 | Christos Stathis | if (array != null) { |
797 | 2c801ad7 | Christos Stathis | deleteObject(folder, i, array, callback); |
798 | 602ebeb4 | Christos Stathis | } |
799 | 602ebeb4 | Christos Stathis | } |
800 | 602ebeb4 | Christos Stathis | } |
801 | 602ebeb4 | Christos Stathis | |
802 | 602ebeb4 | Christos Stathis | @Override
|
803 | ebead1b5 | Christos Stathis | public void onError(Request request, Throwable exception) { |
804 | 3f8622d4 | Christos Stathis | setError(exception); |
805 | a7c43f26 | Christos Stathis | displayError("System error unable to delete folder: " + exception.getMessage());
|
806 | 602ebeb4 | Christos Stathis | } |
807 | 602ebeb4 | Christos Stathis | }); |
808 | 602ebeb4 | Christos Stathis | } |
809 | 602ebeb4 | Christos Stathis | catch (RequestException e) {
|
810 | 602ebeb4 | Christos Stathis | } |
811 | 602ebeb4 | Christos Stathis | } |
812 | 602ebeb4 | Christos Stathis | |
813 | 2c801ad7 | Christos Stathis | void deleteObject(final Folder folder, final int i, final JSONArray array, final Command callback) { |
814 | 602ebeb4 | Christos Stathis | if (i < array.size()) {
|
815 | 602ebeb4 | Christos Stathis | JSONObject o = array.get(i).isObject(); |
816 | 602ebeb4 | Christos Stathis | if (o != null && !o.containsKey("subdir")) { |
817 | 602ebeb4 | Christos Stathis | JSONString name = o.get("name").isString();
|
818 | b51c628b | Christos Stathis | String path = "/" + folder.getContainer() + "/" + name.stringValue(); |
819 | 5f91f72d | Christos Stathis | DeleteRequest delete = new DeleteRequest(getApiPath(), folder.getOwner(), URL.encode(path)) { |
820 | 602ebeb4 | Christos Stathis | @Override
|
821 | ebead1b5 | Christos Stathis | public void onSuccess(Resource result) { |
822 | 2c801ad7 | Christos Stathis | deleteObject(folder, i + 1, array, callback);
|
823 | 602ebeb4 | Christos Stathis | } |
824 | 602ebeb4 | Christos Stathis | |
825 | 602ebeb4 | Christos Stathis | @Override
|
826 | 602ebeb4 | Christos Stathis | public void onError(Throwable t) { |
827 | 602ebeb4 | Christos Stathis | GWT.log("", t);
|
828 | 3f8622d4 | Christos Stathis | setError(t); |
829 | a7c43f26 | Christos Stathis | displayError("System error unable to delete folder: " + t.getMessage());
|
830 | 602ebeb4 | Christos Stathis | } |
831 | 9539e23d | Christos Stathis | |
832 | 9539e23d | Christos Stathis | @Override
|
833 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
834 | 9539e23d | Christos Stathis | sessionExpired(); |
835 | 9539e23d | Christos Stathis | } |
836 | 602ebeb4 | Christos Stathis | }; |
837 | 602ebeb4 | Christos Stathis | delete.setHeader("X-Auth-Token", getToken());
|
838 | 602ebeb4 | Christos Stathis | Scheduler.get().scheduleDeferred(delete); |
839 | 602ebeb4 | Christos Stathis | } |
840 | 7811b9d1 | Christos Stathis | else if (o != null) { |
841 | 602ebeb4 | Christos Stathis | String subdir = o.get("subdir").isString().stringValue(); |
842 | 602ebeb4 | Christos Stathis | subdir = subdir.substring(0, subdir.length() - 1); |
843 | f5023f13 | Christos Stathis | String path = getApiPath() + getUsername() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(subdir) + "&t=" + System.currentTimeMillis(); |
844 | 602ebeb4 | Christos Stathis | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
|
845 | 602ebeb4 | Christos Stathis | builder.setHeader("X-Auth-Token", getToken());
|
846 | 602ebeb4 | Christos Stathis | try {
|
847 | 602ebeb4 | Christos Stathis | builder.sendRequest("", new RequestCallback() { |
848 | 602ebeb4 | Christos Stathis | @Override
|
849 | ebead1b5 | Christos Stathis | public void onResponseReceived(Request request, Response response) { |
850 | 602ebeb4 | Christos Stathis | if (response.getStatusCode() == Response.SC_OK) {
|
851 | 602ebeb4 | Christos Stathis | JSONValue json = JSONParser.parseStrict(response.getText()); |
852 | 602ebeb4 | Christos Stathis | JSONArray array2 = json.isArray(); |
853 | 602ebeb4 | Christos Stathis | if (array2 != null) { |
854 | 602ebeb4 | Christos Stathis | int l = array.size();
|
855 | 602ebeb4 | Christos Stathis | for (int j=0; j<array2.size(); j++) { |
856 | 602ebeb4 | Christos Stathis | array.set(l++, array2.get(j)); |
857 | 602ebeb4 | Christos Stathis | } |
858 | 602ebeb4 | Christos Stathis | } |
859 | 2c801ad7 | Christos Stathis | deleteObject(folder, i + 1, array, callback);
|
860 | 602ebeb4 | Christos Stathis | } |
861 | 602ebeb4 | Christos Stathis | } |
862 | 602ebeb4 | Christos Stathis | |
863 | 602ebeb4 | Christos Stathis | @Override
|
864 | ebead1b5 | Christos Stathis | public void onError(Request request, Throwable exception) { |
865 | 3f8622d4 | Christos Stathis | setError(exception); |
866 | a7c43f26 | Christos Stathis | displayError("System error unable to delete folder: " + exception.getMessage());
|
867 | 602ebeb4 | Christos Stathis | } |
868 | 602ebeb4 | Christos Stathis | }); |
869 | 602ebeb4 | Christos Stathis | } |
870 | 602ebeb4 | Christos Stathis | catch (RequestException e) {
|
871 | 602ebeb4 | Christos Stathis | } |
872 | 602ebeb4 | Christos Stathis | } |
873 | 602ebeb4 | Christos Stathis | } |
874 | 602ebeb4 | Christos Stathis | else {
|
875 | b51c628b | Christos Stathis | String path = folder.getUri();
|
876 | 5f91f72d | Christos Stathis | DeleteRequest deleteFolder = new DeleteRequest(getApiPath(), getUsername(), URL.encode(path)) { |
877 | 602ebeb4 | Christos Stathis | @Override
|
878 | ebead1b5 | Christos Stathis | public void onSuccess(Resource result) { |
879 | 64f42c0b | Christos Stathis | updateFolder(folder.getParent(), true, new Command() { |
880 | 64f42c0b | Christos Stathis | |
881 | 64f42c0b | Christos Stathis | @Override
|
882 | 64f42c0b | Christos Stathis | public void execute() { |
883 | 8d67a0ac | Christos Stathis | folderTreeSelectionModel.setSelected(folder.getParent(), true);
|
884 | 64f42c0b | Christos Stathis | updateStatistics(); |
885 | 2c801ad7 | Christos Stathis | if (callback != null) |
886 | 2c801ad7 | Christos Stathis | callback.execute(); |
887 | 64f42c0b | Christos Stathis | } |
888 | 6acd4df3 | Christos Stathis | }, true);
|
889 | 602ebeb4 | Christos Stathis | } |
890 | 602ebeb4 | Christos Stathis | |
891 | 602ebeb4 | Christos Stathis | @Override
|
892 | 602ebeb4 | Christos Stathis | public void onError(Throwable t) { |
893 | 602ebeb4 | Christos Stathis | GWT.log("", t);
|
894 | 3f8622d4 | Christos Stathis | setError(t); |
895 | 602ebeb4 | Christos Stathis | if (t instanceof RestException) { |
896 | 7b28ae07 | Christos Stathis | if (((RestException) t).getHttpStatusCode() != Response.SC_NOT_FOUND)
|
897 | 7b28ae07 | Christos Stathis | displayError("Unable to delete folder: "+((RestException) t).getHttpStatusText());
|
898 | 7b28ae07 | Christos Stathis | else
|
899 | 7b28ae07 | Christos Stathis | onSuccess(null);
|
900 | 602ebeb4 | Christos Stathis | } |
901 | 602ebeb4 | Christos Stathis | else
|
902 | a7c43f26 | Christos Stathis | displayError("System error unable to delete folder: " + t.getMessage());
|
903 | 602ebeb4 | Christos Stathis | } |
904 | 9539e23d | Christos Stathis | |
905 | 9539e23d | Christos Stathis | @Override
|
906 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
907 | 9539e23d | Christos Stathis | sessionExpired(); |
908 | 9539e23d | Christos Stathis | } |
909 | 602ebeb4 | Christos Stathis | }; |
910 | 602ebeb4 | Christos Stathis | deleteFolder.setHeader("X-Auth-Token", getToken());
|
911 | 602ebeb4 | Christos Stathis | Scheduler.get().scheduleDeferred(deleteFolder); |
912 | 602ebeb4 | Christos Stathis | } |
913 | 602ebeb4 | Christos Stathis | } |
914 | fad48f0d | Christos Stathis | |
915 | fad48f0d | Christos Stathis | public FolderTreeView getFolderTreeView() {
|
916 | fad48f0d | Christos Stathis | return folderTreeView;
|
917 | fad48f0d | Christos Stathis | } |
918 | d6be39da | Christos Stathis | |
919 | 63ee965c | Christos Stathis | public void copyFiles(final Iterator<File> iter, final String targetUsername, final String targetUri, final Command callback) { |
920 | d6be39da | Christos Stathis | if (iter.hasNext()) {
|
921 | d6be39da | Christos Stathis | File file = iter.next();
|
922 | b51c628b | Christos Stathis | String path = targetUri + "/" + file.getName(); |
923 | 63ee965c | Christos Stathis | PutRequest copyFile = new PutRequest(getApiPath(), targetUsername, path) {
|
924 | d6be39da | Christos Stathis | @Override
|
925 | ebead1b5 | Christos Stathis | public void onSuccess(Resource result) { |
926 | 63ee965c | Christos Stathis | copyFiles(iter, targetUsername, targetUri, callback); |
927 | d6be39da | Christos Stathis | } |
928 | d6be39da | Christos Stathis | |
929 | d6be39da | Christos Stathis | @Override
|
930 | d6be39da | Christos Stathis | public void onError(Throwable t) { |
931 | d6be39da | Christos Stathis | GWT.log("", t);
|
932 | 3f8622d4 | Christos Stathis | setError(t); |
933 | d6be39da | Christos Stathis | if (t instanceof RestException) { |
934 | a7c43f26 | Christos Stathis | displayError("Unable to copy file: " + ((RestException) t).getHttpStatusText());
|
935 | d6be39da | Christos Stathis | } |
936 | d6be39da | Christos Stathis | else
|
937 | a7c43f26 | Christos Stathis | displayError("System error unable to copy file: "+t.getMessage());
|
938 | d6be39da | Christos Stathis | } |
939 | 9539e23d | Christos Stathis | |
940 | 9539e23d | Christos Stathis | @Override
|
941 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
942 | 9539e23d | Christos Stathis | sessionExpired(); |
943 | 9539e23d | Christos Stathis | } |
944 | d6be39da | Christos Stathis | }; |
945 | d6be39da | Christos Stathis | copyFile.setHeader("X-Auth-Token", getToken());
|
946 | a2411896 | Christos Stathis | copyFile.setHeader("X-Copy-From", URL.encodePathSegment(file.getUri())); |
947 | 43c372e8 | Christos Stathis | if (!file.getOwner().equals(targetUsername))
|
948 | a2411896 | Christos Stathis | copyFile.setHeader("X-Source-Account", URL.encodePathSegment(file.getOwner())); |
949 | e5af9268 | Christos Stathis | copyFile.setHeader("Content-Type", file.getContentType());
|
950 | d6be39da | Christos Stathis | Scheduler.get().scheduleDeferred(copyFile); |
951 | d6be39da | Christos Stathis | } |
952 | d6be39da | Christos Stathis | else if (callback != null) { |
953 | d6be39da | Christos Stathis | callback.execute(); |
954 | d6be39da | Christos Stathis | } |
955 | d6be39da | Christos Stathis | } |
956 | d6be39da | Christos Stathis | |
957 | 63ee965c | Christos Stathis | public void copySubfolders(final Iterator<Folder> iter, final String targetUsername, final String targetUri, final Command callback) { |
958 | d6be39da | Christos Stathis | if (iter.hasNext()) {
|
959 | d6be39da | Christos Stathis | final Folder f = iter.next();
|
960 | acbb73ac | Christos Stathis | copyFolder(f, targetUsername, targetUri, new Command() {
|
961 | acbb73ac | Christos Stathis | |
962 | acbb73ac | Christos Stathis | @Override
|
963 | acbb73ac | Christos Stathis | public void execute() { |
964 | acbb73ac | Christos Stathis | copySubfolders(iter, targetUsername, targetUri, callback); |
965 | acbb73ac | Christos Stathis | } |
966 | acbb73ac | Christos Stathis | }); |
967 | d6be39da | Christos Stathis | } |
968 | d6be39da | Christos Stathis | else if (callback != null) { |
969 | d6be39da | Christos Stathis | callback.execute(); |
970 | d6be39da | Christos Stathis | } |
971 | d6be39da | Christos Stathis | } |
972 | d6be39da | Christos Stathis | |
973 | 63ee965c | Christos Stathis | public void copyFolder(final Folder f, final String targetUsername, final String targetUri, final Command callback) { |
974 | b51c628b | Christos Stathis | String path = targetUri + "/" + f.getName(); |
975 | 63ee965c | Christos Stathis | PutRequest createFolder = new PutRequest(getApiPath(), targetUsername, path) {
|
976 | d6be39da | Christos Stathis | @Override
|
977 | ebead1b5 | Christos Stathis | public void onSuccess(Resource result) { |
978 | f5023f13 | Christos Stathis | GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, getApiPath(), f.getOwner(), "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix()), f) { |
979 | acbb73ac | Christos Stathis | |
980 | acbb73ac | Christos Stathis | @Override
|
981 | abd8738f | Christos Stathis | public void onSuccess(final Folder _f) { |
982 | abd8738f | Christos Stathis | Iterator<File> iter = _f.getFiles().iterator(); |
983 | abd8738f | Christos Stathis | copyFiles(iter, targetUsername, targetUri + "/" + _f.getName(), new Command() { |
984 | acbb73ac | Christos Stathis | @Override
|
985 | acbb73ac | Christos Stathis | public void execute() { |
986 | abd8738f | Christos Stathis | Iterator<Folder> iterf = _f.getSubfolders().iterator();
|
987 | abd8738f | Christos Stathis | copySubfolders(iterf, targetUsername, targetUri + "/" + _f.getName(), callback);
|
988 | acbb73ac | Christos Stathis | } |
989 | acbb73ac | Christos Stathis | }); |
990 | acbb73ac | Christos Stathis | } |
991 | acbb73ac | Christos Stathis | |
992 | acbb73ac | Christos Stathis | @Override
|
993 | acbb73ac | Christos Stathis | public void onError(Throwable t) { |
994 | acbb73ac | Christos Stathis | GWT.log("", t);
|
995 | 3f8622d4 | Christos Stathis | setError(t); |
996 | acbb73ac | Christos Stathis | if (t instanceof RestException) { |
997 | acbb73ac | Christos Stathis | displayError("Unable to get folder: " + ((RestException) t).getHttpStatusText());
|
998 | acbb73ac | Christos Stathis | } |
999 | acbb73ac | Christos Stathis | else
|
1000 | acbb73ac | Christos Stathis | displayError("System error getting folder: " + t.getMessage());
|
1001 | acbb73ac | Christos Stathis | } |
1002 | 9539e23d | Christos Stathis | |
1003 | 9539e23d | Christos Stathis | @Override
|
1004 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
1005 | 9539e23d | Christos Stathis | sessionExpired(); |
1006 | 9539e23d | Christos Stathis | } |
1007 | acbb73ac | Christos Stathis | }; |
1008 | acbb73ac | Christos Stathis | getFolder.setHeader("X-Auth-Token", getToken());
|
1009 | acbb73ac | Christos Stathis | Scheduler.get().scheduleDeferred(getFolder); |
1010 | d6be39da | Christos Stathis | } |
1011 | d6be39da | Christos Stathis | |
1012 | d6be39da | Christos Stathis | @Override
|
1013 | d6be39da | Christos Stathis | public void onError(Throwable t) { |
1014 | d6be39da | Christos Stathis | GWT.log("", t);
|
1015 | 3f8622d4 | Christos Stathis | setError(t); |
1016 | 3f8622d4 | Christos Stathis | if (t instanceof RestException) { |
1017 | acbb73ac | Christos Stathis | displayError("Unable to create folder: " + ((RestException) t).getHttpStatusText());
|
1018 | d6be39da | Christos Stathis | } |
1019 | d6be39da | Christos Stathis | else
|
1020 | acbb73ac | Christos Stathis | displayError("System error creating folder: " + t.getMessage());
|
1021 | d6be39da | Christos Stathis | } |
1022 | 9539e23d | Christos Stathis | |
1023 | 9539e23d | Christos Stathis | @Override
|
1024 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
1025 | 9539e23d | Christos Stathis | sessionExpired(); |
1026 | 9539e23d | Christos Stathis | } |
1027 | d6be39da | Christos Stathis | }; |
1028 | d6be39da | Christos Stathis | createFolder.setHeader("X-Auth-Token", getToken());
|
1029 | d6be39da | Christos Stathis | createFolder.setHeader("Accept", "*/*"); |
1030 | d6be39da | Christos Stathis | createFolder.setHeader("Content-Length", "0"); |
1031 | d6be39da | Christos Stathis | createFolder.setHeader("Content-Type", "application/folder"); |
1032 | d6be39da | Christos Stathis | Scheduler.get().scheduleDeferred(createFolder); |
1033 | d6be39da | Christos Stathis | } |
1034 | 105b4e49 | Christos Stathis | |
1035 | 7811b9d1 | Christos Stathis | public void addSelectionModel(@SuppressWarnings("rawtypes") SingleSelectionModel model) { |
1036 | 105b4e49 | Christos Stathis | selectionModels.add(model); |
1037 | 105b4e49 | Christos Stathis | } |
1038 | 6d8e0f58 | Christos Stathis | |
1039 | 6d8e0f58 | Christos Stathis | public OtherSharedTreeView getOtherSharedTreeView() {
|
1040 | 6d8e0f58 | Christos Stathis | return otherSharedTreeView;
|
1041 | 6d8e0f58 | Christos Stathis | } |
1042 | 16e8478a | Christos Stathis | |
1043 | 16e8478a | Christos Stathis | public void updateTrash(boolean showFiles, Command callback) { |
1044 | 6acd4df3 | Christos Stathis | updateFolder(trash, showFiles, callback, true);
|
1045 | 16e8478a | Christos Stathis | } |
1046 | 4baffab1 | Christos Stathis | |
1047 | 4baffab1 | Christos Stathis | public void updateGroupsNode() { |
1048 | 4baffab1 | Christos Stathis | groupTreeView.updateGroupNode(null);
|
1049 | 4baffab1 | Christos Stathis | } |
1050 | 4baffab1 | Christos Stathis | |
1051 | 4baffab1 | Christos Stathis | public void addGroup(String groupname) { |
1052 | 4baffab1 | Christos Stathis | Group newGroup = new Group(groupname); |
1053 | 4baffab1 | Christos Stathis | account.addGroup(newGroup); |
1054 | 4baffab1 | Christos Stathis | groupTreeView.updateGroupNode(null);
|
1055 | 4baffab1 | Christos Stathis | } |
1056 | 61f8605d | Christos Stathis | |
1057 | 61f8605d | Christos Stathis | public void removeGroup(Group group) { |
1058 | 61f8605d | Christos Stathis | account.removeGroup(group); |
1059 | 61f8605d | Christos Stathis | updateGroupsNode(); |
1060 | 61f8605d | Christos Stathis | } |
1061 | f1b24b82 | Christos Stathis | |
1062 | f1b24b82 | Christos Stathis | public TreeView getSelectedTree() {
|
1063 | f1b24b82 | Christos Stathis | return selectedTree;
|
1064 | f1b24b82 | Christos Stathis | } |
1065 | f1b24b82 | Christos Stathis | |
1066 | 80a65a5f | Christos Stathis | public void setSelectedTree(TreeView selected) { |
1067 | 80a65a5f | Christos Stathis | selectedTree = selected; |
1068 | 80a65a5f | Christos Stathis | } |
1069 | 80a65a5f | Christos Stathis | |
1070 | f1b24b82 | Christos Stathis | public Folder getSelection() {
|
1071 | f5c86c34 | Christos Stathis | if (selectedTree != null) |
1072 | f5c86c34 | Christos Stathis | return selectedTree.getSelection();
|
1073 | f5c86c34 | Christos Stathis | return null; |
1074 | f1b24b82 | Christos Stathis | } |
1075 | a19f758c | Christos Stathis | |
1076 | a19f758c | Christos Stathis | public void showFolderStatistics(int folderFileCount) { |
1077 | a19f758c | Christos Stathis | numOfFiles.setHTML(String.valueOf(folderFileCount));
|
1078 | a19f758c | Christos Stathis | } |
1079 | b162dfaa | Christos Stathis | |
1080 | b162dfaa | Christos Stathis | public GroupTreeView getGroupTreeView() {
|
1081 | b162dfaa | Christos Stathis | return groupTreeView;
|
1082 | b162dfaa | Christos Stathis | } |
1083 | 9539e23d | Christos Stathis | |
1084 | 9539e23d | Christos Stathis | public void sessionExpired() { |
1085 | 9539e23d | Christos Stathis | new SessionExpiredDialog(this).center(); |
1086 | 9539e23d | Christos Stathis | } |
1087 | 340bf0d6 | Christos Stathis | |
1088 | 340bf0d6 | Christos Stathis | public void updateRootFolder(Command callback) { |
1089 | 6acd4df3 | Christos Stathis | updateFolder(account.getPithos(), false, callback, true); |
1090 | 340bf0d6 | Christos Stathis | } |
1091 | 7c54d867 | Christos Stathis | |
1092 | 7c54d867 | Christos Stathis | void createMySharedTree() {
|
1093 | 7c54d867 | Christos Stathis | mysharedTreeSelectionModel = new SingleSelectionModel<Folder>(); |
1094 | 7c54d867 | Christos Stathis | mysharedTreeSelectionModel.addSelectionChangeHandler(new Handler() { |
1095 | 7c54d867 | Christos Stathis | @Override
|
1096 | ebead1b5 | Christos Stathis | public void onSelectionChange(SelectionChangeEvent event) { |
1097 | 7c54d867 | Christos Stathis | if (mysharedTreeSelectionModel.getSelectedObject() != null) { |
1098 | 7c54d867 | Christos Stathis | deselectOthers(mysharedTreeView, mysharedTreeSelectionModel); |
1099 | 7c54d867 | Christos Stathis | upload.setEnabled(false);
|
1100 | 1238d28d | Christos Stathis | hideUploadArea(); |
1101 | 7c54d867 | Christos Stathis | updateSharedFolder(mysharedTreeSelectionModel.getSelectedObject(), true);
|
1102 | 80a65a5f | Christos Stathis | showRelevantToolbarButtons(); |
1103 | 7c54d867 | Christos Stathis | } |
1104 | 80a65a5f | Christos Stathis | else {
|
1105 | 80a65a5f | Christos Stathis | if (getSelectedTree().equals(mysharedTreeView))
|
1106 | 80a65a5f | Christos Stathis | setSelectedTree(null);
|
1107 | 80a65a5f | Christos Stathis | if (getSelectedTree() == null) |
1108 | 80a65a5f | Christos Stathis | showRelevantToolbarButtons(); |
1109 | 80a65a5f | Christos Stathis | } |
1110 | d7be6c23 | Christos Stathis | } |
1111 | 7c54d867 | Christos Stathis | }); |
1112 | 7c54d867 | Christos Stathis | selectionModels.add(mysharedTreeSelectionModel); |
1113 | 7c54d867 | Christos Stathis | mysharedTreeViewModel = new MysharedTreeViewModel(Pithos.this, mysharedTreeSelectionModel);
|
1114 | 7c54d867 | Christos Stathis | mysharedTreeViewModel.initialize(new Command() {
|
1115 | 7c54d867 | Christos Stathis | |
1116 | 7c54d867 | Christos Stathis | @Override
|
1117 | 7c54d867 | Christos Stathis | public void execute() { |
1118 | 7c54d867 | Christos Stathis | mysharedTreeView = new MysharedTreeView(mysharedTreeViewModel);
|
1119 | 3f62b626 | Christos Stathis | trees.insert(mysharedTreeView, 2);
|
1120 | 0549e173 | Christos Stathis | treeViews.add(mysharedTreeView); |
1121 | 7c54d867 | Christos Stathis | createOtherSharedTree(); |
1122 | 7c54d867 | Christos Stathis | } |
1123 | 7c54d867 | Christos Stathis | }); |
1124 | 7c54d867 | Christos Stathis | } |
1125 | 7c54d867 | Christos Stathis | |
1126 | 7c54d867 | Christos Stathis | void createOtherSharedTree() {
|
1127 | 7c54d867 | Christos Stathis | otherSharedTreeSelectionModel = new SingleSelectionModel<Folder>(); |
1128 | 7c54d867 | Christos Stathis | otherSharedTreeSelectionModel.addSelectionChangeHandler(new Handler() { |
1129 | 7c54d867 | Christos Stathis | @Override
|
1130 | ebead1b5 | Christos Stathis | public void onSelectionChange(SelectionChangeEvent event) { |
1131 | 7c54d867 | Christos Stathis | if (otherSharedTreeSelectionModel.getSelectedObject() != null) { |
1132 | 7c54d867 | Christos Stathis | deselectOthers(otherSharedTreeView, otherSharedTreeSelectionModel); |
1133 | 7c54d867 | Christos Stathis | applyPermissions(otherSharedTreeSelectionModel.getSelectedObject()); |
1134 | 7c54d867 | Christos Stathis | updateOtherSharedFolder(otherSharedTreeSelectionModel.getSelectedObject(), true);
|
1135 | 80a65a5f | Christos Stathis | showRelevantToolbarButtons(); |
1136 | 7c54d867 | Christos Stathis | } |
1137 | 80a65a5f | Christos Stathis | else {
|
1138 | 80a65a5f | Christos Stathis | if (getSelectedTree().equals(otherSharedTreeView))
|
1139 | 80a65a5f | Christos Stathis | setSelectedTree(null);
|
1140 | 80a65a5f | Christos Stathis | if (getSelectedTree() == null) |
1141 | 80a65a5f | Christos Stathis | showRelevantToolbarButtons(); |
1142 | 80a65a5f | Christos Stathis | } |
1143 | d7be6c23 | Christos Stathis | } |
1144 | 7c54d867 | Christos Stathis | }); |
1145 | 7c54d867 | Christos Stathis | selectionModels.add(otherSharedTreeSelectionModel); |
1146 | 7c54d867 | Christos Stathis | otherSharedTreeViewModel = new OtherSharedTreeViewModel(Pithos.this, otherSharedTreeSelectionModel);
|
1147 | 7c54d867 | Christos Stathis | otherSharedTreeViewModel.initialize(new Command() {
|
1148 | 7c54d867 | Christos Stathis | |
1149 | 7c54d867 | Christos Stathis | @Override
|
1150 | 7c54d867 | Christos Stathis | public void execute() { |
1151 | 7c54d867 | Christos Stathis | otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel);
|
1152 | d18749bc | Christos Stathis | trees.insert(otherSharedTreeView, 1);
|
1153 | 0549e173 | Christos Stathis | treeViews.add(otherSharedTreeView); |
1154 | 7c54d867 | Christos Stathis | } |
1155 | 7c54d867 | Christos Stathis | }); |
1156 | 7c54d867 | Christos Stathis | } |
1157 | 4ac4833e | Christos Stathis | |
1158 | c758f656 | Christos Stathis | public native void log1(String message)/*-{ |
1159 | c758f656 | Christos Stathis | $wnd.console.log(message);
|
1160 | c758f656 | Christos Stathis | }-*/;
|
1161 | 3f8622d4 | Christos Stathis | |
1162 | 3f8622d4 | Christos Stathis | public String getErrorData() { |
1163 | 3f8622d4 | Christos Stathis | if (error != null) |
1164 | 3f8622d4 | Christos Stathis | return error.toString();
|
1165 | 3f8622d4 | Christos Stathis | return ""; |
1166 | 3f8622d4 | Christos Stathis | } |
1167 | 3f8622d4 | Christos Stathis | |
1168 | 3f8622d4 | Christos Stathis | public void setError(Throwable t) { |
1169 | 3f8622d4 | Christos Stathis | error = t; |
1170 | 3f8622d4 | Christos Stathis | } |
1171 | b75210b5 | Christos Stathis | |
1172 | b75210b5 | Christos Stathis | public void showRelevantToolbarButtons() { |
1173 | b75210b5 | Christos Stathis | toolbar.showRelevantButtons(); |
1174 | b75210b5 | Christos Stathis | } |
1175 | 1a0db4f4 | Christos Stathis | |
1176 | 1a0db4f4 | Christos Stathis | public FileUploadDialog getFileUploadDialog() {
|
1177 | 1a0db4f4 | Christos Stathis | if (fileUploadDialog == null) |
1178 | 1a0db4f4 | Christos Stathis | fileUploadDialog = new FileUploadDialog(this); |
1179 | 1a0db4f4 | Christos Stathis | return fileUploadDialog;
|
1180 | 1a0db4f4 | Christos Stathis | } |
1181 | 1a0db4f4 | Christos Stathis | |
1182 | 1a0db4f4 | Christos Stathis | public void hideUploadIndicator() { |
1183 | 1a0db4f4 | Christos Stathis | upload.removeStyleName("pithos-uploadButton-loading");
|
1184 | 1a0db4f4 | Christos Stathis | upload.setTitle("");
|
1185 | 1a0db4f4 | Christos Stathis | } |
1186 | 1a0db4f4 | Christos Stathis | |
1187 | 1a0db4f4 | Christos Stathis | public void showUploadIndicator() { |
1188 | 1a0db4f4 | Christos Stathis | upload.addStyleName("pithos-uploadButton-loading");
|
1189 | 1a0db4f4 | Christos Stathis | upload.setTitle("Upload in progress. Click for details.");
|
1190 | 1a0db4f4 | Christos Stathis | } |
1191 | a2f617f8 | Christos Stathis | |
1192 | a2f617f8 | Christos Stathis | public void scheduleFolderHeadCommand(final Folder folder, final Command callback) { |
1193 | 983f9ee2 | Christos Stathis | if (folder == null) { |
1194 | 983f9ee2 | Christos Stathis | if (callback != null) |
1195 | 983f9ee2 | Christos Stathis | callback.execute(); |
1196 | 983f9ee2 | Christos Stathis | } |
1197 | 983f9ee2 | Christos Stathis | else {
|
1198 | 983f9ee2 | Christos Stathis | HeadRequest<Folder> headFolder = new HeadRequest<Folder>(Folder.class, getApiPath(), folder.getOwner(), folder.getUri(), folder) {
|
1199 | 983f9ee2 | Christos Stathis | |
1200 | 983f9ee2 | Christos Stathis | @Override
|
1201 | 983f9ee2 | Christos Stathis | public void onSuccess(Folder _result) { |
1202 | 983f9ee2 | Christos Stathis | if (callback != null) |
1203 | 983f9ee2 | Christos Stathis | callback.execute(); |
1204 | 983f9ee2 | Christos Stathis | } |
1205 | 983f9ee2 | Christos Stathis | |
1206 | 983f9ee2 | Christos Stathis | @Override
|
1207 | 983f9ee2 | Christos Stathis | public void onError(Throwable t) { |
1208 | 983f9ee2 | Christos Stathis | if (t instanceof RestException) { |
1209 | 983f9ee2 | Christos Stathis | if (((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) {
|
1210 | 983f9ee2 | Christos Stathis | final String path = folder.getUri(); |
1211 | 983f9ee2 | Christos Stathis | PutRequest newFolder = new PutRequest(getApiPath(), folder.getOwner(), path) {
|
1212 | 983f9ee2 | Christos Stathis | @Override
|
1213 | 983f9ee2 | Christos Stathis | public void onSuccess(Resource _result) { |
1214 | 983f9ee2 | Christos Stathis | scheduleFolderHeadCommand(folder, callback); |
1215 | 983f9ee2 | Christos Stathis | } |
1216 | 983f9ee2 | Christos Stathis | |
1217 | 983f9ee2 | Christos Stathis | @Override
|
1218 | 983f9ee2 | Christos Stathis | public void onError(Throwable _t) { |
1219 | 983f9ee2 | Christos Stathis | GWT.log("", _t);
|
1220 | 983f9ee2 | Christos Stathis | setError(_t); |
1221 | 983f9ee2 | Christos Stathis | if(_t instanceof RestException){ |
1222 | 983f9ee2 | Christos Stathis | displayError("Unable to create folder: " + ((RestException) _t).getHttpStatusText());
|
1223 | 983f9ee2 | Christos Stathis | } |
1224 | 983f9ee2 | Christos Stathis | else
|
1225 | 983f9ee2 | Christos Stathis | displayError("System error creating folder: " + _t.getMessage());
|
1226 | 983f9ee2 | Christos Stathis | } |
1227 | 983f9ee2 | Christos Stathis | |
1228 | 983f9ee2 | Christos Stathis | @Override
|
1229 | 983f9ee2 | Christos Stathis | protected void onUnauthorized(Response response) { |
1230 | 983f9ee2 | Christos Stathis | sessionExpired(); |
1231 | 983f9ee2 | Christos Stathis | } |
1232 | 983f9ee2 | Christos Stathis | }; |
1233 | 983f9ee2 | Christos Stathis | newFolder.setHeader("X-Auth-Token", getToken());
|
1234 | 983f9ee2 | Christos Stathis | newFolder.setHeader("Content-Type", "application/folder"); |
1235 | 983f9ee2 | Christos Stathis | newFolder.setHeader("Accept", "*/*"); |
1236 | 983f9ee2 | Christos Stathis | newFolder.setHeader("Content-Length", "0"); |
1237 | 983f9ee2 | Christos Stathis | Scheduler.get().scheduleDeferred(newFolder); |
1238 | 983f9ee2 | Christos Stathis | } |
1239 | 983f9ee2 | Christos Stathis | else
|
1240 | 983f9ee2 | Christos Stathis | displayError("Error heading folder: " + ((RestException) t).getHttpStatusText());
|
1241 | 983f9ee2 | Christos Stathis | } |
1242 | 983f9ee2 | Christos Stathis | else
|
1243 | 983f9ee2 | Christos Stathis | displayError("System error heading folder: " + t.getMessage());
|
1244 | 983f9ee2 | Christos Stathis | |
1245 | 983f9ee2 | Christos Stathis | GWT.log("Error heading folder", t);
|
1246 | 983f9ee2 | Christos Stathis | setError(t); |
1247 | 983f9ee2 | Christos Stathis | } |
1248 | 983f9ee2 | Christos Stathis | |
1249 | 983f9ee2 | Christos Stathis | @Override
|
1250 | 983f9ee2 | Christos Stathis | protected void onUnauthorized(Response response) { |
1251 | 983f9ee2 | Christos Stathis | sessionExpired(); |
1252 | 983f9ee2 | Christos Stathis | } |
1253 | 983f9ee2 | Christos Stathis | }; |
1254 | 983f9ee2 | Christos Stathis | headFolder.setHeader("X-Auth-Token", getToken());
|
1255 | 983f9ee2 | Christos Stathis | Scheduler.get().scheduleDeferred(headFolder); |
1256 | 983f9ee2 | Christos Stathis | } |
1257 | a2f617f8 | Christos Stathis | } |
1258 | a2f617f8 | Christos Stathis | |
1259 | a2f617f8 | Christos Stathis | public void scheduleFileHeadCommand(File f, final Command callback) { |
1260 | a2f617f8 | Christos Stathis | HeadRequest<File> headFile = new HeadRequest<File>(File.class, getApiPath(), f.getOwner(), f.getUri(), f) { |
1261 | a2f617f8 | Christos Stathis | |
1262 | a2f617f8 | Christos Stathis | @Override
|
1263 | a2f617f8 | Christos Stathis | public void onSuccess(File _result) { |
1264 | a2f617f8 | Christos Stathis | if (callback != null) |
1265 | a2f617f8 | Christos Stathis | callback.execute(); |
1266 | a2f617f8 | Christos Stathis | } |
1267 | a2f617f8 | Christos Stathis | |
1268 | a2f617f8 | Christos Stathis | @Override
|
1269 | a2f617f8 | Christos Stathis | public void onError(Throwable t) { |
1270 | a2f617f8 | Christos Stathis | GWT.log("Error heading file", t);
|
1271 | a2f617f8 | Christos Stathis | setError(t); |
1272 | a2f617f8 | Christos Stathis | if (t instanceof RestException) |
1273 | a2f617f8 | Christos Stathis | displayError("Error heading file: " + ((RestException) t).getHttpStatusText());
|
1274 | a2f617f8 | Christos Stathis | else
|
1275 | a2f617f8 | Christos Stathis | displayError("System error heading file: " + t.getMessage());
|
1276 | a2f617f8 | Christos Stathis | } |
1277 | a2f617f8 | Christos Stathis | |
1278 | a2f617f8 | Christos Stathis | @Override
|
1279 | a2f617f8 | Christos Stathis | protected void onUnauthorized(Response response) { |
1280 | a2f617f8 | Christos Stathis | sessionExpired(); |
1281 | a2f617f8 | Christos Stathis | } |
1282 | a2f617f8 | Christos Stathis | }; |
1283 | a2f617f8 | Christos Stathis | headFile.setHeader("X-Auth-Token", getToken());
|
1284 | a2f617f8 | Christos Stathis | Scheduler.get().scheduleDeferred(headFile); |
1285 | a2f617f8 | Christos Stathis | } |
1286 | 5d18aa82 | Christos Stathis | |
1287 | 5d18aa82 | Christos Stathis | public boolean isMySharedSelected() { |
1288 | 5d18aa82 | Christos Stathis | return getSelectedTree().equals(getMySharedTreeView());
|
1289 | 5d18aa82 | Christos Stathis | } |
1290 | 1238d28d | Christos Stathis | |
1291 | 1238d28d | Christos Stathis | private FlowPanel createUploadArea() {
|
1292 | 1238d28d | Christos Stathis | FlowPanel area = new FlowPanel();
|
1293 | 1238d28d | Christos Stathis | area.getElement().setId("container");
|
1294 | 1238d28d | Christos Stathis | HTML list = new HTML(); |
1295 | 1238d28d | Christos Stathis | list.getElement().setId("filelist");
|
1296 | 1238d28d | Christos Stathis | area.add(list); |
1297 | 1238d28d | Christos Stathis | Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
1298 | 1238d28d | Christos Stathis | |
1299 | 1238d28d | Christos Stathis | @Override
|
1300 | 1238d28d | Christos Stathis | public void execute() { |
1301 | 1238d28d | Christos Stathis | setupUploadArea(Pithos.this, getToken()); |
1302 | 1238d28d | Christos Stathis | } |
1303 | 1238d28d | Christos Stathis | }); |
1304 | 1238d28d | Christos Stathis | |
1305 | 1238d28d | Christos Stathis | return area;
|
1306 | 1238d28d | Christos Stathis | } |
1307 | 1238d28d | Christos Stathis | |
1308 | 1238d28d | Christos Stathis | native void setupUploadArea(Pithos app, String token) /*-{ |
1309 | 1238d28d | Christos Stathis | $wnd.$("#container").pluploadQueue({
|
1310 | 1238d28d | Christos Stathis | // General settings
|
1311 | 1238d28d | Christos Stathis | runtimes : 'html5',
|
1312 | 1238d28d | Christos Stathis | unique_names : true,
|
1313 | 1238d28d | Christos Stathis | multiple_queues: true,
|
1314 | 1238d28d | Christos Stathis | drop_element: 'filelist',
|
1315 | 1238d28d | Christos Stathis |
|
1316 | 1238d28d | Christos Stathis | preinit: {
|
1317 | 1238d28d | Christos Stathis | Init: function(up, info) {
|
1318 | 1238d28d | Christos Stathis | if ($wnd.console && $wnd.console.log)
|
1319 | 1238d28d | Christos Stathis | $wnd.console.log("Init fired");
|
1320 | 1238d28d | Christos Stathis | up.settings.file_data_name = "X-Object-Data";
|
1321 | 1238d28d | Christos Stathis | }
|
1322 | 1238d28d | Christos Stathis | },
|
1323 | 1238d28d | Christos Stathis |
|
1324 | 1238d28d | Christos Stathis | init: {
|
1325 | 1238d28d | Christos Stathis | FilesAdded: function(up, files) {
|
1326 | 1238d28d | Christos Stathis | $wnd.$('#container').css('border', '');
|
1327 | 1238d28d | Christos Stathis | var api = app.@gr.grnet.pithos.web.client.Pithos::getApiPath()();
|
1328 | 1238d28d | Christos Stathis | var folder = app.@gr.grnet.pithos.web.client.Pithos::getUploadFolder()();
|
1329 | 1238d28d | Christos Stathis | var owner = folder.@gr.grnet.pithos.web.client.foldertree.Folder::getOwner()();
|
1330 | 1238d28d | Christos Stathis | var uri = folder.@gr.grnet.pithos.web.client.foldertree.Folder::getUri()();
|
1331 | 1238d28d | Christos Stathis | var path = api + owner + uri;
|
1332 | 1238d28d | Christos Stathis | for (var j=0; j<files.length; j++) {
|
1333 | 1238d28d | Christos Stathis | files[j].folder = folder;
|
1334 | 1238d28d | Christos Stathis | files[j].url = path + "/" + files[j].name + "?X-Auth-Token=" + encodeURIComponent(token);
|
1335 | 1238d28d | Christos Stathis | }
|
1336 | 1238d28d | Christos Stathis | up.start();
|
1337 | 1238d28d | Christos Stathis | },
|
1338 | 1238d28d | Christos Stathis |
|
1339 | 1238d28d | Christos Stathis | BeforeUpload: function(up, file) {
|
1340 | 1238d28d | Christos Stathis | if ($wnd.console && $wnd.console.log)
|
1341 | 1238d28d | Christos Stathis | $wnd.console.log('About to upload ' + file.url);
|
1342 | 1238d28d | Christos Stathis | up.settings.url = file.url;
|
1343 | 1238d28d | Christos Stathis | },
|
1344 | 1238d28d | Christos Stathis |
|
1345 | 1238d28d | Christos Stathis | FileUploaded: function(up, file, response) {
|
1346 | 1238d28d | Christos Stathis | if ($wnd.console && $wnd.console.log) {
|
1347 | 1238d28d | Christos Stathis | $wnd.console.log('File ' + file.name + ' uploaded');
|
1348 | 1238d28d | Christos Stathis | $wnd.console.log('Response: ' + response);
|
1349 | 1238d28d | Christos Stathis | }
|
1350 | 1238d28d | Christos Stathis | up.removeFile(file);
|
1351 | 1238d28d | Christos Stathis | var folder = app.@gr.grnet.pithos.web.client.Pithos::getUploadFolder()();
|
1352 | 1238d28d | Christos Stathis | if (folder == file.folder)
|
1353 | 1238d28d | Christos Stathis | app.@gr.grnet.pithos.web.client.Pithos::updateUploadFolder()();
|
1354 | 1238d28d | Christos Stathis | },
|
1355 | 1238d28d | Christos Stathis |
|
1356 | 1238d28d | Christos Stathis | UploadComplete: function(up, files) {
|
1357 | 1238d28d | Christos Stathis | if ($wnd.console && $wnd.console.log)
|
1358 | 1238d28d | Christos Stathis | $wnd.console.log('All files finished');
|
1359 | 1238d28d | Christos Stathis | },
|
1360 | 1238d28d | Christos Stathis |
|
1361 | 1238d28d | Christos Stathis | Error: function(up, error) {
|
1362 | 1238d28d | Christos Stathis | if ($wnd.console && $wnd.console.log)
|
1363 | 1238d28d | Christos Stathis | $wnd.console.log("Error occured:" + error);
|
1364 | 1238d28d | Christos Stathis | }
|
1365 | 1238d28d | Christos Stathis | }
|
1366 | 1238d28d | Christos Stathis | });
|
1367 | 1238d28d | Christos Stathis | var uploader = $wnd.$("#container").pluploadQueue();
|
1368 | 1238d28d | Christos Stathis | if (uploader.runtime != 'html5')
|
1369 | 1238d28d | Christos Stathis | $wnd.$("#container").hide();
|
1370 | 1238d28d | Christos Stathis | else {
|
1371 | 1238d28d | Christos Stathis | if ($wnd.console && $wnd.console.log) {
|
1372 | 1238d28d | Christos Stathis | $wnd.console.log(uploader);
|
1373 | 1238d28d | Christos Stathis | $wnd.console.log($wnd.plupload);
|
1374 | 1238d28d | Christos Stathis | }
|
1375 | 1238d28d | Christos Stathis | $wnd.$('.plupload_header').hide();
|
1376 | 1238d28d | Christos Stathis | $wnd.$('.plupload_filelist_header').hide();
|
1377 | 1238d28d | Christos Stathis | $wnd.$('#container_filelist').css('overflow-y', 'auto');
|
1378 | 1238d28d | Christos Stathis | $wnd.$('.plupload_filelist_footer').hide();
|
1379 | 1238d28d | Christos Stathis | $wnd.document.getElementById('container').addEventListener('dragenter', function(event) {
|
1380 | 1238d28d | Christos Stathis | $wnd.$('#container').css('border', '3px inset');
|
1381 | 1238d28d | Christos Stathis | }, false);
|
1382 | 1238d28d | Christos Stathis | $wnd.document.getElementById('container').addEventListener('dragleave', function(event) {
|
1383 | 1238d28d | Christos Stathis | $wnd.$('#container').css('border', '');
|
1384 | 1238d28d | Christos Stathis | }, false);
|
1385 | 1238d28d | Christos Stathis | }
|
1386 | 1238d28d | Christos Stathis | }-*/;
|
1387 | 1238d28d | Christos Stathis | |
1388 | 1238d28d | Christos Stathis | private Folder getUploadFolder() {
|
1389 | 1238d28d | Christos Stathis | if (folderTreeView.equals(getSelectedTree()) || otherSharedTreeView.equals(getSelectedTree())) {
|
1390 | 1238d28d | Christos Stathis | return getSelection();
|
1391 | 1238d28d | Christos Stathis | } |
1392 | 1238d28d | Christos Stathis | return null; |
1393 | 1238d28d | Christos Stathis | } |
1394 | 1238d28d | Christos Stathis | |
1395 | 1238d28d | Christos Stathis | private void updateUploadFolder() { |
1396 | 1238d28d | Christos Stathis | if (folderTreeView.equals(getSelectedTree()) || otherSharedTreeView.equals(getSelectedTree())) {
|
1397 | 1238d28d | Christos Stathis | Folder f = getSelection(); |
1398 | 1238d28d | Christos Stathis | if (getSelectedTree().equals(getFolderTreeView()))
|
1399 | 1238d28d | Christos Stathis | updateFolder(f, true, new Command() { |
1400 | 1238d28d | Christos Stathis | |
1401 | 1238d28d | Christos Stathis | @Override
|
1402 | 1238d28d | Christos Stathis | public void execute() { |
1403 | 1238d28d | Christos Stathis | updateStatistics(); |
1404 | 1238d28d | Christos Stathis | } |
1405 | 1238d28d | Christos Stathis | }, false);
|
1406 | 1238d28d | Christos Stathis | else
|
1407 | 1238d28d | Christos Stathis | updateOtherSharedFolder(f, true);
|
1408 | 1238d28d | Christos Stathis | } |
1409 | 1238d28d | Christos Stathis | } |
1410 | 1238d28d | Christos Stathis | |
1411 | 1238d28d | Christos Stathis | public native void hideUploadArea() /*-{ |
1412 | 1238d28d | Christos Stathis | $wnd.$("#container").hide();
|
1413 | 1238d28d | Christos Stathis | }-*/;
|
1414 | 1238d28d | Christos Stathis | |
1415 | 1238d28d | Christos Stathis | public native void showUploadArea() /*-{ |
1416 | 1238d28d | Christos Stathis | $wnd.$("#container").show();
|
1417 | 1238d28d | Christos Stathis | }-*/;
|
1418 | a57faaf0 | Christos Stathis | } |