A falsely removed import added back
[pithos] / src / gr / ebs / gss / client / FileContextMenu.java
index 84eb7b3..dc4f6ba 100644 (file)
@@ -27,27 +27,29 @@ import gr.ebs.gss.client.commands.RefreshCommand;
 import gr.ebs.gss.client.commands.RestoreTrashCommand;
 import gr.ebs.gss.client.commands.ToTrashCommand;
 import gr.ebs.gss.client.commands.UploadFileCommand;
-import gr.ebs.gss.client.commands.ViewImageCommand;
 import gr.ebs.gss.client.dnd.DnDTreeItem;
 import gr.ebs.gss.client.rest.resource.FileResource;
 import gr.ebs.gss.client.rest.resource.FolderResource;
 
 import java.util.List;
 
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.event.dom.client.ContextMenuEvent;
+import com.google.gwt.resources.client.ClientBundle;
+import com.google.gwt.resources.client.ImageResource;
 import com.google.gwt.user.client.Command;
 import com.google.gwt.user.client.Event;
 import com.google.gwt.user.client.ui.AbstractImagePrototype;
-import com.google.gwt.user.client.ui.ClickListener;
 import com.google.gwt.user.client.ui.MenuBar;
 import com.google.gwt.user.client.ui.MenuItem;
 import com.google.gwt.user.client.ui.PopupPanel;
 import com.google.gwt.user.client.ui.TreeItem;
-import com.google.gwt.user.client.ui.Widget;
 
 /**
  * The 'File Context' menu implementation.
  */
