Revision 50326f36

b/web_client/src/gr/grnet/pithos/web/client/AbstractPropertiesDialog.java
176 176
		GSS.preventIESelection();
177 177
		hide();
178 178
	}
179

  
180 179
}
b/web_client/src/gr/grnet/pithos/web/client/EditMenu.java
174 174
            else if (selectedFolder != null)
175 175
                cutObject = selectedFolder;
176 176

  
177
            MenuItem cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + "&nbsp;" + cutLabel + "</span>", true, new CutCommand(_app, null, cutObject));
178
            addItem(cutItem);
177
            if (selectedFiles.size() != 0 || (selectedFolder != null && !selectedFolder.isContainer())) {
178
                MenuItem cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + "&nbsp;" + cutLabel + "</span>", true, new CutCommand(_app, null, cutObject));
179
                addItem(cutItem);
180
            }
179 181

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

  
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
            if (selectedFiles.size() != 0 || (selectedFolder != null && !selectedFolder.isContainer())) {
186
                MenuItem moveToTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(_app, null, cutObject));
187
                addItem(moveToTrashItem);
185 188

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

  
190 194
        if (selectedFolder != null && !_app.getClipboard().isEmpty()) {
b/web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java
170 170
//			sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, images, 1));
171 171
//            contextMenu.addItem(sharingItem);
172 172

  
173
//			propItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, images, 0));
174
//            contextMenu.addItem(propItem);
173
            contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(GSS.get(), this, selectedFiles, images, 0)));
175 174

  
176 175
			contextMenu.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(newImages.download()).getHTML() + " Download</a></span>", true, (Command) null));
177 176

  
b/web_client/src/gr/grnet/pithos/web/client/FileMenu.java
131 131
//        contextMenu.addItem(sharingItem)
132 132
//                       .setVisible(propertiesVisible);
133 133
//
134
//        MenuItem propertiesItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, images, 0));
135
//        propertiesItem.getElement().setId("topMenu.file.properties");
136
//        contextMenu.addItem(propertiesItem)
137
//                       .setVisible(propertiesVisible);
134
        if (selectedFiles.size() > 0) {
135
            MenuItem propertiesItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(GSS.get(), null, selectedFiles, images, 0));
136
            addItem(propertiesItem);
137
        }
138 138
	}
139 139
}
b/web_client/src/gr/grnet/pithos/web/client/FilePropertiesDialog.java
34 34
 */
35 35
package gr.grnet.pithos.web.client;
36 36

  
37
import com.google.gwt.core.client.Scheduler;
38
import gr.grnet.pithos.web.client.foldertree.File;
39
import gr.grnet.pithos.web.client.foldertree.Resource;
37 40
import gr.grnet.pithos.web.client.rest.PostCommand;
41
import gr.grnet.pithos.web.client.rest.PostRequest;
42
import gr.grnet.pithos.web.client.rest.PutRequest;
38 43
import gr.grnet.pithos.web.client.rest.RestException;
39 44
import gr.grnet.pithos.web.client.rest.resource.FileResource;
40 45
import gr.grnet.pithos.web.client.rest.resource.GroupResource;
......
79 84
 */
