root / gss / src / gr / ebs / gss / client / FileMenu.java @ 2b9d7d53
History | View | Annotate | Download (6.8 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.EmptyTrashCommand; |
22 |
import gr.ebs.gss.client.commands.NewFolderCommand; |
23 |
import gr.ebs.gss.client.commands.PropertiesCommand; |
24 |
import gr.ebs.gss.client.commands.UpdateFileCommand; |
25 |
import gr.ebs.gss.client.commands.UploadFileCommand; |
26 |
import gr.ebs.gss.client.domain.FileHeaderDTO; |
27 |
import gr.ebs.gss.client.domain.UserDTO; |
28 |
|
29 |
import com.google.gwt.user.client.Command; |
30 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
31 |
import com.google.gwt.user.client.ui.ClickListener; |
32 |
import com.google.gwt.user.client.ui.MenuBar; |
33 |
import com.google.gwt.user.client.ui.PopupPanel; |
34 |
import com.google.gwt.user.client.ui.TreeItem; |
35 |
import com.google.gwt.user.client.ui.Widget; |
36 |
|
37 |
/**
|
38 |
* The 'File' menu implementation.
|
39 |
*/
|
40 |
public class FileMenu extends PopupPanel implements ClickListener { |
41 |
|
42 |
/**
|
43 |
* The path info portion of the URL that provides the file download service.
|
44 |
*/
|
45 |
static final String FILE_DOWNLOAD_PATH = "/gss/fileDownload"; |
46 |
|
47 |
/**
|
48 |
* The widget's images.
|
49 |
*/
|
50 |
private final Images images; |
51 |
|
52 |
/**
|
53 |
* An image bundle for this widgets images.
|
54 |
*/
|
55 |
public interface Images extends FilePropertiesDialog.Images { |
56 |
|
57 |
/**
|
58 |
* Will bundle the file 'folder_new.png' residing in the package
|
59 |
* 'gr.ebs.gss.resources'.
|
60 |
*
|
61 |
* @return the image prototype
|
62 |
*/
|
63 |
@Resource("gr/ebs/gss/resources/folder_new.png") |
64 |
AbstractImagePrototype folderNew(); |
65 |
|
66 |
/**
|
67 |
* Will bundle the file 'filenew.png' residing in the package
|
68 |
* 'gr.ebs.gss.resources'.
|
69 |
*
|
70 |
* @return the image prototype
|
71 |
*/
|
72 |
@Resource("gr/ebs/gss/resources/filenew.png") |
73 |
AbstractImagePrototype fileNew(); |
74 |
|
75 |
/**
|
76 |
* Will bundle the file 'update.png' residing in the package
|
77 |
* 'gr.ebs.gss.resources'.
|
78 |
*
|
79 |
* @return the image prototype
|
80 |
*/
|
81 |
@Resource("gr/ebs/gss/resources/update.png") |
82 |
AbstractImagePrototype fileUpdate(); |
83 |
|
84 |
/**
|
85 |
* Will bundle the file 'view_text.png' residing in the package
|
86 |
* 'gr.ebs.gss.resources'.
|
87 |
*
|
88 |
* @return the image prototype
|
89 |
*/
|
90 |
@Resource("gr/ebs/gss/resources/view_text.png") |
91 |
AbstractImagePrototype viewText(); |
92 |
|
93 |
/**
|
94 |
* Will bundle the file 'download_manager.png' residing in the package
|
95 |
* 'gr.ebs.gss.resources'.
|
96 |
*
|
97 |
* @return the image prototype
|
98 |
*/
|
99 |
@Resource("gr/ebs/gss/resources/download_manager.png") |
100 |
AbstractImagePrototype download(); |
101 |
|
102 |
/**
|
103 |
* Will bundle the file 'trashcan_empty.png' residing in the package
|
104 |
* 'gr.ebs.gss.resources'.
|
105 |
*
|
106 |
* @return the image prototype
|
107 |
*/
|
108 |
@Resource("gr/ebs/gss/resources/trashcan_empty.png") |
109 |
AbstractImagePrototype emptyTrash(); |
110 |
} |
111 |
|
112 |
final MenuBar contextMenu = new MenuBar(true); |
113 |
|
114 |
/**
|
115 |
* The widget's constructor.
|
116 |
*
|
117 |
* @param _images the image bundle passed on by the parent object
|
118 |
*/
|
119 |
public FileMenu(final Images _images) { |
120 |
// The popup's constructor's argument is a boolean specifying that it
|
121 |
// auto-close itself when the user clicks outside of it.
|
122 |
super(true); |
123 |
setAnimationEnabled(true);
|
124 |
images = _images; |
125 |
// createMenu();
|
126 |
add(contextMenu); |
127 |
|
128 |
} |
129 |
|
130 |
/*
|
131 |
* (non-Javadoc)
|
132 |
*
|
133 |
* @see com.google.gwt.user.client.ui.ClickListener#onClick(com.google.gwt.user.client.ui.Widget)
|
134 |
*/
|
135 |
public void onClick(final Widget sender) { |
136 |
final FileMenu menu = new FileMenu(images); |
137 |
final int left = sender.getAbsoluteLeft(); |
138 |
final int top = sender.getAbsoluteTop() + sender.getOffsetHeight(); |
139 |
menu.setPopupPosition(left, top); |
140 |
|
141 |
menu.show(); |
142 |
} |
143 |
|
144 |
/**
|
145 |
* Do some validation before downloading a file.
|
146 |
*/
|
147 |
void preDownloadCheck() {
|
148 |
Object selection = GSS.get().getCurrentSelection();
|
149 |
if (selection == null || !(selection instanceof FileHeaderDTO)) { |
150 |
GSS.get().displayError("You have to select a file first");
|
151 |
return;
|
152 |
} |
153 |
} |
154 |
|
155 |
/**
|
156 |
* Create a download link for the respective menu item, if the currently
|
157 |
* selected object is a file.
|
158 |
*
|
159 |
* @param link a String array with two elements that is modified so that the
|
160 |
* first position contains the opening tag and the second one the
|
161 |
* closing tag
|
162 |
*/
|
163 |
void createDownloadLink(String[] link) { |
164 |
Object selection = GSS.get().getCurrentSelection();
|
165 |
if (selection != null && selection instanceof FileHeaderDTO) { |
166 |
FileHeaderDTO file = (FileHeaderDTO) selection; |
167 |
link[0] = "<a class='hidden-link' href='" + FileMenu.FILE_DOWNLOAD_PATH + "?userId=" + GSS.get().getCurrentUser().getId().toString() + "&fileId=" + file.getId() + "' target='_blank'>"; |
168 |
link[1] = "</a>"; |
169 |
} |
170 |
} |
171 |
|
172 |
public MenuBar createMenu() { |
173 |
contextMenu.clearItems(); |
174 |
contextMenu.setAutoOpen(false);
|
175 |
final Command downloadCmd = new Command() { |
176 |
|
177 |
public void execute() { |
178 |
hide(); |
179 |
preDownloadCheck(); |
180 |
} |
181 |
}; |
182 |
Folders folders = GSS.get().getFolders(); |
183 |
TreeItem selectedItem = folders.getCurrent(); |
184 |
boolean downloadVisible = GSS.get().getCurrentSelection() != null && GSS.get().getCurrentSelection() instanceof FileHeaderDTO; |
185 |
boolean propertiesNotVisible = selectedItem != null && (folders.isTrash(selectedItem) || folders.isMyShares(selectedItem) || folders.isOthersShared(selectedItem) || selectedItem.getUserObject() instanceof UserDTO); |
186 |
contextMenu.addItem("<span>" + images.folderNew().getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images)); |
187 |
contextMenu.addItem("<span>" + images.fileNew().getHTML() + " New File</span>", true, new UploadFileCommand(this)); |
188 |
contextMenu .addItem("<span>" + images.fileUpdate().getHTML() + " Update</span>", true, new UpdateFileCommand(this)) |
189 |
.setVisible(!propertiesNotVisible); |
190 |
contextMenu .addItem("<span>" + images.viewText().getHTML() + " Properties</span>", true, new PropertiesCommand(this, images)) |
191 |
.setVisible(!propertiesNotVisible); |
192 |
contextMenu.addItem("<span>" + images.emptyTrash().getHTML() + " Empty Trash</span>", true, new EmptyTrashCommand(this)); |
193 |
if (downloadVisible) {
|
194 |
|
195 |
String[] link = {"", ""}; |
196 |
createDownloadLink(link); |
197 |
contextMenu.addItem("<span>" + link[0] + images.download().getHTML() + " Download File" + link[1] + "</span>", true, downloadCmd); |
198 |
|
199 |
} |
200 |
return contextMenu;
|
201 |
} |
202 |
|
203 |
} |