root / web_client / src / gr / grnet / pithos / web / client / FolderPropertiesDialog.java @ c781386e
History | View | Annotate | Download (15 kB)
1 | ab1eb3f8 | Christos Stathis | /*
|
---|---|---|---|
2 | 58777026 | Christos Stathis | * Copyright 2011 GRNET S.A. All rights reserved.
|
3 | 58777026 | Christos Stathis | *
|
4 | 58777026 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 58777026 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 58777026 | Christos Stathis | * conditions are met:
|
7 | 58777026 | Christos Stathis | *
|
8 | 58777026 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 58777026 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 58777026 | Christos Stathis | * disclaimer.
|
11 | 58777026 | Christos Stathis | *
|
12 | 58777026 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 58777026 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 58777026 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 58777026 | Christos Stathis | * provided with the distribution.
|
16 | 58777026 | Christos Stathis | *
|
17 | 58777026 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 58777026 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 58777026 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 58777026 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 58777026 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 58777026 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 58777026 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 58777026 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 58777026 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 58777026 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 58777026 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 58777026 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 58777026 | Christos Stathis | *
|
30 | 58777026 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 58777026 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 58777026 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 58777026 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | ab1eb3f8 | Christos Stathis | */
|
35 | ab1eb3f8 | Christos Stathis | package gr.grnet.pithos.web.client; |
36 | ab1eb3f8 | Christos Stathis | |
37 | fa5600f7 | Christos Stathis | import com.google.gwt.core.client.Scheduler; |
38 | 287c3d8d | Christos Stathis | import com.google.gwt.event.dom.client.KeyDownEvent; |
39 | 33b61be6 | Christos Stathis | import com.google.gwt.user.client.Command; |
40 | 287c3d8d | Christos Stathis | import com.google.gwt.user.client.Event; |
41 | 33b61be6 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.File; |
42 | 287c3d8d | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Folder; |
43 | fa5600f7 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Resource; |
44 | ab1eb3f8 | Christos Stathis | import gr.grnet.pithos.web.client.rest.PostCommand; |
45 | fa5600f7 | Christos Stathis | import gr.grnet.pithos.web.client.rest.PutRequest; |
46 | ab1eb3f8 | Christos Stathis | import gr.grnet.pithos.web.client.rest.RestException; |
47 | ab1eb3f8 | Christos Stathis | import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper; |
48 | ab1eb3f8 | Christos Stathis | |
49 | ab1eb3f8 | Christos Stathis | import com.google.gwt.core.client.GWT; |
50 | ab1eb3f8 | Christos Stathis | import com.google.gwt.dom.client.NativeEvent; |
51 | ab1eb3f8 | Christos Stathis | import com.google.gwt.event.dom.client.ClickEvent; |
52 | ab1eb3f8 | Christos Stathis | import com.google.gwt.event.dom.client.ClickHandler; |
53 | ab1eb3f8 | Christos Stathis | import com.google.gwt.event.dom.client.KeyCodes; |
54 | ab1eb3f8 | Christos Stathis | import com.google.gwt.http.client.URL; |
55 | ab1eb3f8 | Christos Stathis | import com.google.gwt.i18n.client.DateTimeFormat; |
56 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.DeferredCommand; |
57 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.Event.NativePreviewEvent; |
58 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.Button; |
59 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.CheckBox; |
60 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.DecoratedTabPanel; |
61 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.DialogBox; |
62 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.FlexTable; |
63 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
64 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.HorizontalPanel; |
65 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.Label; |
66 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.TabPanel; |
67 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.TextBox; |
68 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.VerticalPanel; |
69 | 33b61be6 | Christos Stathis | import java.util.Iterator; |
70 | ab1eb3f8 | Christos Stathis | |
71 | ab1eb3f8 | Christos Stathis | /**
|
72 | ab1eb3f8 | Christos Stathis | * The 'Folder properties' dialog box implementation.
|
73 | ab1eb3f8 | Christos Stathis | */
|
74 | ab1eb3f8 | Christos Stathis | public class FolderPropertiesDialog extends DialogBox { |
75 | ab1eb3f8 | Christos Stathis | |
76 | fa5600f7 | Christos Stathis | private GSS app;
|
77 | fa5600f7 | Christos Stathis | |
78 | ab1eb3f8 | Christos Stathis | private CheckBox readForAll;
|
79 | ab1eb3f8 | Christos Stathis | |
80 | ab1eb3f8 | Christos Stathis | /**
|
81 | ab1eb3f8 | Christos Stathis | * The widget that holds the folderName of the folder.
|
82 | ab1eb3f8 | Christos Stathis | */
|
83 | ab1eb3f8 | Christos Stathis | private TextBox folderName = new TextBox(); |
84 | ab1eb3f8 | Christos Stathis | |
85 | ab1eb3f8 | Christos Stathis | /**
|
86 | ab1eb3f8 | Christos Stathis | * A flag that denotes whether the dialog will be used to create or modify a
|
87 | ab1eb3f8 | Christos Stathis | * folder.
|
88 | ab1eb3f8 | Christos Stathis | */
|
89 | ab1eb3f8 | Christos Stathis | private final boolean create; |
90 | ab1eb3f8 | Christos Stathis | |
91 | 287c3d8d | Christos Stathis | final Folder folder;
|
92 | ab1eb3f8 | Christos Stathis | |
93 | ab1eb3f8 | Christos Stathis | final TabPanel inner;
|
94 | ab1eb3f8 | Christos Stathis | |
95 | ab1eb3f8 | Christos Stathis | /**
|
96 | ab1eb3f8 | Christos Stathis | * The widget's constructor.
|
97 | ab1eb3f8 | Christos Stathis | */
|
98 | fa5600f7 | Christos Stathis | public FolderPropertiesDialog(GSS app, boolean _create, Folder selected) { |
99 | fa5600f7 | Christos Stathis | this.app = app;
|
100 | ab1eb3f8 | Christos Stathis | setAnimationEnabled(true);
|
101 | ab1eb3f8 | Christos Stathis | |
102 | ab1eb3f8 | Christos Stathis | // Enable IE selection for the dialog (must disable it upon closing it)
|
103 | fa5600f7 | Christos Stathis | app.enableIESelection(); |
104 | ab1eb3f8 | Christos Stathis | |
105 | ab1eb3f8 | Christos Stathis | create = _create; |
106 | ab1eb3f8 | Christos Stathis | |
107 | 287c3d8d | Christos Stathis | folder = selected; |
108 | ab1eb3f8 | Christos Stathis | |
109 | ab1eb3f8 | Christos Stathis | // Use this opportunity to set the dialog's caption.
|
110 | ab1eb3f8 | Christos Stathis | if (create)
|
111 | ab1eb3f8 | Christos Stathis | setText("Create folder");
|
112 | ab1eb3f8 | Christos Stathis | else
|
113 | ab1eb3f8 | Christos Stathis | setText("Folder properties");
|
114 | ab1eb3f8 | Christos Stathis | |
115 | ab1eb3f8 | Christos Stathis | // Outer contains inner and buttons
|
116 | ab1eb3f8 | Christos Stathis | VerticalPanel outer = new VerticalPanel();
|
117 | ab1eb3f8 | Christos Stathis | // Inner contains generalPanel and permPanel
|
118 | ab1eb3f8 | Christos Stathis | inner = new DecoratedTabPanel();
|
119 | ab1eb3f8 | Christos Stathis | inner.setAnimationEnabled(true);
|
120 | ab1eb3f8 | Christos Stathis | VerticalPanel generalPanel = new VerticalPanel();
|
121 | ab1eb3f8 | Christos Stathis | VerticalPanel permPanel = new VerticalPanel();
|
122 | ab1eb3f8 | Christos Stathis | final HorizontalPanel permForAll = new HorizontalPanel(); |
123 | ab1eb3f8 | Christos Stathis | final HorizontalPanel pathPanel = new HorizontalPanel(); |
124 | ab1eb3f8 | Christos Stathis | HorizontalPanel buttons = new HorizontalPanel();
|
125 | ab1eb3f8 | Christos Stathis | HorizontalPanel permButtons = new HorizontalPanel();
|
126 | ab1eb3f8 | Christos Stathis | |
127 | ab1eb3f8 | Christos Stathis | inner.add(generalPanel, "General");
|
128 | ab1eb3f8 | Christos Stathis | if (!create)
|
129 | ab1eb3f8 | Christos Stathis | inner.add(permPanel, "Sharing");
|
130 | ab1eb3f8 | Christos Stathis | inner.selectTab(0);
|
131 | ab1eb3f8 | Christos Stathis | |
132 | ab1eb3f8 | Christos Stathis | FlexTable generalTable = new FlexTable();
|
133 | ab1eb3f8 | Christos Stathis | generalTable.setText(0, 0, "Name"); |
134 | ab1eb3f8 | Christos Stathis | generalTable.setText(1, 0, "Parent"); |
135 | ab1eb3f8 | Christos Stathis | generalTable.setText(2, 0, "Creator"); |
136 | ab1eb3f8 | Christos Stathis | generalTable.setText(3, 0, "Last modified"); |
137 | ab1eb3f8 | Christos Stathis | folderName.setText(create ? "" : folder.getName());
|
138 | c781386e | Christos Stathis | folderName.setReadOnly(folder.isContainer() && !create); |
139 | ab1eb3f8 | Christos Stathis | generalTable.setWidget(0, 1, folderName); |
140 | ab1eb3f8 | Christos Stathis | |
141 | ab1eb3f8 | Christos Stathis | if (create)
|
142 | ab1eb3f8 | Christos Stathis | generalTable.setText(1, 1, folder.getName()); |
143 | ab1eb3f8 | Christos Stathis | else
|
144 | 287c3d8d | Christos Stathis | generalTable.setText(1, 1, folder.getPrefix()); |
145 | 287c3d8d | Christos Stathis | generalTable.setText(2, 1, ""); |
146 | ab1eb3f8 | Christos Stathis | DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
|
147 | 287c3d8d | Christos Stathis | if(folder.getLastModified() != null) |
148 | 287c3d8d | Christos Stathis | generalTable.setText(3, 1, formatter.format(folder.getLastModified())); |
149 | ab1eb3f8 | Christos Stathis | generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels"); |
150 | ab1eb3f8 | Christos Stathis | generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels"); |
151 | ab1eb3f8 | Christos Stathis | generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels"); |
152 | ab1eb3f8 | Christos Stathis | generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels"); |
153 | ab1eb3f8 | Christos Stathis | generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values"); |
154 | ab1eb3f8 | Christos Stathis | generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values"); |
155 | ab1eb3f8 | Christos Stathis | generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values"); |
156 | ab1eb3f8 | Christos Stathis | generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values"); |
157 | ab1eb3f8 | Christos Stathis | generalTable.setCellSpacing(4);
|
158 | ab1eb3f8 | Christos Stathis | |
159 | ab1eb3f8 | Christos Stathis | // Create the 'Create/Update' button, along with a listener that hides the dialog
|
160 | ab1eb3f8 | Christos Stathis | // when the button is clicked and quits the application.
|
161 | ab1eb3f8 | Christos Stathis | String okLabel;
|
162 | ab1eb3f8 | Christos Stathis | if (create)
|
163 | ab1eb3f8 | Christos Stathis | okLabel = "Create";
|
164 | ab1eb3f8 | Christos Stathis | else
|
165 | ab1eb3f8 | Christos Stathis | okLabel = "Update";
|
166 | ab1eb3f8 | Christos Stathis | Button ok = new Button(okLabel, new ClickHandler() { |
167 | ab1eb3f8 | Christos Stathis | @Override
|
168 | 287c3d8d | Christos Stathis | public void onClick(ClickEvent event) { |
169 | 287c3d8d | Christos Stathis | createOrUpdateFolder(); |
170 | 287c3d8d | Christos Stathis | closeDialog(); |
171 | ab1eb3f8 | Christos Stathis | } |
172 | ab1eb3f8 | Christos Stathis | }); |
173 | ab1eb3f8 | Christos Stathis | buttons.add(ok); |
174 | ab1eb3f8 | Christos Stathis | buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER); |
175 | ab1eb3f8 | Christos Stathis | // Create the 'Cancel' button, along with a listener that hides the
|
176 | ab1eb3f8 | Christos Stathis | // dialog
|
177 | ab1eb3f8 | Christos Stathis | // when the button is clicked.
|
178 | ab1eb3f8 | Christos Stathis | Button cancel = new Button("Cancel", new ClickHandler() { |
179 | ab1eb3f8 | Christos Stathis | @Override
|
180 | ab1eb3f8 | Christos Stathis | public void onClick(ClickEvent event) { |
181 | ab1eb3f8 | Christos Stathis | closeDialog(); |
182 | ab1eb3f8 | Christos Stathis | } |
183 | ab1eb3f8 | Christos Stathis | }); |
184 | ab1eb3f8 | Christos Stathis | buttons.add(cancel); |
185 | ab1eb3f8 | Christos Stathis | buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); |
186 | ab1eb3f8 | Christos Stathis | buttons.setSpacing(8);
|
187 | ab1eb3f8 | Christos Stathis | buttons.addStyleName("pithos-TabPanelBottom");
|
188 | ab1eb3f8 | Christos Stathis | |
189 | ab1eb3f8 | Christos Stathis | generalPanel.add(generalTable); |
190 | ab1eb3f8 | Christos Stathis | |
191 | ab1eb3f8 | Christos Stathis | |
192 | ab1eb3f8 | Christos Stathis | outer.add(inner); |
193 | ab1eb3f8 | Christos Stathis | outer.add(buttons); |
194 | ab1eb3f8 | Christos Stathis | outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); |
195 | ab1eb3f8 | Christos Stathis | outer.addStyleName("pithos-TabPanelBottom");
|
196 | ab1eb3f8 | Christos Stathis | |
197 | ab1eb3f8 | Christos Stathis | setWidget(outer); |
198 | ab1eb3f8 | Christos Stathis | |
199 | ab1eb3f8 | Christos Stathis | /*if (create)
|
200 | ab1eb3f8 | Christos Stathis | folderName.setFocus(true);
|
201 | ab1eb3f8 | Christos Stathis | else
|
202 | ab1eb3f8 | Christos Stathis | ok.setFocus(true);*/
|
203 | ab1eb3f8 | Christos Stathis | } |
204 | ab1eb3f8 | Christos Stathis | |
205 | ab1eb3f8 | Christos Stathis | @Override
|
206 | ab1eb3f8 | Christos Stathis | public void center() { |
207 | ab1eb3f8 | Christos Stathis | super.center();
|
208 | ab1eb3f8 | Christos Stathis | folderName.setFocus(true);
|
209 | ab1eb3f8 | Christos Stathis | } |
210 | ab1eb3f8 | Christos Stathis | |
211 | ab1eb3f8 | Christos Stathis | @Override
|
212 | ab1eb3f8 | Christos Stathis | protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
213 | ab1eb3f8 | Christos Stathis | super.onPreviewNativeEvent(preview);
|
214 | ab1eb3f8 | Christos Stathis | |
215 | ab1eb3f8 | Christos Stathis | NativeEvent evt = preview.getNativeEvent(); |
216 | 287c3d8d | Christos Stathis | if (evt.getType().equals(KeyDownEvent.getType().getName()))
|
217 | ab1eb3f8 | Christos Stathis | // Use the popup's key preview hooks to close the dialog when either
|
218 | ab1eb3f8 | Christos Stathis | // enter or escape is pressed.
|
219 | ab1eb3f8 | Christos Stathis | switch (evt.getKeyCode()) {
|
220 | ab1eb3f8 | Christos Stathis | case KeyCodes.KEY_ENTER:
|
221 | ab1eb3f8 | Christos Stathis | closeDialog(); |
222 | ab1eb3f8 | Christos Stathis | createOrUpdateFolder(); |
223 | ab1eb3f8 | Christos Stathis | break;
|
224 | ab1eb3f8 | Christos Stathis | case KeyCodes.KEY_ESCAPE:
|
225 | ab1eb3f8 | Christos Stathis | closeDialog(); |
226 | ab1eb3f8 | Christos Stathis | break;
|
227 | ab1eb3f8 | Christos Stathis | } |
228 | ab1eb3f8 | Christos Stathis | } |
229 | ab1eb3f8 | Christos Stathis | |
230 | ab1eb3f8 | Christos Stathis | |
231 | ab1eb3f8 | Christos Stathis | /**
|
232 | ab1eb3f8 | Christos Stathis | * Enables IE selection prevention and hides the dialog
|
233 | ab1eb3f8 | Christos Stathis | * (we disable the prevention on creation of the dialog)
|
234 | ab1eb3f8 | Christos Stathis | */
|
235 | ab1eb3f8 | Christos Stathis | public void closeDialog() { |
236 | fa5600f7 | Christos Stathis | app.preventIESelection(); |
237 | ab1eb3f8 | Christos Stathis | hide(); |
238 | ab1eb3f8 | Christos Stathis | } |
239 | ab1eb3f8 | Christos Stathis | |
240 | ab1eb3f8 | Christos Stathis | /**
|
241 | ab1eb3f8 | Christos Stathis | * Generate an RPC request to create a new folder.
|
242 | ab1eb3f8 | Christos Stathis | */
|
243 | ab1eb3f8 | Christos Stathis | private void createFolder() { |
244 | ab1eb3f8 | Christos Stathis | String name = folderName.getText();
|
245 | fa5600f7 | Christos Stathis | String prefix = folder.getPrefix();
|
246 | fa5600f7 | Christos Stathis | String path = app.getApiPath() + app.getUsername() + "/" + folder.getContainer() + "/" + (prefix.length() == 0 ? "" : prefix + "/") + name; |
247 | fa5600f7 | Christos Stathis | PutRequest createFolder = new PutRequest(path) {
|
248 | fa5600f7 | Christos Stathis | @Override
|
249 | fa5600f7 | Christos Stathis | public void onSuccess(Resource result) { |
250 | fa5600f7 | Christos Stathis | app.updateFolder(folder); |
251 | fa5600f7 | Christos Stathis | } |
252 | fa5600f7 | Christos Stathis | |
253 | fa5600f7 | Christos Stathis | @Override
|
254 | fa5600f7 | Christos Stathis | public void onError(Throwable t) { |
255 | fa5600f7 | Christos Stathis | GWT.log("", t);
|
256 | fa5600f7 | Christos Stathis | if (t instanceof RestException) { |
257 | fa5600f7 | Christos Stathis | app.displayError("Unable to create folder:" + ((RestException) t).getHttpStatusText());
|
258 | fa5600f7 | Christos Stathis | } |
259 | fa5600f7 | Christos Stathis | else
|
260 | fa5600f7 | Christos Stathis | app.displayError("System error creating folder:" + t.getMessage());
|
261 | fa5600f7 | Christos Stathis | } |
262 | fa5600f7 | Christos Stathis | }; |
263 | 4bcf5e39 | Christos Stathis | createFolder.setHeader("X-Auth-Token", app.getToken());
|
264 | fa5600f7 | Christos Stathis | createFolder.setHeader("Accept", "*/*"); |
265 | fa5600f7 | Christos Stathis | createFolder.setHeader("Content-Length", "0"); |
266 | fa5600f7 | Christos Stathis | createFolder.setHeader("Content-Type", "application/folder"); |
267 | fa5600f7 | Christos Stathis | Scheduler.get().scheduleDeferred(createFolder); |
268 | ab1eb3f8 | Christos Stathis | } |
269 | ab1eb3f8 | Christos Stathis | |
270 | ab1eb3f8 | Christos Stathis | /**
|
271 | ab1eb3f8 | Christos Stathis | * Upon closing the dialog by clicking OK or pressing ENTER this method does
|
272 | ab1eb3f8 | Christos Stathis | * the actual work of modifying folder properties or creating a new Folder
|
273 | ab1eb3f8 | Christos Stathis | * depending on the value of the create field
|
274 | ab1eb3f8 | Christos Stathis | */
|
275 | ab1eb3f8 | Christos Stathis | private void createOrUpdateFolder() { |
276 | ab1eb3f8 | Christos Stathis | if (create)
|
277 | ab1eb3f8 | Christos Stathis | createFolder(); |
278 | ab1eb3f8 | Christos Stathis | else
|
279 | ab1eb3f8 | Christos Stathis | updateFolder(); |
280 | ab1eb3f8 | Christos Stathis | |
281 | ab1eb3f8 | Christos Stathis | } |
282 | ab1eb3f8 | Christos Stathis | |
283 | ab1eb3f8 | Christos Stathis | private void updateFolder() { |
284 | 287c3d8d | Christos Stathis | // permList.updatePermissionsAccordingToInput();
|
285 | 287c3d8d | Christos Stathis | // Set<PermissionHolder> perms = permList.getPermissions();
|
286 | 287c3d8d | Christos Stathis | // JSONObject json = new JSONObject();
|
287 | 287c3d8d | Christos Stathis | // if(!folder.getName().equals(folderName.getText()))
|
288 | 287c3d8d | Christos Stathis | // json.put("name", new JSONString(folderName.getText()));
|
289 | 287c3d8d | Christos Stathis | // //only update the read for all perm if the user is the owner
|
290 | 287c3d8d | Christos Stathis | // if (readForAll.getValue() != folder.isReadForAll())
|
291 | fa5600f7 | Christos Stathis | // if (folder.getOwner().equals(app.getCurrentUserResource().getUsername()))
|
292 | 287c3d8d | Christos Stathis | // json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue()));
|
293 | 287c3d8d | Christos Stathis | // if (permList.hasChanges()) {
|
294 | 287c3d8d | Christos Stathis | // JSONArray perma = new JSONArray();
|
295 | 287c3d8d | Christos Stathis | // int i=0;
|
296 | 287c3d8d | Christos Stathis | // for(PermissionHolder p : perms){
|
297 | 287c3d8d | Christos Stathis | // JSONObject po = new JSONObject();
|
298 | 287c3d8d | Christos Stathis | // if(p.getUser() != null)
|
299 | 287c3d8d | Christos Stathis | // po.put("user", new JSONString(p.getUser()));
|
300 | 287c3d8d | Christos Stathis | // if(p.getGroup() != null)
|
301 | 287c3d8d | Christos Stathis | // po.put("group", new JSONString(p.getGroup()));
|
302 | 287c3d8d | Christos Stathis | // po.put("read", JSONBoolean.getInstance(p.isRead()));
|
303 | 287c3d8d | Christos Stathis | // po.put("write", JSONBoolean.getInstance(p.isWrite()));
|
304 | 287c3d8d | Christos Stathis | // po.put("modifyACL", JSONBoolean.getInstance(p.isModifyACL()));
|
305 | 287c3d8d | Christos Stathis | // perma.set(i,po);
|
306 | 287c3d8d | Christos Stathis | // i++;
|
307 | 287c3d8d | Christos Stathis | // }
|
308 | 287c3d8d | Christos Stathis | // json.put("permissions", perma);
|
309 | 287c3d8d | Christos Stathis | // GWT.log(json.toString(), null);
|
310 | 287c3d8d | Christos Stathis | // }
|
311 | 287c3d8d | Christos Stathis | // PostCommand ep = new PostCommand(folder.getUri()+"?update=", json.toString(), 200){
|
312 | 287c3d8d | Christos Stathis | //
|
313 | 287c3d8d | Christos Stathis | // @Override
|
314 | 287c3d8d | Christos Stathis | // public void onComplete() {
|
315 | 287c3d8d | Christos Stathis | // //TODO:CELLTREE
|
316 | 287c3d8d | Christos Stathis | //
|
317 | 287c3d8d | Christos Stathis | // if(getPostBody() != null && !"".equals(getPostBody().trim())){
|
318 | 287c3d8d | Christos Stathis | //
|
319 | 287c3d8d | Christos Stathis | //
|
320 | fa5600f7 | Christos Stathis | // FolderResource fres = ((RestResourceWrapper) app.getTreeView().getSelection()).getResource();
|
321 | 287c3d8d | Christos Stathis | // String initialPath = fres.getUri();
|
322 | 287c3d8d | Christos Stathis | // String newPath = getPostBody().trim();
|
323 | 287c3d8d | Christos Stathis | // fres.setUri(newPath);
|
324 | fa5600f7 | Christos Stathis | // ((RestResourceWrapper) app.getTreeView().getSelection()).getResource().setUri(newPath);
|
325 | fa5600f7 | Christos Stathis | // ((RestResourceWrapper) app.getTreeView().getSelection()).setUri(newPath);
|
326 | fa5600f7 | Christos Stathis | // app.getTreeView().updateNodeChildren(fres.getParentURI());
|
327 | 287c3d8d | Christos Stathis | // if (permList.hasChanges()) {
|
328 | fa5600f7 | Christos Stathis | // app.getTreeView().updateMySharedNode();
|
329 | 287c3d8d | Christos Stathis | // }
|
330 | 287c3d8d | Christos Stathis | // /*
|
331 | 287c3d8d | Christos Stathis | // if(folderItem.getParentItem() != null && ((DnDTreeItem)folderItem.getParentItem()).getFolderResource() != null){
|
332 | 287c3d8d | Christos Stathis | // ((DnDTreeItem)folderItem.getParentItem()).getFolderResource().removeSubfolderPath(initialPath);
|
333 | 287c3d8d | Christos Stathis | // ((DnDTreeItem)folderItem.getParentItem()).getFolderResource().getSubfolderPaths().add(newPath);
|
334 | 287c3d8d | Christos Stathis | // }*/
|
335 | 287c3d8d | Christos Stathis | // }
|
336 | fa5600f7 | Christos Stathis | // //app.getFolders().updateFolder( (DnDTreeItem) app.getFolders().getCurrent());
|
337 | 287c3d8d | Christos Stathis | //
|
338 | fa5600f7 | Christos Stathis | // app.get().showFileList(true);
|
339 | 287c3d8d | Christos Stathis | // }
|
340 | 287c3d8d | Christos Stathis | //
|
341 | 287c3d8d | Christos Stathis | // @Override
|
342 | 287c3d8d | Christos Stathis | // public void onError(Throwable t) {
|
343 | 287c3d8d | Christos Stathis | // GWT.log("", t);
|
344 | 287c3d8d | Christos Stathis | // if(t instanceof RestException){
|
345 | 287c3d8d | Christos Stathis | // int statusCode = ((RestException)t).getHttpStatusCode();
|
346 | 287c3d8d | Christos Stathis | // if(statusCode == 405)
|
347 | fa5600f7 | Christos Stathis | // app.displayError("You don't have the necessary permissions or" +
|
348 | 287c3d8d | Christos Stathis | // " a folder with same name already exists");
|
349 | 287c3d8d | Christos Stathis | // else if(statusCode == 404)
|
350 | fa5600f7 | Christos Stathis | // app.displayError("Resource not found, or user specified in sharing does not exist");
|
351 | 287c3d8d | Christos Stathis | // else
|
352 | fa5600f7 | Christos Stathis | // app.displayError("Unable to update folder: "+((RestException)t).getHttpStatusText());
|
353 | 287c3d8d | Christos Stathis | // }
|
354 | 287c3d8d | Christos Stathis | // else
|
355 | fa5600f7 | Christos Stathis | // app.displayError("System error moifying file: "+t.getMessage());
|
356 | 287c3d8d | Christos Stathis | // //TODO:CELLTREE
|
357 | fa5600f7 | Christos Stathis | // //app.getFolders().updateFolder( (DnDTreeItem) app.getFolders().getCurrent());
|
358 | 287c3d8d | Christos Stathis | // }
|
359 | 287c3d8d | Christos Stathis | // };
|
360 | 287c3d8d | Christos Stathis | // DeferredCommand.addCommand(ep);
|
361 | 33b61be6 | Christos Stathis | final String newName = folderName.getText(); |
362 | 33b61be6 | Christos Stathis | if (!folder.isContainer() && !folder.getName().equals(newName)) {
|
363 | 33b61be6 | Christos Stathis | final String path = app.getApiPath() + app.getUsername() + folder.getParent().getUri() + "/" + newName; |
364 | 33b61be6 | Christos Stathis | PutRequest newFolder = new PutRequest(path) {
|
365 | 33b61be6 | Christos Stathis | @Override
|
366 | 33b61be6 | Christos Stathis | public void onSuccess(Resource result) { |
367 | 33b61be6 | Christos Stathis | Iterator<File> iter = folder.getFiles().iterator(); |
368 | 33b61be6 | Christos Stathis | app.copyFiles(iter, folder.getParent().getUri() + "/" + newName, new Command() { |
369 | 33b61be6 | Christos Stathis | @Override
|
370 | 33b61be6 | Christos Stathis | public void execute() { |
371 | 33b61be6 | Christos Stathis | Iterator<Folder> iterf = folder.getSubfolders().iterator();
|
372 | 33b61be6 | Christos Stathis | app.copySubfolders(iterf, folder.getParent().getUri() + "/" + newName, new Command() { |
373 | 33b61be6 | Christos Stathis | @Override
|
374 | 33b61be6 | Christos Stathis | public void execute() { |
375 | 33b61be6 | Christos Stathis | app.deleteFolder(folder); |
376 | 33b61be6 | Christos Stathis | app.updateFolder(folder.getParent()); |
377 | 33b61be6 | Christos Stathis | } |
378 | 33b61be6 | Christos Stathis | }); |
379 | 33b61be6 | Christos Stathis | } |
380 | 33b61be6 | Christos Stathis | }); |
381 | 33b61be6 | Christos Stathis | } |
382 | 33b61be6 | Christos Stathis | |
383 | 33b61be6 | Christos Stathis | @Override
|
384 | 33b61be6 | Christos Stathis | public void onError(Throwable t) { |
385 | 33b61be6 | Christos Stathis | GWT.log("", t);
|
386 | 33b61be6 | Christos Stathis | if(t instanceof RestException){ |
387 | 33b61be6 | Christos Stathis | app.displayError("Unable to update folder: " + ((RestException) t).getHttpStatusText());
|
388 | 33b61be6 | Christos Stathis | } |
389 | 33b61be6 | Christos Stathis | else
|
390 | 33b61be6 | Christos Stathis | app.displayError("System error modifying folder: " + t.getMessage());
|
391 | 33b61be6 | Christos Stathis | } |
392 | 33b61be6 | Christos Stathis | }; |
393 | 33b61be6 | Christos Stathis | newFolder.setHeader("X-Auth-Token", app.getToken());
|
394 | 33b61be6 | Christos Stathis | newFolder.setHeader("Content-Type", "application/folder"); |
395 | 33b61be6 | Christos Stathis | newFolder.setHeader("Accept", "*/*"); |
396 | 33b61be6 | Christos Stathis | newFolder.setHeader("Content-Length", "0"); |
397 | 33b61be6 | Christos Stathis | Scheduler.get().scheduleDeferred(newFolder); |
398 | 33b61be6 | Christos Stathis | } |
399 | ab1eb3f8 | Christos Stathis | } |
400 | ab1eb3f8 | Christos Stathis | |
401 | ab1eb3f8 | Christos Stathis | public void selectTab(int _tab) { |
402 | ab1eb3f8 | Christos Stathis | inner.selectTab(_tab); |
403 | ab1eb3f8 | Christos Stathis | } |
404 | ab1eb3f8 | Christos Stathis | } |