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.Response;\r
import com.google.gwt.i18n.client.DateTimeFormat;\r
import com.google.gwt.user.client.Event.NativePreviewEvent;\r
import com.google.gwt.user.client.ui.Button;\r
*/\r
public class FolderPropertiesDialog extends DialogBox {\r
\r
- private Pithos app;\r
+ protected Pithos app;\r
\r
/**\r
* The widget that holds the folderName of the folder.\r
*/\r
private final boolean create;\r
\r
- private PermissionsList permList;\r
+ protected PermissionsList permList;\r
\r
final Folder folder;\r
\r
setAnimationEnabled(true);\r
\r
// Enable IE selection for the dialog (must disable it upon closing it)\r
- app.enableIESelection();\r
+ Pithos.enableIESelection();\r
\r
create = _create;\r
\r
HorizontalPanel permButtons = new HorizontalPanel();\r
Button add = new Button("Add Group", new ClickHandler() {\r
@Override\r
- public void onClick(ClickEvent event) {\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
Button addUser = new Button("Add User", new ClickHandler() {\r
@Override\r
- public void onClick(ClickEvent event) {\r
+ public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, true);\r
dlg.center();\r
}\r
okLabel = "Update";\r
Button ok = new Button(okLabel, new ClickHandler() {\r
@Override\r
- public void onClick(ClickEvent event) {\r
+ public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
createOrUpdateFolder();\r
closeDialog();\r
}\r
// when the button is clicked.\r
Button cancel = new Button("Cancel", new ClickHandler() {\r
@Override\r
- public void onClick(ClickEvent event) {\r
+ public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
closeDialog();\r
}\r
});\r
* (we disable the prevention on creation of the dialog)\r
*/\r
public void closeDialog() {\r
- app.preventIESelection();\r
+ Pithos.preventIESelection();\r
hide();\r
}\r
\r
private void createFolder() {\r
String name = folderName.getText();\r
String path = folder.getUri() + "/" + name;\r
- PutRequest createFolder = new PutRequest(app.getApiPath(), app.getUsername(), path) {\r
+ PutRequest createFolder = new PutRequest(app.getApiPath(), folder.getOwner(), path) {\r
@Override\r
- public void onSuccess(Resource result) {\r
- app.updateFolder(folder, true);\r
+ public void onSuccess(@SuppressWarnings("unused") Resource result) {\r
+ app.updateFolder(folder, true, new Command() {\r
+ \r
+ @Override\r
+ public void execute() {\r
+ app.updateStatistics();\r
+ }\r
+ });\r
}\r
\r
@Override\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("Accept", "*/*");\r
createFolder.setHeader("Content-Length", "0");\r
* the actual work of modifying folder properties or creating a new Folder\r
* depending on the value of the create field\r
*/\r
- private void createOrUpdateFolder() {\r
+ protected void createOrUpdateFolder() {\r
if (create)\r
createFolder();\r
else\r
final String newName = folderName.getText().trim();\r
if (!folder.isContainer() && !folder.getName().equals(newName)) {\r
final String path = folder.getParent().getUri() + "/" + newName;\r
- PutRequest newFolder = new PutRequest(app.getApiPath(), app.getUsername(), path) {\r
+ PutRequest newFolder = new PutRequest(app.getApiPath(), folder.getParent().getOwner(), path) {\r
@Override\r
- public void onSuccess(Resource result) {\r
+ public void onSuccess(@SuppressWarnings("unused") Resource result) {\r
Iterator<File> iter = folder.getFiles().iterator();\r
- app.copyFiles(iter, folder.getParent().getUri() + "/" + newName, new Command() {\r
+ app.copyFiles(iter, folder.getParent().getOwner(), folder.getParent().getUri() + "/" + newName, new Command() {\r
@Override\r
public void execute() {\r
Iterator<Folder> iterf = folder.getSubfolders().iterator();\r
- app.copySubfolders(iterf, folder.getParent().getUri() + "/" + newName, new Command() {\r
+ app.copySubfolders(iterf, folder.getParent().getOwner(), folder.getParent().getUri() + "/" + newName, new Command() {\r
@Override\r
public void execute() {\r
app.deleteFolder(folder);\r
else\r
app.displayError("System error modifying folder: " + t.getMessage());\r
}\r
+\r
+ @Override\r
+ protected void onUnauthorized(Response response) {\r
+ app.sessionExpired();\r
+ }\r
};\r
newFolder.setHeader("X-Auth-Token", app.getToken());\r
newFolder.setHeader("Content-Type", "application/folder");\r
updateMetadata(folder.getUri() + "?update=", perms);\r
}\r
\r
- private void updateMetadata(String path, Map<String, Boolean[]> newPermissions) {\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(Resource result) {\r
- app.updateFolder(folder.getParent(), false);\r
+ public void onSuccess(@SuppressWarnings("unused") Resource result) {\r
+ app.updateFolder(folder.getParent(), false, null);\r
}\r
\r
@Override\r
public void onError(Throwable t) {\r
GWT.log("", t);\r
- app.displayError("System error modifying folder: " + t.getMessage());\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
+ @Override\r
+ protected void onUnauthorized(Response response) {\r
+ app.sessionExpired();\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
+ else if (((RestException) t).getHttpStatusCode() == Response.SC_CONFLICT) {\r
+ app.displayError("Cannot set permissions. Probably subfolders or files already have permissions set");\r
+ }\r
+ else\r
+ app.displayError("Wrror modifying folder: " + t.getMessage());\r
+ }\r
+ else\r
+ app.displayError("System error modifying folder: " + t.getMessage());\r
}\r
+\r
+ @Override\r
+ protected void onUnauthorized(Response response) {\r
+ app.sessionExpired();\r
+ }\r
};\r
updateFolder.setHeader("X-Auth-Token", app.getToken());\r
- if (newPermissions != null) {\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
+ 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
}\r
else\r
- app.updateFolder(folder.getParent(), false);\r
+ app.updateFolder(folder.getParent(), false, null);\r
}\r
\r
public void selectTab(int _tab) {\r