Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (10.4 kB)

1
/*
2
 * Copyright 2011 GRNET S.A. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or
5
 * without modification, are permitted provided that the following
6
 * conditions are met:
7
 *
8
 *   1. Redistributions of source code must retain the above
9
 *      copyright notice, this list of conditions and the following
10
 *      disclaimer.
11
 *
12
 *   2. Redistributions in binary form must reproduce the above
13
 *      copyright notice, this list of conditions and the following
14
 *      disclaimer in the documentation and/or other materials
15
 *      provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
 * POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * The views and conclusions contained in the software and
31
 * documentation are those of the authors and should not be
32
 * interpreted as representing official policies, either expressed
33
 * or implied, of GRNET S.A.
34
 */
35
package gr.grnet.pithos.web.client;
36

    
37
import gr.grnet.pithos.web.client.components.TristateCheckBox;
38
import gr.grnet.pithos.web.client.foldertree.File;
39
import gr.grnet.pithos.web.client.foldertree.Folder;
40
import gr.grnet.pithos.web.client.rest.MultiplePostCommand;
41
import gr.grnet.pithos.web.client.rest.RestException;
42
import gr.grnet.pithos.web.client.rest.resource.FileResource;
43

    
44
import java.util.ArrayList;
45
import java.util.Iterator;
46
import java.util.List;
47

    
48
import com.google.gwt.core.client.GWT;
49
import com.google.gwt.event.dom.client.ClickEvent;
50
import com.google.gwt.event.dom.client.ClickHandler;
51
import com.google.gwt.event.dom.client.FocusEvent;
52
import com.google.gwt.event.dom.client.FocusHandler;
53
import com.google.gwt.json.client.JSONArray;
54
import com.google.gwt.json.client.JSONBoolean;
55
import com.google.gwt.json.client.JSONObject;
56
import com.google.gwt.json.client.JSONString;
57
import com.google.gwt.user.client.Command;
58
import com.google.gwt.user.client.DeferredCommand;
59
import com.google.gwt.user.client.ui.Button;
60
import com.google.gwt.user.client.ui.DecoratedTabPanel;
61
import com.google.gwt.user.client.ui.DisclosurePanel;
62
import com.google.gwt.user.client.ui.FlexTable;
63
import com.google.gwt.user.client.ui.FlowPanel;
64
import com.google.gwt.user.client.ui.FocusPanel;
65
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
66
import com.google.gwt.user.client.ui.HorizontalPanel;
67
import com.google.gwt.user.client.ui.Label;
68
import com.google.gwt.user.client.ui.VerticalPanel;
69

    
70
/**
71
 * The 'Multiple file properties' dialog box implementation.
72
 *
73
 */
