Revision e3f47376 web_client/src/gr/grnet/pithos/web/client/EditMenu.java

b/web_client/src/gr/grnet/pithos/web/client/EditMenu.java
39 39
import gr.grnet.pithos.web.client.commands.DeleteCommand;
40 40
import gr.grnet.pithos.web.client.commands.PasteCommand;
41 41
import gr.grnet.pithos.web.client.commands.ToTrashCommand;
42
import gr.grnet.pithos.web.client.foldertree.File;
42 43
import gr.grnet.pithos.web.client.foldertree.Folder;
43 44
import gr.grnet.pithos.web.client.rest.resource.FileResource;
44 45

  
......
60 61
/**
61 62
 * The 'Edit' menu implementation.
62 63
 */
63
public class EditMenu extends PopupPanel implements ClickHandler {
64
public class EditMenu extends MenuBar {
64 65

  
65 66
	/**
66 67
	 * The widget's images.
67 68
	 */
68 69
	private final Images images;
69 70

  
70
	private final MenuBar contextMenu  = new MenuBar(true);
71

  
72 71
	/**
73 72
	 * An image bundle for this widget's images.
74 73
	 */
......
135 134
	 *
136 135
	 * @param newImages the image bundle passed on by the parent object
137 136
	 */
138
	public EditMenu(final Images newImages) {
139
		// The popup's constructor's argument is a boolean specifying that it
140
		// auto-close itself when the user clicks outside of it.
137
	public EditMenu(final GSS _app, final Images newImages) {
141 138
		super(true);
142 139
		setAnimationEnabled(true);
143 140
		images = newImages;
144
		createMenu();
145
		add(contextMenu);
146
	}
147

  
148
	@Override
149
	public void onClick(ClickEvent event) {
150
		final EditMenu menu = new EditMenu(images);
151
		final int left = event.getRelativeElement().getAbsoluteLeft();
152
		final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
153
		menu.setPopupPosition(left, top);
154
		menu.show();
155
	}
156 141

  
157
	public MenuBar createMenu() {
158
		contextMenu.clearItems();
159
		contextMenu.setAutoOpen(false);
160

  
161
		final Command selectAllCommand = new Command() {
162

  
163
			@Override
164
			public void execute() {
165
				hide();
166
				if(GSS.get().isFileListShowing())
167
					GSS.get().getFileList().selectAllRows();
168
			}
169
		};
170
		final Command unselectAllCommand = new Command() {
171

  
172
			@Override
173
			public void execute() {
174
				hide();
175
				if(GSS.get().isFileListShowing())
176
					GSS.get().getFileList().clearSelectedRows();
177
			}
178
		};
179

  
180
		boolean cutcopyVisible = GSS.get().getCurrentSelection() != null && (GSS.get().getCurrentSelection() instanceof RestResourceWrapper
181
					|| GSS.get().getCurrentSelection() instanceof FileResource || GSS	.get().getCurrentSelection() instanceof GroupUserResource || GSS	.get().getCurrentSelection() instanceof List);
182
		String cutLabel = "Cut";
183
		String copyLabel ="Copy";
184
		String pasteLabel = "Paste";
185
		if(GSS.get().getCurrentSelection() != null)
186
			if(GSS.get().getCurrentSelection() instanceof RestResourceWrapper){
187
				cutLabel = "Cut Folder";
188
				copyLabel = "Copy Folder";
189
			}
190
			else if(GSS.get().getCurrentSelection() instanceof FileResource){
191
				cutLabel = "Cut File";
192
				copyLabel = "Copy File";
193
			}
194
			else if(GSS.get().getCurrentSelection() instanceof List){
195
				cutLabel = "Cut Files";
196
				copyLabel = "Copy Files";
197
			}
198
		if(GSS.get().getClipboard().getItem() != null)
199
			if(GSS.get().getClipboard().getItem() instanceof List) {
200
                if (((List) GSS.get().getClipboard().getItem()).size() > 1)
201
				    pasteLabel = "Paste Files";
202
                else
203
                    pasteLabel = "Paste File";
142
        Folder selectedFolder = _app.getFolderTreeView().getSelection();
143
        List<File> selectedFiles = _app.getFileList().getSelectedFiles();
144

  
145
        String cutLabel = "Cut";
146
        String copyLabel ="Copy";
147
        String pasteLabel = "Paste";
148
        if(selectedFiles.size() == 1) {
149
            cutLabel = "Cut File";
150
            copyLabel = "Copy File";
151
        }
152
        else if (selectedFiles.size() > 1) {
153
            cutLabel = "Cut Files";
154
            copyLabel = "Copy Files";
155
        }
156
        else if (selectedFolder != null) {
157
            cutLabel = "Cut Folder";
158
            copyLabel = "Copy Folder";
159
        }
160

  
161
        if (_app.getClipboard().hasFiles()) {
162
            if (((List<File>) _app.getClipboard().getItem()).size() > 1)
163
                pasteLabel = "Paste Files";
164
            else
165
                pasteLabel = "Paste File";
166
        }
167
        else
168
            pasteLabel = "Paste Folder";
169

  
170
        if (selectedFiles.size() > 0 || selectedFolder != null) {
171
            Object cutObject = null;
172
            if (selectedFiles.size() > 0)
173
                cutObject = selectedFiles;
174
            else if (selectedFolder != null)
175
                cutObject = selectedFolder;
176

  
177
            MenuItem cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + "&nbsp;" + cutLabel + "</span>", true, new CutCommand(_app, null, cutObject));
178
            addItem(cutItem);
179

  
180
            MenuItem copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.copy()).getHTML() + "&nbsp;"+copyLabel+"</span>", true, new CopyCommand(_app, null, cutObject));
181
            addItem(copyItem);
182

  
183
            MenuItem moveToTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(_app, null, cutObject));
184
            addItem(moveToTrashItem);
185

  
186
            MenuItem deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(null, cutObject, images));
187
            addItem(deleteItem);
188
        }
