root / src / gr / ebs / gss / client / FolderContextMenu.java @ 783db80b
History | View | Annotate | Download (8.9 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
|
3 |
*
|
4 |
* This file is part of GSS.
|
5 |
*
|
6 |
* GSS is free software: you can redistribute it and/or modify
|
7 |
* it under the terms of the GNU General Public License as published by
|
8 |
* the Free Software Foundation, either version 3 of the License, or
|
9 |
* (at your option) any later version.
|
10 |
*
|
11 |
* GSS is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 |
*/
|
19 |
package gr.ebs.gss.client; |
20 |
|
21 |
import gr.ebs.gss.client.commands.CopyCommand; |
22 |
import gr.ebs.gss.client.commands.CutCommand; |
23 |
import gr.ebs.gss.client.commands.DeleteCommand; |
24 |
import gr.ebs.gss.client.commands.EmptyTrashCommand; |
25 |
import gr.ebs.gss.client.commands.NewFolderCommand; |
26 |
import gr.ebs.gss.client.commands.PasteCommand; |
27 |
import gr.ebs.gss.client.commands.PropertiesCommand; |
28 |
import gr.ebs.gss.client.commands.RefreshCommand; |
29 |
import gr.ebs.gss.client.commands.RestoreTrashCommand; |
30 |
import gr.ebs.gss.client.commands.ToTrashCommand; |
31 |
import gr.ebs.gss.client.commands.UploadFileCommand; |
32 |
import gr.ebs.gss.client.rest.resource.OtherUserResource; |
33 |
|
34 |
import com.google.gwt.resources.client.ClientBundle; |
35 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
36 |
import com.google.gwt.user.client.ui.MenuBar; |
37 |
import com.google.gwt.user.client.ui.MenuItem; |
38 |
import com.google.gwt.user.client.ui.PopupPanel; |
39 |
import com.google.gwt.user.client.ui.TreeItem; |
40 |
|
41 |
/**
|
42 |
* The 'Folder Context' menu implementation.
|
43 |
*/
|
44 |
public class FolderContextMenu extends PopupPanel { |
45 |
|
46 |
/**
|
47 |
* The widget's images.
|
48 |
*/
|
49 |
private final Images images; |
50 |
|
51 |
/**
|
52 |
* The image bundle for this widget's images that reuses images defined in
|
53 |
* other menus.
|
54 |
*/
|
55 |
public interface Images extends ClientBundle,FileMenu.Images, EditMenu.Images { |
56 |
} |
57 |
|
58 |
private MenuItem pasteItem; |
59 |
|
60 |
/**
|
61 |
* The widget's constructor.
|
62 |
*
|
63 |
* @param newImages the image bundle passed on by the parent object
|
64 |
*/
|
65 |
public FolderContextMenu(final Images newImages) { |
66 |
// The popup's constructor's argument is a boolean specifying that it
|
67 |
// auto-close itself when the user clicks outside of it.
|
68 |
super(true); |
69 |
setAnimationEnabled(true);
|
70 |
images = newImages; |
71 |
|
72 |
pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + " Paste</span>", true, new PasteCommand(this)); |
73 |
MenuBar contextMenu = new MenuBar(true); |
74 |
Folders folders = GSS.get().getFolders(); |
75 |
TreeItem selectedItem = folders.getCurrent(); |
76 |
|
77 |
|
78 |
if(selectedItem != null) |
79 |
if(folders.isTrashItem(selectedItem)){
|
80 |
if (folders.isTrash(selectedItem)){
|
81 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Empty Trash</span>", true, new EmptyTrashCommand(this)); |
82 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
83 |
} |
84 |
else {
|
85 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Restore folder and contents</span>", true, new RestoreTrashCommand(this)); |
86 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages)); |
87 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
88 |
} |
89 |
} |
90 |
else if(folders.isFileItem(selectedItem)){ |
91 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images)); |
92 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this)); |
93 |
boolean notRootFolder = !folders.getRootItem().equals(selectedItem);
|
94 |
if (notRootFolder) {
|
95 |
// do not show the copy & cut option for the user's root folder
|
96 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this)); |
97 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this)); |
98 |
} |
99 |
contextMenu.addItem(pasteItem); |
100 |
if (notRootFolder) {
|
101 |
// do not show delete options for the user's root folder
|
102 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this)); |
103 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages)); |
104 |
} |
105 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
106 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, newImages, 1)); |
107 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, newImages, 0)); |
108 |
} |
109 |
else if(!folders.isMyShares(selectedItem) && folders.isMySharedItem(selectedItem)){ |
110 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images)); |
111 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this)); |
112 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this)); |
113 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this)); |
114 |
contextMenu.addItem(pasteItem); |
115 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this)); |
116 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages)); |
117 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
118 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, newImages, 1)); |
119 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, newImages, 0)); |
120 |
} |
121 |
else if(!folders.isOthersShared(selectedItem) && folders.isOthersSharedItem(selectedItem) && !(GSS.get().getCurrentSelection() instanceof OtherUserResource)){ |
122 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images)); |
123 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this)); |
124 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this)); |
125 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this)); |
126 |
contextMenu.addItem(pasteItem); |
127 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this)); |
128 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages)); |
129 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
130 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, newImages, 1)); |
131 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, newImages, 0)); |
132 |
} else if(!selectedItem.equals(folders.getSharesItem())) |
133 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
134 |
add(contextMenu); |
135 |
if (GSS.get().getClipboard().hasFolderOrFileItem())
|
136 |
pasteItem.setVisible(true);
|
137 |
else
|
138 |
pasteItem.setVisible(false);
|
139 |
} |
140 |
|
141 |
} |