80 85
public class FilePropertiesDialog extends AbstractPropertiesDialog {
81 86

  
82
	final PermissionsList permList;
87
	private PermissionsList permList;
83 88

  
84 89
	private CheckBox readForAll;
85 90

  
......
111 116

  
112 117
	private final CheckBox versioned = new CheckBox();
113 118

  
114
	final FileResource file;
119
	final File file;
115 120

  
116 121
	private String userFullName;
117 122

  
123
    private GSS app;
124

  
118 125
	/**
119 126
	 * The widget's constructor.
120
	 *
121
	 * @param images the dialog's ImageBundle
122
	 * @param groups
123
	 * @param bodies
124 127
	 */
125
	public FilePropertiesDialog(final Images images, final List<GroupResource> groups, List<FileResource> bodies, String _userFullName) {
128
	public FilePropertiesDialog(GSS _app, File _file) {
129
        app = _app;
130
        file = _file;
126 131

  
127 132
		// Set the dialog's caption.
128 133
		setText("File properties");
129 134

  
130
		file = (FileResource) GSS.get().getCurrentSelection();
131
		userFullName = _userFullName;
132
		permList = new PermissionsList(images, file.getPermissions(), file.getOwner());
133 135

  
134
		GWT.log("FILE PERMISSIONS:"+file.getPermissions());
136
//		permList = new PermissionsList(images, file.getPermissions(), file.getOwner());
137

  
135 138
		// Outer contains inner and buttons.
136 139
		final VerticalPanel outer = new VerticalPanel();
137 140
		final FocusPanel focusPanel = new FocusPanel(outer);
138 141
		// Inner contains generalPanel and permPanel.
139 142
		inner = new DecoratedTabPanel();
140 143
		inner.setAnimationEnabled(true);
141
		final VerticalPanel generalPanel = new VerticalPanel();
142
		final VerticalPanel permPanel = new VerticalPanel();
143
		final HorizontalPanel buttons = new HorizontalPanel();
144
		final HorizontalPanel permButtons = new HorizontalPanel();
145
		final HorizontalPanel permForAll = new HorizontalPanel();
146
		final HorizontalPanel pathPanel = new HorizontalPanel();
147
		final VerticalPanel verPanel = new VerticalPanel();
148
		final HorizontalPanel vPanel = new HorizontalPanel();
149
		final HorizontalPanel vPanel2 = new HorizontalPanel();
150

  
151
		versioned.setValue(file.isVersioned());
152
		versioned.getElement().setId("filePropertiesDialog.chechBox.versioned");
153
		inner.add(generalPanel, "General");
154
		inner.add(permPanel, "Sharing");
155
		inner.add(verPanel, "Versions");
156
		inner.selectTab(0);
157

  
158
		final Label fileNameNote = new Label("Please note that slashes ('/') are not allowed in file names.", true);
159
		fileNameNote.setVisible(false);
160
		fileNameNote.setStylePrimaryName("pithos-readForAllNote");
161

  
162
		final FlexTable generalTable = new FlexTable();
163
		generalTable.setText(0, 0, "Name");
164
		generalTable.setText(1, 0, "Folder");
165
		generalTable.setText(2, 0, "Owner");
166
		generalTable.setText(3, 0, "Last modified");
167
		generalTable.setText(4, 0, "Tags");
168
		name.setWidth("100%");
169
		name.setText(file.getName());
170
		name.getElement().setId("filePropertiesDialog.textBox.name");
171
		generalTable.setWidget(0, 1, name);
172
		name.addChangeHandler(new ChangeHandler() {
173 144

  
174
			@Override
175
			public void onChange(ChangeEvent event) {
176
				if(name.getText().contains("/"))
177
					fileNameNote.setVisible(true);
178
				else
179
					fileNameNote.setVisible(false);
180 145

  
181
			}
182
		});
146
        inner.add(createGeneralPanel(), "General");
183 147

  
184
		if(file.getFolderName() != null)
185
			generalTable.setText(1, 1, file.getFolderName());
186
		else
187
			generalTable.setText(1, 1, "-");
188
		generalTable.setWidget(0, 2, fileNameNote);
189
		generalTable.setText(2, 1,userFullName);
148
        inner.add(createSharingPanel(), "Sharing");
190 149

  
191
		final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
192
		generalTable.setText(3, 1, formatter.format(file.getModificationDate()));
193
		// Get the tags.
194
		StringBuffer tagsBuffer = new StringBuffer();
195
		Iterator i = file.getTags().iterator();
196
		while (i.hasNext()) {
197
			String tag = (String) i.next();
198
			tagsBuffer.append(tag).append(", ");
199
		}
200
		if (tagsBuffer.length() > 1)
201
			tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1);
202
		initialTagText = tagsBuffer.toString();
203
		tags.setWidth("100%");
204
		tags.getElement().setId("filePropertiesDialog.textBox.tags");
205
		tags.setText(initialTagText);
206
		generalTable.setWidget(4, 1, tags);
207
		generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
208
		generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
209
		generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");
210
		generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels");
211
		generalTable.getFlexCellFormatter().setStyleName(4, 0, "props-labels");
212
		generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");
213
		generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");
214
		generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");
215
		generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values");
216
		generalTable.getFlexCellFormatter().setStyleName(4, 1, "props-values");
217
		generalTable.setCellSpacing(4);
150
        inner.add(createVersionPanel(), "Versions");
151

  
152
        inner.selectTab(0);
218 153

  
154
        outer.add(inner);
155

  
156
		final HorizontalPanel buttons = new HorizontalPanel();
219 157
		// Create the 'OK' button, along with a listener that hides the dialog
220 158
		// when the button is clicked.
221 159
		final Button ok = new Button("OK", new ClickHandler() {
222 160
			@Override
223 161
			public void onClick(ClickEvent event) {
224
				if(name.getText().contains("/"))
225
					fileNameNote.setVisible(true);
226
				else{
227
					fileNameNote.setVisible(false);
228
					accept();
229
					closeDialog();
230
				}		
162
				accept();
163
				closeDialog();
231 164
			}
232 165
		});
233
		ok.getElement().setId("filePropertiesDialog.button.ok");		
166

  
234 167
		buttons.add(ok);
235 168
		buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
236 169
		// Create the 'Cancel' button, along with a listener that hides the
......
241 174
				closeDialog();
242 175
			}
243 176
		});
244
		cancel.getElement().setId("filePropertiesDialog.button.cancel");
245 177
		buttons.add(cancel);
246 178
		buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
247 179
		buttons.setSpacing(8);
248 180
		buttons.addStyleName("pithos-TabPanelBottom");
249 181

  
250
		generalPanel.add(generalTable);
182
        outer.add(buttons);
183
        outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
184
        outer.addStyleName("pithos-TabPanelBottom");
185

  
186
        focusPanel.setFocus(true);
187
        setWidget(outer);
251 188

  
252 189
		// Asynchronously retrieve the tags defined by this user.
253 190
		DeferredCommand.addCommand(new Command() {
254 191

  
255 192
			@Override
256 193
			public void execute() {
257
				updateTags();
258
			}
259
		});
260

  
261
		DisclosurePanel allTags = new DisclosurePanel("All tags");
262
		allTagsContent = new FlowPanel();
263
		allTagsContent.setWidth("100%");