189

  
190
        if (selectedFolder != null && !_app.getClipboard().isEmpty()) {
191
            MenuItem pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + "&nbsp;" + pasteLabel + "</span>", true, new PasteCommand(_app, null, selectedFolder));
192
            addItem(pasteItem);
193
        }
194

  
195

  
196
        MenuItem selectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.selectAll()).getHTML() + "&nbsp;Select All</span>", true, new Command() {
197

  
198
            @Override
199
            public void execute() {
200
                _app.getFileList().selectAllRows();
204 201
            }
205
			else if(GSS.get().getClipboard().getItem() instanceof Folder)
206
				pasteLabel = "Paste Folder";
207
		MenuItem cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + "&nbsp;"+cutLabel+"</span>", true, new CutCommand(GSS.get(), this, null));
208
		cutItem.getElement().setId("topMenu.edit.cut");
209
		contextMenu.addItem(cutItem).setVisible(cutcopyVisible);
210
		
211
		MenuItem copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.copy()).getHTML() + "&nbsp;"+copyLabel+"</span>", true, new CopyCommand(GSS.get(), this, null));
212
		copyItem.getElement().setId("topMenu.edit.copy");
213
		contextMenu.addItem(copyItem).setVisible(cutcopyVisible);
214

  
215
		MenuItem pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + "&nbsp;"+pasteLabel+"</span>", true, new PasteCommand(GSS.get(), this, null));
216
		pasteItem.getElement().setId("topMenu.edit.paste");
217
		if (GSS.get().getClipboard().getItem() != null)
218
    		contextMenu.addItem(pasteItem);
219
		MenuItem moveToTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(GSS.get(), this, null));
220
		moveToTrashItem.getElement().setId("topMenu.edit.moveToTrash");
221
		contextMenu	.addItem(moveToTrashItem)
222
					.setVisible(cutcopyVisible);
223
		
224
		MenuItem deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, null, images));
225
		deleteItem.getElement().setId("topMenu.edit.delete");
226
		contextMenu	.addItem(deleteItem)
227
					.setVisible(cutcopyVisible);
228
		
229
		MenuItem selectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.selectAll()).getHTML() + "&nbsp;Select All</span>", true, selectAllCommand);
230
		selectAllItem.getElement().setId("topMenu.edit.selectAll");
231
		contextMenu.addItem(selectAllItem);
232
		
233
		MenuItem unSelectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + "&nbsp;Unselect All</span>", true, unselectAllCommand);
234
		unSelectAllItem.getElement().setId("topMenu.edit.unSelectAll");
235
		contextMenu.addItem(unSelectAllItem);
236
		return contextMenu;
237
	}
238

  
202
        });
203
        addItem(selectAllItem);
239 204

  
205
        MenuItem unSelectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + "&nbsp;Unselect All</span>", true, new Command() {
240 206

  
207
            @Override
208
            public void execute() {
209
                    _app.getFileList().clearSelectedRows();
210
            }
211
        });
212
        addItem(unSelectAllItem);
213
	}
241 214
}

Also available in: Unified diff