2 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
\r
4 * This file is part of GSS.
\r
6 * GSS is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * GSS is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
\r
19 package gr.ebs.gss.client;
\r
21 import gr.ebs.gss.client.rest.GetCommand;
\r
22 import gr.ebs.gss.client.rest.resource.TagsResource;
\r
24 import java.util.Iterator;
\r
25 import java.util.List;
\r
27 import com.google.gwt.core.client.GWT;
\r
28 import com.google.gwt.dom.client.NativeEvent;
\r
29 import com.google.gwt.event.dom.client.ClickEvent;
\r
30 import com.google.gwt.event.dom.client.ClickHandler;
\r
31 import com.google.gwt.event.dom.client.KeyCodes;
\r
32 import com.google.gwt.user.client.DeferredCommand;
\r
33 import com.google.gwt.user.client.Event.NativePreviewEvent;
\r
34 import com.google.gwt.user.client.ui.Button;
\r
35 import com.google.gwt.user.client.ui.DialogBox;
\r
36 import com.google.gwt.user.client.ui.FlowPanel;
\r
37 import com.google.gwt.user.client.ui.TabPanel;
\r
38 import com.google.gwt.user.client.ui.TextBox;
\r
41 * Abstract class, parent of all 'File properties' dialog boxes.
\r
45 public abstract class AbstractPropertiesDialog extends DialogBox {
\r
47 protected static final String MULTIPLE_VALUES_TEXT = "(Multiple values)";
\r
50 * Text box with the tags associated with the file
\r
52 protected TextBox tags = new TextBox();
\r
54 protected String initialTagText;
\r
57 * A FlowPanel with all user tags
\r
59 protected FlowPanel allTagsContent;
\r
62 protected TabPanel inner = null;
\r
65 * The widget's constructor.
\r
68 public AbstractPropertiesDialog() {
\r
70 // Enable IE selection for the dialog (must disable it upon closing it)
\r
71 GSS.enableIESelection();
\r
73 setAnimationEnabled(true);
\r
78 * Retrieves all user tags from the server and updates the FlowPanel
\r
82 protected void updateTags() {
\r
83 GetCommand<TagsResource> tc = new GetCommand<TagsResource>(TagsResource.class, GSS.get().getCurrentUserResource().getTagsPath()) {
\r
86 public void onComplete() {
\r
87 allTagsContent.clear();
\r
88 TagsResource tagr = getResult();
\r
89 List<String> userTags = tagr.getTags();
\r
90 Iterator t = userTags.iterator();
\r
91 while (t.hasNext()) {
\r
92 final Button tag = new Button((String) t.next(), new ClickHandler() {
\r
95 public void onClick(ClickEvent event) {
\r
96 String existing = tags.getText();
\r
97 if (MULTIPLE_VALUES_TEXT.equals(existing)) existing = "";
\r
98 String newTag = ((Button) event.getSource()).getText().trim();
\r
99 // insert the new tag only if it is not in the list
\r
101 if (existing.indexOf(newTag + ",") == -1 && !existing.trim().endsWith(newTag))
\r
102 tags.setText(existing.trim() + (existing.length() > 0 ? ", " : "") + newTag);
\r
105 allTagsContent.add(tag);
\r
110 public void onError(Throwable t) {
\r
112 GSS.get().displayError("Unable to fetch user tags");
\r
115 DeferredCommand.addCommand(tc);
\r
120 * Accepts any change and updates the file
\r
123 protected abstract void accept();
\r
126 @SuppressWarnings("fallthrough")
\r
127 protected void onPreviewNativeEvent(NativePreviewEvent preview) {
\r
128 super.onPreviewNativeEvent(preview);
\r
130 NativeEvent evt = preview.getNativeEvent();
\r
131 if (evt.getType().equals("keydown"))
\r
132 // Use the popup's key preview hooks to close the dialog when either
\r
133 // enter or escape is pressed.
\r
134 switch (evt.getKeyCode()) {
\r
135 case KeyCodes.KEY_ENTER:
\r
137 case KeyCodes.KEY_ESCAPE:
\r
145 public void selectTab(int _tab) {
\r
146 inner.selectTab(_tab);
\r
151 * Enables IE selection prevention and hides the dialog
\r
152 * (we disable the prevention on creation of the dialog)
\r
154 public void closeDialog() {
\r
155 GSS.preventIESelection();
\r