264
		allTags.setContent(allTagsContent);
265
		generalPanel.add(allTags);
266
		generalPanel.setSpacing(4);
267

  
268
		final Button add = new Button("Add Group", new ClickHandler() {
269
			@Override
270
			public void onClick(ClickEvent event) {
271
				PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, false);
272
				dlg.center();
273
			}
274
		});
275
		add.getElement().setId("filePropertiesDialog.button.addGroup");
276
		permButtons.add(add);
277
		permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER);
278

  
279
		final Button addUser = new Button("Add User", new ClickHandler() {
280
			@Override
281
			public void onClick(ClickEvent event) {
282
				PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, true);
283
				dlg.center();
284
			}
285
		});
286
		add.getElement().setId("filePropertiesDialog.button.addUser");
287
		permButtons.add(addUser);
288
		permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER);
289

  
290
		permButtons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
291
		permButtons.setSpacing(8);
292
		permButtons.addStyleName("pithos-TabPanelBottom");
293

  
294
		final Label readForAllNote = new Label("When this option is enabled, the file will be readable" +
295
					" by everyone. By checking this option, you are certifying that you have the right to " +
296
					"distribute this file and that it does not violate the Terms of Use.", true);
297
		readForAllNote.setVisible(false);
298
		readForAllNote.setStylePrimaryName("pithos-readForAllNote");
299

  
300
		readForAll = new CheckBox();
301
		readForAll.getElement().setId("filePropertiesDialog.checkBox.public");
302
		readForAll.setValue(file.isReadForAll());
303
		readForAll.addClickHandler(new ClickHandler() {
304
			@Override
305
			public void onClick(ClickEvent event) {
306
				readForAllNote.setVisible(readForAll.getValue());
307
			}
308

  
309
		});
310

  
311
		permPanel.add(permList);
312
		permPanel.add(permButtons);
313
		// Only show the read for all permission if the user is the owner.
314
		if (file.getOwner().equals(GSS.get().getCurrentUserResource().getUsername())) {
315
			permForAll.add(new Label("Public"));
316
			permForAll.add(readForAll);
317
			permForAll.setSpacing(8);
318
			permForAll.addStyleName("pithos-TabPanelBottom");
319
			permForAll.add(readForAllNote);
320
			permPanel.add(permForAll);
321
		}
322

  
323
		TextBox path = new TextBox();
324
		path.setWidth("100%");
325
		path.addClickHandler(new ClickHandler() {
326
			@Override
327
			public void onClick(ClickEvent event) {
328
				GSS.enableIESelection();
329
				((TextBox) event.getSource()).selectAll();
330
				GSS.preventIESelection();
331
			}
332

  
333
		});
334
		path.setText(file.getUri());
335
		path.getElement().setId("filePropertiesDialog.textBox.link");
336
		path.setTitle("Use this link for sharing the file via e-mail, IM, etc. (crtl-C/cmd-C to copy to system clipboard)");
337
		path.setWidth("100%");
338
		path.setReadOnly(true);
339
		pathPanel.setWidth("100%");
340
		pathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
341
		pathPanel.add(new Label("Link"));
342
		pathPanel.setSpacing(8);
343
		pathPanel.addStyleName("pithos-TabPanelBottom");
344
		pathPanel.add(path);
345
		permPanel.add(pathPanel);
346

  
347
		VersionsList verList = new VersionsList(this, images, bodies);
348
		verPanel.add(verList);
349

  
350
		vPanel.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
351
		vPanel.setSpacing(8);
352
		vPanel.addStyleName("pithos-TabPanelBottom");
353
		vPanel.add(new Label("Versioned"));
354

  
355
		vPanel.add(versioned);
356
		verPanel.add(vPanel);
357
		vPanel2.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
358
		vPanel2.setSpacing(8);
359
		vPanel2.addStyleName("pithos-TabPanelBottom");
360
		Button removeVersionsButton = new Button(AbstractImagePrototype.create(images.delete()).getHTML(), new ClickHandler() {
361
			@Override
362
			public void onClick(ClickEvent event) {
363
				ConfirmationDialog confirm = new ConfirmationDialog("Really " +
364
						"remove all previous versions?", "Remove") {
365

  
366
					@Override
367
					public void cancel() {
368
					}
369

  
370
					@Override
371
					public void confirm() {
372
						FilePropertiesDialog.this.closeDialog();
373
						removeAllOldVersions();
374
					}
375

  
376
				};
377
				confirm.center();
194
//				updateTags();
378 195
			}
379

  
380 196
		});
381
		HTML removeAllVersion = new HTML("<span>Remove all previous versions?</span>");
382
		vPanel2.add(removeAllVersion);
383
		vPanel2.add(removeVersionsButton);
384
		verPanel.add(vPanel2);
385
		if(!file.isVersioned())
386
			vPanel2.setVisible(false);
387
		outer.add(inner);
388
		outer.add(buttons);
389
		outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
390
		outer.addStyleName("pithos-TabPanelBottom");
391

  
392
		focusPanel.setFocus(true);
393
		setWidget(outer);
394 197
	}
