/*\r
- * Copyright 2011 GRNET S.A. All rights reserved.\r
+ * Copyright 2011-2013 GRNET S.A. All rights reserved.\r
*\r
* Redistribution and use in source and binary forms, with or\r
* without modification, are permitted provided that the following\r
*/\r
package gr.grnet.pithos.web.client;\r
\r
-import gr.grnet.pithos.web.client.FilePropertiesDialog.Images;\r
-import gr.grnet.pithos.web.client.rest.PostCommand;\r
-import gr.grnet.pithos.web.client.rest.RestException;\r
-import gr.grnet.pithos.web.client.rest.resource.FolderResource;\r
-import gr.grnet.pithos.web.client.rest.resource.GroupResource;\r
-import gr.grnet.pithos.web.client.rest.resource.PermissionHolder;\r
-import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;\r
-\r
-import java.util.List;\r
-import java.util.Set;\r
-\r
import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.core.client.Scheduler;\r
import com.google.gwt.dom.client.NativeEvent;\r
-import com.google.gwt.event.dom.client.ChangeEvent;\r
-import com.google.gwt.event.dom.client.ChangeHandler;\r
-import com.google.gwt.event.dom.client.ClickEvent;\r
-import com.google.gwt.event.dom.client.ClickHandler;\r
-import com.google.gwt.event.dom.client.KeyCodes;\r
-import com.google.gwt.http.client.URL;\r
+import com.google.gwt.event.dom.client.*;\r
+import com.google.gwt.http.client.Response;\r
import com.google.gwt.i18n.client.DateTimeFormat;\r
-import com.google.gwt.json.client.JSONArray;\r
-import com.google.gwt.json.client.JSONBoolean;\r
-import com.google.gwt.json.client.JSONObject;\r
-import com.google.gwt.json.client.JSONString;\r
-import com.google.gwt.user.client.DeferredCommand;\r
+import com.google.gwt.user.client.Command;\r
import com.google.gwt.user.client.Event.NativePreviewEvent;\r
-import com.google.gwt.user.client.ui.Button;\r
-import com.google.gwt.user.client.ui.CheckBox;\r
-import com.google.gwt.user.client.ui.DecoratedTabPanel;\r
-import com.google.gwt.user.client.ui.DialogBox;\r
-import com.google.gwt.user.client.ui.FlexTable;\r
-import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
-import com.google.gwt.user.client.ui.HorizontalPanel;\r
-import com.google.gwt.user.client.ui.Label;\r
-import com.google.gwt.user.client.ui.TabPanel;\r
-import com.google.gwt.user.client.ui.TextBox;\r
-import com.google.gwt.user.client.ui.VerticalPanel;\r
+import com.google.gwt.user.client.ui.*;\r
+import gr.grnet.pithos.web.client.foldertree.Folder;\r
+import gr.grnet.pithos.web.client.rest.PutRequest;\r
+import gr.grnet.pithos.web.client.rest.RestException;\r
\r
/**\r
* The 'Folder properties' dialog box implementation.\r
*/\r
public class FolderPropertiesDialog extends DialogBox {\r
\r
- private List<GroupResource> groups = null;\r
-\r
- final PermissionsList permList;\r
-\r
- private CheckBox readForAll;\r
-\r
- /**\r
- * The widget that holds the folderName of the folder.\r
- */\r
- private TextBox folderName = new TextBox();\r
-\r
- /**\r
- * A flag that denotes whether the dialog will be used to create or modify a\r
- * folder.\r
- */\r
- private final boolean create;\r
-\r
- final FolderResource folder;\r
-\r
- final TabPanel inner;\r
-\r
- /**\r
- * The widget's constructor.\r
- *\r
- * @param images the image icons from the file properties dialog\r
- * @param _create true if the dialog is displayed for creating a new\r
- * sub-folder of the selected folder, false if it is displayed\r
- * for modifying the selected folder\r
- */\r
- public FolderPropertiesDialog(Images images, boolean _create, final List<GroupResource> _groups) {\r
- setAnimationEnabled(true);\r
-\r
- // Enable IE selection for the dialog (must disable it upon closing it)\r
- GSS.enableIESelection();\r
-\r
- create = _create;\r
- \r
- folder = ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).getResource();\r
- permList = new PermissionsList(images, folder.getPermissions(), folder.getOwner());\r
- groups = _groups;\r
-\r
- // Use this opportunity to set the dialog's caption.\r
- if (create)\r
- setText("Create folder");\r
- else\r
- setText("Folder properties");\r
-\r
- // Outer contains inner and buttons\r
- VerticalPanel outer = new VerticalPanel();\r
- // Inner contains generalPanel and permPanel\r
- inner = new DecoratedTabPanel();\r
- inner.setAnimationEnabled(true);\r
- VerticalPanel generalPanel = new VerticalPanel();\r
- VerticalPanel permPanel = new VerticalPanel();\r
- final HorizontalPanel permForAll = new HorizontalPanel();\r
- final HorizontalPanel pathPanel = new HorizontalPanel();\r
- HorizontalPanel buttons = new HorizontalPanel();\r
- HorizontalPanel permButtons = new HorizontalPanel();\r
-\r
- inner.add(generalPanel, "General");\r
- if (!create)\r
- inner.add(permPanel, "Sharing");\r
- inner.selectTab(0);\r
-\r
- final Label folderNameNote = new Label("Please note that slashes ('/') are not allowed in folder names.", true);\r
- folderNameNote.setVisible(false);\r
- folderNameNote.setStylePrimaryName("pithos-readForAllNote");\r
-\r
- FlexTable generalTable = new FlexTable();\r
- generalTable.setText(0, 0, "Name");\r
- generalTable.setText(1, 0, "Parent");\r
- generalTable.setText(2, 0, "Creator");\r
- generalTable.setText(3, 0, "Last modified");\r
- folderName.setText(create ? "" : folder.getName());\r
- folderName.getElement().setId("folderPropertiesDialog.textBox.name");\r
- generalTable.setWidget(0, 1, folderName);\r
- folderName.addChangeHandler(new ChangeHandler() {\r
- \r
- @Override\r
- public void onChange(ChangeEvent event) {\r
- if(folderName.getText().contains("/"))\r
- folderNameNote.setVisible(true);\r
- else\r
- folderNameNote.setVisible(false); \r
- \r
- }\r
- });\r
-\r
-\r
- if (create)\r
- generalTable.setText(1, 1, folder.getName());\r
- else if(folder.getParentName() == null)\r
- generalTable.setText(1, 1, "-");\r
- else\r
- generalTable.setText(1, 1, folder.getParentName());\r
- generalTable.setWidget(0, 2, folderNameNote);\r
- generalTable.setText(2, 1, folder.getOwner());\r
- DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");\r
- if(folder.getModificationDate() != null)\r
- generalTable.setText(3, 1, formatter.format(folder.getModificationDate()));\r
- generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");\r
- generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");\r
- generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");\r
- generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels");\r
- generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");\r
- generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");\r
- generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");\r
- generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values");\r
- generalTable.setCellSpacing(4);\r
-\r
- // Create the 'Create/Update' button, along with a listener that hides the dialog\r
- // when the button is clicked and quits the application.\r
- String okLabel;\r
- if (create)\r
- okLabel = "Create";\r
- else\r
- okLabel = "Update";\r
- Button ok = new Button(okLabel, new ClickHandler() {\r
- @Override\r
- public void onClick(ClickEvent event) { \r
- if(folderName.getText().contains("/"))\r
- folderNameNote.setVisible(true);\r
- else {\r
- folderNameNote.setVisible(false);\r
- createOrUpdateFolder();\r
- closeDialog();\r
- }\r
-\r
- }\r
- });\r
- ok.getElement().setId("folderPropertiesDialog.button.ok");\r
- buttons.add(ok);\r
- buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);\r
- // Create the 'Cancel' button, along with a listener that hides the\r
- // dialog\r
- // when the button is clicked.\r
- Button cancel = new Button("Cancel", new ClickHandler() {\r
- @Override\r
- public void onClick(ClickEvent event) {\r
- closeDialog();\r
- }\r
- });\r
- cancel.getElement().setId("folderPropertiesDialog.button.cancel");\r
- buttons.add(cancel);\r
- buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
- buttons.setSpacing(8);\r
- buttons.addStyleName("pithos-TabPanelBottom");\r
-\r
- Button add = new Button("Add Group", new ClickHandler() {\r
- @Override\r
- public void onClick(ClickEvent event) {\r
- PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, false);\r
- dlg.center();\r
- }\r
- });\r
- add.getElement().setId("folderPropertiesDialog.button.addGroup");\r
- permButtons.add(add);\r
- permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER);\r
-\r
- Button addUser = new Button("Add User", new ClickHandler() {\r
- @Override\r
- public void onClick(ClickEvent event) {\r
- PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, true);\r
- dlg.center();\r
- }\r
- });\r
- addUser.getElement().setId("folderPropertiesDialog.button.addUser");\r
- permButtons.add(addUser);\r
- permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER);\r
-\r
- permButtons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
- permButtons.setSpacing(8);\r
- permButtons.addStyleName("pithos-TabPanelBottom");\r
-\r
- final Label readForAllNote = new Label("When this option is enabled, the folder will be readable" +\r
- " by everyone. By checking this option, you are certifying that you have the right to " +\r
- "distribute this folder's contents and that it does not violate the Terms of Use.", true);\r
- readForAllNote.setVisible(false);\r
- readForAllNote.setStylePrimaryName("pithos-readForAllNote");\r
-\r
- readForAll = new CheckBox();\r
- readForAll.getElement().setId("folderPropertiesDialog.checkBox.public");\r
- readForAll.setValue(folder.isReadForAll());\r
- readForAll.addClickHandler(new ClickHandler() {\r
- @Override\r
- public void onClick(ClickEvent event) {\r
- readForAllNote.setVisible(readForAll.getValue());\r
- }\r
-\r
- });\r
-\r
- generalPanel.add(generalTable);\r
- permPanel.add(permList);\r
- permPanel.add(permButtons);\r
-\r
- // Only show the read for all permission if the user is the owner.\r
- if (folder.getOwner().equals(GSS.get().getCurrentUserResource().getUsername())) {\r
- permForAll.add(new Label("Public"));\r
- permForAll.add(readForAll);\r
- permForAll.setSpacing(8);\r
- permForAll.addStyleName("pithos-TabPanelBottom");\r
- permForAll.add(readForAllNote);\r
- permPanel.add(permForAll);\r
- }\r
- TextBox path = new TextBox();\r
- path.getElement().setId("folderPropertiesDialog.textBox.link");\r
- path.setWidth("100%");\r
- path.addClickHandler(new ClickHandler() {\r
- @Override\r
- public void onClick(ClickEvent event) {\r
- GSS.enableIESelection();\r
- ((TextBox) event.getSource()).selectAll();\r
- GSS.preventIESelection();\r
- }\r
-\r
- });\r
- path.setText(folder.getUri());\r
- path.setTitle("Use this link for sharing the folder via e-mail, IM, etc. (crtl-C/cmd-C to copy to system clipboard)");\r
- path.setWidth("100%");\r
- path.setReadOnly(true);\r
- pathPanel.setWidth("100%");\r
- pathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);\r
- pathPanel.add(new Label("Link"));\r
- pathPanel.setSpacing(8);\r
- pathPanel.addStyleName("pithos-TabPanelBottom");\r
- pathPanel.add(path);\r
- permPanel.add(pathPanel);\r
-\r
- outer.add(inner);\r
- outer.add(buttons);\r
- outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);\r
- outer.addStyleName("pithos-TabPanelBottom");\r
-\r
- setWidget(outer);\r
-\r
- /*if (create)\r
- folderName.setFocus(true);\r
- else\r
- ok.setFocus(true);*/\r
- }\r
-\r
- @Override\r
- public void center() {\r
- super.center();\r
- folderName.setFocus(true);\r
- }\r
-\r
- @Override\r
- protected void onPreviewNativeEvent(NativePreviewEvent preview) {\r
- super.onPreviewNativeEvent(preview);\r
-\r
- NativeEvent evt = preview.getNativeEvent();\r
- if (evt.getType().equals("keydown"))\r
- // Use the popup's key preview hooks to close the dialog when either\r
- // enter or escape is pressed.\r
- switch (evt.getKeyCode()) {\r
- case KeyCodes.KEY_ENTER:\r
- closeDialog();\r
- createOrUpdateFolder();\r
- break;\r
- case KeyCodes.KEY_ESCAPE:\r
- closeDialog();\r
- break;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Enables IE selection prevention and hides the dialog\r
- * (we disable the prevention on creation of the dialog)\r
- */\r
- public void closeDialog() {\r
- GSS.preventIESelection();\r
- hide();\r
- }\r
-\r
- /**\r
- * Generate an RPC request to create a new folder.\r
- *\r
- * @param userId the ID of the user whose namespace will be searched for\r
- * folders\r
- * @param _folderName the name of the folder to create\r
- */\r
- private void createFolder() {\r
- String name = folderName.getText();\r
- if (!GSS.isValidResourceName(name)) {\r
- GSS.get().displayError("The folder name '" + name + "' is invalid");\r
- return;\r
- }\r
- PostCommand ep = new PostCommand(folder.getUri() + "?new=" +\r
- URL.encodeComponent(name), "", 201) {\r
-\r
- @Override\r
- public void onComplete() {\r
- //TODO:CELLTREE\r
- if(folder.getUri().equals(GSS.get().getTreeView().getMyFolders().getUri())){\r
- GSS.get().getTreeView().updateRootNode();\r
- }\r
- else\r
- GSS.get().getTreeView().updateNodeChildren((RestResourceWrapper) GSS.get().getTreeView().getSelection());\r
- //GSS.get().getFolders().updateFolder((DnDTreeItem) GSS.get().getFolders().getCurrent());\r
- }\r
-\r
- @Override\r
- public void onError(Throwable t) {\r
- GWT.log("", t);\r
- if(t instanceof RestException){\r
- int statusCode = ((RestException)t).getHttpStatusCode();\r
- if(statusCode == 405)\r
- GSS.get().displayError("You don't have the necessary" +\r
- " permissions or a folder with same name " +\r
- "already exists");\r
- else if(statusCode == 404)\r
- GSS.get().displayError("Resource not found");\r
- else\r
- GSS.get().displayError("Unable to create folder:" +\r
- ((RestException)t).getHttpStatusText());\r
- }\r
- else\r
- GSS.get().displayError("System error creating folder:" +\r
- t.getMessage());\r
- }\r
- };\r
- DeferredCommand.addCommand(ep);\r
-\r
- }\r
-\r
- /**\r
- * Upon closing the dialog by clicking OK or pressing ENTER this method does\r
- * the actual work of modifying folder properties or creating a new Folder\r
- * depending on the value of the create field\r
- *\r
- * @param userId\r
- */\r
- private void createOrUpdateFolder() {\r
- if (create)\r
- createFolder();\r
- else\r
- updateFolder();\r
-\r
- }\r
-\r
- private void updateFolder() {\r
- permList.updatePermissionsAccordingToInput();\r
- Set<PermissionHolder> perms = permList.getPermissions();\r
- JSONObject json = new JSONObject();\r
- if(!folder.getName().equals(folderName.getText()))\r
- json.put("name", new JSONString(folderName.getText()));\r
- //only update the read for all perm if the user is the owner\r
- if (readForAll.getValue() != folder.isReadForAll())\r
- if (folder.getOwner().equals(GSS.get().getCurrentUserResource().getUsername()))\r
- json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue()));\r
- if (permList.hasChanges()) {\r
- JSONArray perma = new JSONArray();\r
- int i=0;\r
- for(PermissionHolder p : perms){\r
- JSONObject po = new JSONObject();\r
- if(p.getUser() != null)\r
- po.put("user", new JSONString(p.getUser()));\r
- if(p.getGroup() != null)\r
- po.put("group", new JSONString(p.getGroup()));\r
- po.put("read", JSONBoolean.getInstance(p.isRead()));\r
- po.put("write", JSONBoolean.getInstance(p.isWrite()));\r
- po.put("modifyACL", JSONBoolean.getInstance(p.isModifyACL()));\r
- perma.set(i,po);\r
- i++;\r
- }\r
- json.put("permissions", perma);\r
- GWT.log(json.toString(), null);\r
- }\r
- PostCommand ep = new PostCommand(folder.getUri()+"?update=", json.toString(), 200){\r
-\r
- @Override\r
- public void onComplete() {\r
- //TODO:CELLTREE\r
- \r
- if(getPostBody() != null && !"".equals(getPostBody().trim())){\r
- \r
- \r
- FolderResource fres = ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).getResource();\r
- String initialPath = fres.getUri();\r
- String newPath = getPostBody().trim();\r
- fres.setUri(newPath);\r
- ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).getResource().setUri(newPath);\r
- ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).setUri(newPath);\r
- GSS.get().getTreeView().updateNodeChildren(fres.getParentURI());\r
- if (permList.hasChanges()) {\r
- GSS.get().getTreeView().updateMySharedNode();\r
- }\r
- /*\r
- if(folderItem.getParentItem() != null && ((DnDTreeItem)folderItem.getParentItem()).getFolderResource() != null){\r
- ((DnDTreeItem)folderItem.getParentItem()).getFolderResource().removeSubfolderPath(initialPath);\r
- ((DnDTreeItem)folderItem.getParentItem()).getFolderResource().getSubfolderPaths().add(newPath);\r
- }*/\r
- }\r
- //GSS.get().getFolders().updateFolder( (DnDTreeItem) GSS.get().getFolders().getCurrent());\r
- \r
- GSS.get().showFileList(true);\r
- }\r
-\r
- @Override\r
- public void onError(Throwable t) {\r
- GWT.log("", t);\r
- if(t instanceof RestException){\r
- int statusCode = ((RestException)t).getHttpStatusCode();\r
- if(statusCode == 405)\r
- GSS.get().displayError("You don't have the necessary permissions or" +\r
- " a folder with same name already exists");\r
- else if(statusCode == 404)\r
- GSS.get().displayError("Resource not found, or user specified in sharing does not exist");\r
- else\r
- GSS.get().displayError("Unable to update folder: "+((RestException)t).getHttpStatusText());\r
- }\r
- else\r
- GSS.get().displayError("System error moifying file: "+t.getMessage());\r
- //TODO:CELLTREE\r
- //GSS.get().getFolders().updateFolder( (DnDTreeItem) GSS.get().getFolders().getCurrent());\r
- }\r
- };\r
- DeferredCommand.addCommand(ep);\r
- }\r
-\r
- public void selectTab(int _tab) {\r
- inner.selectTab(_tab);\r
- }\r
-\r
+ protected Pithos app;\r
+\r
+ /**\r
+ * The widget that holds the folderName of the folder.\r
+ */\r
+ TextBox folderName = new TextBox();\r
+\r
+ /**\r
+ * A flag that denotes whether the dialog will be used to create or modify a\r
+ * folder.\r
+ */\r
+ private final boolean create;\r
+\r
+ final Folder folder;\r
+\r
+ final VerticalPanel inner;\r
+\r
+ /**\r
+ * The widget's constructor.\r
+ */\r
+ public FolderPropertiesDialog(final Pithos app, boolean _create, Folder selected) {\r
+ this.app = app;\r
+ Anchor close = new Anchor("close");\r
+ close.addStyleName("close");\r
+ close.addClickHandler(new ClickHandler() {\r
+\r
+ @Override\r
+ public void onClick(ClickEvent event) {\r
+ hide();\r
+ }\r
+ });\r
+\r
+ setGlassEnabled(true);\r
+ setStyleName("pithos-DialogBox");\r
+\r
+ // Enable IE selection for the dialog (must disable it upon closing it)\r
+ Pithos.enableIESelection();\r
+\r
+ create = _create;\r
+\r
+ folder = selected;\r
+\r
+ // Use this opportunity to set the dialog's caption.\r
+ if(create) {\r
+ setText("Create folder");\r
+ }\r
+ else {\r
+ setText("Folder properties");\r
+ }\r
+\r
+ // Outer contains inner and buttons\r
+ VerticalPanel outer = new VerticalPanel();\r
+ outer.add(close);\r
+ // Inner contains generalPanel and permPanel\r
+ inner = new VerticalPanel();\r
+ inner.addStyleName("inner");\r
+\r
+ VerticalPanel generalPanel = new VerticalPanel();\r
+ FlexTable generalTable = new FlexTable();\r
+ generalTable.setText(0, 0, "Name");\r
+ generalTable.setText(1, 0, "Parent");\r
+ generalTable.setText(2, 0, "Creator");\r
+ generalTable.setText(3, 0, "Last modified");\r
+\r
+ folderName.setText(create ? "" : folder.getName());\r
+ folderName.setReadOnly(folder.isContainer() && !create);\r
+ generalTable.setWidget(0, 1, folderName);\r
+\r
+ final Label folderNameNote = new Label("Please note that slashes ('/') are not allowed in folder names.", true);\r
+ folderNameNote.setVisible(false);\r
+ folderNameNote.setStylePrimaryName("gss-readForAllNote");\r
+ generalTable.setWidget(0, 2, folderNameNote);\r
+\r
+ if(create) {\r
+ generalTable.setText(1, 1, folder.getName());\r
+ }\r
+ else {\r
+ generalTable.setText(1, 1, folder.getParent().getName());\r
+ }\r
+ if(create) {\r
+ generalTable.setText(2, 1, app.getCurrentUserDisplayNameOrID());\r
+ }\r
+ else {\r
+ final String ownerID = folder.getOwnerID();\r
+ final String displayName = app.getDisplayNameForUserID(ownerID);\r
+ final String ownerDisplayName;\r
+ if(displayName == null) {\r
+ // FIXME: Get the actual display name and do not use the id\r
+ ownerDisplayName = ownerID;\r
+ }\r
+ else {\r
+ ownerDisplayName = displayName;\r
+ }\r
+ generalTable.setText(2, 1, ownerDisplayName);\r
+ }\r
+ DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");\r
+ if(folder.getLastModified() != null) {\r
+ generalTable.setText(3, 1, formatter.format(folder.getLastModified()));\r
+ }\r
+ generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");\r
+ generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");\r
+ generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");\r
+ generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels");\r
+ generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");\r
+ generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");\r
+ generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");\r
+ generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values");\r
+ generalTable.setCellSpacing(4);\r
+ generalPanel.add(generalTable);\r
+ inner.add(generalPanel);\r
+\r
+ outer.add(inner);\r
+\r
+ // Create the 'Create/Update' button, along with a listener that hides the dialog\r
+ // when the button is clicked and quits the application.\r
+ String okLabel;\r
+ if(create) {\r
+ okLabel = "Create";\r
+ }\r
+ else {\r
+ okLabel = "Update";\r
+ }\r
+ final Button ok = new Button(okLabel, new ClickHandler() {\r
+ @Override\r
+ public void onClick(ClickEvent event) {\r
+ createOrUpdateFolder();\r
+ closeDialog();\r
+ }\r
+ });\r
+ ok.addStyleName("button");\r
+ outer.add(ok);\r
+ outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);\r
+\r
+ folderName.addChangeHandler(new ChangeHandler() {\r
+\r
+ @Override\r
+ public void onChange(ChangeEvent event) {\r
+ if(folderName.getText().contains("/")) {\r
+ folderNameNote.setVisible(true);\r
+ ok.setEnabled(false);\r
+ }\r
+ else {\r
+ folderNameNote.setVisible(false);\r
+ ok.setEnabled(true);\r
+ }\r
+ }\r
+ });\r
+\r
+ setWidget(outer);\r
+ }\r
+\r
+ @Override\r
+ public void center() {\r
+ super.center();\r
+ folderName.setFocus(true);\r
+ }\r
+\r
+ @Override\r
+ protected void onPreviewNativeEvent(NativePreviewEvent preview) {\r
+ super.onPreviewNativeEvent(preview);\r
+\r
+ NativeEvent evt = preview.getNativeEvent();\r
+ if(evt.getType().equals(KeyDownEvent.getType().getName()))\r
+ // Use the popup's key preview hooks to close the dialog when either\r
+ // enter or escape is pressed.\r
+ {\r
+ switch(evt.getKeyCode()) {\r
+ case KeyCodes.KEY_ENTER:\r
+ createOrUpdateFolder();\r
+ closeDialog();\r
+ break;\r
+ case KeyCodes.KEY_ESCAPE:\r
+ closeDialog();\r
+ break;\r
+ }\r
+ }\r
+ }\r
+\r
+\r
+ /**\r
+ * Enables IE selection prevention and hides the dialog\r
+ * (we disable the prevention on creation of the dialog)\r
+ */\r
+ public void closeDialog() {\r
+ Pithos.preventIESelection();\r
+ hide();\r
+ }\r
+\r
+ /**\r
+ * Generate an RPC request to create a new folder.\r
+ */\r
+ private void createFolder() {\r
+ String name = folderName.getText().trim();\r
+ if(name.length() == 0) {\r
+ return;\r
+ }\r
+ String path = folder.getUri() + "/" + name;\r
+ PutRequest createFolder = new PutRequest(app.getApiPath(), folder.getOwnerID(), path) {\r
+ @Override\r
+ public void onSuccess(Resource result) {\r
+ app.updateFolder(folder, true, new Command() {\r
+\r
+ @Override\r
+ public void execute() {\r
+ app.updateStatistics();\r
+ }\r
+ }, true);\r
+ }\r
+\r
+ @Override\r
+ public void onError(Throwable t) {\r
+ GWT.log("", t);\r
+ app.setError(t);\r
+ if(t instanceof RestException) {\r
+ app.displayError("Unable to create folder:" + ((RestException) t).getHttpStatusText());\r
+ }\r
+ else {\r
+ app.displayError("System error creating folder:" + t.getMessage());\r
+ }\r
+ }\r
+\r
+ @Override\r
+ protected void onUnauthorized(Response response) {\r
+ app.sessionExpired();\r
+ }\r
+ };\r
+ createFolder.setHeader("X-Auth-Token", app.getUserToken());\r
+ createFolder.setHeader("Accept", "*/*");\r
+ createFolder.setHeader("Content-Length", "0");\r
+ createFolder.setHeader("Content-Type", "application/directory");\r
+ Scheduler.get().scheduleDeferred(createFolder);\r
+ }\r
+\r
+ /**\r
+ * Upon closing the dialog by clicking OK or pressing ENTER this method does\r
+ * the actual work of modifying folder properties or creating a new Folder\r
+ * depending on the value of the create field\r
+ */\r
+ protected void createOrUpdateFolder() {\r
+ if(create) {\r
+ createFolder();\r
+ }\r
+ else {\r
+ updateFolder();\r
+ }\r
+\r
+ }\r
+\r
+ private void updateFolder() {\r
+ final String newName = folderName.getText().trim();\r
+ if(newName.length() == 0) {\r
+ return;\r
+ }\r
+ if(!folder.isContainer() && !folder.getName().equals(newName)) {\r
+ final String path = folder.getParent().getUri() + "/" + newName;\r
+ app.copyFolder(folder, folder.getOwnerID(), path, true, new Command() {\r
+\r
+ @Override\r
+ public void execute() {\r
+ app.updateFolder(folder.getParent(), false, new Command() {\r
+\r
+ @Override\r
+ public void execute() {\r
+ app.updateMySharedRoot();\r
+ }\r
+ }, true);\r
+ }\r
+ });\r
+ }\r
+ else {\r
+ app.updateFolder(folder.getParent(), false, new Command() {\r
+\r
+ @Override\r
+ public void execute() {\r
+ app.updateMySharedRoot();\r
+ }\r
+ }, true);\r
+ }\r
+ }\r
}\r