root / web_client / src / gr / grnet / pithos / web / client / EditMenu.java @ f55cf326
History | View | Annotate | Download (7.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.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.foldertree.File; |
43 |
import gr.grnet.pithos.web.client.foldertree.Folder; |
44 |
|
45 |
import java.util.List; |
46 |
|
47 |
import com.google.gwt.resources.client.ClientBundle; |
48 |
import com.google.gwt.resources.client.ImageResource; |
49 |
import com.google.gwt.user.client.Command; |
50 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
51 |
import com.google.gwt.user.client.ui.MenuBar; |
52 |
import com.google.gwt.user.client.ui.MenuItem; |
53 |
|
54 |
/**
|
55 |
* The 'Edit' menu implementation.
|
56 |
*/
|
57 |
public class EditMenu extends MenuBar { |
58 |
|
59 |
/**
|
60 |
* The widget's images.
|
61 |
*/
|
62 |
private final Images images; |
63 |
|
64 |
/**
|
65 |
* An image bundle for this widget's images.
|
66 |
*/
|
67 |
public interface Images extends ClientBundle, FileMenu.Images, MessagePanel.Images { |
68 |
|
69 |
/**
|
70 |
* Will bundle the file 'editcut.png' residing in the package
|
71 |
* 'gr.grnet.pithos.web.resources'.
|
72 |
*
|
73 |
* @return the image prototype
|
74 |
*/
|
75 |
@Source("gr/grnet/pithos/resources/editcut.png") |
76 |
ImageResource cut(); |
77 |
|
78 |
/**
|
79 |
* Will bundle the file 'editcopy.png' residing in the package
|
80 |
* 'gr.grnet.pithos.web.resources'.
|
81 |
*
|
82 |
* @return the image prototype
|
83 |
*/
|
84 |
@Source("gr/grnet/pithos/resources/editcopy.png") |
85 |
ImageResource copy(); |
86 |
|
87 |
/**
|
88 |
* Will bundle the file 'editpaste.png' residing in the package
|
89 |
* 'gr.grnet.pithos.web.resources'.
|
90 |
*
|
91 |
* @return the image prototype
|
92 |
*/
|
93 |
@Source("gr/grnet/pithos/resources/editpaste.png") |
94 |
ImageResource paste(); |
95 |
|
96 |
/**
|
97 |
* Will bundle the file 'editdelete.png' residing in the package
|
98 |
* 'gr.grnet.pithos.web.resources'.
|
99 |
*
|
100 |
* @return the image prototype
|
101 |
*/
|
102 |
@Override
|
103 |
@Source("gr/grnet/pithos/resources/editdelete.png") |
104 |
ImageResource delete(); |
105 |
|
106 |
/**
|
107 |
* Will bundle the file 'translate.png' residing in the package
|
108 |
* 'gr.grnet.pithos.web.resources'.
|
109 |
*
|
110 |
* @return the image prototype
|
111 |
*/
|
112 |
@Source("gr/grnet/pithos/resources/translate.png") |
113 |
ImageResource selectAll(); |
114 |
|
115 |
/**
|
116 |
* Will bundle the file 'border_remove.png' residing in the package
|
117 |
* 'gr.grnet.pithos.web.resources'.
|
118 |
*
|
119 |
* @return the image prototype
|
120 |
*/
|
121 |
@Source("gr/grnet/pithos/resources/border_remove.png") |
122 |
ImageResource unselectAll(); |
123 |
} |
124 |
|
125 |
/**
|
126 |
* The widget's constructor.
|
127 |
*
|
128 |
* @param newImages the image bundle passed on by the parent object
|
129 |
*/
|
130 |
public EditMenu(final Pithos _app, final Images newImages) { |
131 |
super(true); |
132 |
setAnimationEnabled(true);
|
133 |
images = newImages; |
134 |
|
135 |
Folder selectedFolder = _app.getFolderTreeView().getSelection(); |
136 |
List<File> selectedFiles = _app.getFileList().getSelectedFiles(); |
137 |
|
138 |
String cutLabel = "Cut"; |
139 |
String copyLabel ="Copy"; |
140 |
String pasteLabel = "Paste"; |
141 |
if(selectedFiles.size() == 1) { |
142 |
cutLabel = "Cut File";
|
143 |
copyLabel = "Copy File";
|
144 |
} |
145 |
else if (selectedFiles.size() > 1) { |
146 |
cutLabel = "Cut Files";
|
147 |
copyLabel = "Copy Files";
|
148 |
} |
149 |
else if (selectedFolder != null) { |
150 |
cutLabel = "Cut Folder";
|
151 |
copyLabel = "Copy Folder";
|
152 |
} |
153 |
|
154 |
if (_app.getClipboard().hasFiles()) {
|
155 |
if (((List<File>) _app.getClipboard().getItem()).size() > 1) |
156 |
pasteLabel = "Paste Files";
|
157 |
else
|
158 |
pasteLabel = "Paste File";
|
159 |
} |
160 |
else
|
161 |
pasteLabel = "Paste Folder";
|
162 |
|
163 |
if (selectedFiles.size() > 0 || selectedFolder != null) { |
164 |
Object cutObject = null; |
165 |
if (selectedFiles.size() > 0) |
166 |
cutObject = selectedFiles; |
167 |
else if (selectedFolder != null) |
168 |
cutObject = selectedFolder; |
169 |
|
170 |
if (selectedFiles.size() != 0 || (selectedFolder != null && !selectedFolder.isContainer())) { |
171 |
MenuItem cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + " " + cutLabel + "</span>", true, new CutCommand(_app, null, cutObject)); |
172 |
addItem(cutItem); |
173 |
} |
174 |
|
175 |
MenuItem copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.copy()).getHTML() + " "+copyLabel+"</span>", true, new CopyCommand(_app, null, cutObject)); |
176 |
addItem(copyItem); |
177 |
|
178 |
if (selectedFiles.size() != 0 || (selectedFolder != null && !selectedFolder.isContainer())) { |
179 |
MenuItem moveToTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(_app, null, cutObject)); |
180 |
addItem(moveToTrashItem); |
181 |
|
182 |
MenuItem deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(null, cutObject, images)); |
183 |
addItem(deleteItem); |
184 |
} |
185 |
} |
186 |
|
187 |
if (selectedFolder != null && !_app.getClipboard().isEmpty()) { |
188 |
MenuItem pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " " + pasteLabel + "</span>", true, new PasteCommand(_app, null, selectedFolder)); |
189 |
addItem(pasteItem); |
190 |
} |
191 |
|
192 |
|
193 |
MenuItem selectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.selectAll()).getHTML() + " Select All</span>", true, new Command() { |
194 |
|
195 |
@Override
|
196 |
public void execute() { |
197 |
_app.getFileList().selectAllRows(); |
198 |
} |
199 |
}); |
200 |
addItem(selectAllItem); |
201 |
|
202 |
MenuItem unSelectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect All</span>", true, new Command() { |
203 |
|
204 |
@Override
|
205 |
public void execute() { |
206 |
_app.getFileList().clearSelectedRows(); |
207 |
} |
208 |
}); |
209 |
addItem(unSelectAllItem); |
210 |
} |
211 |
} |