395 198

  
199
    private VerticalPanel createGeneralPanel() {
200
        final VerticalPanel generalPanel = new VerticalPanel();
201
        final FlexTable generalTable = new FlexTable();
202
        generalTable.setText(0, 0, "Name");
203
        generalTable.setText(1, 0, "Folder");
204
        generalTable.setText(2, 0, "Owner");
205
        generalTable.setText(3, 0, "Last modified");
206
//        generalTable.setText(4, 0, "Tags");
207

  
208
        name.setWidth("100%");
209
        name.setText(file.getName());
210
        generalTable.setWidget(0, 1, name);
211
        if(file.getParent() != null)
212
            generalTable.setText(1, 1, file.getParent().getName());
213
        else
214
            generalTable.setText(1, 1, "-");
215
        generalTable.setText(2, 1, file.getOwner());
216

  
217
        final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
218
        generalTable.setText(3, 1, formatter.format(file.getLastModified()));
219

  
220
		// Get the tags.
221
//		StringBuffer tagsBuffer = new StringBuffer();
222
//		Iterator i = file.getTags().iterator();
223
//		while (i.hasNext()) {
224
//			String tag = (String) i.next();
225
//			tagsBuffer.append(tag).append(", ");
226
//		}
227
//		if (tagsBuffer.length() > 1)
228
//			tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1);
229
//		initialTagText = tagsBuffer.toString();
230
//		tags.setWidth("100%");
231
//		tags.getElement().setId("filePropertiesDialog.textBox.tags");
232
//		tags.setText(initialTagText);
233
//		generalTable.setWidget(4, 1, tags);
234

  
235
        generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
236
        generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
237
        generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");
238
        generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels");
239
//        generalTable.getFlexCellFormatter().setStyleName(4, 0, "props-labels");
240
        generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");
241
        generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");
242
        generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");
243
        generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values");
244
//        generalTable.getFlexCellFormatter().setStyleName(4, 1, "props-values");
245
        generalTable.setCellSpacing(4);
246

  
247
        generalPanel.add(generalTable);
248

  
249
        DisclosurePanel allTags = new DisclosurePanel("All tags");
250
        allTagsContent = new FlowPanel();
251
        allTagsContent.setWidth("100%");
252
        allTags.setContent(allTagsContent);
253
        generalPanel.add(allTags);
254
        generalPanel.setSpacing(4);
255
        return generalPanel;
256
    }
257

  
258
    private VerticalPanel createSharingPanel() {
259
        VerticalPanel permPanel = new VerticalPanel();
260
//
261
//        permList = new PermissionsList(images, file.getPermissions(), file.getOwner());
262
//        permPanel.add(permList);
263
//
264
//        HorizontalPanel permButtons = new HorizontalPanel();
265
//        Button add = new Button("Add Group", new ClickHandler() {
266
//            @Override
267
//            public void onClick(ClickEvent event) {
268
//                PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, false);
269
//                dlg.center();
270
//            }
271
//        });
272
//        permButtons.add(add);
273
//        permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER);
274
//
275
//        final Button addUser = new Button("Add User", new ClickHandler() {
276
//            @Override
277
//            public void onClick(ClickEvent event) {
278
//                PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, true);
279
//                dlg.center();
280
//            }
281
//        });
282
//        permButtons.add(addUser);
283
//        permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER);
284
//
285
//        permButtons.setSpacing(8);
286
//        permButtons.addStyleName("pithos-TabPanelBottom");
287
//        permPanel.add(permButtons);
288
//
289
//        final Label readForAllNote = new Label("When this option is enabled, the file will be readable" +
290
//                    " by everyone. By checking this option, you are certifying that you have the right to " +
291
//                    "distribute this file and that it does not violate the Terms of Use.", true);
292
//        readForAllNote.setVisible(false);
293
//        readForAllNote.setStylePrimaryName("pithos-readForAllNote");
294
//
295
//        readForAll = new CheckBox();
296
//        readForAll.setValue(file.isReadForAll());
297
//        readForAll.addClickHandler(new ClickHandler() {
298
//            @Override
299
//            public void onClick(ClickEvent event) {
300
//                readForAllNote.setVisible(readForAll.getValue());
301
//            }
302
//
303
//        });
304
//
305
//        // Only show the read for all permission if the user is the owner.
306
//        if (file.getOwner().equals(app.getUsername())) {
307
//            final HorizontalPanel permForAll = new HorizontalPanel();
308
//            permForAll.add(new Label("Public"));
309
//            permForAll.add(readForAll);
310
//            permForAll.setSpacing(8);
311
//            permForAll.addStyleName("pithos-TabPanelBottom");
312
//            permForAll.add(readForAllNote);
313
//            permPanel.add(permForAll);
314
//        }
315
//
316
//
317
//        final HorizontalPanel pathPanel = new HorizontalPanel();
318
//        pathPanel.setWidth("100%");
319
//        pathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
320
//        pathPanel.add(new Label("Link"));
321
//        pathPanel.setSpacing(8);
322
//        pathPanel.addStyleName("pithos-TabPanelBottom");
323
//
324
//        TextBox path = new TextBox();
325
//        path.setWidth("100%");
326
//        path.addClickHandler(new ClickHandler() {
327
//            @Override
328
//            public void onClick(ClickEvent event) {
329
//                GSS.enableIESelection();
330
//                ((TextBox) event.getSource()).selectAll();
331
//                GSS.preventIESelection();
332
//            }
333
//        });
334
//        path.setText(file.getUri());
335
//        path.setTitle("Use this link for sharing the file via e-mail, IM, etc. (crtl-C/cmd-C to copy to system clipboard)");
336
//        path.setWidth("100%");
337
//        path.setReadOnly(true);
338
//        pathPanel.add(path);
339
//        permPanel.add(pathPanel);
340

  
341
        return permPanel;
342
    }
