Revision e3f47376

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
}
b/web_client/src/gr/grnet/pithos/web/client/TopPanel.java
91 91
	}
92 92

  
93 93
	/**
94
	 * The menu bar widget.
95
	 */
96
	private MenuBar menu;
97

  
98
	/**
99
	 * The file menu widget.
100
	 */
101
	private FileMenu fileMenu;
102

  
103
	/**
104
	 * The edit menu widget.
105
	 */
106
	private EditMenu editMenu;
107

  
108
	/**
109 94
	 * A widget that displays a message indicating that communication with the
110 95
	 * server is underway.
111 96
	 */
......
117 102
	 * @param images the supplied images
118 103
	 */
119 104
	public TopPanel(final Images images) {
120
		editMenu = new EditMenu(images);
121 105
		loading = new LoadingIndicator(images);
122 106
        loading.hide();
123 107
		HorizontalPanel outer = new HorizontalPanel();
124 108

  
125 109
		outer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
126 110

  
127
		menu = new MenuBar();
111
		MenuBar menu = new MenuBar();
128 112
		menu.setWidth("100%");
129 113
		menu.setAutoOpen(false);
130 114
		menu.setAnimationEnabled(true);
......
152 136
					AbstractImagePrototype.create(images.edit()).getHTML() + "</td><td>Edit</td></tr></table>", true, new MenuBar(true)){
153 137
			@Override
154 138
			public MenuBar getSubMenu() {
155
				return editMenu.createMenu();
139
				return new EditMenu(GSS.get(), images);
156 140
			}
157 141
		};
158 142

  
b/web_client/src/gr/grnet/pithos/web/client/commands/CopyCommand.java
61 61

  
62 62
	@Override
63 63
	public void execute() {
64
		containerPanel.hide();
64
        if (containerPanel != null)
65
		    containerPanel.hide();
65 66

  
66 67
		if (resource instanceof Folder) {
67 68
			app.getClipboard().setItem(Clipboard.COPY, (Folder) resource);
b/web_client/src/gr/grnet/pithos/web/client/commands/CutCommand.java
63 63

  
64 64
	@Override
65 65
	public void execute() {
66
		containerPanel.hide();
66
        if (containerPanel != null)
67
		    containerPanel.hide();
67 68

  
68 69
        if (resource instanceof Folder) {
69 70
            app.getClipboard().setItem(Clipboard.CUT, (Folder) resource);
b/web_client/src/gr/grnet/pithos/web/client/commands/DeleteCommand.java
74 74

  
75 75
	@Override
76 76
	public void execute() {
77
		containerPanel.hide();
77
        if (containerPanel != null)
78
    		containerPanel.hide();
78 79
		displayDelete();
79 80
	}
80 81
	/**
b/web_client/src/gr/grnet/pithos/web/client/commands/PasteCommand.java
64 64

  
65 65
	@Override
66 66
	public void execute() {
67
		containerPanel.hide();
67
        if (containerPanel != null)
68
    		containerPanel.hide();
69

  
68 70
        Object clipboardItem = app.getClipboard().getItem();
69 71
        if (clipboardItem == null)
70 72
            return;
b/web_client/src/gr/grnet/pithos/web/client/commands/ToTrashCommand.java
77 77

  
78 78
	@Override
79 79
	public void execute() {
80
		containerPanel.hide();
80
        if (containerPanel != null)
81
    		containerPanel.hide();
81 82
        if (resource instanceof List) {
82 83
            Iterator<File> iter = ((List<File>) resource).iterator();
83 84
            trashFiles(iter, new Command() {

Also available in: Unified diff