From 50326f366e7ff6ad1aa8fcb856b7d281053f2e0d Mon Sep 17 00:00:00 2001 From: Christos Stathis Date: Thu, 14 Jul 2011 18:47:48 +0300 Subject: [PATCH] Implemented single file properties dialog --- .../web/client/AbstractPropertiesDialog.java | 1 - .../src/gr/grnet/pithos/web/client/EditMenu.java | 16 +- .../grnet/pithos/web/client/FileContextMenu.java | 3 +- .../src/gr/grnet/pithos/web/client/FileMenu.java | 8 +- .../pithos/web/client/FilePropertiesDialog.java | 593 ++++++++++---------- .../pithos/web/client/commands/DeleteCommand.java | 23 +- .../web/client/commands/PropertiesCommand.java | 247 ++------ 7 files changed, 347 insertions(+), 544 deletions(-) diff --git a/web_client/src/gr/grnet/pithos/web/client/AbstractPropertiesDialog.java b/web_client/src/gr/grnet/pithos/web/client/AbstractPropertiesDialog.java index 84dc9b4..e5ab8a4 100644 --- a/web_client/src/gr/grnet/pithos/web/client/AbstractPropertiesDialog.java +++ b/web_client/src/gr/grnet/pithos/web/client/AbstractPropertiesDialog.java @@ -176,5 +176,4 @@ public abstract class AbstractPropertiesDialog extends DialogBox { GSS.preventIESelection(); hide(); } - } diff --git a/web_client/src/gr/grnet/pithos/web/client/EditMenu.java b/web_client/src/gr/grnet/pithos/web/client/EditMenu.java index 9769a7e..3b238d2 100644 --- a/web_client/src/gr/grnet/pithos/web/client/EditMenu.java +++ b/web_client/src/gr/grnet/pithos/web/client/EditMenu.java @@ -174,17 +174,21 @@ public class EditMenu extends MenuBar { else if (selectedFolder != null) cutObject = selectedFolder; - MenuItem cutItem = new MenuItem("" + AbstractImagePrototype.create(images.cut()).getHTML() + " " + cutLabel + "", true, new CutCommand(_app, null, cutObject)); - addItem(cutItem); + if (selectedFiles.size() != 0 || (selectedFolder != null && !selectedFolder.isContainer())) { + MenuItem cutItem = new MenuItem("" + AbstractImagePrototype.create(images.cut()).getHTML() + " " + cutLabel + "", true, new CutCommand(_app, null, cutObject)); + addItem(cutItem); + } MenuItem copyItem = new MenuItem("" + AbstractImagePrototype.create(images.copy()).getHTML() + " "+copyLabel+"", true, new CopyCommand(_app, null, cutObject)); addItem(copyItem); - MenuItem moveToTrashItem = new MenuItem("" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Move to Trash", true, new ToTrashCommand(_app, null, cutObject)); - addItem(moveToTrashItem); + if (selectedFiles.size() != 0 || (selectedFolder != null && !selectedFolder.isContainer())) { + MenuItem moveToTrashItem = new MenuItem("" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Move to Trash", true, new ToTrashCommand(_app, null, cutObject)); + addItem(moveToTrashItem); - MenuItem deleteItem = new MenuItem("" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete", true, new DeleteCommand(null, cutObject, images)); - addItem(deleteItem); + MenuItem deleteItem = new MenuItem("" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete", true, new DeleteCommand(null, cutObject, images)); + addItem(deleteItem); + } } if (selectedFolder != null && !_app.getClipboard().isEmpty()) { diff --git a/web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java b/web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java index e9ba939..84337f9 100644 --- a/web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java +++ b/web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java @@ -170,8 +170,7 @@ public class FileContextMenu extends PopupPanel { // sharingItem = new MenuItem("" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing", true, new PropertiesCommand(this, images, 1)); // contextMenu.addItem(sharingItem); -// propItem = new MenuItem("" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties", true, new PropertiesCommand(this, images, 0)); -// contextMenu.addItem(propItem); + contextMenu.addItem(new MenuItem("" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties", true, new PropertiesCommand(GSS.get(), this, selectedFiles, images, 0))); contextMenu.addItem(new MenuItem("" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download", true, (Command) null)); diff --git a/web_client/src/gr/grnet/pithos/web/client/FileMenu.java b/web_client/src/gr/grnet/pithos/web/client/FileMenu.java index a515180..1da3923 100644 --- a/web_client/src/gr/grnet/pithos/web/client/FileMenu.java +++ b/web_client/src/gr/grnet/pithos/web/client/FileMenu.java @@ -131,9 +131,9 @@ public class FileMenu extends MenuBar { // contextMenu.addItem(sharingItem) // .setVisible(propertiesVisible); // -// MenuItem propertiesItem = new MenuItem("" + AbstractImagePrototype.create(images.viewText()).getHTML() + " Properties", true, new PropertiesCommand(this, images, 0)); -// propertiesItem.getElement().setId("topMenu.file.properties"); -// contextMenu.addItem(propertiesItem) -// .setVisible(propertiesVisible); + if (selectedFiles.size() > 0) { + MenuItem propertiesItem = new MenuItem("" + AbstractImagePrototype.create(images.viewText()).getHTML() + " Properties", true, new PropertiesCommand(GSS.get(), null, selectedFiles, images, 0)); + addItem(propertiesItem); + } } } diff --git a/web_client/src/gr/grnet/pithos/web/client/FilePropertiesDialog.java b/web_client/src/gr/grnet/pithos/web/client/FilePropertiesDialog.java index 9eb8036..6d63d6e 100644 --- a/web_client/src/gr/grnet/pithos/web/client/FilePropertiesDialog.java +++ b/web_client/src/gr/grnet/pithos/web/client/FilePropertiesDialog.java @@ -34,7 +34,12 @@ */ package gr.grnet.pithos.web.client; +import com.google.gwt.core.client.Scheduler; +import gr.grnet.pithos.web.client.foldertree.File; +import gr.grnet.pithos.web.client.foldertree.Resource; import gr.grnet.pithos.web.client.rest.PostCommand; +import gr.grnet.pithos.web.client.rest.PostRequest; +import gr.grnet.pithos.web.client.rest.PutRequest; import gr.grnet.pithos.web.client.rest.RestException; import gr.grnet.pithos.web.client.rest.resource.FileResource; import gr.grnet.pithos.web.client.rest.resource.GroupResource; @@ -79,7 +84,7 @@ import com.google.gwt.user.client.ui.VerticalPanel; */ public class FilePropertiesDialog extends AbstractPropertiesDialog { - final PermissionsList permList; + private PermissionsList permList; private CheckBox readForAll; @@ -111,126 +116,54 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog { private final CheckBox versioned = new CheckBox(); - final FileResource file; + final File file; private String userFullName; + private GSS app; + /** * The widget's constructor. - * - * @param images the dialog's ImageBundle - * @param groups - * @param bodies */ - public FilePropertiesDialog(final Images images, final List groups, List bodies, String _userFullName) { + public FilePropertiesDialog(GSS _app, File _file) { + app = _app; + file = _file; // Set the dialog's caption. setText("File properties"); - file = (FileResource) GSS.get().getCurrentSelection(); - userFullName = _userFullName; - permList = new PermissionsList(images, file.getPermissions(), file.getOwner()); - GWT.log("FILE PERMISSIONS:"+file.getPermissions()); +// permList = new PermissionsList(images, file.getPermissions(), file.getOwner()); + // Outer contains inner and buttons. final VerticalPanel outer = new VerticalPanel(); final FocusPanel focusPanel = new FocusPanel(outer); // Inner contains generalPanel and permPanel. inner = new DecoratedTabPanel(); inner.setAnimationEnabled(true); - final VerticalPanel generalPanel = new VerticalPanel(); - final VerticalPanel permPanel = new VerticalPanel(); - final HorizontalPanel buttons = new HorizontalPanel(); - final HorizontalPanel permButtons = new HorizontalPanel(); - final HorizontalPanel permForAll = new HorizontalPanel(); - final HorizontalPanel pathPanel = new HorizontalPanel(); - final VerticalPanel verPanel = new VerticalPanel(); - final HorizontalPanel vPanel = new HorizontalPanel(); - final HorizontalPanel vPanel2 = new HorizontalPanel(); - - versioned.setValue(file.isVersioned()); - versioned.getElement().setId("filePropertiesDialog.chechBox.versioned"); - inner.add(generalPanel, "General"); - inner.add(permPanel, "Sharing"); - inner.add(verPanel, "Versions"); - inner.selectTab(0); - - final Label fileNameNote = new Label("Please note that slashes ('/') are not allowed in file names.", true); - fileNameNote.setVisible(false); - fileNameNote.setStylePrimaryName("pithos-readForAllNote"); - - final FlexTable generalTable = new FlexTable(); - generalTable.setText(0, 0, "Name"); - generalTable.setText(1, 0, "Folder"); - generalTable.setText(2, 0, "Owner"); - generalTable.setText(3, 0, "Last modified"); - generalTable.setText(4, 0, "Tags"); - name.setWidth("100%"); - name.setText(file.getName()); - name.getElement().setId("filePropertiesDialog.textBox.name"); - generalTable.setWidget(0, 1, name); - name.addChangeHandler(new ChangeHandler() { - @Override - public void onChange(ChangeEvent event) { - if(name.getText().contains("/")) - fileNameNote.setVisible(true); - else - fileNameNote.setVisible(false); - } - }); + inner.add(createGeneralPanel(), "General"); - if(file.getFolderName() != null) - generalTable.setText(1, 1, file.getFolderName()); - else - generalTable.setText(1, 1, "-"); - generalTable.setWidget(0, 2, fileNameNote); - generalTable.setText(2, 1,userFullName); + inner.add(createSharingPanel(), "Sharing"); - final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a"); - generalTable.setText(3, 1, formatter.format(file.getModificationDate())); - // Get the tags. - StringBuffer tagsBuffer = new StringBuffer(); - Iterator i = file.getTags().iterator(); - while (i.hasNext()) { - String tag = (String) i.next(); - tagsBuffer.append(tag).append(", "); - } - if (tagsBuffer.length() > 1) - tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1); - initialTagText = tagsBuffer.toString(); - tags.setWidth("100%"); - tags.getElement().setId("filePropertiesDialog.textBox.tags"); - tags.setText(initialTagText); - generalTable.setWidget(4, 1, tags); - generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels"); - generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels"); - generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels"); - generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels"); - generalTable.getFlexCellFormatter().setStyleName(4, 0, "props-labels"); - generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values"); - generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values"); - generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values"); - generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values"); - generalTable.getFlexCellFormatter().setStyleName(4, 1, "props-values"); - generalTable.setCellSpacing(4); + inner.add(createVersionPanel(), "Versions"); + + inner.selectTab(0); + outer.add(inner); + + final HorizontalPanel buttons = new HorizontalPanel(); // Create the 'OK' button, along with a listener that hides the dialog // when the button is clicked. final Button ok = new Button("OK", new ClickHandler() { @Override public void onClick(ClickEvent event) { - if(name.getText().contains("/")) - fileNameNote.setVisible(true); - else{ - fileNameNote.setVisible(false); - accept(); - closeDialog(); - } + accept(); + closeDialog(); } }); - ok.getElement().setId("filePropertiesDialog.button.ok"); + buttons.add(ok); buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER); // Create the 'Cancel' button, along with a listener that hides the @@ -241,158 +174,225 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog { closeDialog(); } }); - cancel.getElement().setId("filePropertiesDialog.button.cancel"); buttons.add(cancel); buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); buttons.setSpacing(8); buttons.addStyleName("pithos-TabPanelBottom"); - generalPanel.add(generalTable); + outer.add(buttons); + outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); + outer.addStyleName("pithos-TabPanelBottom"); + + focusPanel.setFocus(true); + setWidget(outer); // Asynchronously retrieve the tags defined by this user. DeferredCommand.addCommand(new Command() { @Override public void execute() { - updateTags(); - } - }); - - DisclosurePanel allTags = new DisclosurePanel("All tags"); - allTagsContent = new FlowPanel(); - allTagsContent.setWidth("100%"); - allTags.setContent(allTagsContent); - generalPanel.add(allTags); - generalPanel.setSpacing(4); - - final Button add = new Button("Add Group", new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, false); - dlg.center(); - } - }); - add.getElement().setId("filePropertiesDialog.button.addGroup"); - permButtons.add(add); - permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER); - - final Button addUser = new Button("Add User", new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, true); - dlg.center(); - } - }); - add.getElement().setId("filePropertiesDialog.button.addUser"); - permButtons.add(addUser); - permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER); - - permButtons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); - permButtons.setSpacing(8); - permButtons.addStyleName("pithos-TabPanelBottom"); - - final Label readForAllNote = new Label("When this option is enabled, the file will be readable" + - " by everyone. By checking this option, you are certifying that you have the right to " + - "distribute this file and that it does not violate the Terms of Use.", true); - readForAllNote.setVisible(false); - readForAllNote.setStylePrimaryName("pithos-readForAllNote"); - - readForAll = new CheckBox(); - readForAll.getElement().setId("filePropertiesDialog.checkBox.public"); - readForAll.setValue(file.isReadForAll()); - readForAll.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - readForAllNote.setVisible(readForAll.getValue()); - } - - }); - - permPanel.add(permList); - permPanel.add(permButtons); - // Only show the read for all permission if the user is the owner. - if (file.getOwner().equals(GSS.get().getCurrentUserResource().getUsername())) { - permForAll.add(new Label("Public")); - permForAll.add(readForAll); - permForAll.setSpacing(8); - permForAll.addStyleName("pithos-TabPanelBottom"); - permForAll.add(readForAllNote); - permPanel.add(permForAll); - } - - TextBox path = new TextBox(); - path.setWidth("100%"); - path.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - GSS.enableIESelection(); - ((TextBox) event.getSource()).selectAll(); - GSS.preventIESelection(); - } - - }); - path.setText(file.getUri()); - path.getElement().setId("filePropertiesDialog.textBox.link"); - path.setTitle("Use this link for sharing the file via e-mail, IM, etc. (crtl-C/cmd-C to copy to system clipboard)"); - path.setWidth("100%"); - path.setReadOnly(true); - pathPanel.setWidth("100%"); - pathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); - pathPanel.add(new Label("Link")); - pathPanel.setSpacing(8); - pathPanel.addStyleName("pithos-TabPanelBottom"); - pathPanel.add(path); - permPanel.add(pathPanel); - - VersionsList verList = new VersionsList(this, images, bodies); - verPanel.add(verList); - - vPanel.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); - vPanel.setSpacing(8); - vPanel.addStyleName("pithos-TabPanelBottom"); - vPanel.add(new Label("Versioned")); - - vPanel.add(versioned); - verPanel.add(vPanel); - vPanel2.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); - vPanel2.setSpacing(8); - vPanel2.addStyleName("pithos-TabPanelBottom"); - Button removeVersionsButton = new Button(AbstractImagePrototype.create(images.delete()).getHTML(), new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - ConfirmationDialog confirm = new ConfirmationDialog("Really " + - "remove all previous versions?", "Remove") { - - @Override - public void cancel() { - } - - @Override - public void confirm() { - FilePropertiesDialog.this.closeDialog(); - removeAllOldVersions(); - } - - }; - confirm.center(); +// updateTags(); } - }); - HTML removeAllVersion = new HTML("Remove all previous versions?"); - vPanel2.add(removeAllVersion); - vPanel2.add(removeVersionsButton); - verPanel.add(vPanel2); - if(!file.isVersioned()) - vPanel2.setVisible(false); - outer.add(inner); - outer.add(buttons); - outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); - outer.addStyleName("pithos-TabPanelBottom"); - - focusPanel.setFocus(true); - setWidget(outer); } + private VerticalPanel createGeneralPanel() { + final VerticalPanel generalPanel = new VerticalPanel(); + final FlexTable generalTable = new FlexTable(); + generalTable.setText(0, 0, "Name"); + generalTable.setText(1, 0, "Folder"); + generalTable.setText(2, 0, "Owner"); + generalTable.setText(3, 0, "Last modified"); +// generalTable.setText(4, 0, "Tags"); + + name.setWidth("100%"); + name.setText(file.getName()); + generalTable.setWidget(0, 1, name); + if(file.getParent() != null) + generalTable.setText(1, 1, file.getParent().getName()); + else + generalTable.setText(1, 1, "-"); + generalTable.setText(2, 1, file.getOwner()); + + final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a"); + generalTable.setText(3, 1, formatter.format(file.getLastModified())); + + // Get the tags. +// StringBuffer tagsBuffer = new StringBuffer(); +// Iterator i = file.getTags().iterator(); +// while (i.hasNext()) { +// String tag = (String) i.next(); +// tagsBuffer.append(tag).append(", "); +// } +// if (tagsBuffer.length() > 1) +// tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1); +// initialTagText = tagsBuffer.toString(); +// tags.setWidth("100%"); +// tags.getElement().setId("filePropertiesDialog.textBox.tags"); +// tags.setText(initialTagText); +// generalTable.setWidget(4, 1, tags); + + generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels"); + generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels"); + generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels"); + generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels"); +// generalTable.getFlexCellFormatter().setStyleName(4, 0, "props-labels"); + generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values"); + generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values"); + generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values"); + generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values"); +// generalTable.getFlexCellFormatter().setStyleName(4, 1, "props-values"); + generalTable.setCellSpacing(4); + + generalPanel.add(generalTable); + + DisclosurePanel allTags = new DisclosurePanel("All tags"); + allTagsContent = new FlowPanel(); + allTagsContent.setWidth("100%"); + allTags.setContent(allTagsContent); + generalPanel.add(allTags); + generalPanel.setSpacing(4); + return generalPanel; + } + + private VerticalPanel createSharingPanel() { + VerticalPanel permPanel = new VerticalPanel(); +// +// permList = new PermissionsList(images, file.getPermissions(), file.getOwner()); +// permPanel.add(permList); +// +// HorizontalPanel permButtons = new HorizontalPanel(); +// Button add = new Button("Add Group", new ClickHandler() { +// @Override +// public void onClick(ClickEvent event) { +// PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, false); +// dlg.center(); +// } +// }); +// permButtons.add(add); +// permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER); +// +// final Button addUser = new Button("Add User", new ClickHandler() { +// @Override +// public void onClick(ClickEvent event) { +// PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, true); +// dlg.center(); +// } +// }); +// permButtons.add(addUser); +// permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER); +// +// permButtons.setSpacing(8); +// permButtons.addStyleName("pithos-TabPanelBottom"); +// permPanel.add(permButtons); +// +// final Label readForAllNote = new Label("When this option is enabled, the file will be readable" + +// " by everyone. By checking this option, you are certifying that you have the right to " + +// "distribute this file and that it does not violate the Terms of Use.", true); +// readForAllNote.setVisible(false); +// readForAllNote.setStylePrimaryName("pithos-readForAllNote"); +// +// readForAll = new CheckBox(); +// readForAll.setValue(file.isReadForAll()); +// readForAll.addClickHandler(new ClickHandler() { +// @Override +// public void onClick(ClickEvent event) { +// readForAllNote.setVisible(readForAll.getValue()); +// } +// +// }); +// +// // Only show the read for all permission if the user is the owner. +// if (file.getOwner().equals(app.getUsername())) { +// final HorizontalPanel permForAll = new HorizontalPanel(); +// permForAll.add(new Label("Public")); +// permForAll.add(readForAll); +// permForAll.setSpacing(8); +// permForAll.addStyleName("pithos-TabPanelBottom"); +// permForAll.add(readForAllNote); +// permPanel.add(permForAll); +// } +// +// +// final HorizontalPanel pathPanel = new HorizontalPanel(); +// pathPanel.setWidth("100%"); +// pathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); +// pathPanel.add(new Label("Link")); +// pathPanel.setSpacing(8); +// pathPanel.addStyleName("pithos-TabPanelBottom"); +// +// TextBox path = new TextBox(); +// path.setWidth("100%"); +// path.addClickHandler(new ClickHandler() { +// @Override +// public void onClick(ClickEvent event) { +// GSS.enableIESelection(); +// ((TextBox) event.getSource()).selectAll(); +// GSS.preventIESelection(); +// } +// }); +// path.setText(file.getUri()); +// path.setTitle("Use this link for sharing the file via e-mail, IM, etc. (crtl-C/cmd-C to copy to system clipboard)"); +// path.setWidth("100%"); +// path.setReadOnly(true); +// pathPanel.add(path); +// permPanel.add(pathPanel); + + return permPanel; + } + + private VerticalPanel createVersionPanel() { + VerticalPanel versionPanel = new VerticalPanel(); + +// VersionsList verList = new VersionsList(this, images, bodies); +// versionPanel.add(verList); +// +// HorizontalPanel vPanel = new HorizontalPanel(); +// +// vPanel.setSpacing(8); +// vPanel.addStyleName("pithos-TabPanelBottom"); +// vPanel.add(new Label("Versioned")); +// +// versioned.setValue(file.isVersioned()); +// vPanel.add(versioned); +// versionPanel.add(vPanel); +// +// HorizontalPanel vPanel2 = new HorizontalPanel(); +// vPanel2.setSpacing(8); +// vPanel2.addStyleName("pithos-TabPanelBottom"); +// +// HTML removeAllVersion = new HTML("Remove all previous versions?"); +// vPanel2.add(removeAllVersion); +// +// Button removeVersionsButton = new Button(AbstractImagePrototype.create(images.delete()).getHTML(), new ClickHandler() { +// @Override +// public void onClick(ClickEvent event) { +// ConfirmationDialog confirm = new ConfirmationDialog("Really " + +// "remove all previous versions?", "Remove") { +// +// @Override +// public void cancel() { +// } +// +// @Override +// public void confirm() { +// FilePropertiesDialog.this.closeDialog(); +// removeAllOldVersions(); +// } +// +// }; +// confirm.center(); +// } +// +// }); +// vPanel2.add(removeVersionsButton); +// if(!file.isVersioned()) +// vPanel2.setVisible(false); +// +// versionPanel.add(vPanel2); + + return versionPanel; + } /** * Accepts any change and updates the file @@ -401,84 +401,75 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog { @Override protected void accept() { String newFilename = null; - permList.updatePermissionsAccordingToInput(); - Set perms = permList.getPermissions(); - JSONObject json = new JSONObject(); +// permList.updatePermissionsAccordingToInput(); +// Set perms = permList.getPermissions(); +// JSONObject json = new JSONObject(); if (!name.getText().equals(file.getName())) { newFilename = name.getText(); - json.put("name", new JSONString(newFilename)); +// json.put("name", new JSONString(newFilename)); } - if (versioned.getValue() != file.isVersioned()) - json.put("versioned", JSONBoolean.getInstance(versioned.getValue())); +// if (versioned.getValue() != file.isVersioned()) +// json.put("versioned", JSONBoolean.getInstance(versioned.getValue())); //only update the read for all perm if the user is the owner - if (readForAll.getValue() != file.isReadForAll()) - if (file.getOwner().equals(GSS.get().getCurrentUserResource().getUsername())) - json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue())); - int i = 0; - if (permList.hasChanges()) { - GWT.log("Permissions change", null); - JSONArray perma = new JSONArray(); - - for (PermissionHolder p : perms) { - JSONObject po = new JSONObject(); - if (p.getUser() != null) - po.put("user", new JSONString(p.getUser())); - if (p.getGroup() != null) - po.put("group", new JSONString(p.getGroup())); - po.put("read", JSONBoolean.getInstance(p.isRead())); - po.put("write", JSONBoolean.getInstance(p.isWrite())); - po.put("modifyACL", JSONBoolean.getInstance(p.isModifyACL())); - perma.set(i, po); - i++; - } - json.put("permissions", perma); - } - JSONArray taga = new JSONArray(); - i = 0; - if (!tags.getText().equals(initialTagText)) { - String[] tagset = tags.getText().split(","); - for (String t : tagset) { - JSONString to = new JSONString(t); - taga.set(i, to); - i++; - } - json.put("tags", taga); - } - String jsonString = json.toString(); - if(jsonString.equals("{}")){ - GWT.log("NO CHANGES", null); - return; - } +// if (readForAll.getValue() != file.isReadForAll()) +// if (file.getOwner().equals(GSS.get().getCurrentUserResource().getUsername())) +// json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue())); +// int i = 0; +// if (permList.hasChanges()) { +// GWT.log("Permissions change", null); +// JSONArray perma = new JSONArray(); +// +// for (PermissionHolder p : perms) { +// JSONObject po = new JSONObject(); +// if (p.getUser() != null) +// po.put("user", new JSONString(p.getUser())); +// if (p.getGroup() != null) +// po.put("group", new JSONString(p.getGroup())); +// po.put("read", JSONBoolean.getInstance(p.isRead())); +// po.put("write", JSONBoolean.getInstance(p.isWrite())); +// po.put("modifyACL", JSONBoolean.getInstance(p.isModifyACL())); +// perma.set(i, po); +// i++; +// } +// json.put("permissions", perma); +// } +// JSONArray taga = new JSONArray(); +// i = 0; +// if (!tags.getText().equals(initialTagText)) { +// String[] tagset = tags.getText().split(","); +// for (String t : tagset) { +// JSONString to = new JSONString(t); +// taga.set(i, to); +// i++; +// } +// json.put("tags", taga); +// } +// String jsonString = json.toString(); +// if(jsonString.equals("{}")){ +// GWT.log("NO CHANGES", null); +// return; +// } final String newFilenameFinal = newFilename; - PostCommand cf = new PostCommand(file.getUri() + "?update=", jsonString, 200) { - - @Override - public void onComplete() { - GSS.get().getTreeView().refreshCurrentNode(false); - } - - @Override - public void onError(Throwable t) { - GWT.log("", t); - if (t instanceof RestException) { - int statusCode = ((RestException) t).getHttpStatusCode(); - if (statusCode == 405) - GSS.get().displayError("You don't have the necessary permissions"); - else if (statusCode == 404) - GSS.get().displayError("User in permissions does not exist"); - else if (statusCode == 409) - GSS.get().displayError("A file with the same name already exists"); - else if (statusCode == 413) - GSS.get().displayError("Your quota has been exceeded"); - else - GSS.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText()); - } else - GSS.get().displayError("System error modifying file:" + t.getMessage()); - } - - }; - DeferredCommand.addCommand(cf); + if (newFilename == null) + return; + String path = app.getApiPath() + app.getUsername() + file.getParent().getUri() + "/" + newFilename; + PutRequest updateFile = new PutRequest(path) { + @Override + public void onSuccess(Resource result) { + app.updateFolder(file.getParent()); + } + + @Override + public void onError(Throwable t) { + GWT.log("", t); + app.displayError("System error modifying file:" + t.getMessage()); + } + }; + updateFile.setHeader("X-Auth-Token", app.getToken()); + updateFile.setHeader("X-Move-From", file.getUri()); + updateFile.setHeader("Content-Type", file.getContentType()); + Scheduler.get().scheduleDeferred(updateFile); } private void removeAllOldVersions() { diff --git a/web_client/src/gr/grnet/pithos/web/client/commands/DeleteCommand.java b/web_client/src/gr/grnet/pithos/web/client/commands/DeleteCommand.java index 4e8ad93..c96ec11 100644 --- a/web_client/src/gr/grnet/pithos/web/client/commands/DeleteCommand.java +++ b/web_client/src/gr/grnet/pithos/web/client/commands/DeleteCommand.java @@ -76,20 +76,13 @@ public class DeleteCommand implements Command{ public void execute() { if (containerPanel != null) containerPanel.hide(); - displayDelete(); + + if (resource instanceof Folder) { + DeleteFolderDialog dlg = new DeleteFolderDialog(GSS.get(), newImages, (Folder) resource); + dlg.center(); + } else if (resource instanceof List) { + DeleteFileDialog dlg = new DeleteFileDialog(newImages, (List) resource); + dlg.center(); + } } - /** - * Display the delete dialog, according to the selected object. - * - * - */ - void displayDelete() { - if (resource instanceof Folder) { - DeleteFolderDialog dlg = new DeleteFolderDialog(GSS.get(), newImages, (Folder) resource); - dlg.center(); - } else if (resource instanceof List) { - DeleteFileDialog dlg = new DeleteFileDialog(newImages, (List) resource); - dlg.center(); - } - } } diff --git a/web_client/src/gr/grnet/pithos/web/client/commands/PropertiesCommand.java b/web_client/src/gr/grnet/pithos/web/client/commands/PropertiesCommand.java index 85f53af..bada046 100644 --- a/web_client/src/gr/grnet/pithos/web/client/commands/PropertiesCommand.java +++ b/web_client/src/gr/grnet/pithos/web/client/commands/PropertiesCommand.java @@ -40,6 +40,8 @@ import gr.grnet.pithos.web.client.FilesPropertiesDialog; import gr.grnet.pithos.web.client.FolderPropertiesDialog; import gr.grnet.pithos.web.client.GSS; import gr.grnet.pithos.web.client.FileMenu.Images; +import gr.grnet.pithos.web.client.foldertree.File; +import gr.grnet.pithos.web.client.foldertree.Folder; import gr.grnet.pithos.web.client.rest.GetCommand; import gr.grnet.pithos.web.client.rest.HeadCommand; import gr.grnet.pithos.web.client.rest.MultipleGetCommand; @@ -60,6 +62,7 @@ import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DeferredCommand; import com.google.gwt.user.client.IncrementalCommand; import com.google.gwt.user.client.ui.PopupPanel; +import org.w3c.css.sac.ElementSelector; /** * The command that displays the appropriate Properties dialog, according to the @@ -80,232 +83,46 @@ public class PropertiesCommand implements Command { private String userName; + private Object resource; + + private GSS app; + /** * @param _containerPanel * @param _newImages the images of all the possible delete dialogs * @param _tab the tab to switch to */ - public PropertiesCommand(PopupPanel _containerPanel, final FileMenu.Images _newImages, int _tab) { + public PropertiesCommand(GSS _app, PopupPanel _containerPanel, Object _resource, final FileMenu.Images _newImages, int _tab) { containerPanel = _containerPanel; newImages = _newImages; tabToShow = _tab; + resource = _resource; + app = _app; } @Override public void execute() { - containerPanel.hide(); - if (GSS.get().getCurrentSelection() instanceof RestResourceWrapper) { - GetCommand eg = new GetCommand(FolderResource.class, ((RestResourceWrapper) GSS.get().getCurrentSelection()).getUri(),((RestResourceWrapper) GSS.get().getCurrentSelection()).getResource()) { - - @Override - public void onComplete() { - ((RestResourceWrapper) GSS.get().getCurrentSelection()).setResource(getResult()); - initialize(); - } - - @Override - public void onError(Throwable t) { - - } - - }; - DeferredCommand.addCommand(eg); - } - else if (GSS.get().getCurrentSelection() instanceof FileResource) { - final String path = ((FileResource) GSS.get().getCurrentSelection()).getUri(); - // Needed because firefox caches head requests. - HeadCommand eg = new HeadCommand(FileResource.class, path+"?"+Math.random(), null ) { - - @Override - public void onComplete() { - FileResource res = getResult(); - GSS.get().setCurrentSelection(res); - initialize(); - } - - @Override - public void onError(Throwable t) { - if(t instanceof RestException) - GSS.get().displayError("Unable to retrieve file details:"+((RestException)t).getHttpStatusText()); - } - - }; - DeferredCommand.addCommand(eg); - } - else if (GSS.get().getCurrentSelection() instanceof List) { - List paths = new ArrayList(); - for (FileResource fr : (List) GSS.get().getCurrentSelection()) - paths.add(fr.getUri()+"?"+Math.random()); - Cached[] cached = new Cached[paths.size()]; - int i=0; - for (FileResource fr : (List) GSS.get().getCurrentSelection()){ - Cached c = new Cached(); - c.uri=fr.getUri()+"?"+Math.random(); - c.cache=fr; - cached[i]=c; - i++; - } - MultipleHeadCommand gv = new MultipleHeadCommand(FileResource.class, paths.toArray(new String[] {}),cached) { - - @Override - public void onComplete() { - List res = getResult(); - GSS.get().setCurrentSelection(res); - FilesPropertiesDialog dlg = new FilesPropertiesDialog(res); - dlg.selectTab(tabToShow); - dlg.center(); - } - - @Override - public void onError(Throwable t) { - GWT.log("", t); - GSS.get().displayError("Unable to fetch files details"); - } - - @Override - public void onError(String p, Throwable throwable) { - GWT.log("Path:" + p, throwable); - } - }; - DeferredCommand.addCommand(gv); - } - } - - private void initialize(){ - getGroups(); - getVersions(); - getOwnerFullName(); - DeferredCommand.addCommand(new IncrementalCommand() { - - @Override - public boolean execute() { - boolean res = canContinue(); - if (res) { - displayProperties(newImages, GSS.get().findUserFullName(userName)); - return false; - } - return true; - } - - }); - + if (containerPanel != null) + containerPanel.hide(); + + if (resource instanceof Folder) { + Folder folder = (Folder) resource; + FolderPropertiesDialog dlg = new FolderPropertiesDialog(app, false, folder); + dlg.selectTab(tabToShow); + dlg.center(); + } + else if (resource instanceof List) { + List files = (List) resource; + if (files.size() > 1) { +// FilesPropertiesDialog dlg = new FilesPropertiesDialog(files); +// dlg.selectTab(tabToShow); +// dlg.center(); + } + else { + FilePropertiesDialog dlg = new FilePropertiesDialog(app, files.get(0)); + dlg.selectTab(tabToShow); + dlg.center(); + } + } } - - private boolean canContinue() { - String userFullNameFromMap = GSS.get().findUserFullName(userName); - if(groups == null || versions == null || userFullNameFromMap == null) - return false; - return true; - } - - /** - * Display the appropriate Properties dialog, according to the selected - * object in the application. - * - * @param propImages the images of all the possible properties dialogs - */ - void displayProperties(final Images propImages, final String _userName) { - if (GSS.get().getCurrentSelection() instanceof RestResourceWrapper) { -// FolderPropertiesDialog dlg = new FolderPropertiesDialog(propImages, false, groups); -// dlg.selectTab(tabToShow); -// dlg.center(); - } else if (GSS.get().getCurrentSelection() instanceof FileResource) { - FilePropertiesDialog dlg = new FilePropertiesDialog(propImages, groups, versions, _userName); - dlg.selectTab(tabToShow); - dlg.center(); - } - } - - private void getGroups() { - GetCommand gg = new GetCommand(GroupsResource.class, GSS.get().getCurrentUserResource().getGroupsPath(), null) { - - @Override - public void onComplete() { - GroupsResource res = getResult(); - MultipleGetCommand ga = new MultipleGetCommand(GroupResource.class, res.getGroupPaths().toArray(new String[] {}), null) { - - @Override - public void onComplete() { - List groupList = getResult(); - groups = groupList; - } - - @Override - public void onError(Throwable t) { - GWT.log("", t); - GSS.get().displayError("Unable to fetch groups"); - groups = new ArrayList(); - } - - @Override - public void onError(String p, Throwable throwable) { - GWT.log("Path:" + p, throwable); - } - }; - DeferredCommand.addCommand(ga); - } - - @Override - public void onError(Throwable t) { - GWT.log("", t); - GSS.get().displayError("Unable to fetch groups"); - groups = new ArrayList(); - } - }; - DeferredCommand.addCommand(gg); - } - - private void getVersions() { - if (GSS.get().getCurrentSelection() instanceof FileResource) { - FileResource afile = (FileResource) GSS.get().getCurrentSelection(); - GWT.log("File is versioned:" + afile.isVersioned(), null); - if (afile.isVersioned()) { - List paths = new ArrayList(); - for (int i = 1; i <= afile.getVersion(); i++) - paths.add(afile.getUri() + "?version=" + i); - MultipleHeadCommand gv = new MultipleHeadCommand(FileResource.class, paths.toArray(new String[] {}), null) { - - @Override - public void onComplete() { - versions = getResult(); - } - - @Override - public void onError(Throwable t) { - GWT.log("", t); - GSS.get().displayError("Unable to fetch versions"); - versions = new ArrayList(); - } - - @Override - public void onError(String p, Throwable throwable) { - GWT.log("Path:" + p, throwable); - } - }; - DeferredCommand.addCommand(gv); - } else - versions = new ArrayList(); - } else - versions = new ArrayList(); - } - - private void getOwnerFullName() { - if(GSS.get().getCurrentSelection() instanceof FileResource){ - FileResource fileResource = (FileResource) GSS.get().getCurrentSelection(); - userName = fileResource.getOwner(); - if(GSS.get().findUserFullName(userName) == null){ - GetUserCommand gu = new GetUserCommand(userName); - gu.execute(); - } - }else{ - FolderResource resource = ((RestResourceWrapper) GSS.get().getCurrentSelection()).getResource(); - userName = resource.getOwner(); - if(GSS.get().findUserFullName(userName) == null){ - GetUserCommand gu = new GetUserCommand(userName); - gu.execute(); - } - } - } - - } -- 1.7.10.4