2 * Copyright (c) 2011 Greek Research and Technology Network
\r
4 package gr.grnet.pithos.web.client;
\r
6 import gr.grnet.pithos.web.client.rest.GetCommand;
\r
7 import gr.grnet.pithos.web.client.rest.resource.TagsResource;
\r
9 import java.util.List;
\r
11 import com.google.gwt.core.client.GWT;
\r
12 import com.google.gwt.dom.client.NativeEvent;
\r
13 import com.google.gwt.event.dom.client.ClickEvent;
\r
14 import com.google.gwt.event.dom.client.ClickHandler;
\r
15 import com.google.gwt.event.dom.client.KeyCodes;
\r
16 import com.google.gwt.user.client.DeferredCommand;
\r
17 import com.google.gwt.user.client.Event.NativePreviewEvent;
\r
18 import com.google.gwt.user.client.ui.Anchor;
\r
19 import com.google.gwt.user.client.ui.DialogBox;
\r
20 import com.google.gwt.user.client.ui.FlowPanel;
\r
21 import com.google.gwt.user.client.ui.Label;
\r
22 import com.google.gwt.user.client.ui.TabPanel;
\r
23 import com.google.gwt.user.client.ui.TextBox;
\r
26 * Abstract class, parent of all 'File properties' dialog boxes.
\r
29 public abstract class AbstractPropertiesDialog extends DialogBox {
\r
31 protected static final String MULTIPLE_VALUES_TEXT = "(Multiple values)";
\r
34 * Text box with the tags associated with the file
\r
36 protected TextBox tags = new TextBox();
\r
38 protected String initialTagText;
\r
41 * A FlowPanel with all user tags
\r
43 protected FlowPanel allTagsContent;
\r
46 protected TabPanel inner = null;
\r
49 * The widget's constructor.
\r
52 public AbstractPropertiesDialog() {
\r
54 // Enable IE selection for the dialog (must disable it upon closing it)
\r
55 GSS.enableIESelection();
\r
57 setAnimationEnabled(true);
\r
61 * Retrieves all user tags from the server and updates the FlowPanel
\r
65 protected void updateTags() {
\r
66 GetCommand<TagsResource> tc = new GetCommand<TagsResource>(TagsResource.class, GSS.get().getCurrentUserResource().getTagsPath(),null) {
\r
69 public void onComplete() {
\r
70 allTagsContent.clear();
\r
71 TagsResource tagr = getResult();
\r
72 List<String> userTags = tagr.getTags();
\r
74 for(String usrTag : userTags){
\r
75 tag = new Anchor(usrTag.toString(), false);
\r
76 tag.addStyleName("pithos-tag");
\r
77 allTagsContent.add(tag);
\r
78 Label separator = new Label(", ");
\r
79 separator.addStyleName("pithos-tag");
\r
80 allTagsContent.add(separator);
\r
81 tag.addClickHandler( new ClickHandler() {
\r
84 public void onClick(ClickEvent event) {
\r
85 String existing = tags.getText();
\r
86 if (MULTIPLE_VALUES_TEXT.equals(existing)) existing = "";
\r
87 String newTag = ((Anchor) event.getSource()).getText().trim();
\r
88 // insert the new tag only if it is not in the list
\r
90 if (existing.indexOf(newTag) == -1 && !existing.trim().endsWith(newTag))
\r
91 tags.setText(existing.trim()
\r
92 + (existing.length() > 0 ? ", " : "")
\r
100 public void onError(Throwable t) {
\r
102 GSS.get().displayError("Unable to fetch user tags");
\r
105 DeferredCommand.addCommand(tc);
\r
110 * Accepts any change and updates the file
\r
113 protected abstract void accept();
\r
116 @SuppressWarnings("fallthrough")
\r
117 protected void onPreviewNativeEvent(NativePreviewEvent preview) {
\r
118 super.onPreviewNativeEvent(preview);
\r
120 NativeEvent evt = preview.getNativeEvent();
\r
121 if (evt.getType().equals("keydown"))
\r
122 // Use the popup's key preview hooks to close the dialog when either
\r
123 // enter or escape is pressed.
\r
124 switch (evt.getKeyCode()) {
\r
125 case KeyCodes.KEY_ENTER:
\r
127 case KeyCodes.KEY_ESCAPE:
\r
135 public void selectTab(int _tab) {
\r
136 inner.selectTab(_tab);
\r
141 * Enables IE selection prevention and hides the dialog
\r
142 * (we disable the prevention on creation of the dialog)
\r
144 public void closeDialog() {
\r
145 GSS.preventIESelection();
\r