root / src / gr / grnet / pithos / web / client / FolderContextMenu.java @ 10ff638f
History | View | Annotate | Download (7 kB)
1 | a57faaf0 | Christos Stathis | /*
|
---|---|---|---|
2 | e6e9f6e6 | Christos KK Loverdos | * Copyright 2011-2013 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 | 8ddb4627 | Christos KK Loverdos | import gr.grnet.pithos.web.client.commands.*; |
38 | 8ddb4627 | Christos KK Loverdos | import gr.grnet.pithos.web.client.commands.PurgeContainerCommand; |
39 | 447407c8 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Folder; |
40 | a57faaf0 | Christos Stathis | |
41 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
42 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.MenuBar; |
43 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.MenuItem; |
44 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.PopupPanel; |
45 | a57faaf0 | Christos Stathis | |
46 | a57faaf0 | Christos Stathis | /**
|
47 | a57faaf0 | Christos Stathis | * The 'Folder Context' menu implementation.
|
48 | a57faaf0 | Christos Stathis | */
|
49 | a57faaf0 | Christos Stathis | public class FolderContextMenu extends PopupPanel { |
50 | a57faaf0 | Christos Stathis | |
51 | a57faaf0 | Christos Stathis | /**
|
52 | a57faaf0 | Christos Stathis | * The widget's images.
|
53 | a57faaf0 | Christos Stathis | */
|
54 | a57faaf0 | Christos Stathis | private final Images images; |
55 | a57faaf0 | Christos Stathis | |
56 | a57faaf0 | Christos Stathis | /**
|
57 | a57faaf0 | Christos Stathis | * The image bundle for this widget's images that reuses images defined in
|
58 | a57faaf0 | Christos Stathis | * other menus.
|
59 | a57faaf0 | Christos Stathis | */
|
60 | 7811b9d1 | Christos Stathis | public interface Images extends FileContextMenu.Images { |
61 | a57faaf0 | Christos Stathis | } |
62 | a57faaf0 | Christos Stathis | |
63 | a57faaf0 | Christos Stathis | private MenuItem pasteItem; |
64 | a57faaf0 | Christos Stathis | |
65 | a57faaf0 | Christos Stathis | /**
|
66 | a57faaf0 | Christos Stathis | * The widget's constructor.
|
67 | a57faaf0 | Christos Stathis | *
|
68 | a57faaf0 | Christos Stathis | * @param newImages the image bundle passed on by the parent object
|
69 | a57faaf0 | Christos Stathis | */
|
70 | 02d3a335 | Christos Stathis | public FolderContextMenu(Pithos app, final Images newImages, TreeView selectedTree, Folder folder) { |
71 | a57faaf0 | Christos Stathis | // The popup's constructor's argument is a boolean specifying that it
|
72 | a57faaf0 | Christos Stathis | // auto-close itself when the user clicks outside of it.
|
73 | a57faaf0 | Christos Stathis | super(true); |
74 | a57faaf0 | Christos Stathis | images = newImages; |
75 | 447407c8 | Christos Stathis | MenuBar contextMenu = new MenuBar(true); |
76 | a57faaf0 | Christos Stathis | |
77 | cc0120ab | Christos KK Loverdos | Boolean[] permissions = folder.getPermissions().get(app.getUserID()); |
78 | 4eaecbac | Christos KK Loverdos | boolean canWrite = folder.getOwnerID().equals(app.getUserID()) || (permissions!= null && permissions[1] != null && permissions[1]); |
79 | 02d3a335 | Christos Stathis | boolean isFolderTreeSelected = selectedTree.equals(app.getFolderTreeView());
|
80 | 2f274388 | Christos Stathis | boolean otherSharedTreeSelected = selectedTree.equals(app.getOtherSharedTreeView());
|
81 | 5d18aa82 | Christos Stathis | boolean mysharedTreeSelected = selectedTree.equals(app.getMySharedTreeView());
|
82 | 02d3a335 | Christos Stathis | |
83 | 5d18aa82 | Christos Stathis | MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(app, this, folder)); |
84 | 5d18aa82 | Christos Stathis | contextMenu.addItem(refresh); |
85 | 2f274388 | Christos Stathis | |
86 | 31477486 | Christos Stathis | if (!folder.isInTrash()) {
|
87 | 3ebb88f4 | Christos Stathis | if (canWrite) {
|
88 | 5d18aa82 | Christos Stathis | if (!mysharedTreeSelected) {
|
89 | 5d18aa82 | Christos Stathis | MenuItem newFolder = new MenuItem("<span id = 'folderContextMenu.newFolder'>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + " New Folder</span>", true, new NewFolderCommand(app, this, folder)); |
90 | 5d18aa82 | Christos Stathis | contextMenu.addItem(newFolder); |
91 | 5d18aa82 | Christos Stathis | } |
92 | 31477486 | Christos Stathis | |
93 | 02d3a335 | Christos Stathis | if (isFolderTreeSelected && !folder.isContainer()) {
|
94 | 3ebb88f4 | Christos Stathis | MenuItem cut = new MenuItem("<span id = 'folderContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(app, this, folder)); |
95 | 3ebb88f4 | Christos Stathis | contextMenu.addItem(cut); |
96 | 3ebb88f4 | Christos Stathis | } |
97 | 3ebb88f4 | Christos Stathis | } |
98 | 31477486 | Christos Stathis | |
99 | 006ec41a | Christos Stathis | if (!folder.isContainer()) {
|
100 | 006ec41a | Christos Stathis | MenuItem copy = new MenuItem("<span id = 'folderContextMenu.copy'>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(app, this, folder)); |
101 | 006ec41a | Christos Stathis | contextMenu.addItem(copy); |
102 | 006ec41a | Christos Stathis | } |
103 | 31477486 | Christos Stathis | |
104 | 3ebb88f4 | Christos Stathis | if (canWrite) {
|
105 | 5d18aa82 | Christos Stathis | if (!app.getClipboard().isEmpty() && !mysharedTreeSelected) {
|
106 | e273bf25 | Christos Stathis | Object item = app.getClipboard().getItem();
|
107 | 43c372e8 | Christos Stathis | boolean showPaste = true; |
108 | 43c372e8 | Christos Stathis | if (item instanceof Folder) { |
109 | e273bf25 | Christos Stathis | Folder f = (Folder) item; |
110 | 43c372e8 | Christos Stathis | if (f.contains(folder))
|
111 | 43c372e8 | Christos Stathis | showPaste = false;
|
112 | e273bf25 | Christos Stathis | } |
113 | e273bf25 | Christos Stathis | if (showPaste) {
|
114 | e273bf25 | Christos Stathis | pasteItem = new MenuItem("<span id = 'folderContextMenu.paste'>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + " Paste</span>", true, new PasteCommand(app, this, folder)); |
115 | e273bf25 | Christos Stathis | contextMenu.addItem(pasteItem); |
116 | e273bf25 | Christos Stathis | } |
117 | 3ebb88f4 | Christos Stathis | } |
118 | 31477486 | Christos Stathis | |
119 | 02d3a335 | Christos Stathis | if (isFolderTreeSelected && !folder.isContainer()) {
|
120 | 3ebb88f4 | Christos Stathis | MenuItem moveToTrash = new MenuItem("<span id = 'folderContextMenu.moveToTrash'>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(app, this, folder)); |
121 | 3ebb88f4 | Christos Stathis | contextMenu.addItem(moveToTrash); |
122 | 10ff638f | Christos KK Loverdos | |
123 | 6b7d024f | Christos Stathis | contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(app, this, folder, PropertiesCommand.PROPERTIES))); |
124 | fbb19e02 | Christos KK Loverdos | contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Share</span>", true, new PropertiesCommand(app, this, folder, PropertiesCommand.PERMISSIONS))); |
125 | 3ebb88f4 | Christos Stathis | } |
126 | 42214d4a | Christos Stathis | |
127 | 42214d4a | Christos Stathis | if (folder.isContainer()) {
|
128 | 8ddb4627 | Christos KK Loverdos | MenuItem purgeContainer = new MenuItem( |
129 | 8ddb4627 | Christos KK Loverdos | "<span>" + Const.PurgeContainer(folder.getName()) + "</span>", |
130 | 8ddb4627 | Christos KK Loverdos | true,
|
131 | 8ddb4627 | Christos KK Loverdos | new PurgeContainerCommand(app, this, folder) |
132 | 8ddb4627 | Christos KK Loverdos | ); |
133 | 8ddb4627 | Christos KK Loverdos | contextMenu.addItem(purgeContainer); |
134 | 42214d4a | Christos Stathis | } |
135 | 3ebb88f4 | Christos Stathis | } |
136 | 390f5c04 | Christos Stathis | } |
137 | 10ff638f | Christos KK Loverdos | else if(!folder.isTrash()) { |
138 | 10ff638f | Christos KK Loverdos | MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(app, this, folder)); |
139 | 10ff638f | Christos KK Loverdos | contextMenu.addItem(restore); |
140 | 31477486 | Christos Stathis | |
141 | 10ff638f | Christos KK Loverdos | MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(app, this, folder, MessagePanel.images)); |
142 | 10ff638f | Christos KK Loverdos | contextMenu.addItem(delete); |
143 | 10ff638f | Christos KK Loverdos | } |
144 | 10ff638f | Christos KK Loverdos | else {
|
145 | 10ff638f | Christos KK Loverdos | MenuItem emptyTrash = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Empty Trash</span>", true, new PurgeContainerCommand(app, this, folder)); |
146 | 10ff638f | Christos KK Loverdos | contextMenu.addItem(emptyTrash); |
147 | 390f5c04 | Christos Stathis | } |
148 | a57faaf0 | Christos Stathis | add(contextMenu); |
149 | a57faaf0 | Christos Stathis | } |
150 | a57faaf0 | Christos Stathis | } |