root / web_client / src / gr / grnet / pithos / web / client / EditMenu.java @ 58777026
History | View | Annotate | Download (9 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.CopyCommand; |
38 |
import gr.grnet.pithos.web.client.commands.CutCommand; |
39 |
import gr.grnet.pithos.web.client.commands.DeleteCommand; |
40 |
import gr.grnet.pithos.web.client.commands.PasteCommand; |
41 |
import gr.grnet.pithos.web.client.commands.ToTrashCommand; |
42 |
import gr.grnet.pithos.web.client.rest.resource.FileResource; |
43 |
|
44 |
import gr.grnet.pithos.web.client.rest.resource.GroupUserResource; |
45 |
import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper; |
46 |
|
47 |
import java.util.List; |
48 |
|
49 |
import com.google.gwt.event.dom.client.ClickEvent; |
50 |
import com.google.gwt.event.dom.client.ClickHandler; |
51 |
import com.google.gwt.resources.client.ClientBundle; |
52 |
import com.google.gwt.resources.client.ImageResource; |
53 |
import com.google.gwt.user.client.Command; |
54 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
55 |
import com.google.gwt.user.client.ui.MenuBar; |
56 |
import com.google.gwt.user.client.ui.MenuItem; |
57 |
import com.google.gwt.user.client.ui.PopupPanel; |
58 |
|
59 |
/**
|
60 |
* The 'Edit' menu implementation.
|
61 |
*/
|
62 |
public class EditMenu extends PopupPanel implements ClickHandler { |
63 |
|
64 |
/**
|
65 |
* The widget's images.
|
66 |
*/
|
67 |
private final Images images; |
68 |
|
69 |
private final MenuBar contextMenu = new MenuBar(true); |
70 |
|
71 |
/**
|
72 |
* An image bundle for this widget's images.
|
73 |
*/
|
74 |
public interface Images extends ClientBundle, FileMenu.Images, MessagePanel.Images { |
75 |
|
76 |
/**
|
77 |
* Will bundle the file 'editcut.png' residing in the package
|
78 |
* 'gr.grnet.pithos.web.resources'.
|
79 |
*
|
80 |
* @return the image prototype
|
81 |
*/
|
82 |
@Source("gr/grnet/pithos/resources/editcut.png") |
83 |
ImageResource cut(); |
84 |
|
85 |
/**
|
86 |
* Will bundle the file 'editcopy.png' residing in the package
|
87 |
* 'gr.grnet.pithos.web.resources'.
|
88 |
*
|
89 |
* @return the image prototype
|
90 |
*/
|
91 |
@Source("gr/grnet/pithos/resources/editcopy.png") |
92 |
ImageResource copy(); |
93 |
|
94 |
/**
|
95 |
* Will bundle the file 'editpaste.png' residing in the package
|
96 |
* 'gr.grnet.pithos.web.resources'.
|
97 |
*
|
98 |
* @return the image prototype
|
99 |
*/
|
100 |
@Source("gr/grnet/pithos/resources/editpaste.png") |
101 |
ImageResource paste(); |
102 |
|
103 |
/**
|
104 |
* Will bundle the file 'editdelete.png' residing in the package
|
105 |
* 'gr.grnet.pithos.web.resources'.
|
106 |
*
|
107 |
* @return the image prototype
|
108 |
*/
|
109 |
@Override
|
110 |
@Source("gr/grnet/pithos/resources/editdelete.png") |
111 |
ImageResource delete(); |
112 |
|
113 |
/**
|
114 |
* Will bundle the file 'translate.png' residing in the package
|
115 |
* 'gr.grnet.pithos.web.resources'.
|
116 |
*
|
117 |
* @return the image prototype
|
118 |
*/
|
119 |
@Source("gr/grnet/pithos/resources/translate.png") |
120 |
ImageResource selectAll(); |
121 |
|
122 |
/**
|
123 |
* Will bundle the file 'border_remove.png' residing in the package
|
124 |
* 'gr.grnet.pithos.web.resources'.
|
125 |
*
|
126 |
* @return the image prototype
|
127 |
*/
|
128 |
@Source("gr/grnet/pithos/resources/border_remove.png") |
129 |
ImageResource unselectAll(); |
130 |
} |
131 |
|
132 |
/**
|
133 |
* The widget's constructor.
|
134 |
*
|
135 |
* @param newImages the image bundle passed on by the parent object
|
136 |
*/
|
137 |
public EditMenu(final Images newImages) { |
138 |
// The popup's constructor's argument is a boolean specifying that it
|
139 |
// auto-close itself when the user clicks outside of it.
|
140 |
super(true); |
141 |
setAnimationEnabled(true);
|
142 |
images = newImages; |
143 |
createMenu(); |
144 |
add(contextMenu); |
145 |
} |
146 |
|
147 |
@Override
|
148 |
public void onClick(ClickEvent event) { |
149 |
final EditMenu menu = new EditMenu(images); |
150 |
final int left = event.getRelativeElement().getAbsoluteLeft(); |
151 |
final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight(); |
152 |
menu.setPopupPosition(left, top); |
153 |
menu.show(); |
154 |
} |
155 |
|
156 |
public MenuBar createMenu() { |
157 |
contextMenu.clearItems(); |
158 |
contextMenu.setAutoOpen(false);
|
159 |
|
160 |
final Command selectAllCommand = new Command() { |
161 |
|
162 |
@Override
|
163 |
public void execute() { |
164 |
hide(); |
165 |
if(GSS.get().isFileListShowing())
|
166 |
GSS.get().getFileList().selectAllRows(); |
167 |
} |
168 |
}; |
169 |
final Command unselectAllCommand = new Command() { |
170 |
|
171 |
@Override
|
172 |
public void execute() { |
173 |
hide(); |
174 |
if(GSS.get().isFileListShowing())
|
175 |
GSS.get().getFileList().clearSelectedRows(); |
176 |
} |
177 |
}; |
178 |
|
179 |
boolean cutcopyVisible = GSS.get().getCurrentSelection() != null && (GSS.get().getCurrentSelection() instanceof RestResourceWrapper |
180 |
|| GSS.get().getCurrentSelection() instanceof FileResource || GSS .get().getCurrentSelection() instanceof GroupUserResource || GSS .get().getCurrentSelection() instanceof List); |
181 |
String cutLabel = "Cut"; |
182 |
String copyLabel ="Copy"; |
183 |
String pasteLabel = "Paste"; |
184 |
if(GSS.get().getCurrentSelection() != null) |
185 |
if(GSS.get().getCurrentSelection() instanceof RestResourceWrapper){ |
186 |
cutLabel = "Cut Folder";
|
187 |
copyLabel = "Copy Folder";
|
188 |
} |
189 |
else if(GSS.get().getCurrentSelection() instanceof FileResource){ |
190 |
cutLabel = "Cut File";
|
191 |
copyLabel = "Copy File";
|
192 |
} |
193 |
else if(GSS.get().getCurrentSelection() instanceof List){ |
194 |
cutLabel = "Cut Files";
|
195 |
copyLabel = "Copy Files";
|
196 |
} |
197 |
if(GSS.get().getClipboard().getItem() != null) |
198 |
if(GSS.get().getClipboard().getItem().getFile() != null) |
199 |
pasteLabel = "Paste File";
|
200 |
else if(GSS.get().getClipboard().getItem().getFiles() != null) |
201 |
pasteLabel = "Paste Files";
|
202 |
else if(GSS.get().getClipboard().getItem().getRestResourceWrapper() != null) |
203 |
pasteLabel = "Paste Folder";
|
204 |
MenuItem cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + " "+cutLabel+"</span>", true, new CutCommand(this)); |
205 |
cutItem.getElement().setId("topMenu.edit.cut");
|
206 |
contextMenu.addItem(cutItem).setVisible(cutcopyVisible); |
207 |
|
208 |
MenuItem copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.copy()).getHTML() + " "+copyLabel+"</span>", true, new CopyCommand(this)); |
209 |
copyItem.getElement().setId("topMenu.edit.copy");
|
210 |
contextMenu.addItem(copyItem).setVisible(cutcopyVisible); |
211 |
|
212 |
MenuItem pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " "+pasteLabel+"</span>", true, new PasteCommand(this)); |
213 |
pasteItem.getElement().setId("topMenu.edit.paste");
|
214 |
if (GSS.get().getClipboard().getItem() != null) |
215 |
if(GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() == null){ |
216 |
contextMenu.addItem(pasteItem); |
217 |
} |
218 |
else if(!GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() != null){ |
219 |
//do not show paste
|
220 |
} |
221 |
else if (GSS.get().getTreeView().getSelection() instanceof RestResourceWrapper){ |
222 |
contextMenu.addItem(pasteItem); |
223 |
} |
224 |
MenuItem moveToTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this)); |
225 |
moveToTrashItem.getElement().setId("topMenu.edit.moveToTrash");
|
226 |
contextMenu .addItem(moveToTrashItem) |
227 |
.setVisible(cutcopyVisible); |
228 |
|
229 |
MenuItem deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images)); |
230 |
deleteItem.getElement().setId("topMenu.edit.delete");
|
231 |
contextMenu .addItem(deleteItem) |
232 |
.setVisible(cutcopyVisible); |
233 |
|
234 |
MenuItem selectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.selectAll()).getHTML() + " Select All</span>", true, selectAllCommand); |
235 |
selectAllItem.getElement().setId("topMenu.edit.selectAll");
|
236 |
contextMenu.addItem(selectAllItem); |
237 |
|
238 |
MenuItem unSelectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect All</span>", true, unselectAllCommand); |
239 |
unSelectAllItem.getElement().setId("topMenu.edit.unSelectAll");
|
240 |
contextMenu.addItem(unSelectAllItem); |
241 |
return contextMenu;
|
242 |
} |
243 |
|
244 |
|
245 |
|
246 |
} |