Revision fad48f0d src/gr/grnet/pithos/web/client/FileMenu.java

b/src/gr/grnet/pithos/web/client/FileMenu.java
39 39
import gr.grnet.pithos.web.client.commands.PropertiesCommand;
40 40
import gr.grnet.pithos.web.client.commands.RefreshCommand;
41 41
import gr.grnet.pithos.web.client.commands.UploadFileCommand;
42
import gr.grnet.pithos.web.client.rest.RestCommand;
42
import gr.grnet.pithos.web.client.foldertree.File;
43
import gr.grnet.pithos.web.client.foldertree.Folder;
43 44
import gr.grnet.pithos.web.client.rest.resource.FileResource;
44
import gr.grnet.pithos.web.client.rest.resource.OtherUserResource;
45
import gr.grnet.pithos.web.client.rest.resource.OthersResource;
46
import gr.grnet.pithos.web.client.rest.resource.RestResource;
47
import gr.grnet.pithos.web.client.rest.resource.SharedResource;
48
import gr.grnet.pithos.web.client.rest.resource.TrashFolderResource;
49
import gr.grnet.pithos.web.client.rest.resource.TrashResource;
50 45

  
51 46
import java.util.List;
52 47

  
53 48
import com.google.gwt.event.dom.client.ClickEvent;
54 49
import com.google.gwt.event.dom.client.ClickHandler;
55
import com.google.gwt.http.client.URL;
56 50
import com.google.gwt.resources.client.ClientBundle;
57 51
import com.google.gwt.resources.client.ImageResource;
58 52
import com.google.gwt.user.client.Command;
59 53
import com.google.gwt.user.client.ui.AbstractImagePrototype;
60 54
import com.google.gwt.user.client.ui.MenuBar;
61 55
import com.google.gwt.user.client.ui.MenuItem;
62
import com.google.gwt.user.client.ui.PopupPanel;
63 56

  
64 57
/**
65 58
 * The 'File' menu implementation.
66 59
 */
