root / src / gr / ebs / gss / client / FolderContextMenu.java @ 66cbe681
History | View | Annotate | Download (7.5 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.user.client.ui.MenuBar; |
35 |
import com.google.gwt.user.client.ui.MenuItem; |
36 |
import com.google.gwt.user.client.ui.PopupPanel; |
37 |
import com.google.gwt.user.client.ui.TreeItem; |
38 |
|
39 |
/**
|
40 |
* The 'Folder Context' menu implementation.
|
41 |
*/
|
42 |
public class FolderContextMenu extends PopupPanel { |
43 |
|
44 |
/**
|
45 |
* The widget's images.
|
46 |
*/
|
47 |
private final Images images; |
48 |
|
49 |
/**
|
50 |
* The image bundle for this widget's images that reuses images defined in
|
51 |
* other menus.
|
52 |
*/
|
53 |
public interface Images extends FileMenu.Images, EditMenu.Images { |
54 |
} |
55 |
|
56 |
private MenuItem pasteItem; |
57 |
|
58 |
/**
|
59 |
* The widget's constructor.
|
60 |
*
|
61 |
* @param newImages the image bundle passed on by the parent object
|
62 |
*/
|
63 |
public FolderContextMenu(final Images newImages) { |
64 |
// The popup's constructor's argument is a boolean specifying that it
|
65 |
// auto-close itself when the user clicks outside of it.
|
66 |
super(true); |
67 |
setAnimationEnabled(true);
|
68 |
images = newImages; |
69 |
|
70 |
pasteItem = new MenuItem("<span>" + newImages.paste().getHTML() + " Paste</span>", true, new PasteCommand(this)); |
71 |
MenuBar contextMenu = new MenuBar(true); |
72 |
Folders folders = GSS.get().getFolders(); |
73 |
TreeItem selectedItem = folders.getCurrent(); |
74 |
|
75 |
|
76 |
if(selectedItem != null) |
77 |
if(folders.isTrashItem(selectedItem)){
|
78 |
if (folders.isTrash(selectedItem)){
|
79 |
contextMenu.addItem("<span>" + newImages.delete().getHTML() + " Empty Trash</span>", true, new EmptyTrashCommand(this)); |
80 |
contextMenu.addItem("<span>" + images.refresh().getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
81 |
} |
82 |
else {
|
83 |
contextMenu.addItem("<span>" + newImages.viewText().getHTML() + " Restore folder and contents</span>", true, new RestoreTrashCommand(this)); |
84 |
contextMenu.addItem("<span>" + newImages.delete().getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages)); |
85 |
contextMenu.addItem("<span>" + images.refresh().getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
86 |
} |
87 |
} |
88 |
else if(folders.isFileItem(selectedItem)){ |
89 |
contextMenu.addItem("<span>" + newImages.folderNew().getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images)); |
90 |
contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + " Upload</span>", true, new UploadFileCommand(this)); |
91 |
boolean notRootFolder = !folders.getRootItem().equals(selectedItem);
|
92 |
if (notRootFolder) {
|
93 |
// do not show the copy & cut option for the user's root folder
|
94 |
contextMenu.addItem("<span>" + newImages.cut().getHTML() + " Cut</span>", true, new CutCommand(this)); |
95 |
contextMenu.addItem("<span>" + newImages.copy().getHTML() + " Copy</span>", true, new CopyCommand(this)); |
96 |
} |
97 |
contextMenu.addItem(pasteItem); |
98 |
if (notRootFolder) {
|
99 |
// do not show delete options for the user's root folder
|
100 |
contextMenu.addItem("<span>" + newImages.emptyTrash().getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this)); |
101 |
contextMenu.addItem("<span>" + newImages.delete().getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages)); |
102 |
} |
103 |
contextMenu.addItem("<span>" + images.refresh().getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
104 |
contextMenu.addItem("<span>" + newImages.sharing().getHTML() + " Sharing</span>", true, new PropertiesCommand(this, newImages, 1)); |
105 |
contextMenu.addItem("<span>" + newImages.viewText().getHTML() + " Properties</span>", true, new PropertiesCommand(this, newImages, 0)); |
106 |
} |
107 |
else if(!folders.isMyShares(selectedItem) && folders.isMySharedItem(selectedItem)){ |
108 |
contextMenu.addItem("<span>" + newImages.folderNew().getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images)); |
109 |
contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + " Upload</span>", true, new UploadFileCommand(this)); |
110 |
contextMenu.addItem("<span>" + newImages.cut().getHTML() + " Cut</span>", true, new CutCommand(this)); |
111 |
contextMenu.addItem("<span>" + newImages.copy().getHTML() + " Copy</span>", true, new CopyCommand(this)); |
112 |
contextMenu.addItem(pasteItem); |
113 |
contextMenu.addItem("<span>" + newImages.emptyTrash().getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this)); |
114 |
contextMenu.addItem("<span>" + newImages.delete().getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages)); |
115 |
contextMenu.addItem("<span>" + images.refresh().getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
116 |
contextMenu.addItem("<span>" + newImages.viewText().getHTML() + " Properties</span>", true, new PropertiesCommand(this, newImages, 0)); |
117 |
} |
118 |
else if(!folders.isOthersShared(selectedItem) && folders.isOthersSharedItem(selectedItem) && !(GSS.get().getCurrentSelection() instanceof OtherUserResource)){ |
119 |
contextMenu.addItem("<span>" + newImages.folderNew().getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images)); |
120 |
contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + " Upload</span>", true, new UploadFileCommand(this)); |
121 |
contextMenu.addItem("<span>" + newImages.cut().getHTML() + " Cut</span>", true, new CutCommand(this)); |
122 |
contextMenu.addItem("<span>" + newImages.copy().getHTML() + " Copy</span>", true, new CopyCommand(this)); |
123 |
contextMenu.addItem(pasteItem); |
124 |
contextMenu.addItem("<span>" + newImages.emptyTrash().getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this)); |
125 |
contextMenu.addItem("<span>" + newImages.delete().getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages)); |
126 |
contextMenu.addItem("<span>" + images.refresh().getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
127 |
contextMenu.addItem("<span>" + newImages.viewText().getHTML() + " Properties</span>", true, new PropertiesCommand(this, newImages, 0)); |
128 |
} else if(!selectedItem.equals(folders.getSharesItem())) |
129 |
contextMenu.addItem("<span>" + images.refresh().getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
130 |
add(contextMenu); |
131 |
if (GSS.get().getClipboard().hasFolderOrFileItem())
|
132 |
pasteItem.setVisible(true);
|
133 |
else
|
134 |
pasteItem.setVisible(false);
|
135 |
} |
136 |
|
137 |
} |