root / src / gr / grnet / pithos / web / client / commands / PropertiesCommand.java @ b3832e45
History | View | Annotate | Download (7.9 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.commands; |
36 | a57faaf0 | Christos Stathis | |
37 | 9326b841 | Christos Stathis | import gr.grnet.pithos.web.client.FilePermissionsDialog; |
38 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.FilePropertiesDialog; |
39 | 9326b841 | Christos Stathis | import gr.grnet.pithos.web.client.FileVersionsDialog; |
40 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.FilesPropertiesDialog; |
41 | 6b7d024f | Christos Stathis | import gr.grnet.pithos.web.client.FolderPermissionsDialog; |
42 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.FolderPropertiesDialog; |
43 | 749068ba | Christos Stathis | import gr.grnet.pithos.web.client.Pithos; |
44 | 31997f49 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.File; |
45 | 31997f49 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Folder; |
46 | 68e165a9 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Resource; |
47 | 68e165a9 | Christos Stathis | import gr.grnet.pithos.web.client.rest.HeadRequest; |
48 | b3832e45 | Christos Stathis | import gr.grnet.pithos.web.client.rest.PutRequest; |
49 | 68e165a9 | Christos Stathis | import gr.grnet.pithos.web.client.rest.RestException; |
50 | a57faaf0 | Christos Stathis | |
51 | a57faaf0 | Christos Stathis | import java.util.List; |
52 | a57faaf0 | Christos Stathis | |
53 | 68e165a9 | Christos Stathis | import com.google.gwt.core.client.GWT; |
54 | 68e165a9 | Christos Stathis | import com.google.gwt.core.client.Scheduler; |
55 | 68e165a9 | Christos Stathis | import com.google.gwt.http.client.Response; |
56 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.Command; |
57 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.PopupPanel; |
58 | a57faaf0 | Christos Stathis | |
59 | a57faaf0 | Christos Stathis | /**
|
60 | a57faaf0 | Christos Stathis | * The command that displays the appropriate Properties dialog, according to the
|
61 | a57faaf0 | Christos Stathis | * selected object in the application.
|
62 | a57faaf0 | Christos Stathis | *
|
63 | a57faaf0 | Christos Stathis | */
|
64 | a57faaf0 | Christos Stathis | public class PropertiesCommand implements Command { |
65 | a57faaf0 | Christos Stathis | |
66 | 9326b841 | Christos Stathis | public static final int PROPERTIES = 0; |
67 | 9326b841 | Christos Stathis | public static final int PERMISSIONS = 1; |
68 | 9326b841 | Christos Stathis | public static final int VERSIONS = 2; |
69 | 9326b841 | Christos Stathis | |
70 | a57faaf0 | Christos Stathis | private PopupPanel containerPanel;
|
71 | a57faaf0 | Christos Stathis | |
72 | a57faaf0 | Christos Stathis | private int tabToShow = 0; |
73 | a57faaf0 | Christos Stathis | |
74 | 31997f49 | Christos Stathis | private Object resource; |
75 | 31997f49 | Christos Stathis | |
76 | 68e165a9 | Christos Stathis | Pithos app; |
77 | 31997f49 | Christos Stathis | |
78 | a57faaf0 | Christos Stathis | /**
|
79 | a57faaf0 | Christos Stathis | * @param _containerPanel
|
80 | a57faaf0 | Christos Stathis | * @param _tab the tab to switch to
|
81 | a57faaf0 | Christos Stathis | */
|
82 | 7260b946 | Christos Stathis | public PropertiesCommand(Pithos _app, PopupPanel _containerPanel, Object _resource, int _tab) { |
83 | a57faaf0 | Christos Stathis | containerPanel = _containerPanel; |
84 | a57faaf0 | Christos Stathis | tabToShow = _tab; |
85 | 31997f49 | Christos Stathis | resource = _resource; |
86 | 31997f49 | Christos Stathis | app = _app; |
87 | a57faaf0 | Christos Stathis | } |
88 | a57faaf0 | Christos Stathis | |
89 | a57faaf0 | Christos Stathis | @Override
|
90 | a57faaf0 | Christos Stathis | public void execute() { |
91 | 31997f49 | Christos Stathis | if (containerPanel != null) |
92 | 31997f49 | Christos Stathis | containerPanel.hide(); |
93 | 31997f49 | Christos Stathis | |
94 | 31997f49 | Christos Stathis | if (resource instanceof Folder) { |
95 | b3832e45 | Christos Stathis | final Folder folder = (Folder) resource;
|
96 | 6b7d024f | Christos Stathis | switch (tabToShow) {
|
97 | 6b7d024f | Christos Stathis | case PROPERTIES:
|
98 | 6b7d024f | Christos Stathis | FolderPropertiesDialog dlg = new FolderPropertiesDialog(app, false, folder); |
99 | 6b7d024f | Christos Stathis | dlg.center(); |
100 | 6b7d024f | Christos Stathis | break;
|
101 | 6b7d024f | Christos Stathis | case PERMISSIONS:
|
102 | b3832e45 | Christos Stathis | final FolderPermissionsDialog dlg1 = new FolderPermissionsDialog(app, folder); |
103 | b3832e45 | Christos Stathis | scheduleFolderHeadCommand(folder, dlg1); |
104 | 6b7d024f | Christos Stathis | break;
|
105 | 6b7d024f | Christos Stathis | default:
|
106 | 6b7d024f | Christos Stathis | break;
|
107 | 6b7d024f | Christos Stathis | } |
108 | 31997f49 | Christos Stathis | } |
109 | 31997f49 | Christos Stathis | else if (resource instanceof List) { |
110 | 7811b9d1 | Christos Stathis | @SuppressWarnings("unchecked") |
111 | 7811b9d1 | Christos Stathis | List<File> files = (List<File>) resource; |
112 | 31997f49 | Christos Stathis | if (files.size() > 1) { |
113 | f6cd2099 | Christos Stathis | FilesPropertiesDialog dlg = new FilesPropertiesDialog(app, files);
|
114 | f6cd2099 | Christos Stathis | dlg.center(); |
115 | 31997f49 | Christos Stathis | } |
116 | 31997f49 | Christos Stathis | else {
|
117 | b3832e45 | Christos Stathis | File f = files.get(0); |
118 | b3832e45 | Christos Stathis | PopupPanel dlg = null;
|
119 | 9326b841 | Christos Stathis | switch (tabToShow) {
|
120 | 9326b841 | Christos Stathis | case PROPERTIES:
|
121 | b3832e45 | Christos Stathis | dlg = new FilePropertiesDialog(app, f);
|
122 | b3832e45 | Christos Stathis | scheduleFileHeadCommand(f, dlg); |
123 | 9326b841 | Christos Stathis | break;
|
124 | 9326b841 | Christos Stathis | case PERMISSIONS:
|
125 | b3832e45 | Christos Stathis | dlg = new FilePermissionsDialog(app, f);
|
126 | b3832e45 | Christos Stathis | scheduleFileHeadCommand(f, dlg); |
127 | 9326b841 | Christos Stathis | break;
|
128 | 9326b841 | Christos Stathis | case VERSIONS:
|
129 | 9326b841 | Christos Stathis | FileVersionsDialog dlg2 = new FileVersionsDialog(app, files.get(0)); |
130 | 9326b841 | Christos Stathis | dlg2.center(); |
131 | 9326b841 | Christos Stathis | break;
|
132 | 9326b841 | Christos Stathis | default:
|
133 | 9326b841 | Christos Stathis | break;
|
134 | 9326b841 | Christos Stathis | } |
135 | 31997f49 | Christos Stathis | } |
136 | 31997f49 | Christos Stathis | } |
137 | a57faaf0 | Christos Stathis | } |
138 | b3832e45 | Christos Stathis | |
139 | b3832e45 | Christos Stathis | private void scheduleFileHeadCommand(File f, final PopupPanel dlg) { |
140 | b3832e45 | Christos Stathis | HeadRequest<File> headFile = new HeadRequest<File>(File.class, app.getApiPath(), f.getOwner(), f.getUri(), f) { |
141 | b3832e45 | Christos Stathis | |
142 | b3832e45 | Christos Stathis | @Override
|
143 | b3832e45 | Christos Stathis | public void onSuccess(File _result) { |
144 | b3832e45 | Christos Stathis | dlg.center(); |
145 | b3832e45 | Christos Stathis | } |
146 | b3832e45 | Christos Stathis | |
147 | b3832e45 | Christos Stathis | @Override
|
148 | b3832e45 | Christos Stathis | public void onError(Throwable t) { |
149 | b3832e45 | Christos Stathis | GWT.log("Error heading file", t);
|
150 | b3832e45 | Christos Stathis | app.setError(t); |
151 | b3832e45 | Christos Stathis | if (t instanceof RestException) |
152 | b3832e45 | Christos Stathis | app.displayError("Error heading file: " + ((RestException) t).getHttpStatusText());
|
153 | b3832e45 | Christos Stathis | else
|
154 | b3832e45 | Christos Stathis | app.displayError("System error heading file: " + t.getMessage());
|
155 | b3832e45 | Christos Stathis | } |
156 | b3832e45 | Christos Stathis | |
157 | b3832e45 | Christos Stathis | @Override
|
158 | b3832e45 | Christos Stathis | protected void onUnauthorized(Response response) { |
159 | b3832e45 | Christos Stathis | app.sessionExpired(); |
160 | b3832e45 | Christos Stathis | } |
161 | b3832e45 | Christos Stathis | }; |
162 | b3832e45 | Christos Stathis | headFile.setHeader("X-Auth-Token", app.getToken());
|
163 | b3832e45 | Christos Stathis | Scheduler.get().scheduleDeferred(headFile); |
164 | b3832e45 | Christos Stathis | } |
165 | b3832e45 | Christos Stathis | |
166 | b3832e45 | Christos Stathis | void scheduleFolderHeadCommand(final Folder folder, final FolderPermissionsDialog dlg) { |
167 | b3832e45 | Christos Stathis | HeadRequest<Folder> headFolder = new HeadRequest<Folder>(Folder.class, app.getApiPath(), folder.getOwner(), folder.getUri(), folder) {
|
168 | b3832e45 | Christos Stathis | |
169 | b3832e45 | Christos Stathis | @Override
|
170 | b3832e45 | Christos Stathis | public void onSuccess(Folder _result) { |
171 | b3832e45 | Christos Stathis | dlg.center(); |
172 | b3832e45 | Christos Stathis | } |
173 | b3832e45 | Christos Stathis | |
174 | b3832e45 | Christos Stathis | @Override
|
175 | b3832e45 | Christos Stathis | public void onError(Throwable t) { |
176 | b3832e45 | Christos Stathis | if (t instanceof RestException) { |
177 | b3832e45 | Christos Stathis | if (((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) {
|
178 | b3832e45 | Christos Stathis | final String path = folder.getUri(); |
179 | b3832e45 | Christos Stathis | PutRequest newFolder = new PutRequest(app.getApiPath(), folder.getOwner(), path) {
|
180 | b3832e45 | Christos Stathis | @Override
|
181 | b3832e45 | Christos Stathis | public void onSuccess(Resource _result) { |
182 | b3832e45 | Christos Stathis | scheduleFolderHeadCommand(folder, dlg); |
183 | b3832e45 | Christos Stathis | } |
184 | b3832e45 | Christos Stathis | |
185 | b3832e45 | Christos Stathis | @Override
|
186 | b3832e45 | Christos Stathis | public void onError(Throwable _t) { |
187 | b3832e45 | Christos Stathis | GWT.log("", _t);
|
188 | b3832e45 | Christos Stathis | app.setError(_t); |
189 | b3832e45 | Christos Stathis | if(_t instanceof RestException){ |
190 | b3832e45 | Christos Stathis | app.displayError("Unable to create folder: " + ((RestException) _t).getHttpStatusText());
|
191 | b3832e45 | Christos Stathis | } |
192 | b3832e45 | Christos Stathis | else
|
193 | b3832e45 | Christos Stathis | app.displayError("System error creating folder: " + _t.getMessage());
|
194 | b3832e45 | Christos Stathis | } |
195 | b3832e45 | Christos Stathis | |
196 | b3832e45 | Christos Stathis | @Override
|
197 | b3832e45 | Christos Stathis | protected void onUnauthorized(Response response) { |
198 | b3832e45 | Christos Stathis | app.sessionExpired(); |
199 | b3832e45 | Christos Stathis | } |
200 | b3832e45 | Christos Stathis | }; |
201 | b3832e45 | Christos Stathis | newFolder.setHeader("X-Auth-Token", app.getToken());
|
202 | b3832e45 | Christos Stathis | newFolder.setHeader("Content-Type", "application/folder"); |
203 | b3832e45 | Christos Stathis | newFolder.setHeader("Accept", "*/*"); |
204 | b3832e45 | Christos Stathis | newFolder.setHeader("Content-Length", "0"); |
205 | b3832e45 | Christos Stathis | Scheduler.get().scheduleDeferred(newFolder); |
206 | b3832e45 | Christos Stathis | } |
207 | b3832e45 | Christos Stathis | else
|
208 | b3832e45 | Christos Stathis | app.displayError("Error heading folder: " + ((RestException) t).getHttpStatusText());
|
209 | b3832e45 | Christos Stathis | } |
210 | b3832e45 | Christos Stathis | else
|
211 | b3832e45 | Christos Stathis | app.displayError("System error heading folder: " + t.getMessage());
|
212 | b3832e45 | Christos Stathis | |
213 | b3832e45 | Christos Stathis | GWT.log("Error heading folder", t);
|
214 | b3832e45 | Christos Stathis | app.setError(t); |
215 | b3832e45 | Christos Stathis | } |
216 | b3832e45 | Christos Stathis | |
217 | b3832e45 | Christos Stathis | @Override
|
218 | b3832e45 | Christos Stathis | protected void onUnauthorized(Response response) { |
219 | b3832e45 | Christos Stathis | app.sessionExpired(); |
220 | b3832e45 | Christos Stathis | } |
221 | b3832e45 | Christos Stathis | }; |
222 | b3832e45 | Christos Stathis | headFolder.setHeader("X-Auth-Token", app.getToken());
|
223 | b3832e45 | Christos Stathis | Scheduler.get().scheduleDeferred(headFolder); |
224 | b3832e45 | Christos Stathis | } |
225 | a57faaf0 | Christos Stathis | } |