343

  
344
    private VerticalPanel createVersionPanel() {
345
        VerticalPanel versionPanel = new VerticalPanel();
346

  
347
//        VersionsList verList = new VersionsList(this, images, bodies);
348
//        versionPanel.add(verList);
349
//
350
//        HorizontalPanel vPanel = new HorizontalPanel();
351
//
352
//		vPanel.setSpacing(8);
353
//		vPanel.addStyleName("pithos-TabPanelBottom");
354
//		vPanel.add(new Label("Versioned"));
355
//
356
//		versioned.setValue(file.isVersioned());
357
//		vPanel.add(versioned);
358
//		versionPanel.add(vPanel);
359
//
360
//        HorizontalPanel vPanel2 = new HorizontalPanel();
361
//		vPanel2.setSpacing(8);
362
//		vPanel2.addStyleName("pithos-TabPanelBottom");
363
//
364
//        HTML removeAllVersion = new HTML("<span>Remove all previous versions?</span>");
365
//        vPanel2.add(removeAllVersion);
366
//
367
//		Button removeVersionsButton = new Button(AbstractImagePrototype.create(images.delete()).getHTML(), new ClickHandler() {
368
//			@Override
369
//			public void onClick(ClickEvent event) {
370
//				ConfirmationDialog confirm = new ConfirmationDialog("Really " +
371
//						"remove all previous versions?", "Remove") {
372
//
373
//					@Override
374
//					public void cancel() {
375
//					}
376
//
377
//					@Override
378
//					public void confirm() {
379
//						FilePropertiesDialog.this.closeDialog();
380
//						removeAllOldVersions();
381
//					}
382
//
383
//				};
384
//				confirm.center();
385
//			}
386
//
387
//		});
388
//		vPanel2.add(removeVersionsButton);
389
//        if(!file.isVersioned())
390
//            vPanel2.setVisible(false);
391
//
392
//        versionPanel.add(vPanel2);
393

  
394
        return versionPanel;
395
    }
