Revision 1e861a19 web_client/src/gr/grnet/pithos/web/client/FileMenu.java

b/web_client/src/gr/grnet/pithos/web/client/FileMenu.java
90 90

  
91 91
		@Source("gr/grnet/pithos/resources/refresh.png")
92 92
		ImageResource refresh();
93
}
94 93

  
95
	final MenuBar contextMenu = new MenuBar(true);
94
        @Source("gr/grnet/pithos/resources/")
95
        ImageResource unselectAll();
96
    }
96 97

  
97 98
	/**
98 99
	 * The widget's constructor.
......
100 101
	 * @param _images the image bundle passed on by the parent object
101 102
	 */
102 103
	public FileMenu(GSS _app, final Images _images) {
104
        super(true);
103 105
		setAnimationEnabled(true);
104 106
		images = _images;
105 107

  
106
        final Command downloadCmd = new Command() {
107

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

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

  
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);
114
            MenuItem uploadItem = new MenuItem("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(null, selectedFolder));
115
            addItem(uploadItem);
122 116
        }
123 117
        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);
118
            addItem(new MenuItem("<span><a class='hidden-link' href='" + GSS.get().getApiPath() + GSS.get().getUsername() + selectedFiles.get(0).getUri() + "?X-Auth-Token=" + GSS.get().getToken() + "' target='_blank'>" + AbstractImagePrototype.create(images.download()).getHTML() + " Download</a></span>", true, (Command) null));
129 119
        }
130 120

  
131 121
//        MenuItem emptyTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(this));
......
146 136
//        contextMenu.addItem(propertiesItem)
147 137
//                       .setVisible(propertiesVisible);
148 138
	}
149

  
150
	/**
151
	 * Do some validation before downloading a file.
152
	 */
153
	void preDownloadCheck() {
154
		Object selection = GSS.get().getCurrentSelection();
155
		if (selection == null || !(selection instanceof FileResource)) {
156
			GSS.get().displayError("You have to select a file first");
157
			return;
158
		}
159
	}
160

  
161
	/**
162
	 * Create a download link for the respective menu item, if the currently
163
	 * selected object is a file.
164
	 *
165
	 * @param link a String array with two elements that is modified so that the
166
	 *            first position contains the opening tag and the second one the
167
	 *            closing tag
168
	 * @param forceDownload If true, link will be such that browser should ask for filename
169
	 * 				and save location
170
	 */
171
	void createDownloadLink(String[] link, boolean forceDownload) {
172
		String downloadURL = getDownloadURL();
173
		if (!downloadURL.isEmpty()) {
174
			link[0] = "<a class='hidden-link' href='" + downloadURL
175
					+ (forceDownload ? "&dl=1" : "") + "' target='_blank'>";
176
			link[1] = "</a>";
177
		}
178
	}
179

  
180
	public String getDownloadURL() {
181
		GSS app = GSS.get();
182
		Object selection = app.getCurrentSelection();
183
		if (selection != null && selection instanceof FileResource) {
184
			FileResource file = (FileResource) selection;
185
			return getDownloadURL(file);
186
		}
187
		return "";
188
	}
189

  
190
	public String getDownloadURL(FileResource file) {
191
		GSS app = GSS.get();
192
		if (file != null) {
193
			return file.getUri();
194
		}
195
		return "";
196
	}
197

  
198 139
}

Also available in: Unified diff