-public class FileContextMenu extends PopupPanel implements ClickListener {
+public class FileContextMenu extends PopupPanel implements ClickHandler {
 
        /**
         * The widget's images.
@@ -74,28 +76,28 @@ public class FileContextMenu extends PopupPanel implements ClickListener {
 
        private MenuItem saveAsItem;
 
-       private MenuItem viewImageItem;
-
        /**
         * The image bundle for this widget's images that reuses images defined in
         * other menus.
         */
-       public interface Images extends FileMenu.Images, EditMenu.Images {
+       public interface Images extends ClientBundle,FileMenu.Images, EditMenu.Images {
 
-               @Resource("gr/ebs/gss/resources/mimetypes/document.png")
-               AbstractImagePrototype fileContextMenu();
+               @Source("gr/ebs/gss/resources/mimetypes/document.png")
+               ImageResource fileContextMenu();
 
-               @Resource("gr/ebs/gss/resources/doc_versions.png")
-               AbstractImagePrototype versions();
+               @Source("gr/ebs/gss/resources/doc_versions.png")
+               ImageResource versions();
 
-               @Resource("gr/ebs/gss/resources/group.png")
-               AbstractImagePrototype sharing();
+               @Override
+               @Source("gr/ebs/gss/resources/group.png")
+               ImageResource sharing();
 
-               @Resource("gr/ebs/gss/resources/border_remove.png")
-               AbstractImagePrototype unselectAll();
+               @Override
+               @Source("gr/ebs/gss/resources/border_remove.png")
+               ImageResource unselectAll();
 
-               @Resource("gr/ebs/gss/resources/demo.png")
-               AbstractImagePrototype viewImage();
+               @Source("gr/ebs/gss/resources/demo.png")
+               ImageResource viewImage();
 }
 
        public static native String getDate()/*-{
@@ -118,34 +120,36 @@ public class FileContextMenu extends PopupPanel implements ClickListener {
                // The command that does some validation before downloading a file.
                Command downloadCmd = new Command() {
 
+                       @Override
                        public void execute() {
                                hide();
                                GSS.get().getTopPanel().getFileMenu().preDownloadCheck();
                        }
                };
 
-               pasteItem = new MenuItem("<span>" + newImages.paste().getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(this));
+               pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(this));
 
                MenuBar contextMenu = new MenuBar(true);
                if (isEmpty) {
                        contextMenu.addItem(pasteItem);
                        if (GSS.get().getFolders().getCurrent() != null)
                                if (GSS.get().getFolders().isFileItem(GSS.get().getFolders().getCurrent()))
-                                       contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
+                                       contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
                                else if (GSS.get().getFolders().isMySharedItem(GSS.get().getFolders().getCurrent()) || GSS      .get()
                                                                                                                                                                                                                        .getFolders()
                                                                                                                                                                                                                        .isOthersSharedItem(GSS .get()
                                                                                                                                                                                                                                                                        .getFolders()
                                                                                                                                                                                                                                                                        .getCurrent()))
                                        if(GSS.get().getFolders().getCurrent().getUserObject() instanceof FolderResource)
-                                               contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
-                       contextMenu.addItem("<span>" + images.refresh().getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
+                                               contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
+                       contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
                } else if (isTrash) {
-                       contextMenu.addItem("<span>" + newImages.versions().getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(this));
-                       contextMenu.addItem("<span>" + newImages.delete().getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, images));
+                       contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(this));
+                       contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, images));
                } else {
                        final Command unselectAllCommand = new Command() {
 
+                               @Override
                                public void execute() {
                                        hide();
                                        if(GSS.get().isFileListShowing())
@@ -154,43 +158,35 @@ public class FileContextMenu extends PopupPanel implements ClickListener {
                                                GSS.get().getSearchResults().clearSelectedRows();
                                }
                        };
-                       cutItem = new MenuItem("<span>" + newImages.cut().getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
-                       copyItem = new MenuItem("<span>" + newImages.copy().getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
+                       cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
+                       copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
 
-                       updateItem = new MenuItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
+                       updateItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
 
-                       trashItem = new MenuItem("<span>" + newImages.emptyTrash().getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
-                       deleteItem = new MenuItem("<span>" + newImages.delete().getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, images));
+                       trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
+                       deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, images));
 
-                       sharingItem = new MenuItem("<span>" + newImages.sharing().getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, images, 1));
-                       propItem = new MenuItem("<span>" + newImages.viewText().getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, images, 0));
+                       sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, images, 1));
+                       propItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, images, 0));
 
                        TreeItem currentFolder = gss.getFolders().getCurrent();
                        if(currentFolder!=null && currentFolder.getUserObject() instanceof FolderResource)
                                contextMenu.addItem(updateItem);
                        String[] link = {"", ""};
                        gss.getTopPanel().getFileMenu().createDownloadLink(link, false);
-                       downloadItem = new MenuItem("<span>" + link[0] + newImages.download().getHTML() + " Download" + link[1] + "</span>", true, downloadCmd);
+                       downloadItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download" + link[1] + "</span>", true, downloadCmd);
                        contextMenu.addItem(downloadItem);
                        gss.getTopPanel().getFileMenu().createDownloadLink(link, true);
-                       saveAsItem = new MenuItem("<span>" + link[0] + newImages.download().getHTML() + " Save As" + link[1] + "</span>", true, downloadCmd);
+                       saveAsItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Save As" + link[1] + "</span>", true, downloadCmd);
                        contextMenu.addItem(saveAsItem);
-                       boolean isImage = false;
-                       if (GSS.get().getCurrentSelection() != null && GSS.get().getCurrentSelection() instanceof FileResource)
-                               isImage = ((FileResource) GSS.get().getCurrentSelection()).getContentType().startsWith("image/");
-                       if (isImage) {
-                               viewImageItem = new MenuItem("<span>" + newImages.viewImage().getHTML() + "&nbsp;View Image</span>", true,
-                                                       new ViewImageCommand(this, images, gss.getTopPanel().getFileMenu().getDownloadURL()));
-                               contextMenu.addItem(viewImageItem);
-                       }
                        contextMenu.addItem(cutItem);
                        contextMenu.addItem(copyItem);
                        if(currentFolder!=null && currentFolder.getUserObject() instanceof FolderResource)
                                contextMenu.addItem(pasteItem);
-                       contextMenu.addItem("<span>" + images.unselectAll().getHTML() + "&nbsp;Unselect</span>", true, unselectAllCommand);
+                       contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + "&nbsp;Unselect</span>", true, unselectAllCommand);
                        contextMenu.addItem(trashItem);
                        contextMenu.addItem(deleteItem);
-                       contextMenu.addItem("<span>" + images.refresh().getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
+                       contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
                        contextMenu.addItem(sharingItem);
                        contextMenu.addItem(propItem);
                }
@@ -203,13 +199,12 @@ public class FileContextMenu extends PopupPanel implements ClickListener {
 
        void onMultipleSelection() {
                updateItem.setVisible(false);
-               propItem.setVisible(false);
                downloadItem.setVisible(false);
                saveAsItem.setVisible(false);
                sharingItem.setVisible(false);
        }
-
-       public void onClick(Widget sender) {
+       @Override
+       public void onClick(ClickEvent event) {
                if (GSS.get().getCurrentSelection() != null)
                        if (GSS.get().getCurrentSelection() instanceof FileResource) {
                                FileResource res = (FileResource) GSS.get().getCurrentSelection();
@@ -218,8 +213,8 @@ public class FileContextMenu extends PopupPanel implements ClickListener {
                                        menu = new FileContextMenu(images, true, false);
                                else
                                        menu = new FileContextMenu(images, false, false);
-                               int left = sender.getAbsoluteLeft();
-                               int top = sender.getAbsoluteTop() + sender.getOffsetHeight();
+                               int left = event.getRelativeElement().getAbsoluteLeft();
+                               int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
                                menu.setPopupPosition(left, top);
                                menu.show();
                        } else if (GSS.get().getCurrentSelection() instanceof List) {
@@ -230,14 +225,15 @@ public class FileContextMenu extends PopupPanel implements ClickListener {
                                        menu = new FileContextMenu(images, false, false);
                                        menu.onMultipleSelection();
                                }
-                               int left = sender.getAbsoluteLeft();
-                               int top = sender.getAbsoluteTop() + sender.getOffsetHeight();
+                               int left = event.getRelativeElement().getAbsoluteLeft();
+                               int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
                                menu.setPopupPosition(left, top);
                                menu.show();
                        }
        }
 
-       public void onEvent(Event event) {
+       
+       public void onContextEvent(ContextMenuEvent event) {
                if (GSS.get().getCurrentSelection() != null)
                        if (GSS.get().getCurrentSelection() instanceof FileResource) {
                                FileResource res = (FileResource) GSS.get().getCurrentSelection();
@@ -246,12 +242,42 @@ public class FileContextMenu extends PopupPanel implements ClickListener {
                                        menu = new FileContextMenu(images, true, false);
                                else
                                        menu = new FileContextMenu(images, false, false);
+                               int left = event.getNativeEvent().getClientX();
+                               int top = event.getNativeEvent().getClientY();
+                               menu.setPopupPosition(left, top);
+                               menu.show();
+
+                       } else if (GSS.get().getCurrentSelection() instanceof List) {
+                               FileContextMenu menu;
+                               if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
+                                       menu = new FileContextMenu(images, true, false);
+                               else {
+                                       menu = new FileContextMenu(images, false, false);
+                                       menu.onMultipleSelection();
+                               }
+                               int left = event.getNativeEvent().getClientX();
+                               int top = event.getNativeEvent().getClientY();
+                               menu.setPopupPosition(left, top);
+                               menu.show();
+                       }
+       }
+
+       public FileContextMenu onEvent(Event event) {
+               FileContextMenu menu=null;
+               if (GSS.get().getCurrentSelection() != null)
+                       if (GSS.get().getCurrentSelection() instanceof FileResource) {
+                               FileResource res = (FileResource) GSS.get().getCurrentSelection();
+
+                               if (res.isDeleted())
+                                       menu = new FileContextMenu(images, true, false);
+                               else
+                                       menu = new FileContextMenu(images, false, false);
                                int left = event.getClientX();
                                int top = event.getClientY();
                                menu.setPopupPosition(left, top);
                                menu.show();
                        } else if (GSS.get().getCurrentSelection() instanceof List) {
-                               FileContextMenu menu;
+
                                if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
                                        menu = new FileContextMenu(images, true, false);
                                else {
@@ -263,18 +289,22 @@ public class FileContextMenu extends PopupPanel implements ClickListener {
                                menu.setPopupPosition(left, top);
                                menu.show();
                        }
+               return menu;
        }
 
-       public void onEmptyEvent(Event event) {
-               FileContextMenu menu;
+       public FileContextMenu onEmptyEvent(Event event) {
+               FileContextMenu menu=null;
                if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
                        menu = new FileContextMenu(images, true, true);
                else if(((DnDTreeItem)GSS.get().getFolders().getCurrent()).getFolderResource() != null)
                        menu = new FileContextMenu(images, false, true);
-               else return;
+               else return menu;
                int left = event.getClientX();
                int top = event.getClientY();
                menu.setPopupPosition(left, top);
                menu.show();
+               return menu;
        }
+
+
 }