396 396

  
397 397
	/**
398 398
	 * Accepts any change and updates the file
......
401 401
	@Override
402 402
	protected void accept() {
403 403
		String newFilename = null;
404
		permList.updatePermissionsAccordingToInput();
405
		Set<PermissionHolder> perms = permList.getPermissions();
406
		JSONObject json = new JSONObject();
404
//		permList.updatePermissionsAccordingToInput();
405
//		Set<PermissionHolder> perms = permList.getPermissions();
406
//		JSONObject json = new JSONObject();
407 407
		if (!name.getText().equals(file.getName())) {
408 408
			newFilename = name.getText();
409
			json.put("name", new JSONString(newFilename));
409
//			json.put("name", new JSONString(newFilename));
410 410
		}
411
		if (versioned.getValue() != file.isVersioned())
412
			json.put("versioned", JSONBoolean.getInstance(versioned.getValue()));
411
//		if (versioned.getValue() != file.isVersioned())
412
//			json.put("versioned", JSONBoolean.getInstance(versioned.getValue()));
413 413
		//only update the read for all perm if the user is the owner
414
		if (readForAll.getValue() != file.isReadForAll())
415
			if (file.getOwner().equals(GSS.get().getCurrentUserResource().getUsername()))
416
				json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue()));
417
		int i = 0;
418
		if (permList.hasChanges()) {
419
			GWT.log("Permissions change", null);
420
			JSONArray perma = new JSONArray();
421

  
422
			for (PermissionHolder p : perms) {
423
				JSONObject po = new JSONObject();
424
				if (p.getUser() != null)
425
					po.put("user", new JSONString(p.getUser()));
426
				if (p.getGroup() != null)
427
					po.put("group", new JSONString(p.getGroup()));
428
				po.put("read", JSONBoolean.getInstance(p.isRead()));
429
				po.put("write", JSONBoolean.getInstance(p.isWrite()));
430
				po.put("modifyACL", JSONBoolean.getInstance(p.isModifyACL()));
431
				perma.set(i, po);
432
				i++;
433
			}
434
			json.put("permissions", perma);
435
		}
436
		JSONArray taga = new JSONArray();
437
		i = 0;
438
		if (!tags.getText().equals(initialTagText)) {
439
			String[] tagset = tags.getText().split(",");
440
			for (String t : tagset) {
441
				JSONString to = new JSONString(t);
442
				taga.set(i, to);
443
				i++;
444
			}
445
			json.put("tags", taga);
446
		}
447
		String jsonString = json.toString();
448
		if(jsonString.equals("{}")){
449
			GWT.log("NO CHANGES", null);
450
			return;
451
		}
414
//		if (readForAll.getValue() != file.isReadForAll())
415
//			if (file.getOwner().equals(GSS.get().getCurrentUserResource().getUsername()))
416
//				json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue()));
417
//		int i = 0;
418
//		if (permList.hasChanges()) {
419
//			GWT.log("Permissions change", null);
420
//			JSONArray perma = new JSONArray();
421
//
422
//			for (PermissionHolder p : perms) {
423
//				JSONObject po = new JSONObject();
424
//				if (p.getUser() != null)
425
//					po.put("user", new JSONString(p.getUser()));
426
//				if (p.getGroup() != null)
427
//					po.put("group", new JSONString(p.getGroup()));
428
//				po.put("read", JSONBoolean.getInstance(p.isRead()));
429
//				po.put("write", JSONBoolean.getInstance(p.isWrite()));
430
//				po.put("modifyACL", JSONBoolean.getInstance(p.isModifyACL()));
431
//				perma.set(i, po);
432
//				i++;
433
//			}
434
//			json.put("permissions", perma);
435
//		}
436
//		JSONArray taga = new JSONArray();
437
//		i = 0;
438
//		if (!tags.getText().equals(initialTagText)) {
439
//			String[] tagset = tags.getText().split(",");
440
//			for (String t : tagset) {
441
//				JSONString to = new JSONString(t);
442
//				taga.set(i, to);
443
//				i++;
444
//			}
445
//			json.put("tags", taga);
446
//		}
447
//		String jsonString = json.toString();
448
//		if(jsonString.equals("{}")){
449
//			GWT.log("NO CHANGES", null);
450
//			return;
451
//		}
452 452
		final String newFilenameFinal = newFilename;
453
		PostCommand cf = new PostCommand(file.getUri() + "?update=", jsonString, 200) {
454

  
455
			@Override
456
			public void onComplete() {
457
				GSS.get().getTreeView().refreshCurrentNode(false);
458
			}
459

  
460
			@Override
461
			public void onError(Throwable t) {
462
				GWT.log("", t);
463
				if (t instanceof RestException) {
464
					int statusCode = ((RestException) t).getHttpStatusCode();
465
					if (statusCode == 405)
466
						GSS.get().displayError("You don't have the necessary permissions");
467
					else if (statusCode == 404)
468
						GSS.get().displayError("User in permissions does not exist");
469
					else if (statusCode == 409)
470
						GSS.get().displayError("A file with the same name already exists");
471
					else if (statusCode == 413)
472
						GSS.get().displayError("Your quota has been exceeded");
473
					else
474
						GSS.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());
475
				} else
476
					GSS.get().displayError("System error modifying file:" + t.getMessage());
477
			}
478

  
479
		};
480
		DeferredCommand.addCommand(cf);
481 453

  
454
        if (newFilename == null)
455
            return;
456
        String path = app.getApiPath() + app.getUsername() + file.getParent().getUri() + "/" + newFilename;
457
        PutRequest updateFile = new PutRequest(path) {
458
            @Override
459
            public void onSuccess(Resource result) {
460
                app.updateFolder(file.getParent());
461
            }
462

  
463
            @Override
464
            public void onError(Throwable t) {
465
                GWT.log("", t);
466
                app.displayError("System error modifying file:" + t.getMessage());
467
            }
468
        };
469
        updateFile.setHeader("X-Auth-Token", app.getToken());
470
        updateFile.setHeader("X-Move-From", file.getUri());
471
        updateFile.setHeader("Content-Type", file.getContentType());
472
        Scheduler.get().scheduleDeferred(updateFile);
482 473
	}
483 474

  
484 475
	private void removeAllOldVersions() {
b/web_client/src/gr/grnet/pithos/web/client/commands/DeleteCommand.java
76 76
	public void execute() {
77 77
        if (containerPanel != null)
78 78
    		containerPanel.hide();
79
		displayDelete();
79

  
80
        if (resource instanceof Folder) {
81
            DeleteFolderDialog dlg = new DeleteFolderDialog(GSS.get(), newImages, (Folder) resource);
82
            dlg.center();
83
        } else if (resource instanceof List) {
84
            DeleteFileDialog dlg = new DeleteFileDialog(newImages, (List<File>) resource);
85
            dlg.center();
86
        }
80 87
	}
81
	/**
82
	 * Display the delete dialog, according to the selected object.
83
	 *
84
	 *
85
	 */
86
	void displayDelete() {
87
		if (resource instanceof Folder) {
88
			DeleteFolderDialog dlg = new DeleteFolderDialog(GSS.get(), newImages, (Folder) resource);
89
			dlg.center();
90
		} else if (resource instanceof List) {
91
			DeleteFileDialog dlg = new DeleteFileDialog(newImages, (List<File>) resource);
92
			dlg.center();
93
		}
94
    }
