Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (9.6 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.foldertree.File;
38
import gr.grnet.pithos.web.client.foldertree.Folder;
39

    
40
import java.util.List;
41

    
42
import com.google.gwt.event.dom.client.ClickEvent;
43
import com.google.gwt.event.dom.client.ClickHandler;
44
import com.google.gwt.user.client.ui.Button;
45
import com.google.gwt.user.client.ui.DecoratedTabPanel;
46
import com.google.gwt.user.client.ui.DisclosurePanel;
47
import com.google.gwt.user.client.ui.FlexTable;
48
import com.google.gwt.user.client.ui.FlowPanel;
49
import com.google.gwt.user.client.ui.FocusPanel;
50
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
51
import com.google.gwt.user.client.ui.HorizontalPanel;
52
import com.google.gwt.user.client.ui.VerticalPanel;
53

    
54
/**
55
 * The 'Multiple file properties' dialog box implementation.
56
 *
57
 */
58
public class FilesPropertiesDialog extends AbstractPropertiesDialog {
59

    
60
//        private final TristateCheckBox versionedCheck;
61

    
62
        private final List<File> files;
63

    
64
        private Boolean initialVersioned;
65

    
66

    
67
        /**
68
         * The widget's constructor.
69
         *
70
         * @param _files
71
         */
72
        public FilesPropertiesDialog(Pithos _app, final List<File> _files) {
73
                super();
74

    
75
                files = _files;
76
//                int versionedNum = 0;
77
//                for (File fr : files)
78
//                        if (fr.isVersioned()) versionedNum++;
79
//                Boolean versioned = null;
80
//                if (versionedNum == 0)
81
//            versioned = false;
82
//                if (versionedNum == files.size())
83
//            versioned = true;
84

    
85
//                initialVersioned = versioned;
86
//                versionedCheck = new TristateCheckBox(versioned);
87

    
88
                // Set the dialog's caption.
89
                setText("Files properties");
90

    
91
                // Outer contains inner and buttons.
92
                final VerticalPanel outer = new VerticalPanel();
93
                final FocusPanel focusPanel = new FocusPanel(outer);
94
                // Inner contains generalPanel and permPanel.
95
                inner = new DecoratedTabPanel();
96
                inner.setAnimationEnabled(true);
97

    
98
                inner.add(createGeneralPanel(), "General");
99

    
100
        final VerticalPanel verPanel = new VerticalPanel();
101

    
102
//        final HorizontalPanel vPanel = new HorizontalPanel();
103
//        vPanel.setSpacing(8);
104
//        vPanel.addStyleName("pithos-TabPanelBottom");
105
//        vPanel.add(new Label("Versioned"));
106
//        vPanel.add(versionedCheck);
107
//
108
//        verPanel.add(vPanel);
109

    
110
                inner.add(verPanel, "Versions");
111
                inner.selectTab(0);
112
        outer.add(inner);
113

    
114
        final HorizontalPanel buttons = new HorizontalPanel();
115
                // Create the 'OK' button, along with a listener that hides the dialog
116
                // when the button is clicked.
117
                final Button ok = new Button("OK", new ClickHandler() {
118
                        @Override
119
                        public void onClick(ClickEvent event) {
120
                                accept();
121
                                closeDialog();
122
                        }
123
                });
124
                buttons.add(ok);
125
                buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
126
                // Create the 'Cancel' button, along with a listener that hides the
127
                // dialog when the button is clicked.
128
                final Button cancel = new Button("Cancel", new ClickHandler() {
129
                        @Override
130
                        public void onClick(ClickEvent event) {
131
                                closeDialog();
132
                        }
133
                });
134
                buttons.add(cancel);
135
                buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
136
                buttons.setSpacing(8);
137
                buttons.addStyleName("pithos-TabPanelBottom");
138
                outer.add(buttons);
139
                outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
140
                outer.addStyleName("pithos-TabPanelBottom");
141

    
142
                focusPanel.setFocus(true);
143
                setWidget(outer);
144
        }
145

    
146
    private VerticalPanel createGeneralPanel() {
147
        VerticalPanel generalPanel = new VerticalPanel();
148

    
149
        final FlexTable generalTable = new FlexTable();
150
        generalTable.setText(0, 0, String.valueOf(files.size())+" files selected");
151
        generalTable.setText(1, 0, "Folder");
152
        generalTable.setText(2, 0, "Tags");
153
        Folder parent = files.get(0).getParent();
154
        if(parent != null)
155
            generalTable.setText(1, 1, parent.getName());
156
        else
157
            generalTable.setText(1, 1, "-");
158

    
159
                // Find if tags are identical
160
//                List<String> tagsList = files.get(0).getTags();
161
//                List<String> tagss;
162
//                for (int i=1; i<files.size(); i++) {
163
//                        tagss = files.get(i).getTags();
164
//                        if (tagsList.size() != tagss.size() || !tagsList.containsAll(tagss)) {
165
//                                tagsList = null;
166
//                                break;
167
//                        }
168
//                }
169
//                // Get the tags.
170
//                StringBuffer tagsBuffer = new StringBuffer();
171
//                if (tagsList==null)
172
//                        tagsBuffer.append(MULTIPLE_VALUES_TEXT);
173
//                else {
174
//                        Iterator i = tagsList.iterator();
175
//                        while (i.hasNext()) {
176
//                                String tag = (String) i.next();
177
//                                tagsBuffer.append(tag).append(", ");
178
//                        }
179
//                        if (tagsBuffer.length() > 1)
180
//                                tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1);
181
//                }
182
//                initialTagText = tagsBuffer.toString();
183
//                tags.setText(initialTagText);
184
//                tags.addFocusHandler(new FocusHandler() {
185
//                        @Override
186
//                        public void onFocus(FocusEvent event) {
187
//                                if (MULTIPLE_VALUES_TEXT.equals(tags.getText()))
188
//                                        tags.setText("");
189
//                        }
190
//                }
191
//                );
192
//
193
//                generalTable.setWidget(2, 1, tags);
194
                generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
195
                generalTable.getFlexCellFormatter().setColSpan(0, 0, 2);
196
                generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
197
                generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");
198
                generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");
199
                generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");
200
                generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");
201
                generalTable.setCellSpacing(4);
202

    
203
        generalPanel.add(generalTable);
204

    
205
                // Asynchronously retrieve the tags defined by this user.
206
//                DeferredCommand.addCommand(new Command() {
207
//
208
//                        @Override
209
//                        public void execute() {
210
//                                updateTags();
211
//                        }
212
//                });
213

    
214
                DisclosurePanel allTags = new DisclosurePanel("All tags");
215
                allTagsContent = new FlowPanel();
216
                allTags.setContent(allTagsContent);
217
                generalPanel.add(allTags);
218
                generalPanel.setSpacing(4);
219

    
220
        return generalPanel;
221
    }
222

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