Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / FolderContextMenu.java @ b3c3954b

History | View | Annotate | Download (7.4 kB)

1 a57faaf0 Christos Stathis
/*
2 cae2a8db Christos Stathis
 * Copyright 2011-2012 GRNET S.A. All rights reserved.
3 63366925 Christos Stathis
 *
4 63366925 Christos Stathis
 * Redistribution and use in source and binary forms, with or
5 63366925 Christos Stathis
 * without modification, are permitted provided that the following
6 63366925 Christos Stathis
 * conditions are met:
7 63366925 Christos Stathis
 *
8 63366925 Christos Stathis
 *   1. Redistributions of source code must retain the above
9 63366925 Christos Stathis
 *      copyright notice, this list of conditions and the following
10 63366925 Christos Stathis
 *      disclaimer.
11 63366925 Christos Stathis
 *
12 63366925 Christos Stathis
 *   2. Redistributions in binary form must reproduce the above
13 63366925 Christos Stathis
 *      copyright notice, this list of conditions and the following
14 63366925 Christos Stathis
 *      disclaimer in the documentation and/or other materials
15 63366925 Christos Stathis
 *      provided with the distribution.
16 63366925 Christos Stathis
 *
17 63366925 Christos Stathis
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 63366925 Christos Stathis
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 63366925 Christos Stathis
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 63366925 Christos Stathis
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 63366925 Christos Stathis
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 63366925 Christos Stathis
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 63366925 Christos Stathis
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 63366925 Christos Stathis
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 63366925 Christos Stathis
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 63366925 Christos Stathis
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 63366925 Christos Stathis
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 63366925 Christos Stathis
 * POSSIBILITY OF SUCH DAMAGE.
29 63366925 Christos Stathis
 *
30 63366925 Christos Stathis
 * The views and conclusions contained in the software and
31 63366925 Christos Stathis
 * documentation are those of the authors and should not be
32 63366925 Christos Stathis
 * interpreted as representing official policies, either expressed
33 63366925 Christos Stathis
 * or implied, of GRNET S.A.
34 a57faaf0 Christos Stathis
 */
35 a57faaf0 Christos Stathis
package gr.grnet.pithos.web.client;
36 a57faaf0 Christos Stathis
37 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.CopyCommand;
38 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.CutCommand;
39 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.DeleteCommand;
40 31477486 Christos Stathis
import gr.grnet.pithos.web.client.commands.EmptyTrashCommand;
41 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.NewFolderCommand;
42 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.PasteCommand;
43 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.PropertiesCommand;
44 2f274388 Christos Stathis
import gr.grnet.pithos.web.client.commands.RefreshCommand;
45 31477486 Christos Stathis
import gr.grnet.pithos.web.client.commands.RestoreTrashCommand;
46 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.ToTrashCommand;
47 447407c8 Christos Stathis
import gr.grnet.pithos.web.client.foldertree.Folder;
48 a57faaf0 Christos Stathis
49 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.AbstractImagePrototype;
50 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.MenuBar;
51 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.MenuItem;
52 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.PopupPanel;
53 a57faaf0 Christos Stathis
54 a57faaf0 Christos Stathis
/**
55 a57faaf0 Christos Stathis
 * The 'Folder Context' menu implementation.
56 a57faaf0 Christos Stathis
 */
57 a57faaf0 Christos Stathis
public class FolderContextMenu extends PopupPanel {
58 a57faaf0 Christos Stathis
59 a57faaf0 Christos Stathis
        /**
60 a57faaf0 Christos Stathis
         * The widget's images.
61 a57faaf0 Christos Stathis
         */
62 a57faaf0 Christos Stathis
        private final Images images;
63 a57faaf0 Christos Stathis
64 a57faaf0 Christos Stathis
        /**
65 a57faaf0 Christos Stathis
         * The image bundle for this widget's images that reuses images defined in
66 a57faaf0 Christos Stathis
         * other menus.
67 a57faaf0 Christos Stathis
         */
68 7811b9d1 Christos Stathis
        public interface Images extends FileContextMenu.Images {
69 a57faaf0 Christos Stathis
        }
70 a57faaf0 Christos Stathis
71 a57faaf0 Christos Stathis
        private MenuItem pasteItem;
72 a57faaf0 Christos Stathis
73 a57faaf0 Christos Stathis
        /**
74 a57faaf0 Christos Stathis
         * The widget's constructor.
75 a57faaf0 Christos Stathis
         *
76 a57faaf0 Christos Stathis
         * @param newImages the image bundle passed on by the parent object
77 a57faaf0 Christos Stathis
         */
78 02d3a335 Christos Stathis
        public FolderContextMenu(Pithos app, final Images newImages, TreeView selectedTree, Folder folder) {
79 a57faaf0 Christos Stathis
                // The popup's constructor's argument is a boolean specifying that it
80 a57faaf0 Christos Stathis
                // auto-close itself when the user clicks outside of it.
81 a57faaf0 Christos Stathis
                super(true);
82 a57faaf0 Christos Stathis
                setAnimationEnabled(true);
83 a57faaf0 Christos Stathis
                images = newImages;
84 447407c8 Christos Stathis
        MenuBar contextMenu = new MenuBar(true);
85 a57faaf0 Christos Stathis
86 3ebb88f4 Christos Stathis
        Boolean[] permissions = folder.getPermissions().get(app.getUsername());
87 3ebb88f4 Christos Stathis
            boolean canWrite = folder.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]);
