From e3f47376634810cb13fa5078a31a5ec7393e5ca2 Mon Sep 17 00:00:00 2001 From: Christos Stathis Date: Thu, 14 Jul 2011 17:07:49 +0300 Subject: [PATCH] Cleaned up Edit menu --- .../src/gr/grnet/pithos/web/client/EditMenu.java | 171 +++++++++----------- .../src/gr/grnet/pithos/web/client/TopPanel.java | 20 +-- .../pithos/web/client/commands/CopyCommand.java | 3 +- .../pithos/web/client/commands/CutCommand.java | 3 +- .../pithos/web/client/commands/DeleteCommand.java | 3 +- .../pithos/web/client/commands/PasteCommand.java | 4 +- .../pithos/web/client/commands/ToTrashCommand.java | 3 +- 7 files changed, 85 insertions(+), 122 deletions(-) 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 5869ccd..9769a7e 100644 --- a/web_client/src/gr/grnet/pithos/web/client/EditMenu.java +++ b/web_client/src/gr/grnet/pithos/web/client/EditMenu.java @@ -39,6 +39,7 @@ import gr.grnet.pithos.web.client.commands.CutCommand; import gr.grnet.pithos.web.client.commands.DeleteCommand; import gr.grnet.pithos.web.client.commands.PasteCommand; import gr.grnet.pithos.web.client.commands.ToTrashCommand; +import gr.grnet.pithos.web.client.foldertree.File; import gr.grnet.pithos.web.client.foldertree.Folder; import gr.grnet.pithos.web.client.rest.resource.FileResource; @@ -60,15 +61,13 @@ import com.google.gwt.user.client.ui.PopupPanel; /** * The 'Edit' menu implementation. */ -public class EditMenu extends PopupPanel implements ClickHandler { +public class EditMenu extends MenuBar { /** * The widget's images. */ private final Images images; - private final MenuBar contextMenu = new MenuBar(true); - /** * An image bundle for this widget's images. */ @@ -135,107 +134,81 @@ public class EditMenu extends PopupPanel implements ClickHandler { * * @param newImages the image bundle passed on by the parent object */ - public EditMenu(final Images newImages) { - // The popup's constructor's argument is a boolean specifying that it - // auto-close itself when the user clicks outside of it. + public EditMenu(final GSS _app, final Images newImages) { super(true); setAnimationEnabled(true); images = newImages; - createMenu(); - add(contextMenu); - } - - @Override - public void onClick(ClickEvent event) { - final EditMenu menu = new EditMenu(images); - final int left = event.getRelativeElement().getAbsoluteLeft(); - final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight(); - menu.setPopupPosition(left, top); - menu.show(); - } - public MenuBar createMenu() { - contextMenu.clearItems(); - contextMenu.setAutoOpen(false); - - final Command selectAllCommand = new Command() { - - @Override - public void execute() { - hide(); - if(GSS.get().isFileListShowing()) - GSS.get().getFileList().selectAllRows(); - } - }; - final Command unselectAllCommand = new Command() { - - @Override - public void execute() { - hide(); - if(GSS.get().isFileListShowing()) - GSS.get().getFileList().clearSelectedRows(); - } - }; - - boolean cutcopyVisible = GSS.get().getCurrentSelection() != null && (GSS.get().getCurrentSelection() instanceof RestResourceWrapper - || GSS.get().getCurrentSelection() instanceof FileResource || GSS .get().getCurrentSelection() instanceof GroupUserResource || GSS .get().getCurrentSelection() instanceof List); - String cutLabel = "Cut"; - String copyLabel ="Copy"; - String pasteLabel = "Paste"; - if(GSS.get().getCurrentSelection() != null) - if(GSS.get().getCurrentSelection() instanceof RestResourceWrapper){ - cutLabel = "Cut Folder"; - copyLabel = "Copy Folder"; - } - else if(GSS.get().getCurrentSelection() instanceof FileResource){ - cutLabel = "Cut File"; - copyLabel = "Copy File"; - } - else if(GSS.get().getCurrentSelection() instanceof List){ - cutLabel = "Cut Files"; - copyLabel = "Copy Files"; - } - if(GSS.get().getClipboard().getItem() != null) - if(GSS.get().getClipboard().getItem() instanceof List) { - if (((List) GSS.get().getClipboard().getItem()).size() > 1) - pasteLabel = "Paste Files"; - else - pasteLabel = "Paste File"; + Folder selectedFolder = _app.getFolderTreeView().getSelection(); + List selectedFiles = _app.getFileList().getSelectedFiles(); + + String cutLabel = "Cut"; + String copyLabel ="Copy"; + String pasteLabel = "Paste"; + if(selectedFiles.size() == 1) { + cutLabel = "Cut File"; + copyLabel = "Copy File"; + } + else if (selectedFiles.size() > 1) { + cutLabel = "Cut Files"; + copyLabel = "Copy Files"; + } + else if (selectedFolder != null) { + cutLabel = "Cut Folder"; + copyLabel = "Copy Folder"; + } + + if (_app.getClipboard().hasFiles()) { + if (((List) _app.getClipboard().getItem()).size() > 1) + pasteLabel = "Paste Files"; + else + pasteLabel = "Paste File"; + } + else + pasteLabel = "Paste Folder"; + + if (selectedFiles.size() > 0 || selectedFolder != null) { + Object cutObject = null; + if (selectedFiles.size() > 0) + cutObject = selectedFiles; + else if (selectedFolder != null) + cutObject = selectedFolder; + + 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); + + MenuItem deleteItem = new MenuItem("" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete", true, new DeleteCommand(null, cutObject, images)); + addItem(deleteItem); + } + + if (selectedFolder != null && !_app.getClipboard().isEmpty()) { + MenuItem pasteItem = new MenuItem("" + AbstractImagePrototype.create(images.paste()).getHTML() + " " + pasteLabel + "", true, new PasteCommand(_app, null, selectedFolder)); + addItem(pasteItem); + } + + + MenuItem selectAllItem = new MenuItem("" + AbstractImagePrototype.create(images.selectAll()).getHTML() + " Select All", true, new Command() { + + @Override + public void execute() { + _app.getFileList().selectAllRows(); } - else if(GSS.get().getClipboard().getItem() instanceof Folder) - pasteLabel = "Paste Folder"; - MenuItem cutItem = new MenuItem("" + AbstractImagePrototype.create(images.cut()).getHTML() + " "+cutLabel+"", true, new CutCommand(GSS.get(), this, null)); - cutItem.getElement().setId("topMenu.edit.cut"); - contextMenu.addItem(cutItem).setVisible(cutcopyVisible); - - MenuItem copyItem = new MenuItem("" + AbstractImagePrototype.create(images.copy()).getHTML() + " "+copyLabel+"", true, new CopyCommand(GSS.get(), this, null)); - copyItem.getElement().setId("topMenu.edit.copy"); - contextMenu.addItem(copyItem).setVisible(cutcopyVisible); - - MenuItem pasteItem = new MenuItem("" + AbstractImagePrototype.create(images.paste()).getHTML() + " "+pasteLabel+"", true, new PasteCommand(GSS.get(), this, null)); - pasteItem.getElement().setId("topMenu.edit.paste"); - if (GSS.get().getClipboard().getItem() != null) - contextMenu.addItem(pasteItem); - MenuItem moveToTrashItem = new MenuItem("" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Move to Trash", true, new ToTrashCommand(GSS.get(), this, null)); - moveToTrashItem.getElement().setId("topMenu.edit.moveToTrash"); - contextMenu .addItem(moveToTrashItem) - .setVisible(cutcopyVisible); - - MenuItem deleteItem = new MenuItem("" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete", true, new DeleteCommand(this, null, images)); - deleteItem.getElement().setId("topMenu.edit.delete"); - contextMenu .addItem(deleteItem) - .setVisible(cutcopyVisible); - - MenuItem selectAllItem = new MenuItem("" + AbstractImagePrototype.create(images.selectAll()).getHTML() + " Select All", true, selectAllCommand); - selectAllItem.getElement().setId("topMenu.edit.selectAll"); - contextMenu.addItem(selectAllItem); - - MenuItem unSelectAllItem = new MenuItem("" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect All", true, unselectAllCommand); - unSelectAllItem.getElement().setId("topMenu.edit.unSelectAll"); - contextMenu.addItem(unSelectAllItem); - return contextMenu; - } - + }); + addItem(selectAllItem); + MenuItem unSelectAllItem = new MenuItem("" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect All", true, new Command() { + @Override + public void execute() { + _app.getFileList().clearSelectedRows(); + } + }); + addItem(unSelectAllItem); + } } diff --git a/web_client/src/gr/grnet/pithos/web/client/TopPanel.java b/web_client/src/gr/grnet/pithos/web/client/TopPanel.java index 33a757a..8e9c05a 100644 --- a/web_client/src/gr/grnet/pithos/web/client/TopPanel.java +++ b/web_client/src/gr/grnet/pithos/web/client/TopPanel.java @@ -91,21 +91,6 @@ public class TopPanel extends Composite { } /** - * The menu bar widget. - */ - private MenuBar menu; - - /** - * The file menu widget. - */ - private FileMenu fileMenu; - - /** - * The edit menu widget. - */ - private EditMenu editMenu; - - /** * A widget that displays a message indicating that communication with the * server is underway. */ @@ -117,14 +102,13 @@ public class TopPanel extends Composite { * @param images the supplied images */ public TopPanel(final Images images) { - editMenu = new EditMenu(images); loading = new LoadingIndicator(images); loading.hide(); HorizontalPanel outer = new HorizontalPanel(); outer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); - menu = new MenuBar(); + MenuBar menu = new MenuBar(); menu.setWidth("100%"); menu.setAutoOpen(false); menu.setAnimationEnabled(true); @@ -152,7 +136,7 @@ public class TopPanel extends Composite { AbstractImagePrototype.create(images.edit()).getHTML() + "Edit", true, new MenuBar(true)){ @Override public MenuBar getSubMenu() { - return editMenu.createMenu(); + return new EditMenu(GSS.get(), images); } }; diff --git a/web_client/src/gr/grnet/pithos/web/client/commands/CopyCommand.java b/web_client/src/gr/grnet/pithos/web/client/commands/CopyCommand.java index 780865b..0681547 100644 --- a/web_client/src/gr/grnet/pithos/web/client/commands/CopyCommand.java +++ b/web_client/src/gr/grnet/pithos/web/client/commands/CopyCommand.java @@ -61,7 +61,8 @@ public class CopyCommand implements Command{ @Override public void execute() { - containerPanel.hide(); + if (containerPanel != null) + containerPanel.hide(); if (resource instanceof Folder) { app.getClipboard().setItem(Clipboard.COPY, (Folder) resource); diff --git a/web_client/src/gr/grnet/pithos/web/client/commands/CutCommand.java b/web_client/src/gr/grnet/pithos/web/client/commands/CutCommand.java index de7fd9b..0e71aca 100644 --- a/web_client/src/gr/grnet/pithos/web/client/commands/CutCommand.java +++ b/web_client/src/gr/grnet/pithos/web/client/commands/CutCommand.java @@ -63,7 +63,8 @@ public class CutCommand implements Command { @Override public void execute() { - containerPanel.hide(); + if (containerPanel != null) + containerPanel.hide(); if (resource instanceof Folder) { app.getClipboard().setItem(Clipboard.CUT, (Folder) resource); 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 a76052c..4e8ad93 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 @@ -74,7 +74,8 @@ public class DeleteCommand implements Command{ @Override public void execute() { - containerPanel.hide(); + if (containerPanel != null) + containerPanel.hide(); displayDelete(); } /** diff --git a/web_client/src/gr/grnet/pithos/web/client/commands/PasteCommand.java b/web_client/src/gr/grnet/pithos/web/client/commands/PasteCommand.java index c9d217c..465c712 100644 --- a/web_client/src/gr/grnet/pithos/web/client/commands/PasteCommand.java +++ b/web_client/src/gr/grnet/pithos/web/client/commands/PasteCommand.java @@ -64,7 +64,9 @@ public class PasteCommand implements Command { @Override public void execute() { - containerPanel.hide(); + if (containerPanel != null) + containerPanel.hide(); + Object clipboardItem = app.getClipboard().getItem(); if (clipboardItem == null) return; diff --git a/web_client/src/gr/grnet/pithos/web/client/commands/ToTrashCommand.java b/web_client/src/gr/grnet/pithos/web/client/commands/ToTrashCommand.java index 9050e3d..32946d9 100644 --- a/web_client/src/gr/grnet/pithos/web/client/commands/ToTrashCommand.java +++ b/web_client/src/gr/grnet/pithos/web/client/commands/ToTrashCommand.java @@ -77,7 +77,8 @@ public class ToTrashCommand implements Command{ @Override public void execute() { - containerPanel.hide(); + if (containerPanel != null) + containerPanel.hide(); if (resource instanceof List) { Iterator iter = ((List) resource).iterator(); trashFiles(iter, new Command() { -- 1.7.10.4