74
public class FilesPropertiesDialog extends AbstractPropertiesDialog {
75

    
76
//        private final TristateCheckBox versionedCheck;
77

    
78
        private final List<File> files;
79

    
80
        private Boolean initialVersioned;
81

    
82

    
83
        /**
84
         * The widget's constructor.
85
         *
86
         * @param _files
87
         */
88
        public FilesPropertiesDialog(GSS _app, final List<File> _files) {
89
                super();
90

    
91
                files = _files;
92
//                int versionedNum = 0;
93
//                for (File fr : files)
94
//                        if (fr.isVersioned()) versionedNum++;
95
//                Boolean versioned = null;
96
//                if (versionedNum == 0)
97
//            versioned = false;
98
//                if (versionedNum == files.size())
99
//            versioned = true;
100

    
101
//                initialVersioned = versioned;
102
//                versionedCheck = new TristateCheckBox(versioned);
103

    
104
                // Set the dialog's caption.
105
                setText("Files properties");
106

    
107
                // Outer contains inner and buttons.
108
                final VerticalPanel outer = new VerticalPanel();
109
                final FocusPanel focusPanel = new FocusPanel(outer);
110
                // Inner contains generalPanel and permPanel.
111
                inner = new DecoratedTabPanel();
112
                inner.setAnimationEnabled(true);
113

    
114
                inner.add(createGeneralPanel(), "General");
115

    
116
        final VerticalPanel verPanel = new VerticalPanel();
117

    
118
//        final HorizontalPanel vPanel = new HorizontalPanel();
119
//        vPanel.setSpacing(8);
120
//        vPanel.addStyleName("pithos-TabPanelBottom");
121
//        vPanel.add(new Label("Versioned"));
122
//        vPanel.add(versionedCheck);
123
//
124
//        verPanel.add(vPanel);
125

    
126
                inner.add(verPanel, "Versions");
127
                inner.selectTab(0);
128
        outer.add(inner);
129

    
130
        final HorizontalPanel buttons = new HorizontalPanel();
131
                // Create the 'OK' button, along with a listener that hides the dialog
132
                // when the button is clicked.
133
                final Button ok = new Button("OK", new ClickHandler() {
134
                        @Override
135
                        public void onClick(ClickEvent event) {
136
                                accept();
137
                                closeDialog();
138
                        }
139
                });
140
                buttons.add(ok);
141
                buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
142
                // Create the 'Cancel' button, along with a listener that hides the
143
                // dialog when the button is clicked.
144
                final Button cancel = new Button("Cancel", new ClickHandler() {
145
                        @Override
146
                        public void onClick(ClickEvent event) {
147
                                closeDialog();
148
                        }
149
                });
150
                buttons.add(cancel);
151
                buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
152
                buttons.setSpacing(8);
153
                buttons.addStyleName("pithos-TabPanelBottom");
154
                outer.add(buttons);
155
                outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
156
                outer.addStyleName("pithos-TabPanelBottom");
157

    
158
                focusPanel.setFocus(true);
159
                setWidget(outer);
160
        }
161

    
162
    private VerticalPanel createGeneralPanel() {
163
        VerticalPanel generalPanel = new VerticalPanel();
164

    
165
        final FlexTable generalTable = new FlexTable();
166
        generalTable.setText(0, 0, String.valueOf(files.size())+" files selected");
167
        generalTable.setText(1, 0, "Folder");
168
        generalTable.setText(2, 0, "Tags");
169
        Folder parent = files.get(0).getParent();
170
        if(parent != null)
171
            generalTable.setText(1, 1, parent.getName());
172
        else
173
            generalTable.setText(1, 1, "-");
174

    
175
                // Find if tags are identical
176
//                List<String> tagsList = files.get(0).getTags();
177
//                List<String> tagss;
178
//                for (int i=1; i<files.size(); i++) {
179
//                        tagss = files.get(i).getTags();
180
//                        if (tagsList.size() != tagss.size() || !tagsList.containsAll(tagss)) {
181
//                                tagsList = null;
182
//                                break;
183
//                        }
184
//                }
185
//                // Get the tags.
186
//                StringBuffer tagsBuffer = new StringBuffer();
187
//                if (tagsList==null)
188
//                        tagsBuffer.append(MULTIPLE_VALUES_TEXT);
189
//                else {
190
//                        Iterator i = tagsList.iterator();
191
//                        while (i.hasNext()) {
192
//                                String tag = (String) i.next();
193
//                                tagsBuffer.append(tag).append(", ");
194
//                        }
195
//                        if (tagsBuffer.length() > 1)
196
//                                tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1);
197
//                }
198
//                initialTagText = tagsBuffer.toString();
199
//                tags.setText(initialTagText);
200
//                tags.addFocusHandler(new FocusHandler() {
201
//                        @Override
202
//                        public void onFocus(FocusEvent event) {
203
//                                if (MULTIPLE_VALUES_TEXT.equals(tags.getText()))
204
//                                        tags.setText("");
205
//                        }
206
//                }
207
//                );
208
//
209
//                generalTable.setWidget(2, 1, tags);
210
                generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
211
                generalTable.getFlexCellFormatter().setColSpan(0, 0, 2);
212
                generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
213
                generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");
214
                generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");
215
                generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");
216
                generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");
217
                generalTable.setCellSpacing(4);
218

    
219
        generalPanel.add(generalTable);
220

    
221
                // Asynchronously retrieve the tags defined by this user.
222
//                DeferredCommand.addCommand(new Command() {
223
//
224
//                        @Override
225
//                        public void execute() {
226
//                                updateTags();
227
//                        }
228
//                });
229

    
230
                DisclosurePanel allTags = new DisclosurePanel("All tags");
231
                allTagsContent = new FlowPanel();
232
                allTags.setContent(allTagsContent);
233
                generalPanel.add(allTags);
234
                generalPanel.setSpacing(4);
235

    
236
        return generalPanel;
237
    }
238

    
239
        /**
240
         * Accepts any change and updates the file
241
         *
242
         */
243
        @Override
244
        protected void accept() {
245
//                JSONObject json = new JSONObject();
246
//                if ( versionedCheck.getState()!=null && !versionedCheck.getState().equals(initialVersioned) )
247
//                                json.put("versioned", JSONBoolean.getInstance(versionedCheck.getState()));
248
//
249
//                JSONArray taga = new JSONArray();
250
//                int i = 0;
251
//                String tagText = tags.getText();
252
//                if (!MULTIPLE_VALUES_TEXT.equals(tagText) && !initialTagText.equals(tagText)) {
253
//                        String[] tagset = tagText.split(",");
254
//                        for (String t : tagset) {
255
//                                JSONString to = new JSONString(t);
256
//                                taga.set(i, to);
257
//                                i++;
258
//                        }
259
//                        json.put("tags", taga);
260
//                }
261
//                String jsonString = json.toString();
262
//                if(jsonString.equals("{}")){
263
//                        GWT.log("NO CHANGES", null);
264
//                        return;
265
//                }
266
//                final List<String> fileIds = new ArrayList<String>();
267
//                for(FileResource f : files)
268
//                        fileIds.add(f.getUri()+"?update=");
269
//                MultiplePostCommand rt = new MultiplePostCommand(fileIds.toArray(new String[0]), jsonString, 200){
270
//
271
//                        @Override
272
//                        public void onComplete() {
273
//                                GSS.get().getTreeView().refreshCurrentNode(false);
274
//                        }
275
//
276
//                        @Override
277
//                        public void onError(String p, Throwable t) {
278
//                                GWT.log("", t);
279
//                                if(t instanceof RestException){
280
//                                        int statusCode = ((RestException)t).getHttpStatusCode();
281
//                                        if(statusCode == 405)
282
//                                                GSS.get().displayError("You don't have the necessary permissions");
283
//                                        else if(statusCode == 404)
284
//                                                GSS.get().displayError("File does not exist");
285
//                                        else if(statusCode == 409)
286
//                                                GSS.get().displayError("A file with the same name already exists");
287
//                                        else if(statusCode == 413)
288
//                                                GSS.get().displayError("Your quota has been exceeded");
289
//                                        else
290
//                                                GSS.get().displayError("Unable to modify file::"+((RestException)t).getHttpStatusText());
291
//                                }
292
//                                else
293
//                                        GSS.get().displayError("System error modifying file:"+t.getMessage());
294
//                        }
295
//                };
296
//                DeferredCommand.addCommand(rt);
297
        }
298
}