95 88
}
b/web_client/src/gr/grnet/pithos/web/client/commands/PropertiesCommand.java
40 40
import gr.grnet.pithos.web.client.FolderPropertiesDialog;
41 41
import gr.grnet.pithos.web.client.GSS;
42 42
import gr.grnet.pithos.web.client.FileMenu.Images;
43
import gr.grnet.pithos.web.client.foldertree.File;
44
import gr.grnet.pithos.web.client.foldertree.Folder;
43 45
import gr.grnet.pithos.web.client.rest.GetCommand;
44 46
import gr.grnet.pithos.web.client.rest.HeadCommand;
45 47
import gr.grnet.pithos.web.client.rest.MultipleGetCommand;
......
60 62
import com.google.gwt.user.client.DeferredCommand;
61 63
import com.google.gwt.user.client.IncrementalCommand;
62 64
import com.google.gwt.user.client.ui.PopupPanel;
65
import org.w3c.css.sac.ElementSelector;
63 66

  
64 67
/**
65 68
 * The command that displays the appropriate Properties dialog, according to the
......
80 83

  
81 84
	private String userName;
82 85

  
86
    private Object resource;
87

  
88
    private GSS app;
89

  
83 90
	/**
84 91
	 * @param _containerPanel
85 92
	 * @param _newImages the images of all the possible delete dialogs
86 93
	 * @param _tab the tab to switch to
87 94
	 */
