X-Git-Url: https://code.grnet.gr/git/pithos/blobdiff_plain/16baf609bb746ccbc6cd8da7213ee74cf474f2a9..c5070ebed39e7c90d2abaa6deb9aa0f0a3668156:/src/gr/ebs/gss/client/FilePropertiesDialog.java diff --git a/src/gr/ebs/gss/client/FilePropertiesDialog.java b/src/gr/ebs/gss/client/FilePropertiesDialog.java index bc62883..be108cc 100644 --- a/src/gr/ebs/gss/client/FilePropertiesDialog.java +++ b/src/gr/ebs/gss/client/FilePropertiesDialog.java @@ -18,31 +18,32 @@ */ package gr.ebs.gss.client; -import gr.ebs.gss.client.rest.GetCommand; import gr.ebs.gss.client.rest.PostCommand; import gr.ebs.gss.client.rest.RestException; import gr.ebs.gss.client.rest.resource.FileResource; import gr.ebs.gss.client.rest.resource.GroupResource; import gr.ebs.gss.client.rest.resource.PermissionHolder; -import gr.ebs.gss.client.rest.resource.TagsResource; import java.util.Iterator; import java.util.List; import java.util.Set; import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.json.client.JSONArray; import com.google.gwt.json.client.JSONBoolean; import com.google.gwt.json.client.JSONObject; import com.google.gwt.json.client.JSONString; +import com.google.gwt.resources.client.ClientBundle; +import com.google.gwt.resources.client.ImageResource; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DeferredCommand; import com.google.gwt.user.client.ui.AbstractImagePrototype; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.CheckBox; -import com.google.gwt.user.client.ui.ClickListener; -import com.google.gwt.user.client.ui.DialogBox; +import com.google.gwt.user.client.ui.DecoratedTabPanel; import com.google.gwt.user.client.ui.DisclosurePanel; import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.FlowPanel; @@ -50,19 +51,16 @@ import com.google.gwt.user.client.ui.FocusPanel; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HasHorizontalAlignment; import com.google.gwt.user.client.ui.HorizontalPanel; -import com.google.gwt.user.client.ui.KeyboardListener; import com.google.gwt.user.client.ui.Label; -import com.google.gwt.user.client.ui.TabPanel; import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.VerticalPanel; -import com.google.gwt.user.client.ui.Widget; /** * The 'File properties' dialog box implementation. * * @author past */ -public class FilePropertiesDialog extends DialogBox { +public class FilePropertiesDialog extends AbstractPropertiesDialog { final PermissionsList permList; @@ -71,22 +69,22 @@ public class FilePropertiesDialog extends DialogBox { /** * An image bundle for this widgets images. */ - public interface Images extends MessagePanel.Images { + public interface Images extends ClientBundle,MessagePanel.Images { - @Resource("gr/ebs/gss/resources/edit_user.png") - AbstractImagePrototype permUser(); + @Source("gr/ebs/gss/resources/edit_user.png") + ImageResource permUser(); - @Resource("gr/ebs/gss/resources/groupevent.png") - AbstractImagePrototype permGroup(); + @Source("gr/ebs/gss/resources/groupevent.png") + ImageResource permGroup(); - @Resource("gr/ebs/gss/resources/editdelete.png") - AbstractImagePrototype delete(); + @Source("gr/ebs/gss/resources/editdelete.png") + ImageResource delete(); - @Resource("gr/ebs/gss/resources/db_update.png") - AbstractImagePrototype restore(); + @Source("gr/ebs/gss/resources/db_update.png") + ImageResource restore(); - @Resource("gr/ebs/gss/resources/folder_inbox.png") - AbstractImagePrototype download(); + @Source("gr/ebs/gss/resources/folder_inbox.png") + ImageResource download(); } /** @@ -94,24 +92,10 @@ public class FilePropertiesDialog extends DialogBox { */ private TextBox name = new TextBox(); - /** - * Text box with the tags associated with the file - */ - private TextBox tags = new TextBox(); - - /** - * A FlowPanel with all user tags - */ - private FlowPanel allTagsContent; - private final CheckBox versioned = new CheckBox(); final FileResource file; - String initialTagText; - - final TabPanel inner; - /** * The widget's constructor. * @@ -121,12 +105,9 @@ public class FilePropertiesDialog extends DialogBox { */ public FilePropertiesDialog(final Images images, final List groups, List bodies) { - // Enable IE selection for the dialog (must disable it upon closing it) - GSS.enableIESelection(); - // Set the dialog's caption. setText("File properties"); - setAnimationEnabled(true); + file = (FileResource) GSS.get().getCurrentSelection(); permList = new PermissionsList(images, file.getPermissions(), file.getOwner()); @@ -134,7 +115,8 @@ public class FilePropertiesDialog extends DialogBox { final VerticalPanel outer = new VerticalPanel(); final FocusPanel focusPanel = new FocusPanel(outer); // Inner contains generalPanel and permPanel. - inner = new TabPanel(); + inner = new DecoratedTabPanel(); + inner.setAnimationEnabled(true); final VerticalPanel generalPanel = new VerticalPanel(); final VerticalPanel permPanel = new VerticalPanel(); final HorizontalPanel buttons = new HorizontalPanel(); @@ -145,7 +127,7 @@ public class FilePropertiesDialog extends DialogBox { final HorizontalPanel vPanel = new HorizontalPanel(); final HorizontalPanel vPanel2 = new HorizontalPanel(); - versioned.setChecked(file.isVersioned()); + versioned.setValue(file.isVersioned()); inner.add(generalPanel, "General"); inner.add(permPanel, "Sharing"); inner.add(verPanel, "Versions"); @@ -155,7 +137,7 @@ public class FilePropertiesDialog extends DialogBox { generalTable.setText(0, 0, "Name"); generalTable.setText(1, 0, "Folder"); generalTable.setText(2, 0, "Owner"); - generalTable.setText(3, 0, "Date"); + generalTable.setText(3, 0, "Last modified"); generalTable.setText(4, 0, "Tags"); name.setText(file.getName()); generalTable.setWidget(0, 1, name); @@ -165,7 +147,7 @@ public class FilePropertiesDialog extends DialogBox { generalTable.setText(1, 1, "-"); generalTable.setText(2, 1, file.getOwner()); final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a"); - generalTable.setText(3, 1, formatter.format(file.getCreationDate())); + generalTable.setText(3, 1, formatter.format(file.getModificationDate())); // Get the tags. StringBuffer tagsBuffer = new StringBuffer(); Iterator i = file.getTags().iterator(); @@ -192,9 +174,9 @@ public class FilePropertiesDialog extends DialogBox { // Create the 'OK' button, along with a listener that hides the dialog // when the button is clicked. - final Button ok = new Button("OK", new ClickListener() { - - public void onClick(Widget sender) { + final Button ok = new Button("OK", new ClickHandler() { + @Override + public void onClick(ClickEvent event) { accept(); closeDialog(); } @@ -203,16 +185,16 @@ public class FilePropertiesDialog extends DialogBox { buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER); // Create the 'Cancel' button, along with a listener that hides the // dialog when the button is clicked. - final Button cancel = new Button("Cancel", new ClickListener() { - - public void onClick(Widget sender) { + final Button cancel = new Button("Cancel", new ClickHandler() { + @Override + public void onClick(ClickEvent event) { closeDialog(); } }); buttons.add(cancel); buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); buttons.setSpacing(8); - buttons.addStyleName("gwt-TabPanelBottom"); + buttons.addStyleName("gss-TabPanelBottom"); generalPanel.add(generalTable); @@ -230,9 +212,9 @@ public class FilePropertiesDialog extends DialogBox { generalPanel.add(allTags); generalPanel.setSpacing(4); - final Button add = new Button("Add Group", new ClickListener() { - - public void onClick(Widget sender) { + final Button add = new Button("Add Group", new ClickHandler() { + @Override + public void onClick(ClickEvent event) { PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, false); dlg.center(); } @@ -240,9 +222,9 @@ public class FilePropertiesDialog extends DialogBox { permButtons.add(add); permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER); - final Button addUser = new Button("Add User", new ClickListener() { - - public void onClick(Widget sender) { + final Button addUser = new Button("Add User", new ClickHandler() { + @Override + public void onClick(ClickEvent event) { PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, true); dlg.center(); } @@ -252,7 +234,7 @@ public class FilePropertiesDialog extends DialogBox { permButtons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); permButtons.setSpacing(8); - permButtons.addStyleName("gwt-TabPanelBottom"); + permButtons.addStyleName("gss-TabPanelBottom"); final Label readForAllNote = new Label("When this option is enabled, the file will be readable" + " by everyone. By checking this option, you are certifying that you have the right to " + @@ -261,11 +243,11 @@ public class FilePropertiesDialog extends DialogBox { readForAllNote.setStylePrimaryName("gss-readForAllNote"); readForAll = new CheckBox(); - readForAll.setChecked(file.isReadForAll()); - readForAll.addClickListener(new ClickListener() { - - public void onClick(Widget sender) { - if (readForAll.isChecked()) { + readForAll.setValue(file.isReadForAll()); + readForAll.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + if (readForAll.getValue()) { readForAllNote.setVisible(true); pathPanel.setVisible(true); } @@ -284,27 +266,31 @@ public class FilePropertiesDialog extends DialogBox { permForAll.add(new Label("Make Public")); permForAll.add(readForAll); permForAll.setSpacing(8); - permForAll.addStyleName("gwt-TabPanelBottom"); + permForAll.addStyleName("gss-TabPanelBottom"); + permForAll.add(readForAllNote); permPanel.add(permForAll); - permPanel.add(readForAllNote); } TextBox path = new TextBox(); - path.addClickListener(new ClickListener () { - - public void onClick(Widget sender) { + path.setWidth("100%"); + path.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { GSS.enableIESelection(); - ((TextBox) sender).selectAll(); + ((TextBox) event.getSource()).selectAll(); GSS.preventIESelection(); } }); path.setText(file.getUri()); - path.setTitle("Use this URI for sharing this file with the world"); + path.setTitle("Use this URI for sharing this file with the world (crtl-C/cmd-C to copy to system clipboard)"); + path.setWidth("100%"); path.setReadOnly(true); + pathPanel.setWidth("100%"); + pathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); pathPanel.add(new Label("Sharing URI")); pathPanel.setSpacing(8); - pathPanel.addStyleName("gwt-TabPanelBottom"); + pathPanel.addStyleName("gss-TabPanelBottom"); pathPanel.add(path); pathPanel.setVisible(file.isReadForAll()); permPanel.add(pathPanel); @@ -314,23 +300,25 @@ public class FilePropertiesDialog extends DialogBox { vPanel.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); vPanel.setSpacing(8); - vPanel.addStyleName("gwt-TabPanelBottom"); + vPanel.addStyleName("gss-TabPanelBottom"); vPanel.add(new Label("Versioned")); vPanel.add(versioned); verPanel.add(vPanel); vPanel2.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); vPanel2.setSpacing(8); - vPanel2.addStyleName("gwt-TabPanelBottom"); - Button removeVersionsButton = new Button(images.delete().getHTML(), new ClickListener() { - - public void onClick(Widget sender) { - ConfirmationDialog confirm = new ConfirmationDialog(images,"Really remove all previous versions?","Remove"){ + vPanel2.addStyleName("gss-TabPanelBottom"); + Button removeVersionsButton = new Button(AbstractImagePrototype.create(images.delete()).getHTML(), new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + ConfirmationDialog confirm = new ConfirmationDialog("Really " + + "remove all previous versions?", "Remove") { + @Override public void cancel() { } - + @Override public void confirm() { FilePropertiesDialog.this.closeDialog(); removeAllOldVersions(); @@ -350,84 +338,33 @@ public class FilePropertiesDialog extends DialogBox { outer.add(inner); outer.add(buttons); outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); - outer.addStyleName("gwt-TabPanelBottom"); + outer.addStyleName("gss-TabPanelBottom"); focusPanel.setFocus(true); setWidget(outer); } - /** - * Retrieves all user tags from the server and updates the FlowPanel - * - * @param userId - */ - private void updateTags() { - GetCommand tc = new GetCommand(TagsResource.class, GSS.get().getCurrentUserResource().getTagsPath()) { - - public void onComplete() { - allTagsContent.clear(); - TagsResource tagr = getResult(); - List userTags = tagr.getTags(); - Iterator t = userTags.iterator(); - while (t.hasNext()) { - final Button tag = new Button((String) t.next(), new ClickListener() { - - public void onClick(Widget sender) { - String existing = tags.getText(); - String newTag = ((Button) sender).getText().trim(); - // insert the new tag only if it is not in the list - // already - if (existing.indexOf(newTag + ",") == -1 && !existing.trim().endsWith(newTag)) - tags.setText(existing.trim() + (existing.length() > 0 ? ", " : "") + newTag); - } - }); - allTagsContent.add(tag); - } - } - - @Override - public void onError(Throwable t) { - GWT.log("", t); - GSS.get().displayError("Unable to fetch user tags"); - } - }; - DeferredCommand.addCommand(tc); - - } - - @Override - @SuppressWarnings("fallthrough") - public boolean onKeyDownPreview(char key, int modifiers) { - // Use the popup's key preview hooks to close the dialog when either - // enter or escape is pressed. - switch (key) { - case KeyboardListener.KEY_ENTER: - accept(); - case KeyboardListener.KEY_ESCAPE: - closeDialog(); - break; - } - - return true; - } /** * Accepts any change and updates the file * - * @param userId */ - private void accept() { + @Override + protected void accept() { + String newFilename = null; permList.updatePermissionsAccordingToInput(); Set perms = permList.getPermissions(); JSONObject json = new JSONObject(); - if (!name.getText().equals(file.getName())) - json.put("name", new JSONString(name.getText())); - if (versioned.isChecked() != file.isVersioned()) - json.put("versioned", JSONBoolean.getInstance(versioned.isChecked())); + if (!name.getText().equals(file.getName())) { + newFilename = name.getText(); + json.put("name", new JSONString(newFilename)); + } + if (versioned.getValue() != file.isVersioned()) + json.put("versioned", JSONBoolean.getInstance(versioned.getValue())); //only update the read for all perm if the user is the owner - if (readForAll.isChecked() != file.isReadForAll()) + if (readForAll.getValue() != file.isReadForAll()) if (file.getOwner().equals(GSS.get().getCurrentUserResource().getUsername())) - json.put("readForAll", JSONBoolean.getInstance(readForAll.isChecked())); + json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue())); int i = 0; if (permList.hasChanges()) { GWT.log("Permissions change", null); @@ -463,12 +400,15 @@ public class FilePropertiesDialog extends DialogBox { GWT.log("NO CHANGES", null); return; } + final String newFilenameFinal = newFilename; PostCommand cf = new PostCommand(file.getUri() + "?update=", jsonString, 200) { + @Override public void onComplete() { - GSS.get().getFileList().updateFileCache(true, false /* do not clear selected file*/); + GSS.get().getFileList().updateFileCache(true, false /* do not clear selected file*/, newFilenameFinal); } + @Override public void onError(Throwable t) { GWT.log("", t); if (t instanceof RestException) { @@ -498,10 +438,12 @@ public class FilePropertiesDialog extends DialogBox { GWT.log(json.toString(), null); PostCommand cf = new PostCommand(file.getUri() + "?update=", json.toString(), 200) { + @Override public void onComplete() { toggleVersioned(true); } + @Override public void onError(Throwable t) { GWT.log("", t); if (t instanceof RestException) { @@ -529,10 +471,12 @@ public class FilePropertiesDialog extends DialogBox { GWT.log(json.toString(), null); PostCommand cf = new PostCommand(file.getUri() + "?update=", json.toString(), 200) { + @Override public void onComplete() { GSS.get().getFileList().updateFileCache(true, false /* do not clear selected file*/); } + @Override public void onError(Throwable t) { GWT.log("", t); if (t instanceof RestException) { @@ -554,17 +498,5 @@ public class FilePropertiesDialog extends DialogBox { DeferredCommand.addCommand(cf); } - public void selectTab(int _tab) { - inner.selectTab(_tab); - } - - /** - * Enables IE selection prevention and hides the dialog - * (we disable the prevention on creation of the dialog) - */ - public void closeDialog() { - GSS.preventIESelection(); - hide(); - } }