Statistics
| Branch: | Tag: | Revision:

root / web_client / src / gr / grnet / pithos / web / client / FilesPropertiesDialog.java @ ba0078a6

History | View | Annotate | Download (9.6 kB)

1 ab1eb3f8 Christos Stathis
/*
2 58777026 Christos Stathis
 * Copyright 2011 GRNET S.A. All rights reserved.
3 58777026 Christos Stathis
 *
4 58777026 Christos Stathis
 * Redistribution and use in source and binary forms, with or
5 58777026 Christos Stathis
 * without modification, are permitted provided that the following
6 58777026 Christos Stathis
 * conditions are met:
7 58777026 Christos Stathis
 *
8 58777026 Christos Stathis
 *   1. Redistributions of source code must retain the above
9 58777026 Christos Stathis
 *      copyright notice, this list of conditions and the following
10 58777026 Christos Stathis
 *      disclaimer.
11 58777026 Christos Stathis
 *
12 58777026 Christos Stathis
 *   2. Redistributions in binary form must reproduce the above
13 58777026 Christos Stathis
 *      copyright notice, this list of conditions and the following
14 58777026 Christos Stathis
 *      disclaimer in the documentation and/or other materials
15 58777026 Christos Stathis
 *      provided with the distribution.
16 58777026 Christos Stathis
 *
17 58777026 Christos Stathis
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 58777026 Christos Stathis
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 58777026 Christos Stathis
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 58777026 Christos Stathis
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 58777026 Christos Stathis
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 58777026 Christos Stathis
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 58777026 Christos Stathis
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 58777026 Christos Stathis
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 58777026 Christos Stathis
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 58777026 Christos Stathis
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 58777026 Christos Stathis
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 58777026 Christos Stathis
 * POSSIBILITY OF SUCH DAMAGE.
29 58777026 Christos Stathis
 *
30 58777026 Christos Stathis
 * The views and conclusions contained in the software and
31 58777026 Christos Stathis
 * documentation are those of the authors and should not be
32 58777026 Christos Stathis
 * interpreted as representing official policies, either expressed
33 58777026 Christos Stathis
 * or implied, of GRNET S.A.
34 ab1eb3f8 Christos Stathis
 */
35 ab1eb3f8 Christos Stathis
package gr.grnet.pithos.web.client;
36 ab1eb3f8 Christos Stathis
37 feeaebc3 Christos Stathis
import gr.grnet.pithos.web.client.foldertree.File;
38 feeaebc3 Christos Stathis
import gr.grnet.pithos.web.client.foldertree.Folder;
39 ab1eb3f8 Christos Stathis
40 ab1eb3f8 Christos Stathis
import java.util.List;
41 ab1eb3f8 Christos Stathis
42 ab1eb3f8 Christos Stathis
import com.google.gwt.event.dom.client.ClickEvent;
43 ab1eb3f8 Christos Stathis
import com.google.gwt.event.dom.client.ClickHandler;
44 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.Button;
45 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.DecoratedTabPanel;
46 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.DisclosurePanel;
47 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.FlexTable;
48 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.FlowPanel;
49 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.FocusPanel;
50 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
51 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.HorizontalPanel;
52 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.VerticalPanel;
53 ab1eb3f8 Christos Stathis
54 ab1eb3f8 Christos Stathis
/**
55 ab1eb3f8 Christos Stathis
 * The 'Multiple file properties' dialog box implementation.
56 ab1eb3f8 Christos Stathis
 *
57 ab1eb3f8 Christos Stathis
 */
