Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (7.3 kB)

1 a57faaf0 Christos Stathis
/*
2 63366925 Christos Stathis
 * Copyright 2011 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 e273bf25 Christos Stathis
import gr.grnet.pithos.web.client.foldertree.File;
48 447407c8 Christos Stathis
import gr.grnet.pithos.web.client.foldertree.Folder;
49 a57faaf0 Christos Stathis
50 2f274388 Christos Stathis
import java.util.List;
51 2f274388 Christos Stathis
52 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.AbstractImagePrototype;
53 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.MenuBar;
54 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.MenuItem;
55 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.PopupPanel;
56 a57faaf0 Christos Stathis
57 a57faaf0 Christos Stathis
/**
58 a57faaf0 Christos Stathis
 * The 'Folder Context' menu implementation.
59 a57faaf0 Christos Stathis
 */
60 a57faaf0 Christos Stathis
public class FolderContextMenu extends PopupPanel {
61 a57faaf0 Christos Stathis
62 a57faaf0 Christos Stathis
        /**
63 a57faaf0 Christos Stathis
         * The widget's images.
64 a57faaf0 Christos Stathis
         */
65 a57faaf0 Christos Stathis
        private final Images images;
66 a57faaf0 Christos Stathis
67 a57faaf0 Christos Stathis
        /**
68 a57faaf0 Christos Stathis
         * The image bundle for this widget's images that reuses images defined in
69 a57faaf0 Christos Stathis
         * other menus.
70 a57faaf0 Christos Stathis
         */
71 7811b9d1 Christos Stathis
        public interface Images extends FileContextMenu.Images {
72 a57faaf0 Christos Stathis
        }
73 a57faaf0 Christos Stathis
74 a57faaf0 Christos Stathis
        private MenuItem pasteItem;
75 a57faaf0 Christos Stathis
76 a57faaf0 Christos Stathis
        /**
77 a57faaf0 Christos Stathis
         * The widget's constructor.
78 a57faaf0 Christos Stathis
         *
79 a57faaf0 Christos Stathis
         * @param newImages the image bundle passed on by the parent object
80 a57faaf0 Christos Stathis
         */
81 02d3a335 Christos Stathis
        public FolderContextMenu(Pithos app, final Images newImages, TreeView selectedTree, Folder folder) {
82 a57faaf0 Christos Stathis
                // The popup's constructor's argument is a boolean specifying that it
83 a57faaf0 Christos Stathis
                // auto-close itself when the user clicks outside of it.
84 a57faaf0 Christos Stathis
                super(true);
85 a57faaf0 Christos Stathis
                setAnimationEnabled(true);
86 a57faaf0 Christos Stathis
                images = newImages;
87 447407c8 Christos Stathis
        MenuBar contextMenu = new MenuBar(true);
88 a57faaf0 Christos Stathis
89 3ebb88f4 Christos Stathis
        Boolean[] permissions = folder.getPermissions().get(app.getUsername());
90 3ebb88f4 Christos Stathis
            boolean canWrite = folder.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]);
91 02d3a335 Christos Stathis
            boolean isFolderTreeSelected = selectedTree.equals(app.getFolderTreeView());
92 2f274388 Christos Stathis
            boolean otherSharedTreeSelected = selectedTree.equals(app.getOtherSharedTreeView());
93 02d3a335 Christos Stathis
            
94 2f274388 Christos Stathis
            if (isFolderTreeSelected || otherSharedTreeSelected) {
95 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));
96 2f274388 Christos Stathis
                contextMenu.addItem(refresh);
97 2f274388 Christos Stathis
            }
98 2f274388 Christos Stathis
99 31477486 Christos Stathis
        if (!folder.isInTrash()) {
100 3ebb88f4 Christos Stathis
                if (canWrite) {
101 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));
102 3ebb88f4 Christos Stathis
                        contextMenu.addItem(newFolder);
103 31477486 Christos Stathis
104 02d3a335 Christos Stathis
                        if (isFolderTreeSelected && !folder.isContainer()) {
105 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));
106 3ebb88f4 Christos Stathis
                            contextMenu.addItem(cut);
107 3ebb88f4 Christos Stathis
                        }
108 3ebb88f4 Christos Stathis
                }
109 31477486 Christos Stathis
110 006ec41a Christos Stathis
                if (!folder.isContainer()) {
111 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));
112 006ec41a Christos Stathis
                        contextMenu.addItem(copy);
113 006ec41a Christos Stathis
                }
114 31477486 Christos Stathis
        
115 3ebb88f4 Christos Stathis
                if (canWrite) {
116 3ebb88f4 Christos Stathis
                        if (!app.getClipboard().isEmpty()) {
117 e273bf25 Christos Stathis
                                Object item = app.getClipboard().getItem();
118 43c372e8 Christos Stathis
                                boolean showPaste = true;
119 43c372e8 Christos Stathis
                                if (item instanceof Folder) {
120 e273bf25 Christos Stathis
                                        Folder f = (Folder) item;
121 43c372e8 Christos Stathis
                                        if (f.contains(folder))
122 43c372e8 Christos Stathis
                                                showPaste = false;
123 e273bf25 Christos Stathis
                                }
124 e273bf25 Christos Stathis
                                if (showPaste) {
125 e273bf25 Christos Stathis
                                    pasteItem = new MenuItem("<span id = 'folderContextMenu.paste'>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(app, this, folder));
126 e273bf25 Christos Stathis
                                    contextMenu.addItem(pasteItem);
127 e273bf25 Christos Stathis
                                }
128 3ebb88f4 Christos Stathis
                        }
129 31477486 Christos Stathis
130 02d3a335 Christos Stathis
                            if (isFolderTreeSelected && !folder.isContainer()) {
131 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));
132 3ebb88f4 Christos Stathis
                                contextMenu.addItem(moveToTrash);
133 3ebb88f4 Christos Stathis
                        
134 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));
135 3ebb88f4 Christos Stathis
                                contextMenu.addItem(delete);
136 3ebb88f4 Christos Stathis
                        
137 7260b946 Christos Stathis
                                MenuItem properties = new MenuItem("<span id = 'folderContextMenu.properties'>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(app, this, folder, 0));
138 3ebb88f4 Christos Stathis
                                contextMenu.addItem(properties);
139 3ebb88f4 Christos Stathis
                            }
140 3ebb88f4 Christos Stathis
                }
141 390f5c04 Christos Stathis
        }
142 31477486 Christos Stathis
        else {
143 31477486 Christos Stathis
                if (!folder.isTrash()) {
144 31477486 Christos Stathis
                            MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(app, this, folder));
145 31477486 Christos Stathis
                            contextMenu.addItem(restore);
146 31477486 Christos Stathis
147 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));
148 31477486 Christos Stathis
                        contextMenu.addItem(delete);
149 31477486 Christos Stathis
                }
150 31477486 Christos Stathis
                else {
151 31477486 Christos Stathis
                            MenuItem emptyTrash = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(app, this));
152 31477486 Christos Stathis
                            contextMenu.addItem(emptyTrash);
153 31477486 Christos Stathis
                }
154 390f5c04 Christos Stathis
        }
155 a57faaf0 Christos Stathis
                add(contextMenu);
156 a57faaf0 Christos Stathis
        }
157 a57faaf0 Christos Stathis
}