88
	public PropertiesCommand(PopupPanel _containerPanel, final FileMenu.Images _newImages, int _tab) {
95
	public PropertiesCommand(GSS _app, PopupPanel _containerPanel, Object _resource, final FileMenu.Images _newImages, int _tab) {
89 96
		containerPanel = _containerPanel;
90 97
		newImages = _newImages;
91 98
		tabToShow = _tab;
99
        resource = _resource;
100
        app = _app;
92 101
	}
93 102

  
94 103
	@Override
95 104
	public void execute() {
96
		containerPanel.hide();
97
		if (GSS.get().getCurrentSelection() instanceof RestResourceWrapper) {
98
			GetCommand<FolderResource> eg = new GetCommand<FolderResource>(FolderResource.class, ((RestResourceWrapper) GSS.get().getCurrentSelection()).getUri(),((RestResourceWrapper) GSS.get().getCurrentSelection()).getResource()) {
99

  
100
				@Override
101
				public void onComplete() {
102
					((RestResourceWrapper) GSS.get().getCurrentSelection()).setResource(getResult());
103
					initialize();
104
				}
105

  
106
				@Override
107
				public void onError(Throwable t) {
108

  
109
				}
110

  
111
			};
112
			DeferredCommand.addCommand(eg);
113
		}
114
		else if (GSS.get().getCurrentSelection() instanceof FileResource) {
115
			final String path = ((FileResource) GSS.get().getCurrentSelection()).getUri();
116
			// Needed because firefox caches head requests.
117
			HeadCommand<FileResource> eg = new HeadCommand<FileResource>(FileResource.class, path+"?"+Math.random(), null ) {
118

  
119
				@Override
120
				public void onComplete() {
121
					FileResource res = getResult();
122
					GSS.get().setCurrentSelection(res);
123
					initialize();
124
				}
125

  
126
				@Override
127
				public void onError(Throwable t) {
128
					if(t instanceof RestException)
129
						GSS.get().displayError("Unable to retrieve file details:"+((RestException)t).getHttpStatusText());
130
				}
131

  
132
			};
133
			DeferredCommand.addCommand(eg);
134
		}
135
		else if (GSS.get().getCurrentSelection() instanceof List) {
136
			List<String> paths = new ArrayList<String>();
137
			for (FileResource fr : (List<FileResource>) GSS.get().getCurrentSelection())
138
				paths.add(fr.getUri()+"?"+Math.random());
139
			Cached[] cached = new Cached[paths.size()];
140
			int i=0;
141
			for (FileResource fr : (List<FileResource>) GSS.get().getCurrentSelection()){
142
				Cached c = new Cached();
143
				c.uri=fr.getUri()+"?"+Math.random();
144
				c.cache=fr;
145
				cached[i]=c;
146
				i++;
147
			}
148
			MultipleHeadCommand<FileResource> gv = new MultipleHeadCommand<FileResource>(FileResource.class, paths.toArray(new String[] {}),cached) {
149

  
150
				@Override
151
				public void onComplete() {
152
					List<FileResource> res = getResult();
153
					GSS.get().setCurrentSelection(res);
154
					FilesPropertiesDialog dlg = new FilesPropertiesDialog(res);
155
					dlg.selectTab(tabToShow);
156
					dlg.center();
157
				}
158

  
159
				@Override
160
				public void onError(Throwable t) {
161
					GWT.log("", t);
162
					GSS.get().displayError("Unable to fetch files details");
163
				}
164

  
165
				@Override
166
				public void onError(String p, Throwable throwable) {
167
					GWT.log("Path:" + p, throwable);
168
				}
169
			};
170
			DeferredCommand.addCommand(gv);
171
		}
172
	}
173

  
174
	private void initialize(){
175
		getGroups();
176
		getVersions();
177
		getOwnerFullName();
178
		DeferredCommand.addCommand(new IncrementalCommand() {
179

  
180
			@Override
181
			public boolean execute() {
182
				boolean res = canContinue();
183
				if (res) {
184
					displayProperties(newImages, GSS.get().findUserFullName(userName));
185
					return false;
186
				}
187
				return true;
188
			}
189

  
190
		});
191

  
105
        if (containerPanel != null)
106
		    containerPanel.hide();
107

  
108
        if (resource instanceof Folder) {
109
            Folder folder = (Folder) resource;
110
            FolderPropertiesDialog dlg = new FolderPropertiesDialog(app, false, folder);
111
            dlg.selectTab(tabToShow);
112
            dlg.center();
113
        }
114
        else if (resource instanceof List) {
115
            List<File> files = (List<File>) resource;
116
            if (files.size() > 1) {
117
//                FilesPropertiesDialog dlg = new FilesPropertiesDialog(files);
118
//                dlg.selectTab(tabToShow);
119
//                dlg.center();
120
            }
121
            else {
122
                FilePropertiesDialog dlg = new FilePropertiesDialog(app, files.get(0));
123
                dlg.selectTab(tabToShow);
124
                dlg.center();
125
            }
126
        }
192 127
	}
193

  
194
	private boolean canContinue() {
195
		String userFullNameFromMap = GSS.get().findUserFullName(userName);
196
		if(groups == null || versions == null || userFullNameFromMap == null)
197
			return false;
198
		return true;
199
	}
200

  
201
	/**
202
	 * Display the appropriate Properties dialog, according to the selected
203
	 * object in the application.
204
	 *
205
	 * @param propImages the images of all the possible properties dialogs
206
	 */
207
	void displayProperties(final Images propImages, final String _userName) {
208
		if (GSS.get().getCurrentSelection() instanceof RestResourceWrapper) {
209
//			FolderPropertiesDialog dlg = new FolderPropertiesDialog(propImages, false, groups);
210
//			dlg.selectTab(tabToShow);
211
//			dlg.center();
212
		} else if (GSS.get().getCurrentSelection() instanceof FileResource) {
213
			FilePropertiesDialog dlg = new FilePropertiesDialog(propImages, groups, versions, _userName);
214
			dlg.selectTab(tabToShow);
215
			dlg.center();
216
		}
217
	}
218

  
219
	private void getGroups() {
220
		GetCommand<GroupsResource> gg = new GetCommand<GroupsResource>(GroupsResource.class, GSS.get().getCurrentUserResource().getGroupsPath(), null) {
221

  
222
			@Override
223
			public void onComplete() {
224
				GroupsResource res = getResult();
225
				MultipleGetCommand<GroupResource> ga = new MultipleGetCommand<GroupResource>(GroupResource.class, res.getGroupPaths().toArray(new String[] {}), null) {
226

  
227
					@Override
228
					public void onComplete() {
229
						List<GroupResource> groupList = getResult();
230
						groups = groupList;
231
					}
232

  
233
					@Override
234
					public void onError(Throwable t) {
235
						GWT.log("", t);
236
						GSS.get().displayError("Unable to fetch groups");
237
						groups = new ArrayList<GroupResource>();
238
					}
239

  
240
					@Override
241
					public void onError(String p, Throwable throwable) {
242
						GWT.log("Path:" + p, throwable);
243
					}
244
				};
245
				DeferredCommand.addCommand(ga);
246
			}
247

  
248
			@Override
249
			public void onError(Throwable t) {
250
				GWT.log("", t);
251
				GSS.get().displayError("Unable to fetch groups");
252
				groups = new ArrayList<GroupResource>();
253
			}
254
		};
255
		DeferredCommand.addCommand(gg);
256
	}
257

  
258
	private void getVersions() {
259
		if (GSS.get().getCurrentSelection() instanceof FileResource) {
260
			FileResource afile = (FileResource) GSS.get().getCurrentSelection();
261
			GWT.log("File is versioned:" + afile.isVersioned(), null);
262
			if (afile.isVersioned()) {
263
				List<String> paths = new ArrayList<String>();
264
				for (int i = 1; i <= afile.getVersion(); i++)
265
					paths.add(afile.getUri() + "?version=" + i);
266
				MultipleHeadCommand<FileResource> gv = new MultipleHeadCommand<FileResource>(FileResource.class, paths.toArray(new String[] {}), null) {
267

  
268
					@Override
269
					public void onComplete() {
270
						versions = getResult();
271
					}
272

  
273
					@Override
274
					public void onError(Throwable t) {
275
						GWT.log("", t);
276
						GSS.get().displayError("Unable to fetch versions");
277
						versions = new ArrayList<FileResource>();
278
					}
279

  
280
					@Override
281
					public void onError(String p, Throwable throwable) {
282
						GWT.log("Path:" + p, throwable);
283
					}
284
				};
285
				DeferredCommand.addCommand(gv);
286
			} else
287
				versions = new ArrayList<FileResource>();
288
		} else
289
			versions = new ArrayList<FileResource>();
290
	}
291

  
292
	private void getOwnerFullName() {
293
		if(GSS.get().getCurrentSelection() instanceof FileResource){			
294
			FileResource fileResource = (FileResource) GSS.get().getCurrentSelection();
295
			userName = fileResource.getOwner();
296
			if(GSS.get().findUserFullName(userName) == null){
297
				GetUserCommand gu = new GetUserCommand(userName);
298
				gu.execute();
299
			}
300
		}else{			
301
			FolderResource resource = ((RestResourceWrapper) GSS.get().getCurrentSelection()).getResource();
302
			userName = resource.getOwner();
303
			if(GSS.get().findUserFullName(userName) == null){
304
				GetUserCommand gu = new GetUserCommand(userName);
305
				gu.execute();
306
			}
307
		}
308
	}
309

  
310

  
311 128
}

Also available in: Unified diff