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
68 * The widget's constructor.
\r
72 public FilesPropertiesDialog(Pithos _app, final List<File> _files) {
\r
76 // int versionedNum = 0;
\r
77 // for (File fr : files)
\r
78 // if (fr.isVersioned()) versionedNum++;
\r
79 // Boolean versioned = null;
\r
80 // if (versionedNum == 0)
\r
81 // versioned = false;
\r
82 // if (versionedNum == files.size())
\r
83 // versioned = true;
\r
85 // initialVersioned = versioned;
\r
86 // versionedCheck = new TristateCheckBox(versioned);
\r
88 // Set the dialog's caption.
\r
89 setText("Files properties");
\r
91 // Outer contains inner and buttons.
\r
92 final VerticalPanel outer = new VerticalPanel();
\r
93 final FocusPanel focusPanel = new FocusPanel(outer);
\r
94 // Inner contains generalPanel and permPanel.
\r
95 inner = new DecoratedTabPanel();
\r
96 inner.setAnimationEnabled(true);
\r
98 inner.add(createGeneralPanel(), "General");
\r
100 final VerticalPanel verPanel = new VerticalPanel();
\r
102 // final HorizontalPanel vPanel = new HorizontalPanel();
\r
103 // vPanel.setSpacing(8);
\r
104 // vPanel.addStyleName("pithos-TabPanelBottom");
\r
105 // vPanel.add(new Label("Versioned"));
\r
106 // vPanel.add(versionedCheck);
\r
108 // verPanel.add(vPanel);
\r
110 inner.add(verPanel, "Versions");
\r
111 inner.selectTab(0);
\r
114 final HorizontalPanel buttons = new HorizontalPanel();
\r
115 // Create the 'OK' button, along with a listener that hides the dialog
\r
116 // when the button is clicked.
\r
117 final Button ok = new Button("OK", new ClickHandler() {
\r
119 public void onClick(ClickEvent event) {
\r
125 buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
\r
126 // Create the 'Cancel' button, along with a listener that hides the
\r
127 // dialog when the button is clicked.
\r
128 final Button cancel = new Button("Cancel", new ClickHandler() {
\r
130 public void onClick(ClickEvent event) {
\r
134 buttons.add(cancel);
\r
135 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
\r
136 buttons.setSpacing(8);
\r
137 buttons.addStyleName("pithos-TabPanelBottom");
\r
138 outer.add(buttons);
\r
139 outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
\r
140 outer.addStyleName("pithos-TabPanelBottom");
\r
142 focusPanel.setFocus(true);
\r
146 private VerticalPanel createGeneralPanel() {
\r
147 VerticalPanel generalPanel = new VerticalPanel();
\r
149 final FlexTable generalTable = new FlexTable();
\r
150 generalTable.setText(0, 0, String.valueOf(files.size())+" files selected");
\r
151 generalTable.setText(1, 0, "Folder");
\r
152 generalTable.setText(2, 0, "Tags");
\r
153 Folder parent = files.get(0).getParent();
\r
155 generalTable.setText(1, 1, parent.getName());
\r
157 generalTable.setText(1, 1, "-");
\r
159 // Find if tags are identical
\r
160 // List<String> tagsList = files.get(0).getTags();
\r
161 // List<String> tagss;
\r
162 // for (int i=1; i<files.size(); i++) {
\r
163 // tagss = files.get(i).getTags();
\r
164 // if (tagsList.size() != tagss.size() || !tagsList.containsAll(tagss)) {
\r
165 // tagsList = null;
\r
169 // // Get the tags.
\r
170 // StringBuffer tagsBuffer = new StringBuffer();
\r
171 // if (tagsList==null)
\r
172 // tagsBuffer.append(MULTIPLE_VALUES_TEXT);
\r
174 // Iterator i = tagsList.iterator();
\r
175 // while (i.hasNext()) {
\r
176 // String tag = (String) i.next();
\r
177 // tagsBuffer.append(tag).append(", ");
\r
179 // if (tagsBuffer.length() > 1)
\r
180 // tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1);
\r
182 // initialTagText = tagsBuffer.toString();
\r
183 // tags.setText(initialTagText);
\r
184 // tags.addFocusHandler(new FocusHandler() {
\r
186 // public void onFocus(FocusEvent event) {
\r
187 // if (MULTIPLE_VALUES_TEXT.equals(tags.getText()))
\r
188 // tags.setText("");
\r
193 // generalTable.setWidget(2, 1, tags);
\r
194 generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
\r
195 generalTable.getFlexCellFormatter().setColSpan(0, 0, 2);
\r
196 generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
\r
197 generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");
\r
198 generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");
\r
199 generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");
\r
200 generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");
\r
201 generalTable.setCellSpacing(4);
\r
203 generalPanel.add(generalTable);
\r
205 // Asynchronously retrieve the tags defined by this user.
\r
206 // DeferredCommand.addCommand(new Command() {
\r
209 // public void execute() {
\r
214 DisclosurePanel allTags = new DisclosurePanel("All tags");
\r
215 allTagsContent = new FlowPanel();
\r
216 allTags.setContent(allTagsContent);
\r
217 generalPanel.add(allTags);
\r
218 generalPanel.setSpacing(4);
\r
220 return generalPanel;
\r
224 * Accepts any change and updates the file
\r
228 protected void accept() {
\r
229 // JSONObject json = new JSONObject();
\r
230 // if ( versionedCheck.getState()!=null && !versionedCheck.getState().equals(initialVersioned) )
\r
231 // json.put("versioned", JSONBoolean.getInstance(versionedCheck.getState()));
\r
233 // JSONArray taga = new JSONArray();
\r
235 // String tagText = tags.getText();
\r
236 // if (!MULTIPLE_VALUES_TEXT.equals(tagText) && !initialTagText.equals(tagText)) {
\r
237 // String[] tagset = tagText.split(",");
\r
238 // for (String t : tagset) {
\r
239 // JSONString to = new JSONString(t);
\r
240 // taga.set(i, to);
\r
243 // json.put("tags", taga);
\r
245 // String jsonString = json.toString();
\r
246 // if(jsonString.equals("{}")){
\r
247 // GWT.log("NO CHANGES", null);
\r
250 // final List<String> fileIds = new ArrayList<String>();
\r
251 // for(FileResource f : files)
\r
252 // fileIds.add(f.getUri()+"?update=");
\r
253 // MultiplePostCommand rt = new MultiplePostCommand(fileIds.toArray(new String[0]), jsonString, 200){
\r
256 // public void onComplete() {
\r
257 // Pithos.get().getTreeView().refreshCurrentNode(false);
\r
261 // public void onError(String p, Throwable t) {
\r
263 // if(t instanceof RestException){
\r
264 // int statusCode = ((RestException)t).getHttpStatusCode();
\r
265 // if(statusCode == 405)
\r
266 // Pithos.get().displayError("You don't have the necessary permissions");
\r
267 // else if(statusCode == 404)
\r
268 // Pithos.get().displayError("File does not exist");
\r
269 // else if(statusCode == 409)
\r
270 // Pithos.get().displayError("A file with the same name already exists");
\r
271 // else if(statusCode == 413)
\r
272 // Pithos.get().displayError("Your quota has been exceeded");
\r
274 // Pithos.get().displayError("Unable to modify file::"+((RestException)t).getHttpStatusText());
\r
277 // Pithos.get().displayError("System error modifying file:"+t.getMessage());
\r
280 // DeferredCommand.addCommand(rt);
\r