Statistics
| Branch: | Tag: | Revision:

root / web_client / src / gr / grnet / pithos / web / client / ToolsMenu.java @ fe79d412

History | View | Annotate | Download (11.5 kB)

1
/*
2
 * Copyright 2011 GRNET S.A. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or
5
 * without modification, are permitted provided that the following
6
 * conditions are met:
7
 *
8
 *   1. Redistributions of source code must retain the above
9
 *      copyright notice, this list of conditions and the following
10
 *      disclaimer.
11
 *
12
 *   2. Redistributions in binary form must reproduce the above
13
 *      copyright notice, this list of conditions and the following
14
 *      disclaimer in the documentation and/or other materials
15
 *      provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
 * POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * The views and conclusions contained in the software and
31
 * documentation are those of the authors and should not be
32
 * interpreted as representing official policies, either expressed
33
 * or implied, of GRNET S.A.
34
 */
35
package gr.grnet.pithos.web.client;
36

    
37
import gr.grnet.pithos.web.client.commands.AddUserCommand;
38
import gr.grnet.pithos.web.client.commands.CopyCommand;
39
import gr.grnet.pithos.web.client.commands.CreateGroupCommand;
40
import gr.grnet.pithos.web.client.commands.CutCommand;
41
import gr.grnet.pithos.web.client.commands.DeleteCommand;
42
import gr.grnet.pithos.web.client.commands.DeleteGroupCommand;
43
import gr.grnet.pithos.web.client.commands.EmptyTrashCommand;
44
import gr.grnet.pithos.web.client.commands.NewFolderCommand;
45
import gr.grnet.pithos.web.client.commands.PasteCommand;
46
import gr.grnet.pithos.web.client.commands.PropertiesCommand;
47
import gr.grnet.pithos.web.client.commands.RefreshCommand;
48
import gr.grnet.pithos.web.client.commands.RemoveUserCommand;
49
import gr.grnet.pithos.web.client.commands.RestoreTrashCommand;
50
import gr.grnet.pithos.web.client.commands.ToTrashCommand;
51
import gr.grnet.pithos.web.client.foldertree.File;
52
import gr.grnet.pithos.web.client.foldertree.Folder;
53
import gr.grnet.pithos.web.client.grouptree.Group;
54
import gr.grnet.pithos.web.client.grouptree.GroupTreeView;
55
import gr.grnet.pithos.web.client.grouptree.User;
56

    
57
import java.util.List;
58

    
59
import com.google.gwt.user.client.Command;
60
import com.google.gwt.user.client.ui.AbstractImagePrototype;
61
import com.google.gwt.user.client.ui.MenuBar;
62
import com.google.gwt.user.client.ui.MenuItem;
63
import com.google.gwt.user.client.ui.PopupPanel;
64

    
65
/**
66
 * The 'Folder Context' menu implementation.
67
 */
68
public class ToolsMenu extends PopupPanel {
69

    
70
        /**
71
         * The widget's images.
72
         */
73
        private final Images images;
74

    
75
        /**
76
         * The image bundle for this widget's images that reuses images defined in
77
         * other menus.
78
         */
79
        public interface Images extends GroupTreeView.Images {
80
        }
81

    
82
        private MenuItem pasteItem;
83

    
84
        private boolean empty = false;;
85
        
86
        /**
87
         * The widget's constructor.
88
         *
89
         * @param newImages the image bundle passed on by the parent object
90
         */
91
        public ToolsMenu(Pithos app, Images newImages, TreeView selectedTree, Folder folder, List<File> files) {
92
                // The popup's constructor's argument is a boolean specifying that it
93
                // auto-close itself when the user clicks outside of it.
94
                super(true);
95
                setAnimationEnabled(true);
96
                images = newImages;
97
        MenuBar contextMenu = new MenuBar(true);
98

    
99
        if (folder != null) {
100
                Boolean[] permissions = folder.getPermissions().get(app.getUsername());
101
                    boolean canWrite = folder.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]);
102
                    boolean isFolderTreeSelected = selectedTree.equals(app.getFolderTreeView());
103
                    boolean otherSharedTreeSelected = selectedTree.equals(app.getOtherSharedTreeView());
104
                    
105
                    if (isFolderTreeSelected || otherSharedTreeSelected) {
106
                            MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(app, this, folder));
107
                        contextMenu.addItem(refresh);
108
                    }
109
        
