2 * Copyright 2011 GRNET S.A. All rights reserved.
\r
4 * Redistribution and use in source and binary forms, with or
\r
5 * without modification, are permitted provided that the following
\r
6 * conditions are met:
\r
8 * 1. Redistributions of source code must retain the above
\r
9 * copyright notice, this list of conditions and the following
\r
12 * 2. Redistributions in binary form must reproduce the above
\r
13 * copyright notice, this list of conditions and the following
\r
14 * disclaimer in the documentation and/or other materials
\r
15 * provided with the distribution.
\r
17 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
\r
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
\r
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
\r
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
\r
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
\r
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
\r
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
\r
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
\r
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
\r
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
28 * POSSIBILITY OF SUCH DAMAGE.
\r
30 * The views and conclusions contained in the software and
\r
31 * documentation are those of the authors and should not be
\r
32 * interpreted as representing official policies, either expressed
\r
33 * or implied, of GRNET S.A.
\r
35 package gr.grnet.pithos.web.client;
\r
37 import com.google.gwt.core.client.Scheduler;
\r
38 import gr.grnet.pithos.web.client.foldertree.File;
\r
39 import gr.grnet.pithos.web.client.foldertree.Resource;
\r
40 import gr.grnet.pithos.web.client.rest.PostCommand;
\r
41 import gr.grnet.pithos.web.client.rest.PostRequest;
\r
42 import gr.grnet.pithos.web.client.rest.PutRequest;
\r
43 import gr.grnet.pithos.web.client.rest.RestException;
\r
44 import gr.grnet.pithos.web.client.rest.resource.FileResource;
\r
45 import gr.grnet.pithos.web.client.rest.resource.GroupResource;
\r
46 import gr.grnet.pithos.web.client.rest.resource.PermissionHolder;
\r
48 import java.util.Iterator;
\r
49 import java.util.List;
\r
50 import java.util.Set;
\r
52 import com.google.gwt.core.client.GWT;
\r
53 import com.google.gwt.event.dom.client.ChangeEvent;
\r
54 import com.google.gwt.event.dom.client.ChangeHandler;
\r
55 import com.google.gwt.event.dom.client.ClickEvent;
\r
56 import com.google.gwt.event.dom.client.ClickHandler;
\r
57 import com.google.gwt.i18n.client.DateTimeFormat;
\r
58 import com.google.gwt.json.client.JSONArray;
\r
59 import com.google.gwt.json.client.JSONBoolean;
\r
60 import com.google.gwt.json.client.JSONObject;
\r
61 import com.google.gwt.json.client.JSONString;
\r
62 import com.google.gwt.resources.client.ClientBundle;
\r
63 import com.google.gwt.resources.client.ImageResource;
\r
64 import com.google.gwt.user.client.Command;
\r
65 import com.google.gwt.user.client.DeferredCommand;
\r
66 import com.google.gwt.user.client.ui.AbstractImagePrototype;
\r
67 import com.google.gwt.user.client.ui.Button;
\r
68 import com.google.gwt.user.client.ui.CheckBox;
\r
69 import com.google.gwt.user.client.ui.DecoratedTabPanel;
\r
70 import com.google.gwt.user.client.ui.DisclosurePanel;
\r
71 import com.google.gwt.user.client.ui.FlexTable;
\r
72 import com.google.gwt.user.client.ui.FlowPanel;
\r
73 import com.google.gwt.user.client.ui.FocusPanel;
\r
74 import com.google.gwt.user.client.ui.HTML;
\r
75 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
\r
76 import com.google.gwt.user.client.ui.HorizontalPanel;
\r
77 import com.google.gwt.user.client.ui.Label;
\r
78 import com.google.gwt.user.client.ui.TextBox;
\r
79 import com.google.gwt.user.client.ui.VerticalPanel;
\r
82 * The 'File properties' dialog box implementation.
\r
85 public class FilePropertiesDialog extends AbstractPropertiesDialog {
\r
87 private PermissionsList permList;
\r
89 private CheckBox readForAll;
\r
92 * An image bundle for this widgets images.
\r
94 public interface Images extends ClientBundle,MessagePanel.Images {
\r
96 @Source("gr/grnet/pithos/resources/edit_user.png")
\r
97 ImageResource permUser();
\r
99 @Source("gr/grnet/pithos/resources/groupevent.png")
\r
100 ImageResource permGroup();
\r
102 @Source("gr/grnet/pithos/resources/editdelete.png")
\r
103 ImageResource delete();
\r
105 @Source("gr/grnet/pithos/resources/db_update.png")
\r
106 ImageResource restore();
\r
108 @Source("gr/grnet/pithos/resources/folder_inbox.png")
\r
109 ImageResource download();
\r
113 * The widget that holds the name of the file.
\r
115 private TextBox name = new TextBox();
\r
117 private final CheckBox versioned = new CheckBox();
\r
121 private String userFullName;
\r
126 * The widget's constructor.
\r
128 public FilePropertiesDialog(GSS _app, File _file) {
\r
132 // Set the dialog's caption.
\r
133 setText("File properties");
\r
136 // permList = new PermissionsList(images, file.getPermissions(), file.getOwner());
\r
138 // Outer contains inner and buttons.
\r
139 final VerticalPanel outer = new VerticalPanel();
\r
140 final FocusPanel focusPanel = new FocusPanel(outer);
\r
141 // Inner contains generalPanel and permPanel.
\r
142 inner = new DecoratedTabPanel();
\r
143 inner.setAnimationEnabled(true);
\r
146 inner.add(createGeneralPanel(), "General");
\r
148 inner.add(createSharingPanel(), "Sharing");
\r
150 inner.add(createVersionPanel(), "Versions");
\r
152 inner.selectTab(0);
\r
156 final HorizontalPanel buttons = new HorizontalPanel();
\r
157 // Create the 'OK' button, along with a listener that hides the dialog
\r
158 // when the button is clicked.
\r
159 final Button ok = new Button("OK", new ClickHandler() {
\r
161 public void onClick(ClickEvent event) {
\r
168 buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
\r
169 // Create the 'Cancel' button, along with a listener that hides the
\r
170 // dialog when the button is clicked.
\r
171 final Button cancel = new Button("Cancel", new ClickHandler() {
\r
173 public void onClick(ClickEvent event) {
\r
177 buttons.add(cancel);
\r
178 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
\r
179 buttons.setSpacing(8);
\r
180 buttons.addStyleName("pithos-TabPanelBottom");
\r
182 outer.add(buttons);
\r
183 outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
\r
184 outer.addStyleName("pithos-TabPanelBottom");
\r
186 focusPanel.setFocus(true);
\r
189 // Asynchronously retrieve the tags defined by this user.
\r
190 DeferredCommand.addCommand(new Command() {
\r
193 public void execute() {
\r
199 private VerticalPanel createGeneralPanel() {
\r
200 final VerticalPanel generalPanel = new VerticalPanel();
\r
201 final FlexTable generalTable = new FlexTable();
\r
202 generalTable.setText(0, 0, "Name");
\r
203 generalTable.setText(1, 0, "Folder");
\r
204 generalTable.setText(2, 0, "Owner");
\r
205 generalTable.setText(3, 0, "Last modified");
\r
206 // generalTable.setText(4, 0, "Tags");
\r
208 name.setWidth("100%");
\r
209 name.setText(file.getName());
\r
210 generalTable.setWidget(0, 1, name);
\r
211 if(file.getParent() != null)
\r
212 generalTable.setText(1, 1, file.getParent().getName());
\r
214 generalTable.setText(1, 1, "-");
\r
215 generalTable.setText(2, 1, file.getOwner());
\r
217 final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
\r
218 generalTable.setText(3, 1, formatter.format(file.getLastModified()));
\r
221 // StringBuffer tagsBuffer = new StringBuffer();
\r
222 // Iterator i = file.getTags().iterator();
\r
223 // while (i.hasNext()) {
\r
224 // String tag = (String) i.next();
\r
225 // tagsBuffer.append(tag).append(", ");
\r
227 // if (tagsBuffer.length() > 1)
\r
228 // tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1);
\r
229 // initialTagText = tagsBuffer.toString();
\r
230 // tags.setWidth("100%");
\r
231 // tags.getElement().setId("filePropertiesDialog.textBox.tags");
\r
232 // tags.setText(initialTagText);
\r
233 // generalTable.setWidget(4, 1, tags);
\r
235 generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
\r
236 generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
\r
237 generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");
\r
238 generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels");
\r
239 // generalTable.getFlexCellFormatter().setStyleName(4, 0, "props-labels");
\r
240 generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");
\r
241 generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");
\r
242 generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");
\r
243 generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values");
\r
244 // generalTable.getFlexCellFormatter().setStyleName(4, 1, "props-values");
\r
245 generalTable.setCellSpacing(4);
\r
247 generalPanel.add(generalTable);
\r
249 DisclosurePanel allTags = new DisclosurePanel("All tags");
\r
250 allTagsContent = new FlowPanel();
\r
251 allTagsContent.setWidth("100%");
\r
252 allTags.setContent(allTagsContent);
\r
253 generalPanel.add(allTags);
\r
254 generalPanel.setSpacing(4);
\r
255 return generalPanel;
\r
258 private VerticalPanel createSharingPanel() {
\r
259 VerticalPanel permPanel = new VerticalPanel();
\r
261 // permList = new PermissionsList(images, file.getPermissions(), file.getOwner());
\r
262 // permPanel.add(permList);
\r
264 // HorizontalPanel permButtons = new HorizontalPanel();
\r
265 // Button add = new Button("Add Group", new ClickHandler() {
\r
267 // public void onClick(ClickEvent event) {
\r
268 // PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, false);
\r
272 // permButtons.add(add);
\r
273 // permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER);
\r
275 // final Button addUser = new Button("Add User", new ClickHandler() {
\r
277 // public void onClick(ClickEvent event) {
\r
278 // PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, true);
\r
282 // permButtons.add(addUser);
\r
283 // permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER);
\r
285 // permButtons.setSpacing(8);
\r
286 // permButtons.addStyleName("pithos-TabPanelBottom");
\r
287 // permPanel.add(permButtons);
\r
289 // final Label readForAllNote = new Label("When this option is enabled, the file will be readable" +
\r
290 // " by everyone. By checking this option, you are certifying that you have the right to " +
\r
291 // "distribute this file and that it does not violate the Terms of Use.", true);
\r
292 // readForAllNote.setVisible(false);
\r
293 // readForAllNote.setStylePrimaryName("pithos-readForAllNote");
\r
295 // readForAll = new CheckBox();
\r
296 // readForAll.setValue(file.isReadForAll());
\r
297 // readForAll.addClickHandler(new ClickHandler() {
\r
299 // public void onClick(ClickEvent event) {
\r
300 // readForAllNote.setVisible(readForAll.getValue());
\r
305 // // Only show the read for all permission if the user is the owner.
\r
306 // if (file.getOwner().equals(app.getUsername())) {
\r
307 // final HorizontalPanel permForAll = new HorizontalPanel();
\r
308 // permForAll.add(new Label("Public"));
\r
309 // permForAll.add(readForAll);
\r
310 // permForAll.setSpacing(8);
\r
311 // permForAll.addStyleName("pithos-TabPanelBottom");
\r
312 // permForAll.add(readForAllNote);
\r
313 // permPanel.add(permForAll);
\r
317 // final HorizontalPanel pathPanel = new HorizontalPanel();
\r
318 // pathPanel.setWidth("100%");
\r
319 // pathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
\r
320 // pathPanel.add(new Label("Link"));
\r
321 // pathPanel.setSpacing(8);
\r
322 // pathPanel.addStyleName("pithos-TabPanelBottom");
\r
324 // TextBox path = new TextBox();
\r
325 // path.setWidth("100%");
\r
326 // path.addClickHandler(new ClickHandler() {
\r
328 // public void onClick(ClickEvent event) {
\r
329 // GSS.enableIESelection();
\r
330 // ((TextBox) event.getSource()).selectAll();
\r
331 // GSS.preventIESelection();
\r
334 // path.setText(file.getUri());
\r
335 // path.setTitle("Use this link for sharing the file via e-mail, IM, etc. (crtl-C/cmd-C to copy to system clipboard)");
\r
336 // path.setWidth("100%");
\r
337 // path.setReadOnly(true);
\r
338 // pathPanel.add(path);
\r
339 // permPanel.add(pathPanel);
\r
344 private VerticalPanel createVersionPanel() {
\r
345 VerticalPanel versionPanel = new VerticalPanel();
\r
347 // VersionsList verList = new VersionsList(this, images, bodies);
\r
348 // versionPanel.add(verList);
\r
350 // HorizontalPanel vPanel = new HorizontalPanel();
\r
352 // vPanel.setSpacing(8);
\r
353 // vPanel.addStyleName("pithos-TabPanelBottom");
\r
354 // vPanel.add(new Label("Versioned"));
\r
356 // versioned.setValue(file.isVersioned());
\r
357 // vPanel.add(versioned);
\r
358 // versionPanel.add(vPanel);
\r
360 // HorizontalPanel vPanel2 = new HorizontalPanel();
\r
361 // vPanel2.setSpacing(8);
\r
362 // vPanel2.addStyleName("pithos-TabPanelBottom");
\r
364 // HTML removeAllVersion = new HTML("<span>Remove all previous versions?</span>");
\r
365 // vPanel2.add(removeAllVersion);
\r
367 // Button removeVersionsButton = new Button(AbstractImagePrototype.create(images.delete()).getHTML(), new ClickHandler() {
\r
369 // public void onClick(ClickEvent event) {
\r
370 // ConfirmationDialog confirm = new ConfirmationDialog("Really " +
\r
371 // "remove all previous versions?", "Remove") {
\r
374 // public void cancel() {
\r
378 // public void confirm() {
\r
379 // FilePropertiesDialog.this.closeDialog();
\r
380 // removeAllOldVersions();
\r
384 // confirm.center();
\r
388 // vPanel2.add(removeVersionsButton);
\r
389 // if(!file.isVersioned())
\r
390 // vPanel2.setVisible(false);
\r
392 // versionPanel.add(vPanel2);
\r
394 return versionPanel;
\r
398 * Accepts any change and updates the file
\r
402 protected void accept() {
\r
403 String newFilename = null;
\r
404 // permList.updatePermissionsAccordingToInput();
\r
405 // Set<PermissionHolder> perms = permList.getPermissions();
\r
406 // JSONObject json = new JSONObject();
\r
407 if (!name.getText().equals(file.getName())) {
\r
408 newFilename = name.getText();
\r
409 // json.put("name", new JSONString(newFilename));
\r
411 // if (versioned.getValue() != file.isVersioned())
\r
412 // json.put("versioned", JSONBoolean.getInstance(versioned.getValue()));
\r
413 //only update the read for all perm if the user is the owner
\r
414 // if (readForAll.getValue() != file.isReadForAll())
\r
415 // if (file.getOwner().equals(GSS.get().getCurrentUserResource().getUsername()))
\r
416 // json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue()));
\r
418 // if (permList.hasChanges()) {
\r
419 // GWT.log("Permissions change", null);
\r
420 // JSONArray perma = new JSONArray();
\r
422 // for (PermissionHolder p : perms) {
\r
423 // JSONObject po = new JSONObject();
\r
424 // if (p.getUser() != null)
\r
425 // po.put("user", new JSONString(p.getUser()));
\r
426 // if (p.getGroup() != null)
\r
427 // po.put("group", new JSONString(p.getGroup()));
\r
428 // po.put("read", JSONBoolean.getInstance(p.isRead()));
\r
429 // po.put("write", JSONBoolean.getInstance(p.isWrite()));
\r
430 // po.put("modifyACL", JSONBoolean.getInstance(p.isModifyACL()));
\r
431 // perma.set(i, po);
\r
434 // json.put("permissions", perma);
\r
436 // JSONArray taga = new JSONArray();
\r
438 // if (!tags.getText().equals(initialTagText)) {
\r
439 // String[] tagset = tags.getText().split(",");
\r
440 // for (String t : tagset) {
\r
441 // JSONString to = new JSONString(t);
\r
442 // taga.set(i, to);
\r
445 // json.put("tags", taga);
\r
447 // String jsonString = json.toString();
\r
448 // if(jsonString.equals("{}")){
\r
449 // GWT.log("NO CHANGES", null);
\r
452 final String newFilenameFinal = newFilename;
\r
454 if (newFilename == null)
\r
456 String path = app.getApiPath() + app.getUsername() + file.getParent().getUri() + "/" + newFilename;
\r
457 PutRequest updateFile = new PutRequest(path) {
\r
459 public void onSuccess(Resource result) {
\r
460 app.updateFolder(file.getParent());
\r
464 public void onError(Throwable t) {
\r
466 app.displayError("System error modifying file:" + t.getMessage());
\r
469 updateFile.setHeader("X-Auth-Token", app.getToken());
\r
470 updateFile.setHeader("X-Move-From", file.getUri());
\r
471 updateFile.setHeader("Content-Type", file.getContentType());
\r
472 Scheduler.get().scheduleDeferred(updateFile);
\r
475 private void removeAllOldVersions() {
\r
476 JSONObject json = new JSONObject();
\r
477 json.put("versioned", JSONBoolean.getInstance(false));
\r
478 GWT.log(json.toString(), null);
\r
479 PostCommand cf = new PostCommand(file.getUri() + "?update=", json.toString(), 200) {
\r
482 public void onComplete() {
\r
483 toggleVersioned(true);
\r
487 public void onError(Throwable t) {
\r
489 if (t instanceof RestException) {
\r
490 int statusCode = ((RestException) t).getHttpStatusCode();
\r
491 if (statusCode == 405)
\r
492 GSS.get().displayError("You don't have the necessary permissions");
\r
493 else if (statusCode == 404)
\r
494 GSS.get().displayError("User in permissions does not exist");
\r
495 else if (statusCode == 409)
\r
496 GSS.get().displayError("A folder with the same name already exists");
\r
497 else if (statusCode == 413)
\r
498 GSS.get().displayError("Your quota has been exceeded");
\r
500 GSS.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());
\r
502 GSS.get().displayError("System error moifying file:" + t.getMessage());
\r
505 DeferredCommand.addCommand(cf);
\r
508 private void toggleVersioned(boolean versionedValue) {
\r
509 JSONObject json = new JSONObject();
\r
510 json.put("versioned", JSONBoolean.getInstance(versionedValue));
\r
511 GWT.log(json.toString(), null);
\r
512 PostCommand cf = new PostCommand(file.getUri() + "?update=", json.toString(), 200) {
\r
515 public void onComplete() {
\r
516 GSS.get().getTreeView().refreshCurrentNode(false);
\r
520 public void onError(Throwable t) {
\r
522 if (t instanceof RestException) {
\r
523 int statusCode = ((RestException) t).getHttpStatusCode();
\r
524 if (statusCode == 405)
\r
525 GSS.get().displayError("You don't have the necessary permissions");
\r
526 else if (statusCode == 404)
\r
527 GSS.get().displayError("User in permissions does not exist");
\r
528 else if (statusCode == 409)
\r
529 GSS.get().displayError("A folder with the same name already exists");
\r
530 else if (statusCode == 413)
\r
531 GSS.get().displayError("Your quota has been exceeded");
\r
533 GSS.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());
\r
535 GSS.get().displayError("System error moifying file:" + t.getMessage());
\r
538 DeferredCommand.addCommand(cf);
\r