67
public class FileMenu extends PopupPanel implements ClickHandler {
60
public class FileMenu extends MenuBar {
68 61

  
69 62
	/**
70 63
	 * The widget's images.
......
106 99
	 *
107 100
	 * @param _images the image bundle passed on by the parent object
108 101
	 */
109
	public FileMenu(final Images _images) {
110
		// The popup's constructor's argument is a boolean specifying that it
111
		// auto-close itself when the user clicks outside of it.
112
		super(true);
102
	public FileMenu(GSS _app, final Images _images) {
113 103
		setAnimationEnabled(true);
114 104
		images = _images;
115
		add(contextMenu);
116 105

  
106
        final Command downloadCmd = new Command() {
107

  
108
            @Override
109
            public void execute() {
110
                preDownloadCheck();
111
            }
112
        };
113

  
114
        Folder selectedFolder = _app.getFolderTreeView().getSelection();
115
        List<File> selectedFiles = _app.getFileList().getSelectedFiles();
116
        if (selectedFolder != null) {
117
		    MenuItem newFolderItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(null, selectedFolder, images));
118
		    addItem(newFolderItem);
119

  
120
//            MenuItem uploadItem = new MenuItem("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this, null));
121
//            addItem(uploadItem);
122
        }
123
        if (selectedFiles.size() == 1) {
124
//            String[] link = {"", ""};
125
//            createDownloadLink(link, false);
126
//
127
//            MenuItem downloadItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(images.download()).getHTML() + "&nbsp;Download" + link[1] + "</span>", true, downloadCmd);
128
//            addItem(downloadItem);
129
        }
130

  
131
//        MenuItem emptyTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(this));
132
//        emptyTrashItem.getElement().setId("topMenu.file.emptyTrash");
133
//        contextMenu.addItem(emptyTrashItem);
134

  
135
//        MenuItem refreshItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
136
//        refreshItem.getElement().setId("topMenu.file.refresh");
137
//        contextMenu.addItem(refreshItem);
138

  
139
//        MenuItem sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, images, 1));
140
//        sharingItem.getElement().setId("topMenu.file.sharing");
141
//        contextMenu.addItem(sharingItem)
142
//                       .setVisible(propertiesVisible);
143
//
144
//        MenuItem propertiesItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, images, 0));
145
//        propertiesItem.getElement().setId("topMenu.file.properties");
146
//        contextMenu.addItem(propertiesItem)
147
//                       .setVisible(propertiesVisible);
117 148
	}
118 149

  
119
	@Override
120
	public void onClick(ClickEvent event) {
121
		final FileMenu menu = new FileMenu(images);
122
		final int left = event.getRelativeElement().getAbsoluteLeft();
123
		final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
124
		menu.setPopupPosition(left, top);
125
		menu.show();
126

  
127
	}
128

  
129

  
130 150
	/**
131 151
	 * Do some validation before downloading a file.
132 152
	 */
......
175 195
		return "";
176 196
	}
177 197

  
178
	public MenuBar createMenu() {
179
		contextMenu.clearItems();
180
		contextMenu.setAutoOpen(false);
181
		final Command downloadCmd = new Command() {
182

  
183
			@Override
184
			public void execute() {
185
				hide();
186
				preDownloadCheck();
187
			}
188
		};
189
        CellTreeView treeView = GSS.get().getTreeView();
190
        if (treeView == null)
191
            return contextMenu;
192
		RestResource selectedItem = treeView.getSelection();
193
		boolean downloadVisible = GSS.get().getCurrentSelection() != null && GSS.get().getCurrentSelection() instanceof FileResource;
194
		boolean propertiesVisible = !(selectedItem != null && (selectedItem instanceof TrashResource || selectedItem instanceof TrashFolderResource || selectedItem instanceof SharedResource || selectedItem instanceof OthersResource || selectedItem instanceof OtherUserResource 
195
					//|| folders.isOthersShared(selectedItem) || selectedItem.getUserObject() instanceof GroupUserResource 
196
					|| GSS.get().getCurrentSelection() instanceof List));
197
		boolean newFolderVisible = !(selectedItem != null && (selectedItem instanceof TrashResource || selectedItem instanceof TrashFolderResource || selectedItem instanceof SharedResource || selectedItem instanceof OthersResource || selectedItem instanceof OtherUserResource));
198
		boolean uploadVisible = !(selectedItem != null && (selectedItem instanceof TrashResource || selectedItem instanceof TrashFolderResource || selectedItem instanceof SharedResource || selectedItem instanceof OthersResource || selectedItem instanceof OtherUserResource));
199
		if(newFolderVisible){
200
//			MenuItem newFolderItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
201
//			newFolderItem.getElement().setId("topMenu.file.newFolder");
202
//			contextMenu.addItem(newFolderItem);
203
		}
204
		if(uploadVisible){
205
			MenuItem uploadItem = new MenuItem("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this, null));
206
			contextMenu.addItem(uploadItem);
207
		}
208
		if (downloadVisible) {
209
			String[] link = {"", ""};
210
			createDownloadLink(link, false);
211
			
212
			MenuItem downloadItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(images.download()).getHTML() + "&nbsp;Download" + link[1] + "</span>", true, downloadCmd);
213
			contextMenu.addItem(downloadItem);
214
			
215
			createDownloadLink(link, true);
216
			
217
			MenuItem saveAsItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(images.download()).getHTML() + "&nbsp;Save As" + link[1] + "</span>", true, downloadCmd);			
218
			contextMenu.addItem(saveAsItem);
219
		}
220
		MenuItem emptyTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(this));
221
		emptyTrashItem.getElement().setId("topMenu.file.emptyTrash");
222
		contextMenu.addItem(emptyTrashItem);
223
		
224
		MenuItem refreshItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
225
		refreshItem.getElement().setId("topMenu.file.refresh");
226
		contextMenu.addItem(refreshItem);
227
		
228
		MenuItem sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, images, 1));
229
		sharingItem.getElement().setId("topMenu.file.sharing");
230
		contextMenu.addItem(sharingItem)
231
		   			.setVisible(propertiesVisible);
232
		
233
		MenuItem propertiesItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, images, 0));
234
		propertiesItem.getElement().setId("topMenu.file.properties");
235
		contextMenu.addItem(propertiesItem)
236
		   			.setVisible(propertiesVisible);
237
		return contextMenu;
238
	}
239

  
240 198
}

Also available in: Unified diff