/*\r
- * Copyright 2011 GRNET S.A. All rights reserved.\r
+ * Copyright 2011-2012 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.rest.PostCommand;\r
-import gr.grnet.pithos.web.client.rest.RestException;\r
-import gr.grnet.pithos.web.client.rest.resource.FileResource;\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.foldertree.File;\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
\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Set;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
\r
import com.google.gwt.core.client.GWT;\r
-import com.google.gwt.event.dom.client.ChangeEvent;\r
-import com.google.gwt.event.dom.client.ChangeHandler;\r
+import com.google.gwt.core.client.Scheduler;\r
import com.google.gwt.event.dom.client.ClickEvent;\r
import com.google.gwt.event.dom.client.ClickHandler;\r
+import com.google.gwt.http.client.Response;\r
+import com.google.gwt.http.client.URL;\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.resources.client.ClientBundle;\r
-import com.google.gwt.resources.client.ImageResource;\r
import com.google.gwt.user.client.Command;\r
-import com.google.gwt.user.client.DeferredCommand;\r
-import com.google.gwt.user.client.ui.AbstractImagePrototype;\r
+import com.google.gwt.user.client.ui.Anchor;\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.DisclosurePanel;\r
import com.google.gwt.user.client.ui.FlexTable;\r
-import com.google.gwt.user.client.ui.FlowPanel;\r
-import com.google.gwt.user.client.ui.FocusPanel;\r
-import com.google.gwt.user.client.ui.HTML;\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.Image;\r
import com.google.gwt.user.client.ui.Label;\r
import com.google.gwt.user.client.ui.TextBox;\r
import com.google.gwt.user.client.ui.VerticalPanel;\r
*/\r
public class FilePropertiesDialog extends AbstractPropertiesDialog {\r
\r
- final PermissionsList permList;\r
-\r
- private CheckBox readForAll;\r
-\r
- /**\r
- * An image bundle for this widgets images.\r
- */\r
- public interface Images extends ClientBundle,MessagePanel.Images {\r
-\r
- @Source("gr/grnet/pithos/resources/edit_user.png")\r
- ImageResource permUser();\r
-\r
- @Source("gr/grnet/pithos/resources/groupevent.png")\r
- ImageResource permGroup();\r
-\r
- @Source("gr/grnet/pithos/resources/editdelete.png")\r
- ImageResource delete();\r
-\r
- @Source("gr/grnet/pithos/resources/db_update.png")\r
- ImageResource restore();\r
-\r
- @Source("gr/grnet/pithos/resources/folder_inbox.png")\r
- ImageResource download();\r
- }\r
-\r
/**\r
* The widget that holds the name of the file.\r
*/\r
private TextBox name = new TextBox();\r
\r
- private final CheckBox versioned = new CheckBox();\r
-\r
- final FileResource file;\r
-\r
- private String userFullName;\r
+ final File file;\r
\r
+ FlexTable metaTable;\r
/**\r
* The widget's constructor.\r
- *\r
- * @param images the dialog's ImageBundle\r
- * @param groups\r
- * @param bodies\r
*/\r
- public FilePropertiesDialog(final Images images, final List<GroupResource> groups, List<FileResource> bodies, String _userFullName) {\r
-\r
+ public FilePropertiesDialog(Pithos _app, File _file) {\r
+ super(_app);\r
+ file = _file;\r
+\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
// Set the dialog's caption.\r
setText("File properties");\r
+ setAnimationEnabled(true);\r
+ setGlassEnabled(true);\r
+ setStyleName("pithos-DialogBox");\r
\r
- file = (FileResource) GSS.get().getCurrentSelection();\r
- userFullName = _userFullName;\r
- permList = new PermissionsList(images, file.getPermissions(), file.getOwner());\r
-\r
- GWT.log("FILE PERMISSIONS:"+file.getPermissions());\r
// Outer contains inner and buttons.\r
final VerticalPanel outer = new VerticalPanel();\r
- final FocusPanel focusPanel = new FocusPanel(outer);\r
+ outer.add(close);\r
// Inner contains generalPanel and permPanel.\r
- inner = new DecoratedTabPanel();\r
- inner.setAnimationEnabled(true);\r
- final VerticalPanel generalPanel = new VerticalPanel();\r
- final VerticalPanel permPanel = new VerticalPanel();\r
- final HorizontalPanel buttons = new HorizontalPanel();\r
- final HorizontalPanel permButtons = new HorizontalPanel();\r
- final HorizontalPanel permForAll = new HorizontalPanel();\r
- final HorizontalPanel pathPanel = new HorizontalPanel();\r
- final VerticalPanel verPanel = new VerticalPanel();\r
- final HorizontalPanel vPanel = new HorizontalPanel();\r
- final HorizontalPanel vPanel2 = new HorizontalPanel();\r
-\r
- versioned.setValue(file.isVersioned());\r
- versioned.getElement().setId("filePropertiesDialog.chechBox.versioned");\r
- inner.add(generalPanel, "General");\r
- inner.add(permPanel, "Sharing");\r
- inner.add(verPanel, "Versions");\r
- inner.selectTab(0);\r
-\r
- final Label fileNameNote = new Label("Please note that slashes ('/') are not allowed in file names.", true);\r
- fileNameNote.setVisible(false);\r
- fileNameNote.setStylePrimaryName("pithos-readForAllNote");\r
-\r
- final FlexTable generalTable = new FlexTable();\r
- generalTable.setText(0, 0, "Name");\r
- generalTable.setText(1, 0, "Folder");\r
- generalTable.setText(2, 0, "Owner");\r
- generalTable.setText(3, 0, "Last modified");\r
- generalTable.setText(4, 0, "Tags");\r
- name.setWidth("100%");\r
- name.setText(file.getName());\r
- name.getElement().setId("filePropertiesDialog.textBox.name");\r
- generalTable.setWidget(0, 1, name);\r
- name.addChangeHandler(new ChangeHandler() {\r
-\r
- @Override\r
- public void onChange(ChangeEvent event) {\r
- if(name.getText().contains("/"))\r
- fileNameNote.setVisible(true);\r
- else\r
- fileNameNote.setVisible(false);\r
+ inner = new VerticalPanel();\r
+ inner.addStyleName("inner");\r
\r
- }\r
- });\r
+ inner.add(createGeneralPanel());\r
\r
- if(file.getFolderName() != null)\r
- generalTable.setText(1, 1, file.getFolderName());\r
- else\r
- generalTable.setText(1, 1, "-");\r
- generalTable.setWidget(0, 2, fileNameNote);\r
- generalTable.setText(2, 1,userFullName);\r
-\r
- final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");\r
- generalTable.setText(3, 1, formatter.format(file.getModificationDate()));\r
- // Get the tags.\r
- StringBuffer tagsBuffer = new StringBuffer();\r
- Iterator i = file.getTags().iterator();\r
- while (i.hasNext()) {\r
- String tag = (String) i.next();\r
- tagsBuffer.append(tag).append(", ");\r
- }\r
- if (tagsBuffer.length() > 1)\r
- tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1);\r
- initialTagText = tagsBuffer.toString();\r
- tags.setWidth("100%");\r
- tags.getElement().setId("filePropertiesDialog.textBox.tags");\r
- tags.setText(initialTagText);\r
- generalTable.setWidget(4, 1, tags);\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(4, 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.getFlexCellFormatter().setStyleName(4, 1, "props-values");\r
- generalTable.setCellSpacing(4);\r
+ outer.add(inner);\r
\r
// Create the 'OK' button, along with a listener that hides the dialog\r
// when the button is clicked.\r
final Button ok = new Button("OK", new ClickHandler() {\r
@Override\r
public void onClick(ClickEvent event) {\r
- if(name.getText().contains("/"))\r
- fileNameNote.setVisible(true);\r
- else{\r
- fileNameNote.setVisible(false);\r
- accept();\r
+ if (accept())\r
closeDialog();\r
- } \r
- }\r
- });\r
- ok.getElement().setId("filePropertiesDialog.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 when the button is clicked.\r
- final Button cancel = new Button("Cancel", new ClickHandler() {\r
- @Override\r
- public void onClick(ClickEvent event) {\r
- closeDialog();\r
- }\r
- });\r
- cancel.getElement().setId("filePropertiesDialog.button.cancel");\r
- buttons.add(cancel);\r
- buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
- buttons.setSpacing(8);\r
- buttons.addStyleName("pithos-TabPanelBottom");\r
-\r
- generalPanel.add(generalTable);\r
-\r
- // Asynchronously retrieve the tags defined by this user.\r
- DeferredCommand.addCommand(new Command() {\r
-\r
- @Override\r
- public void execute() {\r
- updateTags();\r
}\r
});\r
+ ok.addStyleName("button");\r
\r
- DisclosurePanel allTags = new DisclosurePanel("All tags");\r
- allTagsContent = new FlowPanel();\r
- allTagsContent.setWidth("100%");\r
- allTags.setContent(allTagsContent);\r
- generalPanel.add(allTags);\r
- generalPanel.setSpacing(4);\r
-\r
- final 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("filePropertiesDialog.button.addGroup");\r
- permButtons.add(add);\r
- permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER);\r
-\r
- final 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
- add.getElement().setId("filePropertiesDialog.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 file will be readable" +\r
- " by everyone. By checking this option, you are certifying that you have the right to " +\r
- "distribute this file 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("filePropertiesDialog.checkBox.public");\r
- readForAll.setValue(file.isReadForAll());\r
- readForAll.addClickHandler(new ClickHandler() {\r
- @Override\r
- public void onClick(ClickEvent event) {\r
- readForAllNote.setVisible(readForAll.getValue());\r
- }\r
+ outer.add(ok);\r
+ outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);\r
\r
- });\r
+ setWidget(outer);\r
+ }\r
\r
- permPanel.add(permList);\r
- permPanel.add(permButtons);\r
- // Only show the read for all permission if the user is the owner.\r
- if (file.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
+ private VerticalPanel createGeneralPanel() {\r
+ final VerticalPanel generalPanel = new VerticalPanel();\r
+ final FlexTable generalTable = new FlexTable();\r
+ generalTable.setText(0, 0, "Name");\r
+ generalTable.setText(1, 0, "Folder");\r
+ generalTable.setText(2, 0, "Owner");\r
+ generalTable.setText(3, 0, "Last modified");\r
+\r
+ name.setWidth("100%");\r
+ name.setText(file.getName());\r
+ generalTable.setWidget(0, 1, name);\r
+ if(file.getParent() != null)\r
+ generalTable.setText(1, 1, file.getParent().getName());\r
+ else\r
+ generalTable.setText(1, 1, "-");\r
+ generalTable.setText(2, 1, file.getOwner());\r
+\r
+ final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");\r
+ generalTable.setText(3, 1, file.getLastModified() != null ? formatter.format(file.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(4, 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
+ generalPanel.add(generalTable);\r
+\r
+ HorizontalPanel metaTitlePanel = new HorizontalPanel();\r
+ metaTitlePanel.setSpacing(5);\r
+ Label meta = new Label("Meta data");\r
+ meta.addStyleName("pithos-metaTitle");\r
+ metaTitlePanel.add(meta);\r
+ \r
+ Anchor plus = new Anchor("add");\r
+ plus.addStyleName(Pithos.resources.pithosCss().commandAnchor());\r
+ metaTitlePanel.add(plus);\r
+ \r
+ generalPanel.add(metaTitlePanel);\r
+ \r
+ metaTable = new FlexTable();\r
+ metaTable.setCellSpacing(0);\r
+ metaTable.setHTML(0, 0, "Name");\r
+ metaTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");\r
+ metaTable.setText(0, 1, "Value");\r
+ metaTable.getFlexCellFormatter().setStyleName(0, 1, "props-labels");\r
+ int rows = 1;\r
+ for (String metaKey : file.getMeta().keySet()) {\r
+ addFormLine(metaTable, rows++, metaKey, file.getMeta().get(metaKey));\r
}\r
-\r
- TextBox path = new TextBox();\r
- path.setWidth("100%");\r
- path.addClickHandler(new ClickHandler() {\r
+ if (rows == 1) //If no meta add an empty line\r
+ addFormLine(metaTable, rows++, "", "");\r
+ \r
+ plus.addClickHandler(new ClickHandler() {\r
+ \r
@Override\r
public void onClick(ClickEvent event) {\r
- GSS.enableIESelection();\r
- ((TextBox) event.getSource()).selectAll();\r
- GSS.preventIESelection();\r
+ addFormLine(metaTable, metaTable.getRowCount(), "", "");\r
}\r
-\r
});\r
- path.setText(file.getUri());\r
- path.getElement().setId("filePropertiesDialog.textBox.link");\r
- path.setTitle("Use this link for sharing the file 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
- VersionsList verList = new VersionsList(this, images, bodies);\r
- verPanel.add(verList);\r
-\r
- vPanel.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
- vPanel.setSpacing(8);\r
- vPanel.addStyleName("pithos-TabPanelBottom");\r
- vPanel.add(new Label("Versioned"));\r
-\r
- vPanel.add(versioned);\r
- verPanel.add(vPanel);\r
- vPanel2.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
- vPanel2.setSpacing(8);\r
- vPanel2.addStyleName("pithos-TabPanelBottom");\r
- Button removeVersionsButton = new Button(AbstractImagePrototype.create(images.delete()).getHTML(), new ClickHandler() {\r
+\r
+ generalPanel.add(metaTable);\r
+ generalPanel.setSpacing(4);\r
+ return generalPanel;\r
+ }\r
+\r
+ void addFormLine(final FlexTable table, int row, String _name, String _value) {\r
+ TextBox nameBox = new TextBox();\r
+ nameBox.setText(_name);\r
+ nameBox.addStyleName("pithos-metaName");\r
+ table.setWidget(row, 0, nameBox);\r
+ table.getFlexCellFormatter().setStyleName(1, 0, "props-values");\r
+\r
+ TextBox valueBox = new TextBox();\r
+ valueBox.setText(_value);\r
+ valueBox.addStyleName("pithos-metaValue");\r
+ table.setWidget(row, 1, valueBox);\r
+ table.getFlexCellFormatter().setStyleName(1, 1, "props-values");\r
+ \r
+ Anchor delete = new Anchor("remove");\r
+ delete.addStyleName(Pithos.resources.pithosCss().commandAnchor());\r
+ delete.addClickHandler(new ClickHandler() {\r
+ \r
@Override\r
public void onClick(ClickEvent event) {\r
- ConfirmationDialog confirm = new ConfirmationDialog("Really " +\r
- "remove all previous versions?", "Remove") {\r
-\r
- @Override\r
- public void cancel() {\r
- }\r
-\r
- @Override\r
- public void confirm() {\r
- FilePropertiesDialog.this.closeDialog();\r
- removeAllOldVersions();\r
- }\r
-\r
- };\r
- confirm.center();\r
+ int rowIndex = table.getCellForEvent(event).getRowIndex();\r
+ table.removeRow(rowIndex);\r
}\r
-\r
});\r
- HTML removeAllVersion = new HTML("<span>Remove all previous versions?</span>");\r
- vPanel2.add(removeAllVersion);\r
- vPanel2.add(removeVersionsButton);\r
- verPanel.add(vPanel2);\r
- if(!file.isVersioned())\r
- vPanel2.setVisible(false);\r
- outer.add(inner);\r
- outer.add(buttons);\r
- outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);\r
- outer.addStyleName("pithos-TabPanelBottom");\r
-\r
- focusPanel.setFocus(true);\r
- setWidget(outer);\r
+ table.setWidget(row, 2, delete);\r
}\r
\r
-\r
/**\r
* Accepts any change and updates the file\r
*\r
*/\r
@Override\r
- protected void accept() {\r
+ protected boolean accept() {\r
String newFilename = null;\r
- permList.updatePermissionsAccordingToInput();\r
- Set<PermissionHolder> perms = permList.getPermissions();\r
- JSONObject json = new JSONObject();\r
- if (!name.getText().equals(file.getName())) {\r
- newFilename = name.getText();\r
- json.put("name", new JSONString(newFilename));\r
- }\r
- if (versioned.getValue() != file.isVersioned())\r
- json.put("versioned", JSONBoolean.getInstance(versioned.getValue()));\r
- //only update the read for all perm if the user is the owner\r
- if (readForAll.getValue() != file.isReadForAll())\r
- if (file.getOwner().equals(GSS.get().getCurrentUserResource().getUsername()))\r
- json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue()));\r
- int i = 0;\r
- if (permList.hasChanges()) {\r
- GWT.log("Permissions change", null);\r
- JSONArray perma = new JSONArray();\r
-\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
- }\r
- JSONArray taga = new JSONArray();\r
- i = 0;\r
- if (!tags.getText().equals(initialTagText)) {\r
- String[] tagset = tags.getText().split(",");\r
- for (String t : tagset) {\r
- JSONString to = new JSONString(t);\r
- taga.set(i, to);\r
- i++;\r
- }\r
- json.put("tags", taga);\r
- }\r
- String jsonString = json.toString();\r
- if(jsonString.equals("{}")){\r
- GWT.log("NO CHANGES", null);\r
- return;\r
- }\r
- final String newFilenameFinal = newFilename;\r
- PostCommand cf = new PostCommand(file.getUri() + "?update=", jsonString, 200) {\r
-\r
- @Override\r
- public void onComplete() {\r
- GSS.get().getTreeView().refreshCurrentNode(false);\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");\r
- else if (statusCode == 404)\r
- GSS.get().displayError("User in permissions does not exist");\r
- else if (statusCode == 409)\r
- GSS.get().displayError("A file with the same name already exists");\r
- else if (statusCode == 413)\r
- GSS.get().displayError("Your quota has been exceeded");\r
- else\r
- GSS.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());\r
- } else\r
- GSS.get().displayError("System error modifying file:" + t.getMessage());\r
- }\r
-\r
- };\r
- DeferredCommand.addCommand(cf);\r
-\r
- }\r
-\r
- private void removeAllOldVersions() {\r
- JSONObject json = new JSONObject();\r
- json.put("versioned", JSONBoolean.getInstance(false));\r
- GWT.log(json.toString(), null);\r
- PostCommand cf = new PostCommand(file.getUri() + "?update=", json.toString(), 200) {\r
-\r
- @Override\r
- public void onComplete() {\r
- toggleVersioned(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");\r
- else if (statusCode == 404)\r
- GSS.get().displayError("User in permissions does not exist");\r
- else if (statusCode == 409)\r
- GSS.get().displayError("A folder with the same name already exists");\r
- else if (statusCode == 413)\r
- GSS.get().displayError("Your quota has been exceeded");\r
- else\r
- GSS.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());\r
- } else\r
- GSS.get().displayError("System error moifying file:" + t.getMessage());\r
- }\r
- };\r
- DeferredCommand.addCommand(cf);\r
- }\r
-\r
- private void toggleVersioned(boolean versionedValue) {\r
- JSONObject json = new JSONObject();\r
- json.put("versioned", JSONBoolean.getInstance(versionedValue));\r
- GWT.log(json.toString(), null);\r
- PostCommand cf = new PostCommand(file.getUri() + "?update=", json.toString(), 200) {\r
-\r
- @Override\r
- public void onComplete() {\r
- GSS.get().getTreeView().refreshCurrentNode(false);\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");\r
- else if (statusCode == 404)\r
- GSS.get().displayError("User in permissions does not exist");\r
- else if (statusCode == 409)\r
- GSS.get().displayError("A folder with the same name already exists");\r
- else if (statusCode == 413)\r
- GSS.get().displayError("Your quota has been exceeded");\r
- else\r
- GSS.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());\r
- } else\r
- GSS.get().displayError("System error moifying file:" + t.getMessage());\r
- }\r
- };\r
- DeferredCommand.addCommand(cf);\r
+ if (!name.getText().trim().equals(file.getName())) {\r
+ newFilename = name.getText().trim();\r
+ if (newFilename.length() == 0)\r
+ newFilename = null;\r
+ }\r
+ \r
+\r
+ final Map<String, String> newMeta = new HashMap<String, String>();\r
+ for (int row = 1; row < metaTable.getRowCount(); row++) {\r
+ String key = ((TextBox) metaTable.getWidget(row, 0)).getText().trim();\r
+ String value = ((TextBox) metaTable.getWidget(row, 1)).getText().trim();\r
+ if (key.length() > 0 && value.length() > 0)\r
+ newMeta.put(key, value);\r
+ else if ((key.length() > 0 && value.length() == 0) || (key.length() == 0 && value.length() > 0)) {\r
+ app.displayError("You have empty keys or values");\r
+ return false;\r
+ }\r
+ }\r
+\r
+ if (newFilename != null) {\r
+ final String path = file.getParent().getUri() + "/" + newFilename;\r
+ PutRequest updateFile = new PutRequest(app.getApiPath(), app.getUsername(), path) {\r
+ @Override\r
+ public void onSuccess(Resource result) {\r
+ updateMetaData(app.getApiPath(), file.getOwner(), path + "?update=", newMeta);\r
+ }\r
+\r
+ @Override\r
+ public void onError(Throwable t) {\r
+ GWT.log("", t);\r
+ app.setError(t);\r
+ app.displayError("System error modifying file:" + t.getMessage());\r
+ }\r
+\r
+ @Override\r
+ protected void onUnauthorized(Response response) {\r
+ app.sessionExpired();\r
+ }\r
+ };\r
+ updateFile.setHeader("X-Auth-Token", app.getToken());\r
+ updateFile.setHeader("X-Move-From", URL.encodePathSegment(file.getUri()));\r
+ updateFile.setHeader("Content-Type", file.getContentType());\r
+ for (String key : file.getMeta().keySet())\r
+ updateFile.setHeader("X-Object-Meta-" + URL.encodePathSegment(key.trim()), URL.encodePathSegment(newMeta.get(key)));\r
+ if (file.isPublished())\r
+ updateFile.setHeader("X-Object-Public", "true");\r
+ String readPermHeader = "read=";\r
+ String writePermHeader = "write=";\r
+ for (String u : file.getPermissions().keySet()) {\r
+ Boolean[] p = file.getPermissions().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
+ else\r
+ permHeader = URL.encodePathSegment(permHeader);\r
+ updateFile.setHeader("X-Object-Sharing", permHeader);\r
+\r
+ Scheduler.get().scheduleDeferred(updateFile);\r
+ }\r
+ else\r
+ updateMetaData(app.getApiPath(), app.getUsername(), file.getUri() + "?update=", newMeta);\r
+ return true;\r
}\r
\r
+ protected void updateMetaData(String api, String owner, String path, Map<String, String> newMeta) {\r
+ if (newMeta != null) {\r
+ PostRequest updateFile = new PostRequest(api, owner, path) {\r
+ @Override\r
+ public void onSuccess(Resource result) {\r
+ if (!app.isMySharedSelected())\r
+ app.updateFolder(file.getParent(), true, new Command() {\r
+ \r
+ @Override\r
+ public void execute() {\r
+ app.updateMySharedRoot();\r
+ }\r
+ }, true);\r
+ else\r
+ app.updateSharedFolder(file.getParent(), true);\r
+ }\r
+\r
+ @Override\r
+ public void onError(Throwable t) {\r
+ GWT.log("", t);\r
+ app.setError(t);\r
+ app.displayError("System error modifying file:" + t.getMessage());\r
+ }\r
+\r
+ @Override\r
+ protected void onUnauthorized(Response response) {\r
+ app.sessionExpired();\r
+ }\r
+ };\r
+ updateFile.setHeader("X-Auth-Token", app.getToken());\r
+ \r
+ for (String t : file.getMeta().keySet()) {\r
+ updateFile.setHeader("X-Object-Meta-" + URL.encodePathSegment(t.trim()), "~");\r
+ }\r
+ \r
+ for (String key : newMeta.keySet())\r
+ updateFile.setHeader("X-Object-Meta-" + URL.encodePathSegment(key.trim()), URL.encodePathSegment(newMeta.get(key)));\r
+ \r
+ Scheduler.get().scheduleDeferred(updateFile);\r
+ }\r
+ else if (!app.isMySharedSelected())\r
+ app.updateFolder(file.getParent(), true, new Command() {\r
+ \r
+ @Override\r
+ public void execute() {\r
+ if (file.isSharedOrPublished())\r
+ app.updateMySharedRoot();\r
+ }\r
+ }, true);\r
+ else\r
+ app.updateSharedFolder(file.getParent(), true);\r
+ }\r
}\r