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 gr.grnet.pithos.web.client.foldertree.File;
\r
38 import gr.grnet.pithos.web.client.foldertree.Folder;
\r
40 import java.util.List;
\r
42 import com.google.gwt.event.dom.client.ClickEvent;
\r
43 import com.google.gwt.event.dom.client.ClickHandler;
\r
44 import com.google.gwt.user.client.ui.Button;
\r
45 import com.google.gwt.user.client.ui.DecoratedTabPanel;
\r
46 import com.google.gwt.user.client.ui.DisclosurePanel;
\r
47 import com.google.gwt.user.client.ui.FlexTable;
\r
48 import com.google.gwt.user.client.ui.FlowPanel;
\r
49 import com.google.gwt.user.client.ui.FocusPanel;
\r
50 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
\r
51 import com.google.gwt.user.client.ui.HorizontalPanel;
\r
52 import com.google.gwt.user.client.ui.VerticalPanel;
\r
55 * The 'Multiple file properties' dialog box implementation.
\r
58 public class FilesPropertiesDialog extends AbstractPropertiesDialog {
\r
60 // private final TristateCheckBox versionedCheck;
\r
62 private final List<File> files;
\r
64 private Boolean initialVersioned;
\r
67 * The widget's constructor.
\r
71 public FilesPropertiesDialog(Pithos _app, final List<File> _files) {
\r
75 // int versionedNum = 0;
\r
76 // for (File fr : files)
\r
77 // if (fr.isVersioned()) versionedNum++;
\r
78 // Boolean versioned = null;
\r
79 // if (versionedNum == 0)
\r
80 // versioned = false;
\r
81 // if (versionedNum == files.size())
\r
82 // versioned = true;
\r
84 // initialVersioned = versioned;
\r
85 // versionedCheck = new TristateCheckBox(versioned);
\r
87 // Set the dialog's caption.
\r
88 setText("Files properties");
\r
90 // Outer contains inner and buttons.
\r
91 final VerticalPanel outer = new VerticalPanel();
\r
92 final FocusPanel focusPanel = new FocusPanel(outer);
\r
93 // Inner contains generalPanel and permPanel.
\r
94 inner = new DecoratedTabPanel();
\r
95 inner.setAnimationEnabled(true);
\r
97 inner.add(createGeneralPanel(), "General");
\r
99 final VerticalPanel verPanel = new VerticalPanel();
\r
101 // final HorizontalPanel vPanel = new HorizontalPanel();
\r
102 // vPanel.setSpacing(8);
\r
103 // vPanel.addStyleName("pithos-TabPanelBottom");
\r
104 // vPanel.add(new Label("Versioned"));
\r
105 // vPanel.add(versionedCheck);
\r
107 // verPanel.add(vPanel);
\r
109 inner.add(verPanel, "Versions");
\r
110 inner.selectTab(0);
\r
113 final HorizontalPanel buttons = new HorizontalPanel();
\r
114 // Create the 'OK' button, along with a listener that hides the dialog
\r
115 // when the button is clicked.
\r
116 final Button ok = new Button("OK", new ClickHandler() {
\r
118 public void onClick(ClickEvent event) {
\r
124 buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
\r
125 // Create the 'Cancel' button, along with a listener that hides the
\r
126 // dialog when the button is clicked.
\r
127 final Button cancel = new Button("Cancel", new ClickHandler() {
\r
129 public void onClick(ClickEvent event) {
\r
133 buttons.add(cancel);
\r
134 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
\r
135 buttons.setSpacing(8);
\r
136 buttons.addStyleName("pithos-TabPanelBottom");
\r
137 outer.add(buttons);
\r
138 outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
\r
139 outer.addStyleName("pithos-TabPanelBottom");
\r
141 focusPanel.setFocus(true);
\r
145 private VerticalPanel createGeneralPanel() {
\r
146 VerticalPanel generalPanel = new VerticalPanel();
\r
148 final FlexTable generalTable = new FlexTable();
\r
149 generalTable.setText(0, 0, String.valueOf(files.size())+" files selected");
\r
150 generalTable.setText(1, 0, "Folder");
\r
151 generalTable.setText(2, 0, "Tags");
\r
152 Folder parent = files.get(0).getParent();
\r
154 generalTable.setText(1, 1, parent.getName());
\r
156 generalTable.setText(1, 1, "-");
\r
158 // Find if tags are identical
\r
159 // List<String> tagsList = files.get(0).getTags();
\r
160 // List<String> tagss;
\r
161 // for (int i=1; i<files.size(); i++) {
\r
162 // tagss = files.get(i).getTags();
\r
163 // if (tagsList.size() != tagss.size() || !tagsList.containsAll(tagss)) {
\r
164 // tagsList = null;
\r
168 // // Get the tags.
\r
169 // StringBuffer tagsBuffer = new StringBuffer();
\r
170 // if (tagsList==null)
\r
171 // tagsBuffer.append(MULTIPLE_VALUES_TEXT);
\r
173 // Iterator i = tagsList.iterator();
\r
174 // while (i.hasNext()) {
\r
175 // String tag = (String) i.next();
\r
176 // tagsBuffer.append(tag).append(", ");
\r
178 // if (tagsBuffer.length() > 1)
\r
179 // tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1);
\r
181 // initialTagText = tagsBuffer.toString();
\r
182 // tags.setText(initialTagText);
\r
183 // tags.addFocusHandler(new FocusHandler() {
\r
185 // public void onFocus(FocusEvent event) {
\r
186 // if (MULTIPLE_VALUES_TEXT.equals(tags.getText()))
\r
187 // tags.setText("");
\r
192 // generalTable.setWidget(2, 1, tags);
\r
193 generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
\r
194 generalTable.getFlexCellFormatter().setColSpan(0, 0, 2);
\r
195 generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
\r
196 generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");
\r
197 generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");
\r
198 generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");
\r
199 generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");
\r
200 generalTable.setCellSpacing(4);
\r
202 generalPanel.add(generalTable);
\r
204 // Asynchronously retrieve the tags defined by this user.
\r
205 // DeferredCommand.addCommand(new Command() {
\r
208 // public void execute() {
\r
213 DisclosurePanel allTags = new DisclosurePanel("All tags");
\r
214 allTagsContent = new FlowPanel();
\r
215 allTags.setContent(allTagsContent);
\r
216 generalPanel.add(allTags);
\r
217 generalPanel.setSpacing(4);
\r
219 return generalPanel;
\r
223 * Accepts any change and updates the file
\r
227 protected void accept() {
\r
228 // JSONObject json = new JSONObject();
\r
229 // if ( versionedCheck.getState()!=null && !versionedCheck.getState().equals(initialVersioned) )
\r
230 // json.put("versioned", JSONBoolean.getInstance(versionedCheck.getState()));
\r
232 // JSONArray taga = new JSONArray();
\r
234 // String tagText = tags.getText();
\r
235 // if (!MULTIPLE_VALUES_TEXT.equals(tagText) && !initialTagText.equals(tagText)) {
\r
236 // String[] tagset = tagText.split(",");
\r
237 // for (String t : tagset) {
\r
238 // JSONString to = new JSONString(t);
\r
239 // taga.set(i, to);
\r
242 // json.put("tags", taga);
\r
244 // String jsonString = json.toString();
\r
245 // if(jsonString.equals("{}")){
\r
246 // GWT.log("NO CHANGES", null);
\r
249 // final List<String> fileIds = new ArrayList<String>();
\r
250 // for(FileResource f : files)
\r
251 // fileIds.add(f.getUri()+"?update=");
\r
252 // MultiplePostCommand rt = new MultiplePostCommand(fileIds.toArray(new String[0]), jsonString, 200){
\r
255 // public void onComplete() {
\r
256 // app.getTreeView().refreshCurrentNode(false);
\r
260 // public void onError(String p, Throwable t) {
\r
262 // if(t instanceof RestException){
\r
263 // int statusCode = ((RestException)t).getHttpStatusCode();
\r
264 // if(statusCode == 405)
\r
265 // app.displayError("You don't have the necessary permissions");
\r
266 // else if(statusCode == 404)
\r
267 // app.displayError("File does not exist");
\r
268 // else if(statusCode == 409)
\r
269 // app.displayError("A file with the same name already exists");
\r
270 // else if(statusCode == 413)
\r
271 // app.displayError("Your quota has been exceeded");
\r
273 // app.displayError("Unable to modify file::"+((RestException)t).getHttpStatusText());
\r
276 // app.displayError("System error modifying file:"+t.getMessage());
\r
279 // DeferredCommand.addCommand(rt);
\r