88 02d3a335 Christos Stathis
            boolean isFolderTreeSelected = selectedTree.equals(app.getFolderTreeView());
89 2f274388 Christos Stathis
            boolean otherSharedTreeSelected = selectedTree.equals(app.getOtherSharedTreeView());
90 02d3a335 Christos Stathis
            
91 2f274388 Christos Stathis
            if (isFolderTreeSelected || otherSharedTreeSelected) {
92 2f274388 Christos Stathis
                    MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(app, this, folder));
93 2f274388 Christos Stathis
                contextMenu.addItem(refresh);
94 2f274388 Christos Stathis
            }
95 2f274388 Christos Stathis
96 31477486 Christos Stathis
        if (!folder.isInTrash()) {
97 3ebb88f4 Christos Stathis
                if (canWrite) {
98 bd187dfb Christos Stathis
                        MenuItem newFolder = new MenuItem("<span id = 'folderContextMenu.newFolder'>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(app, this, folder));
99 3ebb88f4 Christos Stathis
                        contextMenu.addItem(newFolder);
100 31477486 Christos Stathis
101 02d3a335 Christos Stathis
                        if (isFolderTreeSelected && !folder.isContainer()) {
102 3ebb88f4 Christos Stathis
                            MenuItem cut = new MenuItem("<span id = 'folderContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(app, this, folder));
103 3ebb88f4 Christos Stathis
                            contextMenu.addItem(cut);
104 3ebb88f4 Christos Stathis
                        }
105 3ebb88f4 Christos Stathis
                }
106 31477486 Christos Stathis
107 006ec41a Christos Stathis
                if (!folder.isContainer()) {
108 006ec41a Christos Stathis
                        MenuItem copy = new MenuItem("<span id = 'folderContextMenu.copy'>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(app, this, folder));
109 006ec41a Christos Stathis
                        contextMenu.addItem(copy);
110 006ec41a Christos Stathis
                }
111 31477486 Christos Stathis
        
112 3ebb88f4 Christos Stathis
                if (canWrite) {
113 3ebb88f4 Christos Stathis
                        if (!app.getClipboard().isEmpty()) {
114 e273bf25 Christos Stathis
                                Object item = app.getClipboard().getItem();
115 43c372e8 Christos Stathis
                                boolean showPaste = true;
116 43c372e8 Christos Stathis
                                if (item instanceof Folder) {
117 e273bf25 Christos Stathis
                                        Folder f = (Folder) item;
118 43c372e8 Christos Stathis
                                        if (f.contains(folder))
119 43c372e8 Christos Stathis
                                                showPaste = false;
120 e273bf25 Christos Stathis
                                }
121 e273bf25 Christos Stathis
                                if (showPaste) {
122 e273bf25 Christos Stathis
                                    pasteItem = new MenuItem("<span id = 'folderContextMenu.paste'>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(app, this, folder));
123 e273bf25 Christos Stathis
                                    contextMenu.addItem(pasteItem);
124 e273bf25 Christos Stathis
                                }
125 3ebb88f4 Christos Stathis
                        }
126 31477486 Christos Stathis
127 02d3a335 Christos Stathis
                            if (isFolderTreeSelected && !folder.isContainer()) {
128 3ebb88f4 Christos Stathis
                                MenuItem moveToTrash = new MenuItem("<span id = 'folderContextMenu.moveToTrash'>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(app, this, folder));
129 3ebb88f4 Christos Stathis
                                contextMenu.addItem(moveToTrash);
130 3ebb88f4 Christos Stathis
                        
131 3ebb88f4 Christos Stathis
                                MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(app, this, folder, MessagePanel.images));
132 3ebb88f4 Christos Stathis
                                contextMenu.addItem(delete);
133 3ebb88f4 Christos Stathis
                        
134 6b7d024f Christos Stathis
                                contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(app, this, folder, PropertiesCommand.PROPERTIES)));
135 6b7d024f Christos Stathis
                                contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(app, this, folder, PropertiesCommand.PERMISSIONS)));
136 3ebb88f4 Christos Stathis
                            }
137 3ebb88f4 Christos Stathis
                }
138 390f5c04 Christos Stathis
        }
139 31477486 Christos Stathis
        else {
140 31477486 Christos Stathis
                if (!folder.isTrash()) {
141 31477486 Christos Stathis
                            MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(app, this, folder));
142 31477486 Christos Stathis
                            contextMenu.addItem(restore);
143 31477486 Christos Stathis
144 31477486 Christos Stathis
                            MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(app, this, folder, MessagePanel.images));
145 31477486 Christos Stathis
                        contextMenu.addItem(delete);
146 31477486 Christos Stathis
                }
147 31477486 Christos Stathis
                else {
148 31477486 Christos Stathis
                            MenuItem emptyTrash = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(app, this));
149 31477486 Christos Stathis
                            contextMenu.addItem(emptyTrash);
150 31477486 Christos Stathis
                }
151 390f5c04 Christos Stathis
        }
152 a57faaf0 Christos Stathis
                add(contextMenu);
153 a57faaf0 Christos Stathis
        }
154 a57faaf0 Christos Stathis
}