58 ab1eb3f8 Christos Stathis
public class FilesPropertiesDialog extends AbstractPropertiesDialog {
59 ab1eb3f8 Christos Stathis
60 feeaebc3 Christos Stathis
//        private final TristateCheckBox versionedCheck;
61 ab1eb3f8 Christos Stathis
62 feeaebc3 Christos Stathis
        private final List<File> files;
63 ab1eb3f8 Christos Stathis
64 ab1eb3f8 Christos Stathis
        private Boolean initialVersioned;
65 ab1eb3f8 Christos Stathis
66 ab1eb3f8 Christos Stathis
67 ab1eb3f8 Christos Stathis
        /**
68 ab1eb3f8 Christos Stathis
         * The widget's constructor.
69 ab1eb3f8 Christos Stathis
         *
70 ab1eb3f8 Christos Stathis
         * @param _files
71 ab1eb3f8 Christos Stathis
         */
72 f55cf326 Christos Stathis
        public FilesPropertiesDialog(Pithos _app, final List<File> _files) {
73 ab1eb3f8 Christos Stathis
                super();
74 ab1eb3f8 Christos Stathis
75 ab1eb3f8 Christos Stathis
                files = _files;
76 feeaebc3 Christos Stathis
//                int versionedNum = 0;
77 feeaebc3 Christos Stathis
//                for (File fr : files)
78 feeaebc3 Christos Stathis
//                        if (fr.isVersioned()) versionedNum++;
79 feeaebc3 Christos Stathis
//                Boolean versioned = null;
80 feeaebc3 Christos Stathis
//                if (versionedNum == 0)
81 feeaebc3 Christos Stathis
//            versioned = false;
82 feeaebc3 Christos Stathis
//                if (versionedNum == files.size())
83 feeaebc3 Christos Stathis
//            versioned = true;
84 feeaebc3 Christos Stathis
85 feeaebc3 Christos Stathis
//                initialVersioned = versioned;
86 feeaebc3 Christos Stathis
//                versionedCheck = new TristateCheckBox(versioned);
87 ab1eb3f8 Christos Stathis
88 ab1eb3f8 Christos Stathis
                // Set the dialog's caption.
89 ab1eb3f8 Christos Stathis
                setText("Files properties");
90 ab1eb3f8 Christos Stathis
91 ab1eb3f8 Christos Stathis
                // Outer contains inner and buttons.
92 ab1eb3f8 Christos Stathis
                final VerticalPanel outer = new VerticalPanel();
93 ab1eb3f8 Christos Stathis
                final FocusPanel focusPanel = new FocusPanel(outer);
94 ab1eb3f8 Christos Stathis
                // Inner contains generalPanel and permPanel.
95 ab1eb3f8 Christos Stathis
                inner = new DecoratedTabPanel();
96 ab1eb3f8 Christos Stathis
                inner.setAnimationEnabled(true);
97 ab1eb3f8 Christos Stathis
98 feeaebc3 Christos Stathis
                inner.add(createGeneralPanel(), "General");
99 ab1eb3f8 Christos Stathis
100 feeaebc3 Christos Stathis
        final VerticalPanel verPanel = new VerticalPanel();
101 ab1eb3f8 Christos Stathis
102 feeaebc3 Christos Stathis
//        final HorizontalPanel vPanel = new HorizontalPanel();
103 feeaebc3 Christos Stathis
//        vPanel.setSpacing(8);
104 feeaebc3 Christos Stathis
//        vPanel.addStyleName("pithos-TabPanelBottom");
105 feeaebc3 Christos Stathis
//        vPanel.add(new Label("Versioned"));
106 feeaebc3 Christos Stathis
//        vPanel.add(versionedCheck);
107 feeaebc3 Christos Stathis
//
108 feeaebc3 Christos Stathis
//        verPanel.add(vPanel);
109 ab1eb3f8 Christos Stathis
110 feeaebc3 Christos Stathis
                inner.add(verPanel, "Versions");
111 feeaebc3 Christos Stathis
                inner.selectTab(0);
112 feeaebc3 Christos Stathis
        outer.add(inner);
113 ab1eb3f8 Christos Stathis
114 feeaebc3 Christos Stathis
        final HorizontalPanel buttons = new HorizontalPanel();
115 ab1eb3f8 Christos Stathis
                // Create the 'OK' button, along with a listener that hides the dialog
116 ab1eb3f8 Christos Stathis
                // when the button is clicked.
117 ab1eb3f8 Christos Stathis
                final Button ok = new Button("OK", new ClickHandler() {
118 ab1eb3f8 Christos Stathis
                        @Override
119 ab1eb3f8 Christos Stathis
                        public void onClick(ClickEvent event) {
120 ab1eb3f8 Christos Stathis
                                accept();
121 ab1eb3f8 Christos Stathis
                                closeDialog();
122 ab1eb3f8 Christos Stathis
                        }
123 ab1eb3f8 Christos Stathis
                });
124 ab1eb3f8 Christos Stathis
                buttons.add(ok);
125 ab1eb3f8 Christos Stathis
                buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
126 ab1eb3f8 Christos Stathis
                // Create the 'Cancel' button, along with a listener that hides the
127 ab1eb3f8 Christos Stathis
                // dialog when the button is clicked.
128 ab1eb3f8 Christos Stathis
                final Button cancel = new Button("Cancel", new ClickHandler() {
129 ab1eb3f8 Christos Stathis
                        @Override
130 ab1eb3f8 Christos Stathis
                        public void onClick(ClickEvent event) {
131 ab1eb3f8 Christos Stathis
                                closeDialog();
132 ab1eb3f8 Christos Stathis
                        }
133 ab1eb3f8 Christos Stathis
                });
134 ab1eb3f8 Christos Stathis
                buttons.add(cancel);
135 ab1eb3f8 Christos Stathis
                buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
136 ab1eb3f8 Christos Stathis
                buttons.setSpacing(8);
137 ab1eb3f8 Christos Stathis
                buttons.addStyleName("pithos-TabPanelBottom");
138 feeaebc3 Christos Stathis
                outer.add(buttons);
139 feeaebc3 Christos Stathis
                outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
140 feeaebc3 Christos Stathis
                outer.addStyleName("pithos-TabPanelBottom");
141 ab1eb3f8 Christos Stathis
142 feeaebc3 Christos Stathis
                focusPanel.setFocus(true);
143 feeaebc3 Christos Stathis
                setWidget(outer);
144 feeaebc3 Christos Stathis
        }
145 ab1eb3f8 Christos Stathis
146 feeaebc3 Christos Stathis
    private VerticalPanel createGeneralPanel() {
147 feeaebc3 Christos Stathis
        VerticalPanel generalPanel = new VerticalPanel();
148 ab1eb3f8 Christos Stathis
149 feeaebc3 Christos Stathis
        final FlexTable generalTable = new FlexTable();
150 feeaebc3 Christos Stathis
        generalTable.setText(0, 0, String.valueOf(files.size())+" files selected");
151 feeaebc3 Christos Stathis
        generalTable.setText(1, 0, "Folder");
152 feeaebc3 Christos Stathis
        generalTable.setText(2, 0, "Tags");
153 feeaebc3 Christos Stathis
        Folder parent = files.get(0).getParent();
154 feeaebc3 Christos Stathis
        if(parent != null)
155 feeaebc3 Christos Stathis
            generalTable.setText(1, 1, parent.getName());
156 feeaebc3 Christos Stathis
        else
157 feeaebc3 Christos Stathis
            generalTable.setText(1, 1, "-");
158 feeaebc3 Christos Stathis
159 feeaebc3 Christos Stathis
                // Find if tags are identical
160 feeaebc3 Christos Stathis
//                List<String> tagsList = files.get(0).getTags();
161 feeaebc3 Christos Stathis
//                List<String> tagss;
162 feeaebc3 Christos Stathis
//                for (int i=1; i<files.size(); i++) {
163 feeaebc3 Christos Stathis
//                        tagss = files.get(i).getTags();
164 feeaebc3 Christos Stathis
//                        if (tagsList.size() != tagss.size() || !tagsList.containsAll(tagss)) {
165 feeaebc3 Christos Stathis
//                                tagsList = null;
166 feeaebc3 Christos Stathis
//                                break;
167 feeaebc3 Christos Stathis
//                        }
168 feeaebc3 Christos Stathis
//                }
169 feeaebc3 Christos Stathis
//                // Get the tags.
170 feeaebc3 Christos Stathis
//                StringBuffer tagsBuffer = new StringBuffer();
171 feeaebc3 Christos Stathis
//                if (tagsList==null)
172 feeaebc3 Christos Stathis
//                        tagsBuffer.append(MULTIPLE_VALUES_TEXT);
173 feeaebc3 Christos Stathis
//                else {
174 feeaebc3 Christos Stathis
//                        Iterator i = tagsList.iterator();
175 feeaebc3 Christos Stathis
//                        while (i.hasNext()) {
176 feeaebc3 Christos Stathis
//                                String tag = (String) i.next();
177 feeaebc3 Christos Stathis
//                                tagsBuffer.append(tag).append(", ");
178 feeaebc3 Christos Stathis
//                        }
179 feeaebc3 Christos Stathis
//                        if (tagsBuffer.length() > 1)
180 feeaebc3 Christos Stathis
//                                tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1);
181 feeaebc3 Christos Stathis
//                }
182 feeaebc3 Christos Stathis
//                initialTagText = tagsBuffer.toString();
183 feeaebc3 Christos Stathis
//                tags.setText(initialTagText);
184 feeaebc3 Christos Stathis
//                tags.addFocusHandler(new FocusHandler() {
185 feeaebc3 Christos Stathis
//                        @Override
186 feeaebc3 Christos Stathis
//                        public void onFocus(FocusEvent event) {
187 feeaebc3 Christos Stathis
//                                if (MULTIPLE_VALUES_TEXT.equals(tags.getText()))
188 feeaebc3 Christos Stathis
//                                        tags.setText("");
189 feeaebc3 Christos Stathis
//                        }
190 feeaebc3 Christos Stathis
//                }
191 feeaebc3 Christos Stathis
//                );
192 feeaebc3 Christos Stathis
//
193 feeaebc3 Christos Stathis
//                generalTable.setWidget(2, 1, tags);
194 feeaebc3 Christos Stathis
                generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
195 feeaebc3 Christos Stathis
                generalTable.getFlexCellFormatter().setColSpan(0, 0, 2);
196 feeaebc3 Christos Stathis
                generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
197 feeaebc3 Christos Stathis
                generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");
198 feeaebc3 Christos Stathis
                generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");
199 feeaebc3 Christos Stathis
                generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");
200 feeaebc3 Christos Stathis
                generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");
201 feeaebc3 Christos Stathis
                generalTable.setCellSpacing(4);
202 feeaebc3 Christos Stathis
203 feeaebc3 Christos Stathis
        generalPanel.add(generalTable);
204 feeaebc3 Christos Stathis
205 feeaebc3 Christos Stathis
                // Asynchronously retrieve the tags defined by this user.
206 feeaebc3 Christos Stathis
//                DeferredCommand.addCommand(new Command() {
207 feeaebc3 Christos Stathis
//
208 feeaebc3 Christos Stathis
//                        @Override
209 feeaebc3 Christos Stathis
//                        public void execute() {
210 feeaebc3 Christos Stathis
//                                updateTags();
211 feeaebc3 Christos Stathis
//                        }
212 feeaebc3 Christos Stathis
//                });
213 ab1eb3f8 Christos Stathis
214 ab1eb3f8 Christos Stathis
                DisclosurePanel allTags = new DisclosurePanel("All tags");
215 ab1eb3f8 Christos Stathis
                allTagsContent = new FlowPanel();
216 ab1eb3f8 Christos Stathis
                allTags.setContent(allTagsContent);
217 ab1eb3f8 Christos Stathis
                generalPanel.add(allTags);
218 ab1eb3f8 Christos Stathis
                generalPanel.setSpacing(4);
219 ab1eb3f8 Christos Stathis
220 feeaebc3 Christos Stathis
        return generalPanel;
221 feeaebc3 Christos Stathis
    }
222 ab1eb3f8 Christos Stathis
223 ab1eb3f8 Christos Stathis
        /**
224 ab1eb3f8 Christos Stathis
         * Accepts any change and updates the file
225 ab1eb3f8 Christos Stathis
         *
226 ab1eb3f8 Christos Stathis
         */
227 ab1eb3f8 Christos Stathis
        @Override
228 ab1eb3f8 Christos Stathis
        protected void accept() {
229 feeaebc3 Christos Stathis
//                JSONObject json = new JSONObject();
230 feeaebc3 Christos Stathis
//                if ( versionedCheck.getState()!=null && !versionedCheck.getState().equals(initialVersioned) )
231 feeaebc3 Christos Stathis
//                                json.put("versioned", JSONBoolean.getInstance(versionedCheck.getState()));
232 feeaebc3 Christos Stathis
//
233 feeaebc3 Christos Stathis
//                JSONArray taga = new JSONArray();
234 feeaebc3 Christos Stathis
//                int i = 0;
235 feeaebc3 Christos Stathis
//                String tagText = tags.getText();
236 feeaebc3 Christos Stathis
//                if (!MULTIPLE_VALUES_TEXT.equals(tagText) && !initialTagText.equals(tagText)) {
237 feeaebc3 Christos Stathis
//                        String[] tagset = tagText.split(",");
238 feeaebc3 Christos Stathis
//                        for (String t : tagset) {
239 feeaebc3 Christos Stathis
//                                JSONString to = new JSONString(t);
240 feeaebc3 Christos Stathis
//                                taga.set(i, to);
241 feeaebc3 Christos Stathis
//                                i++;
242 feeaebc3 Christos Stathis
//                        }
243 feeaebc3 Christos Stathis
//                        json.put("tags", taga);
244 feeaebc3 Christos Stathis
//                }
245 feeaebc3 Christos Stathis
//                String jsonString = json.toString();
246 feeaebc3 Christos Stathis
//                if(jsonString.equals("{}")){
247 feeaebc3 Christos Stathis
//                        GWT.log("NO CHANGES", null);
248 feeaebc3 Christos Stathis
//                        return;
249 feeaebc3 Christos Stathis
//                }
250 feeaebc3 Christos Stathis
//                final List<String> fileIds = new ArrayList<String>();
251 feeaebc3 Christos Stathis
//                for(FileResource f : files)
252 feeaebc3 Christos Stathis
//                        fileIds.add(f.getUri()+"?update=");
253 feeaebc3 Christos Stathis
//                MultiplePostCommand rt = new MultiplePostCommand(fileIds.toArray(new String[0]), jsonString, 200){
254 feeaebc3 Christos Stathis
//
255 feeaebc3 Christos Stathis
//                        @Override
256 feeaebc3 Christos Stathis
//                        public void onComplete() {
257 f55cf326 Christos Stathis
//                                Pithos.get().getTreeView().refreshCurrentNode(false);
258 feeaebc3 Christos Stathis
//                        }
259 feeaebc3 Christos Stathis
//
260 feeaebc3 Christos Stathis
//                        @Override
261 feeaebc3 Christos Stathis
//                        public void onError(String p, Throwable t) {
262 feeaebc3 Christos Stathis
//                                GWT.log("", t);
263 feeaebc3 Christos Stathis
//                                if(t instanceof RestException){
264 feeaebc3 Christos Stathis
//                                        int statusCode = ((RestException)t).getHttpStatusCode();
265 feeaebc3 Christos Stathis
//                                        if(statusCode == 405)
266 f55cf326 Christos Stathis
//                                                Pithos.get().displayError("You don't have the necessary permissions");
267 feeaebc3 Christos Stathis
//                                        else if(statusCode == 404)
268 f55cf326 Christos Stathis
//                                                Pithos.get().displayError("File does not exist");
269 feeaebc3 Christos Stathis
//                                        else if(statusCode == 409)
270 f55cf326 Christos Stathis
//                                                Pithos.get().displayError("A file with the same name already exists");
271 feeaebc3 Christos Stathis
//                                        else if(statusCode == 413)
272 f55cf326 Christos Stathis
//                                                Pithos.get().displayError("Your quota has been exceeded");
273 feeaebc3 Christos Stathis
//                                        else
274 f55cf326 Christos Stathis
//                                                Pithos.get().displayError("Unable to modify file::"+((RestException)t).getHttpStatusText());
275 feeaebc3 Christos Stathis
//                                }
276 feeaebc3 Christos Stathis
//                                else
277 f55cf326 Christos Stathis
//                                        Pithos.get().displayError("System error modifying file:"+t.getMessage());
278 feeaebc3 Christos Stathis
//                        }
279 feeaebc3 Christos Stathis
//                };
280 feeaebc3 Christos Stathis
//                DeferredCommand.addCommand(rt);
281 ab1eb3f8 Christos Stathis
        }
282 ab1eb3f8 Christos Stathis
}