2 * Copyright 2011 GRNET S.A. All rights reserved.
\r
4 * Redistribution and use in source and binary forms, with or
\r
5 * without modification, are permitted provided that the following
\r
6 * conditions are met:
\r
8 * 1. Redistributions of source code must retain the above
\r
9 * copyright notice, this list of conditions and the following
\r
12 * 2. Redistributions in binary form must reproduce the above
\r
13 * copyright notice, this list of conditions and the following
\r
14 * disclaimer in the documentation and/or other materials
\r
15 * provided with the distribution.
\r
17 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
\r
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
\r
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
\r
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
\r
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
\r
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
\r
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
\r
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
\r
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
\r
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
28 * POSSIBILITY OF SUCH DAMAGE.
\r
30 * The views and conclusions contained in the software and
\r
31 * documentation are those of the authors and should not be
\r
32 * interpreted as representing official policies, either expressed
\r
33 * or implied, of GRNET S.A.
\r
35 package gr.grnet.pithos.web.client;
\r
37 import com.google.gwt.core.client.Scheduler;
\r
38 import com.google.gwt.event.dom.client.KeyDownEvent;
\r
39 import com.google.gwt.user.client.Event;
\r
40 import gr.grnet.pithos.web.client.foldertree.Folder;
\r
41 import gr.grnet.pithos.web.client.foldertree.Resource;
\r
42 import gr.grnet.pithos.web.client.rest.PostCommand;
\r
43 import gr.grnet.pithos.web.client.rest.PutRequest;
\r
44 import gr.grnet.pithos.web.client.rest.RestException;
\r
45 import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
\r
47 import com.google.gwt.core.client.GWT;
\r
48 import com.google.gwt.dom.client.NativeEvent;
\r
49 import com.google.gwt.event.dom.client.ClickEvent;
\r
50 import com.google.gwt.event.dom.client.ClickHandler;
\r
51 import com.google.gwt.event.dom.client.KeyCodes;
\r
52 import com.google.gwt.http.client.URL;
\r
53 import com.google.gwt.i18n.client.DateTimeFormat;
\r
54 import com.google.gwt.user.client.DeferredCommand;
\r
55 import com.google.gwt.user.client.Event.NativePreviewEvent;
\r
56 import com.google.gwt.user.client.ui.Button;
\r
57 import com.google.gwt.user.client.ui.CheckBox;
\r
58 import com.google.gwt.user.client.ui.DecoratedTabPanel;
\r
59 import com.google.gwt.user.client.ui.DialogBox;
\r
60 import com.google.gwt.user.client.ui.FlexTable;
\r
61 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
\r
62 import com.google.gwt.user.client.ui.HorizontalPanel;
\r
63 import com.google.gwt.user.client.ui.Label;
\r
64 import com.google.gwt.user.client.ui.TabPanel;
\r
65 import com.google.gwt.user.client.ui.TextBox;
\r
66 import com.google.gwt.user.client.ui.VerticalPanel;
\r
69 * The 'Folder properties' dialog box implementation.
\r
71 public class FolderPropertiesDialog extends DialogBox {
\r
75 private CheckBox readForAll;
\r
78 * The widget that holds the folderName of the folder.
\r
80 private TextBox folderName = new TextBox();
\r
83 * A flag that denotes whether the dialog will be used to create or modify a
\r
86 private final boolean create;
\r
88 final Folder folder;
\r
90 final TabPanel inner;
\r
93 * The widget's constructor.
\r
95 public FolderPropertiesDialog(GSS app, boolean _create, Folder selected) {
\r
97 setAnimationEnabled(true);
\r
99 // Enable IE selection for the dialog (must disable it upon closing it)
\r
100 app.enableIESelection();
\r
106 // Use this opportunity to set the dialog's caption.
\r
108 setText("Create folder");
\r
110 setText("Folder properties");
\r
112 // Outer contains inner and buttons
\r
113 VerticalPanel outer = new VerticalPanel();
\r
114 // Inner contains generalPanel and permPanel
\r
115 inner = new DecoratedTabPanel();
\r
116 inner.setAnimationEnabled(true);
\r
117 VerticalPanel generalPanel = new VerticalPanel();
\r
118 VerticalPanel permPanel = new VerticalPanel();
\r
119 final HorizontalPanel permForAll = new HorizontalPanel();
\r
120 final HorizontalPanel pathPanel = new HorizontalPanel();
\r
121 HorizontalPanel buttons = new HorizontalPanel();
\r
122 HorizontalPanel permButtons = new HorizontalPanel();
\r
124 inner.add(generalPanel, "General");
\r
126 inner.add(permPanel, "Sharing");
\r
127 inner.selectTab(0);
\r
129 FlexTable generalTable = new FlexTable();
\r
130 generalTable.setText(0, 0, "Name");
\r
131 generalTable.setText(1, 0, "Parent");
\r
132 generalTable.setText(2, 0, "Creator");
\r
133 generalTable.setText(3, 0, "Last modified");
\r
134 folderName.setText(create ? "" : folder.getName());
\r
135 generalTable.setWidget(0, 1, folderName);
\r
138 generalTable.setText(1, 1, folder.getName());
\r
140 generalTable.setText(1, 1, folder.getPrefix());
\r
141 generalTable.setText(2, 1, "");
\r
142 DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
\r
143 if(folder.getLastModified() != null)
\r
144 generalTable.setText(3, 1, formatter.format(folder.getLastModified()));
\r
145 generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
\r
146 generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
\r
147 generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");
\r
148 generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels");
\r
149 generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");
\r
150 generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");
\r
151 generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");
\r
152 generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values");
\r
153 generalTable.setCellSpacing(4);
\r
155 // Create the 'Create/Update' button, along with a listener that hides the dialog
\r
156 // when the button is clicked and quits the application.
\r
159 okLabel = "Create";
\r
161 okLabel = "Update";
\r
162 Button ok = new Button(okLabel, new ClickHandler() {
\r
164 public void onClick(ClickEvent event) {
\r
165 createOrUpdateFolder();
\r
170 buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
\r
171 // Create the 'Cancel' button, along with a listener that hides the
\r
173 // when the button is clicked.
\r
174 Button cancel = new Button("Cancel", new ClickHandler() {
\r
176 public void onClick(ClickEvent event) {
\r
180 buttons.add(cancel);
\r
181 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
\r
182 buttons.setSpacing(8);
\r
183 buttons.addStyleName("pithos-TabPanelBottom");
\r
185 generalPanel.add(generalTable);
\r
189 outer.add(buttons);
\r
190 outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
\r
191 outer.addStyleName("pithos-TabPanelBottom");
\r
196 folderName.setFocus(true);
\r
198 ok.setFocus(true);*/
\r
202 public void center() {
\r
204 folderName.setFocus(true);
\r
208 protected void onPreviewNativeEvent(NativePreviewEvent preview) {
\r
209 super.onPreviewNativeEvent(preview);
\r
211 NativeEvent evt = preview.getNativeEvent();
\r
212 if (evt.getType().equals(KeyDownEvent.getType().getName()))
\r
213 // Use the popup's key preview hooks to close the dialog when either
\r
214 // enter or escape is pressed.
\r
215 switch (evt.getKeyCode()) {
\r
216 case KeyCodes.KEY_ENTER:
\r
218 createOrUpdateFolder();
\r
220 case KeyCodes.KEY_ESCAPE:
\r
228 * Enables IE selection prevention and hides the dialog
\r
229 * (we disable the prevention on creation of the dialog)
\r
231 public void closeDialog() {
\r
232 app.preventIESelection();
\r
237 * Generate an RPC request to create a new folder.
\r
239 private void createFolder() {
\r
240 String name = folderName.getText();
\r
241 String prefix = folder.getPrefix();
\r
242 String path = app.getApiPath() + app.getUsername() + "/" + folder.getContainer() + "/" + (prefix.length() == 0 ? "" : prefix + "/") + name;
\r
243 PutRequest createFolder = new PutRequest(path) {
\r
245 public void onSuccess(Resource result) {
\r
246 app.updateFolder(folder);
\r
250 public void onError(Throwable t) {
\r
252 if (t instanceof RestException) {
\r
253 app.displayError("Unable to create folder:" + ((RestException) t).getHttpStatusText());
\r
256 app.displayError("System error creating folder:" + t.getMessage());
\r
259 createFolder.setHeader("X-Auth-Token", app.getToken());
\r
260 createFolder.setHeader("Accept", "*/*");
\r
261 createFolder.setHeader("Content-Length", "0");
\r
262 createFolder.setHeader("Content-Type", "application/folder");
\r
263 Scheduler.get().scheduleDeferred(createFolder);
\r
267 * Upon closing the dialog by clicking OK or pressing ENTER this method does
\r
268 * the actual work of modifying folder properties or creating a new Folder
\r
269 * depending on the value of the create field
\r
271 private void createOrUpdateFolder() {
\r
279 private void updateFolder() {
\r
280 // permList.updatePermissionsAccordingToInput();
\r
281 // Set<PermissionHolder> perms = permList.getPermissions();
\r
282 // JSONObject json = new JSONObject();
\r
283 // if(!folder.getName().equals(folderName.getText()))
\r
284 // json.put("name", new JSONString(folderName.getText()));
\r
285 // //only update the read for all perm if the user is the owner
\r
286 // if (readForAll.getValue() != folder.isReadForAll())
\r
287 // if (folder.getOwner().equals(app.getCurrentUserResource().getUsername()))
\r
288 // json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue()));
\r
289 // if (permList.hasChanges()) {
\r
290 // JSONArray perma = new JSONArray();
\r
292 // for(PermissionHolder p : perms){
\r
293 // JSONObject po = new JSONObject();
\r
294 // if(p.getUser() != null)
\r
295 // po.put("user", new JSONString(p.getUser()));
\r
296 // if(p.getGroup() != null)
\r
297 // po.put("group", new JSONString(p.getGroup()));
\r
298 // po.put("read", JSONBoolean.getInstance(p.isRead()));
\r
299 // po.put("write", JSONBoolean.getInstance(p.isWrite()));
\r
300 // po.put("modifyACL", JSONBoolean.getInstance(p.isModifyACL()));
\r
301 // perma.set(i,po);
\r
304 // json.put("permissions", perma);
\r
305 // GWT.log(json.toString(), null);
\r
307 // PostCommand ep = new PostCommand(folder.getUri()+"?update=", json.toString(), 200){
\r
310 // public void onComplete() {
\r
313 // if(getPostBody() != null && !"".equals(getPostBody().trim())){
\r
316 // FolderResource fres = ((RestResourceWrapper) app.getTreeView().getSelection()).getResource();
\r
317 // String initialPath = fres.getUri();
\r
318 // String newPath = getPostBody().trim();
\r
319 // fres.setUri(newPath);
\r
320 // ((RestResourceWrapper) app.getTreeView().getSelection()).getResource().setUri(newPath);
\r
321 // ((RestResourceWrapper) app.getTreeView().getSelection()).setUri(newPath);
\r
322 // app.getTreeView().updateNodeChildren(fres.getParentURI());
\r
323 // if (permList.hasChanges()) {
\r
324 // app.getTreeView().updateMySharedNode();
\r
327 // if(folderItem.getParentItem() != null && ((DnDTreeItem)folderItem.getParentItem()).getFolderResource() != null){
\r
328 // ((DnDTreeItem)folderItem.getParentItem()).getFolderResource().removeSubfolderPath(initialPath);
\r
329 // ((DnDTreeItem)folderItem.getParentItem()).getFolderResource().getSubfolderPaths().add(newPath);
\r
332 // //app.getFolders().updateFolder( (DnDTreeItem) app.getFolders().getCurrent());
\r
334 // app.get().showFileList(true);
\r
338 // public void onError(Throwable t) {
\r
340 // if(t instanceof RestException){
\r
341 // int statusCode = ((RestException)t).getHttpStatusCode();
\r
342 // if(statusCode == 405)
\r
343 // app.displayError("You don't have the necessary permissions or" +
\r
344 // " a folder with same name already exists");
\r
345 // else if(statusCode == 404)
\r
346 // app.displayError("Resource not found, or user specified in sharing does not exist");
\r
348 // app.displayError("Unable to update folder: "+((RestException)t).getHttpStatusText());
\r
351 // app.displayError("System error moifying file: "+t.getMessage());
\r
353 // //app.getFolders().updateFolder( (DnDTreeItem) app.getFolders().getCurrent());
\r
356 // DeferredCommand.addCommand(ep);
\r
359 public void selectTab(int _tab) {
\r
360 inner.selectTab(_tab);
\r