/*\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 com.google.gwt.core.client.Scheduler;\r
-import com.google.gwt.event.dom.client.KeyDownEvent;\r
-import com.google.gwt.user.client.Command;\r
-import gr.grnet.pithos.web.client.foldertree.File;\r
-import gr.grnet.pithos.web.client.foldertree.Folder;\r
-import gr.grnet.pithos.web.client.foldertree.Resource;\r
-import gr.grnet.pithos.web.client.rest.PostRequest;\r
-import gr.grnet.pithos.web.client.rest.PutRequest;\r
-import gr.grnet.pithos.web.client.rest.RestException;\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.ClickEvent;\r
-import com.google.gwt.event.dom.client.ClickHandler;\r
-import com.google.gwt.event.dom.client.KeyCodes;\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.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.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.TabPanel;\r
-import com.google.gwt.user.client.ui.TextBox;\r
-import com.google.gwt.user.client.ui.VerticalPanel;\r
-import java.util.Iterator;\r
-import java.util.Map;\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
protected Pithos app;\r
\r
- /**\r
- * The widget that holds the folderName of the folder.\r
- */\r
- private TextBox folderName = new TextBox();\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
+ * 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
- protected PermissionsList permList;\r
+ final Folder folder;\r
\r
- final Folder folder;\r
+ final VerticalPanel inner;\r
\r
- final TabPanel inner;\r
-\r
- /**\r
- * The widget's constructor.\r
- */\r
- public FolderPropertiesDialog(final Pithos app, boolean _create, Folder selected) {\r
+ /**\r
+ * The widget's constructor.\r
+ */\r
+ public FolderPropertiesDialog(final Pithos app, boolean _create, Folder selected) {\r
this.app = app;\r
- setAnimationEnabled(true);\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
- // Enable IE selection for the dialog (must disable it upon closing it)\r
- Pithos.enableIESelection();\r
+ setGlassEnabled(true);\r
+ setStyleName("pithos-DialogBox");\r
\r
- create = _create;\r
- \r
- folder = selected;\r
+ // Enable IE selection for the dialog (must disable it upon closing it)\r
+ Pithos.enableIESelection();\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
+ create = _create;\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
+ folder = selected;\r
\r
- VerticalPanel generalPanel = new VerticalPanel();\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
- if (create)\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
- else\r
- generalTable.setText(1, 1, folder.getPrefix());\r
- generalTable.setText(2, 1, "");\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
+ 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, 1, "props-values");\r
generalTable.setCellSpacing(4);\r
generalPanel.add(generalTable);\r
- inner.add(generalPanel, "General");\r
+ inner.add(generalPanel);\r
\r
- VerticalPanel permPanel = new VerticalPanel();\r
- FilePropertiesDialog.Images images = GWT.create(FilePropertiesDialog.Images.class);\r
- boolean permsReadonly = folder.getInheritedPermissionsFrom() != null || folder.existChildrenPermissions();\r
- permList = new PermissionsList(images, folder.getPermissions(), folder.getOwner(), permsReadonly);\r
- permPanel.add(permList);\r
-\r
- if (!permsReadonly) {\r
- HorizontalPanel permButtons = new HorizontalPanel();\r
- Button add = new Button("Add Group", new ClickHandler() {\r
- @Override\r
- public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
- PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, false);\r
- dlg.center();\r
- }\r
- });\r
- permButtons.add(add);\r
- permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER);\r
+ outer.add(inner);\r
\r
- Button addUser = new Button("Add User", new ClickHandler() {\r
- @Override\r
- public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
- PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), 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
- permButtons.setSpacing(8);\r
- permButtons.addStyleName("gss-TabPanelBottom");\r
- permPanel.add(permButtons);\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
- if (!create)\r
- inner.add(permPanel, "Sharing");\r
- inner.selectTab(0);\r
-\r
- outer.add(inner);\r
+ folderName.addChangeHandler(new ChangeHandler() {\r
\r
- HorizontalPanel buttons = new HorizontalPanel();\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(@SuppressWarnings("unused") ClickEvent event) {\r
- createOrUpdateFolder();\r
- closeDialog();\r
- }\r
- });\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(@SuppressWarnings("unused") ClickEvent event) {\r
- closeDialog();\r
- }\r
- });\r
- buttons.add(cancel);\r
- buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
- buttons.setSpacing(8);\r
- buttons.addStyleName("pithos-TabPanelBottom");\r
- outer.add(buttons);\r
- outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);\r
- outer.addStyleName("pithos-TabPanelBottom");\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
- switch (evt.getKeyCode()) {\r
- case KeyCodes.KEY_ENTER:\r
- createOrUpdateFolder();\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
- * 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();\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.getOwner(), path) {\r
+ PutRequest createFolder = new PutRequest(app.getApiPath(), folder.getOwnerID(), path) {\r
@Override\r
- public void onSuccess(@SuppressWarnings("unused") Resource result) {\r
- app.updateFolder(folder, true, null);\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
- 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
+ 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.getToken());\r
+ createFolder.setHeader("X-Auth-Token", app.getUserToken());\r
createFolder.setHeader("Accept", "*/*");\r
createFolder.setHeader("Content-Length", "0");\r
- createFolder.setHeader("Content-Type", "application/folder");\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
- else\r
- updateFolder();\r
-\r
- }\r
-\r
- private void updateFolder() {\r
- final Map<String, Boolean[]> perms = (permList.hasChanges() ? permList.getPermissions() : null);\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 (!folder.isContainer() && !folder.getName().equals(newName)) {\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
- PutRequest newFolder = new PutRequest(app.getApiPath(), folder.getParent().getOwner(), path) {\r
+ app.copyFolder(folder, folder.getOwnerID(), path, true, new Command() {\r
+\r
@Override\r
- public void onSuccess(@SuppressWarnings("unused") Resource result) {\r
- Iterator<File> iter = folder.getFiles().iterator();\r
- app.copyFiles(iter, folder.getParent().getOwner(), folder.getParent().getUri() + "/" + newName, new Command() {\r
+ public void execute() {\r
+ app.updateFolder(folder.getParent(), false, new Command() {\r
+\r
@Override\r
public void execute() {\r
- Iterator<Folder> iterf = folder.getSubfolders().iterator();\r
- app.copySubfolders(iterf, folder.getParent().getOwner(), folder.getParent().getUri() + "/" + newName, new Command() {\r
- @Override\r
- public void execute() {\r
- app.deleteFolder(folder);\r
- updateMetadata(path + "?update=", perms);\r
- }\r
- });\r
+ app.updateMySharedRoot();\r
}\r
- });\r
+ }, true);\r
}\r
-\r
- @Override\r
- public void onError(Throwable t) {\r
- GWT.log("", t);\r
- if(t instanceof RestException){\r
- app.displayError("Unable to update folder: " + ((RestException) t).getHttpStatusText());\r
- }\r
- else\r
- app.displayError("System error modifying folder: " + t.getMessage());\r
- }\r
- };\r
- newFolder.setHeader("X-Auth-Token", app.getToken());\r
- newFolder.setHeader("Content-Type", "application/folder");\r
- newFolder.setHeader("Accept", "*/*");\r
- newFolder.setHeader("Content-Length", "0");\r
- Scheduler.get().scheduleDeferred(newFolder);\r
+ });\r
}\r
- else\r
- updateMetadata(folder.getUri() + "?update=", perms);\r
- }\r
-\r
- protected void updateMetadata(final String path, final Map<String, Boolean[]> newPermissions) {\r
- if (newPermissions != null) {\r
- PostRequest updateFolder = new PostRequest(app.getApiPath(), folder.getOwner(), path) {\r
- @Override\r
- public void onSuccess(@SuppressWarnings("unused") Resource result) {\r
- app.updateFolder(folder.getParent(), false, null);\r
- }\r
+ else {\r
+ app.updateFolder(folder.getParent(), false, new Command() {\r
\r
@Override\r
- public void onError(Throwable t) {\r
- GWT.log("", t);\r
- if (t instanceof RestException) {\r
- if (((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) { //Probably a virtual folder\r
- final String path1 = folder.getUri();\r
- PutRequest newFolder = new PutRequest(app.getApiPath(), folder.getOwner(), path1) {\r
- @Override\r
- public void onSuccess(@SuppressWarnings("unused") Resource result) {\r
- updateMetadata(path, newPermissions);\r
- }\r
-\r
- @Override\r
- public void onError(Throwable t) {\r
- GWT.log("", t);\r
- if(t instanceof RestException){\r
- app.displayError("Unable to update folder: " + ((RestException) t).getHttpStatusText());\r
- }\r
- else\r
- app.displayError("System error modifying folder: " + t.getMessage());\r
- }\r
- };\r
- newFolder.setHeader("X-Auth-Token", app.getToken());\r
- newFolder.setHeader("Content-Type", "application/folder");\r
- newFolder.setHeader("Accept", "*/*");\r
- newFolder.setHeader("Content-Length", "0");\r
- Scheduler.get().scheduleDeferred(newFolder);\r
- }\r
- }\r
- else\r
- app.displayError("System error modifying folder: " + t.getMessage());\r
+ public void execute() {\r
+ app.updateMySharedRoot();\r
}\r
- };\r
- updateFolder.setHeader("X-Auth-Token", app.getToken());\r
- String readPermHeader = "read=";\r
- String writePermHeader = "write=";\r
- for (String u : newPermissions.keySet()) {\r
- Boolean[] p = newPermissions.get(u);\r
- if (p[0] != null && p[0])\r
- readPermHeader += u + ",";\r
- if (p[1] != null && p[1])\r
- writePermHeader += u + ",";\r
- }\r
- if (readPermHeader.endsWith("="))\r
- readPermHeader = "";\r
- else if (readPermHeader.endsWith(","))\r
- readPermHeader = readPermHeader.substring(0, readPermHeader.length() - 1);\r
- if (writePermHeader.endsWith("="))\r
- writePermHeader = "";\r
- else if (writePermHeader.endsWith(","))\r
- writePermHeader = writePermHeader.substring(0, writePermHeader.length() - 1);\r
- String permHeader = readPermHeader + ((readPermHeader.length() > 0 && writePermHeader.length() > 0) ? ";" : "") + writePermHeader;\r
- if (permHeader.length() == 0)\r
- permHeader="~";\r
- updateFolder.setHeader("X-Object-Sharing", permHeader);\r
- Scheduler.get().scheduleDeferred(updateFolder);\r
+ }, true);\r
}\r
- else\r
- app.updateFolder(folder.getParent(), false, null);\r
}\r
-\r
- public void selectTab(int _tab) {\r
- inner.selectTab(_tab);\r
- }\r
}\r