110
                if (!folder.isInTrash()) {
111
                        if (canWrite) {
112
                                MenuItem newFolder = new MenuItem("<span id = 'folderContextMenu.newFolder'>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(app, this, folder, images));
113
                                contextMenu.addItem(newFolder);
114

    
115
                                if (isFolderTreeSelected) {
116
                                        MenuItem cut = null;
117
                                        if (files != null && !files.isEmpty()) {
118
                                                        cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut files</span>", true, new CutCommand(app, this, files));
119
                                        }
120
                                        else if (!folder.isContainer()) {
121
                                            cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut folder</span>", true, new CutCommand(app, this, folder));
122
                                        }
123
                                        if (cut != null)
124
                                                contextMenu.addItem(cut);
125
                                }
126
                        }
127
        
128
                        MenuItem copy = null;
129
                        if (files != null && !files.isEmpty())
130
                                copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy files</span>", true, new CopyCommand(app, this, files));
131
                        else
132
                                copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy folder</span>", true, new CopyCommand(app, this, folder));
133
                        contextMenu.addItem(copy);
134
                
135
                        if (canWrite) {
136
                                if (!app.getClipboard().isEmpty()) {
137
                                        Object item = app.getClipboard().getItem();
138
                                        boolean showPaste = false;
139
                                        if (item instanceof List) {
140
                                                List<File> _files = (List<File>) item;
141
                                                if (_files.get(0).getOwner().equals(folder.getOwner()))
142
                                                        showPaste = true;
143
                                        }
144
                                        else {
145
                                                Folder f = (Folder) item;
146
                                                if (f.getOwner().equals(folder.getOwner()))
147
                                                        showPaste = true;
148
                                        }
149
                                        if (showPaste) {
150
                                            pasteItem = new MenuItem("<span id = 'folderContextMenu.paste'>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(app, this, folder));
151
                                            contextMenu.addItem(pasteItem);
152
                                        }
153
                                }
154
        
155
                                    if (isFolderTreeSelected) {
156
                                            MenuItem moveToTrash = null;
157
                                            if (files != null && !files.isEmpty()) {
158
                                                    moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move files to Trash</span>", true, new ToTrashCommand(app, this, files));
159
                                            }
160
                                            else if (!folder.isContainer()) {
161
                                                    moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move folder to Trash</span>", true, new ToTrashCommand(app, this, folder));
162
                                            }
163
                                            if (moveToTrash != null)
164
                                                    contextMenu.addItem(moveToTrash);
165
                                
166
                                        MenuItem delete = null;
167
                                        if (files != null && !files.isEmpty()) {
168
                                                delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete files</span>", true, new DeleteCommand(app, this, files, MessagePanel.images));
169
                                        }
170
                                        else if (!folder.isContainer())
171
                                                delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete folder</span>", true, new DeleteCommand(app, this, folder, MessagePanel.images));
172
                                        if (delete != null)
173
                                                contextMenu.addItem(delete);
174
                                
175
                                        MenuItem properties = null;
176
                                        if (files != null && files.size() == 1)
177
                                                properties = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;File properties</span>", true, new PropertiesCommand(app, this, files, images, 0));
178
                                        else if (!folder.isContainer())
179
                                                properties = new MenuItem("<span id = 'folderContextMenu.properties'>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Folder properties</span>", true, new PropertiesCommand(app, this, folder, newImages, 0));
180
                                        if (properties != null)
181
                                                contextMenu.addItem(properties);
182
                                    }
183
                                if (files != null && files.size() == 1)
184
                                            contextMenu.addItem(new MenuItem("<span><a class='hidden-link' href='" + app.getApiPath() + files.get(0).getOwner() + files.get(0).getUri() + "?X-Auth-Token=" + app.getToken() + "' target='_blank'>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</a></span>", true, (Command) null));
185
                        }
186
                }
187
                else {
188
                        if (!folder.isTrash()) {
189
                                MenuItem restore = null;
190
                                if (files != null && !files.isEmpty())
191
                                        restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(app, this, files));
192
                                else
193
                                        restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(app, this, folder));
194
                                contextMenu.addItem(restore);
195
        
196
                                    MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(app, this, folder, MessagePanel.images));
197
                                contextMenu.addItem(delete);
198
                        }
199
                        else {
200
                                    MenuItem emptyTrash = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(app, this));
201
                                    contextMenu.addItem(emptyTrash);
202
                        }
203
                }
204
        }
205
        else {
206
                Object o = app.getGroupTreeView().getSelected();
207
                if (o != null) {
208
                        if (o instanceof User) {
209
                        MenuItem removeUser = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Remove User</span>", true, new RemoveUserCommand(app, this, (User) o));
210
                        contextMenu.addItem(removeUser);
211
                        }
212
                        else if (o instanceof Group) {
213
                            MenuItem addUser = new MenuItem("<span>" + AbstractImagePrototype.create(images.user()).getHTML() + "&nbsp;Add User</span>", true, new AddUserCommand(app, this, (Group) o));
214
                            contextMenu.addItem(addUser);
215
                    
216
                            MenuItem deleteGroup = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete Group</span>", true, new DeleteGroupCommand(app, this, (Group) o));
217
                            contextMenu.addItem(deleteGroup);
218
                        }
219
                        else {
220
                            MenuItem createGroup = new MenuItem("<span>" + AbstractImagePrototype.create(images.group()).getHTML() + "&nbsp;Create Group</span>", true, new CreateGroupCommand(app, this));
221
                            contextMenu.addItem(createGroup);
222
                        }
223
                }
224
                else
225
                        empty = true;
226
        }
227
                add(contextMenu);
228
        }
229
        
230
        public boolean isEmpty() {
231
                return empty;
232
        }
233
}