Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / client / FilePropertiesDialog.java @ 4cef6f04

History | View | Annotate | Download (18.3 kB)

1 14ad7326 pastith
/*
2 9ab5db6d Natasa Kapravelou
 * Copyright 2007, 2008, 2009, 2010 Electronic Business Systems Ltd.
3 14ad7326 pastith
 *
4 14ad7326 pastith
 * This file is part of GSS.
5 14ad7326 pastith
 *
6 14ad7326 pastith
 * GSS is free software: you can redistribute it and/or modify
7 14ad7326 pastith
 * it under the terms of the GNU General Public License as published by
8 14ad7326 pastith
 * the Free Software Foundation, either version 3 of the License, or
9 14ad7326 pastith
 * (at your option) any later version.
10 14ad7326 pastith
 *
11 14ad7326 pastith
 * GSS is distributed in the hope that it will be useful,
12 14ad7326 pastith
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 14ad7326 pastith
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14ad7326 pastith
 * GNU General Public License for more details.
15 14ad7326 pastith
 *
16 14ad7326 pastith
 * You should have received a copy of the GNU General Public License
17 14ad7326 pastith
 * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18 14ad7326 pastith
 */
19 14ad7326 pastith
package gr.ebs.gss.client;
20 14ad7326 pastith
21 895035a2 pastith
import gr.ebs.gss.client.rest.PostCommand;
22 a52ea5e4 pastith
import gr.ebs.gss.client.rest.RestException;
23 a52ea5e4 pastith
import gr.ebs.gss.client.rest.resource.FileResource;
24 a52ea5e4 pastith
import gr.ebs.gss.client.rest.resource.GroupResource;
25 a52ea5e4 pastith
import gr.ebs.gss.client.rest.resource.PermissionHolder;
26 14ad7326 pastith
27 14ad7326 pastith
import java.util.Iterator;
28 14ad7326 pastith
import java.util.List;
29 14ad7326 pastith
import java.util.Set;
30 14ad7326 pastith
31 14ad7326 pastith
import com.google.gwt.core.client.GWT;
32 78729465 Natasa Kapravelou
import com.google.gwt.event.dom.client.ChangeEvent;
33 78729465 Natasa Kapravelou
import com.google.gwt.event.dom.client.ChangeHandler;
34 afd3a0ef Giannis Koutsoubos
import com.google.gwt.event.dom.client.ClickEvent;
35 afd3a0ef Giannis Koutsoubos
import com.google.gwt.event.dom.client.ClickHandler;
36 8b79a1c8 Natasa Kapravelou
import com.google.gwt.event.dom.client.KeyDownEvent;
37 8b79a1c8 Natasa Kapravelou
import com.google.gwt.event.dom.client.KeyDownHandler;
38 14ad7326 pastith
import com.google.gwt.i18n.client.DateTimeFormat;
39 a52ea5e4 pastith
import com.google.gwt.json.client.JSONArray;
40 a52ea5e4 pastith
import com.google.gwt.json.client.JSONBoolean;
41 a52ea5e4 pastith
import com.google.gwt.json.client.JSONObject;
42 a52ea5e4 pastith
import com.google.gwt.json.client.JSONString;
43 afd3a0ef Giannis Koutsoubos
import com.google.gwt.resources.client.ClientBundle;
44 afd3a0ef Giannis Koutsoubos
import com.google.gwt.resources.client.ImageResource;
45 14ad7326 pastith
import com.google.gwt.user.client.Command;
46 14ad7326 pastith
import com.google.gwt.user.client.DeferredCommand;
47 14ad7326 pastith
import com.google.gwt.user.client.ui.AbstractImagePrototype;
48 14ad7326 pastith
import com.google.gwt.user.client.ui.Button;
49 14ad7326 pastith
import com.google.gwt.user.client.ui.CheckBox;
50 5c6b2883 Panagiotis Astithas
import com.google.gwt.user.client.ui.DecoratedTabPanel;
51 14ad7326 pastith
import com.google.gwt.user.client.ui.DisclosurePanel;
52 14ad7326 pastith
import com.google.gwt.user.client.ui.FlexTable;
53 14ad7326 pastith
import com.google.gwt.user.client.ui.FlowPanel;
54 14ad7326 pastith
import com.google.gwt.user.client.ui.FocusPanel;
55 14ad7326 pastith
import com.google.gwt.user.client.ui.HTML;
56 14ad7326 pastith
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
57 14ad7326 pastith
import com.google.gwt.user.client.ui.HorizontalPanel;
58 14ad7326 pastith
import com.google.gwt.user.client.ui.Label;
59 14ad7326 pastith
import com.google.gwt.user.client.ui.TextBox;
60 14ad7326 pastith
import com.google.gwt.user.client.ui.VerticalPanel;
61 14ad7326 pastith
62 14ad7326 pastith
/**
63 14ad7326 pastith
 * The 'File properties' dialog box implementation.
64 220675e1 pastith
 *
65 14ad7326 pastith
 * @author past
66 14ad7326 pastith
 */
67 2002c1dc Dimitris Routsis
public class FilePropertiesDialog extends AbstractPropertiesDialog {
68 14ad7326 pastith
69 14ad7326 pastith
        final PermissionsList permList;
70 14ad7326 pastith
71 14ad7326 pastith
        private CheckBox readForAll;
72 14ad7326 pastith
73 14ad7326 pastith
        /**
74 14ad7326 pastith
         * An image bundle for this widgets images.
75 14ad7326 pastith
         */
76 afd3a0ef Giannis Koutsoubos
        public interface Images extends ClientBundle,MessagePanel.Images {
77 409e932c koutsoub
78 afd3a0ef Giannis Koutsoubos
                @Source("gr/ebs/gss/resources/edit_user.png")
79 afd3a0ef Giannis Koutsoubos
                ImageResource permUser();
80 14ad7326 pastith
81 afd3a0ef Giannis Koutsoubos
                @Source("gr/ebs/gss/resources/groupevent.png")
82 afd3a0ef Giannis Koutsoubos
                ImageResource permGroup();
83 14ad7326 pastith
84 afd3a0ef Giannis Koutsoubos
                @Source("gr/ebs/gss/resources/editdelete.png")
85 afd3a0ef Giannis Koutsoubos
                ImageResource delete();
86 14ad7326 pastith
87 afd3a0ef Giannis Koutsoubos
                @Source("gr/ebs/gss/resources/db_update.png")
88 afd3a0ef Giannis Koutsoubos
                ImageResource restore();
89 14ad7326 pastith
90 afd3a0ef Giannis Koutsoubos
                @Source("gr/ebs/gss/resources/folder_inbox.png")
91 afd3a0ef Giannis Koutsoubos
                ImageResource download();
92 14ad7326 pastith
        }
93 14ad7326 pastith
94 14ad7326 pastith
        /**
95 14ad7326 pastith
         * The widget that holds the name of the file.
96 14ad7326 pastith
         */
97 14ad7326 pastith
        private TextBox name = new TextBox();
98 14ad7326 pastith
99 14ad7326 pastith
        private final CheckBox versioned = new CheckBox();
100 409e932c koutsoub
101 a52ea5e4 pastith
        final FileResource file;
102 220675e1 pastith
103 9ab5db6d Natasa Kapravelou
        private String userFullName;
104 9ab5db6d Natasa Kapravelou
105 14ad7326 pastith
        /**
106 14ad7326 pastith
         * The widget's constructor.
107 14ad7326 pastith
         *
108 14ad7326 pastith
         * @param images the dialog's ImageBundle
109 14ad7326 pastith
         * @param groups
110 14ad7326 pastith
         * @param bodies
111 14ad7326 pastith
         */
112 9ab5db6d Natasa Kapravelou
        public FilePropertiesDialog(final Images images, final List<GroupResource> groups, List<FileResource> bodies, String _userFullName) {
113 f46a13ff fstamatelopoulos
114 226e8af7 pastith
                // Set the dialog's caption.
115 14ad7326 pastith
                setText("File properties");
116 2002c1dc Dimitris Routsis
117 a52ea5e4 pastith
                file = (FileResource) GSS.get().getCurrentSelection();
118 9ab5db6d Natasa Kapravelou
                userFullName = _userFullName;
119 ce2716a9 Natasa Kapravelou
                permList = new PermissionsList(images, file.getPermissions(), file.getOwner());
120 ce2716a9 Natasa Kapravelou
121 14ad7326 pastith
122 226e8af7 pastith
                // Outer contains inner and buttons.
123 14ad7326 pastith
                final VerticalPanel outer = new VerticalPanel();
124 14ad7326 pastith
                final FocusPanel focusPanel = new FocusPanel(outer);
125 226e8af7 pastith
                // Inner contains generalPanel and permPanel.
126 5c6b2883 Panagiotis Astithas
                inner = new DecoratedTabPanel();
127 5c6b2883 Panagiotis Astithas
                inner.setAnimationEnabled(true);
128 14ad7326 pastith
                final VerticalPanel generalPanel = new VerticalPanel();
129 14ad7326 pastith
                final VerticalPanel permPanel = new VerticalPanel();
130 14ad7326 pastith
                final HorizontalPanel buttons = new HorizontalPanel();
131 14ad7326 pastith
                final HorizontalPanel permButtons = new HorizontalPanel();
132 14ad7326 pastith
                final HorizontalPanel permForAll = new HorizontalPanel();
133 d74a42f5 fstamatelopoulos
                final HorizontalPanel pathPanel = new HorizontalPanel();
134 14ad7326 pastith
                final VerticalPanel verPanel = new VerticalPanel();
135 14ad7326 pastith
                final HorizontalPanel vPanel = new HorizontalPanel();
136 14ad7326 pastith
                final HorizontalPanel vPanel2 = new HorizontalPanel();
137 14ad7326 pastith
138 afd3a0ef Giannis Koutsoubos
                versioned.setValue(file.isVersioned());
139 14ad7326 pastith
                inner.add(generalPanel, "General");
140 d74a42f5 fstamatelopoulos
                inner.add(permPanel, "Sharing");
141 14ad7326 pastith
                inner.add(verPanel, "Versions");
142 14ad7326 pastith
                inner.selectTab(0);
143 14ad7326 pastith
144 8b79a1c8 Natasa Kapravelou
                final Label fileNameNote = new Label("Please note that slashes ('/') are not allowed in file names.", true);
145 8b79a1c8 Natasa Kapravelou
                fileNameNote.setVisible(false);
146 8b79a1c8 Natasa Kapravelou
                fileNameNote.setStylePrimaryName("gss-readForAllNote");
147 8b79a1c8 Natasa Kapravelou
148 14ad7326 pastith
                final FlexTable generalTable = new FlexTable();
149 14ad7326 pastith
                generalTable.setText(0, 0, "Name");
150 14ad7326 pastith
                generalTable.setText(1, 0, "Folder");
151 14ad7326 pastith
                generalTable.setText(2, 0, "Owner");
152 e164b7ca Panagiotis Astithas
                generalTable.setText(3, 0, "Last modified");
153 14ad7326 pastith
                generalTable.setText(4, 0, "Tags");
154 6735a2ab Panagiotis Astithas
                name.setWidth("100%");
155 14ad7326 pastith
                name.setText(file.getName());
156 14ad7326 pastith
                generalTable.setWidget(0, 1, name);
157 78729465 Natasa Kapravelou
                name.addChangeHandler(new ChangeHandler() {
158 8b79a1c8 Natasa Kapravelou
159 8b79a1c8 Natasa Kapravelou
                        @Override
160 78729465 Natasa Kapravelou
                        public void onChange(ChangeEvent event) {
161 78729465 Natasa Kapravelou
                                if(name.getText().contains("/"))
162 78729465 Natasa Kapravelou
                                        fileNameNote.setVisible(true);
163 78729465 Natasa Kapravelou
                                else
164 78729465 Natasa Kapravelou
                                        fileNameNote.setVisible(false);
165 8b79a1c8 Natasa Kapravelou
166 8b79a1c8 Natasa Kapravelou
                        }
167 8b79a1c8 Natasa Kapravelou
                });
168 8b79a1c8 Natasa Kapravelou
169 d6ba3052 koutsoub
                if(file.getFolderName() != null)
170 d6ba3052 koutsoub
                        generalTable.setText(1, 1, file.getFolderName());
171 d6ba3052 koutsoub
                else
172 d6ba3052 koutsoub
                        generalTable.setText(1, 1, "-");
173 8b79a1c8 Natasa Kapravelou
                generalTable.setWidget(0, 2, fileNameNote);
174 9ab5db6d Natasa Kapravelou
                generalTable.setText(2, 1,userFullName);
175 9ab5db6d Natasa Kapravelou
176 14ad7326 pastith
                final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
177 e164b7ca Panagiotis Astithas
                generalTable.setText(3, 1, formatter.format(file.getModificationDate()));
178 226e8af7 pastith
                // Get the tags.
179 14ad7326 pastith
                StringBuffer tagsBuffer = new StringBuffer();
180 14ad7326 pastith
                Iterator i = file.getTags().iterator();
181 14ad7326 pastith
                while (i.hasNext()) {
182 14ad7326 pastith
                        String tag = (String) i.next();
183 14ad7326 pastith
                        tagsBuffer.append(tag).append(", ");
184 14ad7326 pastith
                }
185 14ad7326 pastith
                if (tagsBuffer.length() > 1)
186 14ad7326 pastith
                        tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1);
187 409e932c koutsoub
                initialTagText = tagsBuffer.toString();
188 6735a2ab Panagiotis Astithas
                tags.setWidth("100%");
189 409e932c koutsoub
                tags.setText(initialTagText);
190 14ad7326 pastith
                generalTable.setWidget(4, 1, tags);
191 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
192 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
193 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");
194 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels");
195 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(4, 0, "props-labels");
196 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");
197 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");
198 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");
199 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values");
200 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(4, 1, "props-values");
201 14ad7326 pastith
                generalTable.setCellSpacing(4);
202 14ad7326 pastith
203 14ad7326 pastith
                // Create the 'OK' button, along with a listener that hides the dialog
204 14ad7326 pastith
                // when the button is clicked.
205 afd3a0ef Giannis Koutsoubos
                final Button ok = new Button("OK", new ClickHandler() {
206 afd3a0ef Giannis Koutsoubos
                        @Override
207 afd3a0ef Giannis Koutsoubos
                        public void onClick(ClickEvent event) {
208 78729465 Natasa Kapravelou
                                if(name.getText().contains("/"))
209 78729465 Natasa Kapravelou
                                        fileNameNote.setVisible(true);
210 78729465 Natasa Kapravelou
                                else{
211 78729465 Natasa Kapravelou
                                        fileNameNote.setVisible(true);
212 78729465 Natasa Kapravelou
                                        accept();
213 78729465 Natasa Kapravelou
                                        closeDialog();
214 78729465 Natasa Kapravelou
                                }                
215 14ad7326 pastith
                        }
216 14ad7326 pastith
                });
217 14ad7326 pastith
                buttons.add(ok);
218 14ad7326 pastith
                buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
219 14ad7326 pastith
                // Create the 'Cancel' button, along with a listener that hides the
220 226e8af7 pastith
                // dialog when the button is clicked.
221 afd3a0ef Giannis Koutsoubos
                final Button cancel = new Button("Cancel", new ClickHandler() {
222 afd3a0ef Giannis Koutsoubos
                        @Override
223 afd3a0ef Giannis Koutsoubos
                        public void onClick(ClickEvent event) {
224 f46a13ff fstamatelopoulos
                                closeDialog();
225 14ad7326 pastith
                        }
226 14ad7326 pastith
                });
227 14ad7326 pastith
                buttons.add(cancel);
228 14ad7326 pastith
                buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
229 14ad7326 pastith
                buttons.setSpacing(8);
230 5c6b2883 Panagiotis Astithas
                buttons.addStyleName("gss-TabPanelBottom");
231 14ad7326 pastith
232 14ad7326 pastith
                generalPanel.add(generalTable);
233 14ad7326 pastith
234 226e8af7 pastith
                // Asynchronously retrieve the tags defined by this user.
235 14ad7326 pastith
                DeferredCommand.addCommand(new Command() {
236 14ad7326 pastith
237 023f6f1e Panagiotis Astithas
                        @Override
238 14ad7326 pastith
                        public void execute() {
239 a52ea5e4 pastith
                                updateTags();
240 14ad7326 pastith
                        }
241 14ad7326 pastith
                });
242 14ad7326 pastith
243 14ad7326 pastith
                DisclosurePanel allTags = new DisclosurePanel("All tags");
244 14ad7326 pastith
                allTagsContent = new FlowPanel();
245 6735a2ab Panagiotis Astithas
                allTagsContent.setWidth("100%");
246 14ad7326 pastith
                allTags.setContent(allTagsContent);
247 14ad7326 pastith
                generalPanel.add(allTags);
248 14ad7326 pastith
                generalPanel.setSpacing(4);
249 14ad7326 pastith
250 afd3a0ef Giannis Koutsoubos
                final Button add = new Button("Add Group", new ClickHandler() {
251 afd3a0ef Giannis Koutsoubos
                        @Override
252 afd3a0ef Giannis Koutsoubos
                        public void onClick(ClickEvent event) {
253 41d05cc8 pastith
                                PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, false);
254 14ad7326 pastith
                                dlg.center();
255 14ad7326 pastith
                        }
256 14ad7326 pastith
                });
257 14ad7326 pastith
                permButtons.add(add);
258 14ad7326 pastith
                permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER);
259 14ad7326 pastith
260 afd3a0ef Giannis Koutsoubos
                final Button addUser = new Button("Add User", new ClickHandler() {
261 afd3a0ef Giannis Koutsoubos
                        @Override
262 afd3a0ef Giannis Koutsoubos
                        public void onClick(ClickEvent event) {
263 41d05cc8 pastith
                                PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, true);
264 14ad7326 pastith
                                dlg.center();
265 14ad7326 pastith
                        }
266 14ad7326 pastith
                });
267 14ad7326 pastith
                permButtons.add(addUser);
268 14ad7326 pastith
                permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER);
269 14ad7326 pastith
270 14ad7326 pastith
                permButtons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
271 14ad7326 pastith
                permButtons.setSpacing(8);
272 5c6b2883 Panagiotis Astithas
                permButtons.addStyleName("gss-TabPanelBottom");
273 14ad7326 pastith
274 226e8af7 pastith
                final Label readForAllNote = new Label("When this option is enabled, the file will be readable" +
275 226e8af7 pastith
                                        " by everyone. By checking this option, you are certifying that you have the right to " +
276 226e8af7 pastith
                                        "distribute this file and that it does not violate the Terms of Use.", true);
277 220675e1 pastith
                readForAllNote.setVisible(false);
278 220675e1 pastith
                readForAllNote.setStylePrimaryName("gss-readForAllNote");
279 220675e1 pastith
280 14ad7326 pastith
                readForAll = new CheckBox();
281 afd3a0ef Giannis Koutsoubos
                readForAll.setValue(file.isReadForAll());
282 afd3a0ef Giannis Koutsoubos
                readForAll.addClickHandler(new ClickHandler() {
283 afd3a0ef Giannis Koutsoubos
                        @Override
284 afd3a0ef Giannis Koutsoubos
                        public void onClick(ClickEvent event) {
285 f841ed5b Panagiotis Astithas
                                readForAllNote.setVisible(readForAll.getValue());
286 220675e1 pastith
                        }
287 220675e1 pastith
288 220675e1 pastith
                });
289 d74a42f5 fstamatelopoulos
290 14ad7326 pastith
                permPanel.add(permList);
291 14ad7326 pastith
                permPanel.add(permButtons);
292 226e8af7 pastith
                // Only show the read for all permission if the user is the owner.
293 52938043 fstamatelopoulos
                if (file.getOwner().equals(GSS.get().getCurrentUserResource().getUsername())) {
294 afcd9a21 Panagiotis Astithas
                        permForAll.add(new Label("Public"));
295 52938043 fstamatelopoulos
                        permForAll.add(readForAll);
296 52938043 fstamatelopoulos
                        permForAll.setSpacing(8);
297 5c6b2883 Panagiotis Astithas
                        permForAll.addStyleName("gss-TabPanelBottom");
298 8960233b Fotis Stamatelopoulos
                        permForAll.add(readForAllNote);
299 52938043 fstamatelopoulos
                        permPanel.add(permForAll);
300 52938043 fstamatelopoulos
                }
301 14ad7326 pastith
302 d74a42f5 fstamatelopoulos
                TextBox path = new TextBox();
303 8960233b Fotis Stamatelopoulos
                path.setWidth("100%");
304 afd3a0ef Giannis Koutsoubos
                path.addClickHandler(new ClickHandler() {
305 afd3a0ef Giannis Koutsoubos
                        @Override
306 afd3a0ef Giannis Koutsoubos
                        public void onClick(ClickEvent event) {
307 18cd8128 fstamatelopoulos
                                GSS.enableIESelection();
308 afd3a0ef Giannis Koutsoubos
                                ((TextBox) event.getSource()).selectAll();
309 18cd8128 fstamatelopoulos
                                GSS.preventIESelection();
310 d74a42f5 fstamatelopoulos
                        }
311 d0dd62e3 fstamatelopoulos
312 d74a42f5 fstamatelopoulos
                });
313 555e8e59 pastith
                path.setText(file.getUri());
314 f841ed5b Panagiotis Astithas
                path.setTitle("Use this link for sharing the file via e-mail, IM, etc. (crtl-C/cmd-C to copy to system clipboard)");
315 8960233b Fotis Stamatelopoulos
                path.setWidth("100%");
316 d74a42f5 fstamatelopoulos
                path.setReadOnly(true);
317 8960233b Fotis Stamatelopoulos
                pathPanel.setWidth("100%");
318 8960233b Fotis Stamatelopoulos
                pathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
319 f841ed5b Panagiotis Astithas
                pathPanel.add(new Label("Link"));
320 d74a42f5 fstamatelopoulos
                pathPanel.setSpacing(8);
321 5c6b2883 Panagiotis Astithas
                pathPanel.addStyleName("gss-TabPanelBottom");
322 d74a42f5 fstamatelopoulos
                pathPanel.add(path);
323 d74a42f5 fstamatelopoulos
                permPanel.add(pathPanel);
324 d74a42f5 fstamatelopoulos
325 14ad7326 pastith
                VersionsList verList = new VersionsList(this, images, bodies);
326 14ad7326 pastith
                verPanel.add(verList);
327 14ad7326 pastith
328 14ad7326 pastith
                vPanel.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
329 14ad7326 pastith
                vPanel.setSpacing(8);
330 5c6b2883 Panagiotis Astithas
                vPanel.addStyleName("gss-TabPanelBottom");
331 226e8af7 pastith
                vPanel.add(new Label("Versioned"));
332 14ad7326 pastith
333 14ad7326 pastith
                vPanel.add(versioned);
334 14ad7326 pastith
                verPanel.add(vPanel);
335 14ad7326 pastith
                vPanel2.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
336 14ad7326 pastith
                vPanel2.setSpacing(8);
337 5c6b2883 Panagiotis Astithas
                vPanel2.addStyleName("gss-TabPanelBottom");
338 afd3a0ef Giannis Koutsoubos
                Button removeVersionsButton = new Button(AbstractImagePrototype.create(images.delete()).getHTML(), new ClickHandler() {
339 afd3a0ef Giannis Koutsoubos
                        @Override
340 afd3a0ef Giannis Koutsoubos
                        public void onClick(ClickEvent event) {
341 5c6b4b2c Panagiotis Astithas
                                ConfirmationDialog confirm = new ConfirmationDialog("Really " +
342 5c6b4b2c Panagiotis Astithas
                                                "remove all previous versions?", "Remove") {
343 14ad7326 pastith
344 5c6b4b2c Panagiotis Astithas
                                        @Override
345 f98f18c2 koutsoub
                                        public void cancel() {
346 f98f18c2 koutsoub
                                        }
347 f98f18c2 koutsoub
348 5c6b4b2c Panagiotis Astithas
                                        @Override
349 f98f18c2 koutsoub
                                        public void confirm() {
350 f46a13ff fstamatelopoulos
                                                FilePropertiesDialog.this.closeDialog();
351 f98f18c2 koutsoub
                                                removeAllOldVersions();
352 f98f18c2 koutsoub
                                        }
353 f98f18c2 koutsoub
354 f98f18c2 koutsoub
                                };
355 f98f18c2 koutsoub
                                confirm.center();
356 14ad7326 pastith
                        }
357 14ad7326 pastith
358 14ad7326 pastith
                });
359 14ad7326 pastith
                HTML removeAllVersion = new HTML("<span>Remove all previous versions?</span>");
360 14ad7326 pastith
                vPanel2.add(removeAllVersion);
361 14ad7326 pastith
                vPanel2.add(removeVersionsButton);
362 14ad7326 pastith
                verPanel.add(vPanel2);
363 f98f18c2 koutsoub
                if(!file.isVersioned())
364 f98f18c2 koutsoub
                        vPanel2.setVisible(false);
365 14ad7326 pastith
                outer.add(inner);
366 14ad7326 pastith
                outer.add(buttons);
367 14ad7326 pastith
                outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
368 5c6b2883 Panagiotis Astithas
                outer.addStyleName("gss-TabPanelBottom");
369 14ad7326 pastith
370 14ad7326 pastith
                focusPanel.setFocus(true);
371 14ad7326 pastith
                setWidget(outer);
372 14ad7326 pastith
        }
373 14ad7326 pastith
374 14ad7326 pastith
375 14ad7326 pastith
        /**
376 14ad7326 pastith
         * Accepts any change and updates the file
377 14ad7326 pastith
         *
378 14ad7326 pastith
         */
379 2002c1dc Dimitris Routsis
        @Override
380 2002c1dc Dimitris Routsis
        protected void accept() {
381 5e9d7683 Dimitris Routsis
                String newFilename = null;
382 14ad7326 pastith
                permList.updatePermissionsAccordingToInput();
383 a52ea5e4 pastith
                Set<PermissionHolder> perms = permList.getPermissions();
384 a52ea5e4 pastith
                JSONObject json = new JSONObject();
385 5e9d7683 Dimitris Routsis
                if (!name.getText().equals(file.getName())) {
386 5e9d7683 Dimitris Routsis
                        newFilename = name.getText();
387 5e9d7683 Dimitris Routsis
                        json.put("name", new JSONString(newFilename));
388 5e9d7683 Dimitris Routsis
                }
389 afd3a0ef Giannis Koutsoubos
                if (versioned.getValue() != file.isVersioned())
390 afd3a0ef Giannis Koutsoubos
                        json.put("versioned", JSONBoolean.getInstance(versioned.getValue()));
391 52938043 fstamatelopoulos
                //only update the read for all perm if the user is the owner
392 afd3a0ef Giannis Koutsoubos
                if (readForAll.getValue() != file.isReadForAll())
393 409e932c koutsoub
                        if (file.getOwner().equals(GSS.get().getCurrentUserResource().getUsername()))
394 afd3a0ef Giannis Koutsoubos
                                json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue()));
395 409e932c koutsoub
                int i = 0;
396 409e932c koutsoub
                if (permList.hasChanges()) {
397 409e932c koutsoub
                        GWT.log("Permissions change", null);
398 409e932c koutsoub
                        JSONArray perma = new JSONArray();
399 409e932c koutsoub
400 409e932c koutsoub
                        for (PermissionHolder p : perms) {
401 409e932c koutsoub
                                JSONObject po = new JSONObject();
402 409e932c koutsoub
                                if (p.getUser() != null)
403 409e932c koutsoub
                                        po.put("user", new JSONString(p.getUser()));
404 409e932c koutsoub
                                if (p.getGroup() != null)
405 409e932c koutsoub
                                        po.put("group", new JSONString(p.getGroup()));
406 409e932c koutsoub
                                po.put("read", JSONBoolean.getInstance(p.isRead()));
407 409e932c koutsoub
                                po.put("write", JSONBoolean.getInstance(p.isWrite()));
408 409e932c koutsoub
                                po.put("modifyACL", JSONBoolean.getInstance(p.isModifyACL()));
409 409e932c koutsoub
                                perma.set(i, po);
410 409e932c koutsoub
                                i++;
411 409e932c koutsoub
                        }
412 409e932c koutsoub
                        json.put("permissions", perma);
413 14ad7326 pastith
                }
414 a52ea5e4 pastith
                JSONArray taga = new JSONArray();
415 409e932c koutsoub
                i = 0;
416 409e932c koutsoub
                if (!tags.getText().equals(initialTagText)) {
417 409e932c koutsoub
                        String[] tagset = tags.getText().split(",");
418 409e932c koutsoub
                        for (String t : tagset) {
419 409e932c koutsoub
                                JSONString to = new JSONString(t);
420 409e932c koutsoub
                                taga.set(i, to);
421 409e932c koutsoub
                                i++;
422 409e932c koutsoub
                        }
423 409e932c koutsoub
                        json.put("tags", taga);
424 a52ea5e4 pastith
                }
425 409e932c koutsoub
                String jsonString = json.toString();
426 409e932c koutsoub
                if(jsonString.equals("{}")){
427 409e932c koutsoub
                        GWT.log("NO CHANGES", null);
428 409e932c koutsoub
                        return;
429 409e932c koutsoub
                }
430 5e9d7683 Dimitris Routsis
                final String newFilenameFinal = newFilename;
431 895035a2 pastith
                PostCommand cf = new PostCommand(file.getUri() + "?update=", jsonString, 200) {
432 409e932c koutsoub
433 5c6b4b2c Panagiotis Astithas
                        @Override
434 a52ea5e4 pastith
                        public void onComplete() {
435 5e9d7683 Dimitris Routsis
                                GSS.get().getFileList().updateFileCache(true, false /* do not clear selected file*/, newFilenameFinal);
436 14ad7326 pastith
                        }
437 14ad7326 pastith
438 5c6b4b2c Panagiotis Astithas
                        @Override
439 a52ea5e4 pastith
                        public void onError(Throwable t) {
440 a52ea5e4 pastith
                                GWT.log("", t);
441 409e932c koutsoub
                                if (t instanceof RestException) {
442 409e932c koutsoub
                                        int statusCode = ((RestException) t).getHttpStatusCode();
443 409e932c koutsoub
                                        if (statusCode == 405)
444 a52ea5e4 pastith
                                                GSS.get().displayError("You don't have the necessary permissions");
445 409e932c koutsoub
                                        else if (statusCode == 404)
446 a52ea5e4 pastith
                                                GSS.get().displayError("User in permissions does not exist");
447 409e932c koutsoub
                                        else if (statusCode == 409)
448 a52ea5e4 pastith
                                                GSS.get().displayError("A file with the same name already exists");
449 409e932c koutsoub
                                        else if (statusCode == 413)
450 a52ea5e4 pastith
                                                GSS.get().displayError("Your quota has been exceeded");
451 a52ea5e4 pastith
                                        else
452 409e932c koutsoub
                                                GSS.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());
453 409e932c koutsoub
                                } else
454 409e932c koutsoub
                                        GSS.get().displayError("System error modifying file:" + t.getMessage());
455 14ad7326 pastith
                        }
456 14ad7326 pastith
457 a52ea5e4 pastith
                };
458 a52ea5e4 pastith
                DeferredCommand.addCommand(cf);
459 14ad7326 pastith
460 a52ea5e4 pastith
        }
461 14ad7326 pastith
462 a52ea5e4 pastith
        private void removeAllOldVersions() {
463 f98f18c2 koutsoub
                JSONObject json = new JSONObject();
464 f98f18c2 koutsoub
                json.put("versioned", JSONBoolean.getInstance(false));
465 f98f18c2 koutsoub
                GWT.log(json.toString(), null);
466 895035a2 pastith
                PostCommand cf = new PostCommand(file.getUri() + "?update=", json.toString(), 200) {
467 f98f18c2 koutsoub
468 5c6b4b2c Panagiotis Astithas
                        @Override
469 f98f18c2 koutsoub
                        public void onComplete() {
470 f98f18c2 koutsoub
                                toggleVersioned(true);
471 f98f18c2 koutsoub
                        }
472 f98f18c2 koutsoub
473 5c6b4b2c Panagiotis Astithas
                        @Override
474 f98f18c2 koutsoub
                        public void onError(Throwable t) {
475 f98f18c2 koutsoub
                                GWT.log("", t);
476 f98f18c2 koutsoub
                                if (t instanceof RestException) {
477 f98f18c2 koutsoub
                                        int statusCode = ((RestException) t).getHttpStatusCode();
478 f98f18c2 koutsoub
                                        if (statusCode == 405)
479 f98f18c2 koutsoub
                                                GSS.get().displayError("You don't have the necessary permissions");
480 f98f18c2 koutsoub
                                        else if (statusCode == 404)
481 f98f18c2 koutsoub
                                                GSS.get().displayError("User in permissions does not exist");
482 f98f18c2 koutsoub
                                        else if (statusCode == 409)
483 f98f18c2 koutsoub
                                                GSS.get().displayError("A folder with the same name already exists");
484 f98f18c2 koutsoub
                                        else if (statusCode == 413)
485 f98f18c2 koutsoub
                                                GSS.get().displayError("Your quota has been exceeded");
486 f98f18c2 koutsoub
                                        else
487 f98f18c2 koutsoub
                                                GSS.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());
488 f98f18c2 koutsoub
                                } else
489 f98f18c2 koutsoub
                                        GSS.get().displayError("System error moifying file:" + t.getMessage());
490 f98f18c2 koutsoub
                        }
491 f98f18c2 koutsoub
                };
492 f98f18c2 koutsoub
                DeferredCommand.addCommand(cf);
493 14ad7326 pastith
        }
494 14ad7326 pastith
495 409e932c koutsoub
        private void toggleVersioned(boolean versionedValue) {
496 a52ea5e4 pastith
                JSONObject json = new JSONObject();
497 a52ea5e4 pastith
                json.put("versioned", JSONBoolean.getInstance(versionedValue));
498 a52ea5e4 pastith
                GWT.log(json.toString(), null);
499 895035a2 pastith
                PostCommand cf = new PostCommand(file.getUri() + "?update=", json.toString(), 200) {
500 409e932c koutsoub
501 5c6b4b2c Panagiotis Astithas
                        @Override
502 a52ea5e4 pastith
                        public void onComplete() {
503 18a508ee fstamatelopoulos
                                GSS.get().getFileList().updateFileCache(true, false /* do not clear selected file*/);
504 14ad7326 pastith
                        }
505 14ad7326 pastith
506 5c6b4b2c Panagiotis Astithas
                        @Override
507 a52ea5e4 pastith
                        public void onError(Throwable t) {
508 a52ea5e4 pastith
                                GWT.log("", t);
509 409e932c koutsoub
                                if (t instanceof RestException) {
510 409e932c koutsoub
                                        int statusCode = ((RestException) t).getHttpStatusCode();
511 409e932c koutsoub
                                        if (statusCode == 405)
512 a52ea5e4 pastith
                                                GSS.get().displayError("You don't have the necessary permissions");
513 409e932c koutsoub
                                        else if (statusCode == 404)
514 a52ea5e4 pastith
                                                GSS.get().displayError("User in permissions does not exist");
515 409e932c koutsoub
                                        else if (statusCode == 409)
516 a52ea5e4 pastith
                                                GSS.get().displayError("A folder with the same name already exists");
517 409e932c koutsoub
                                        else if (statusCode == 413)
518 a52ea5e4 pastith
                                                GSS.get().displayError("Your quota has been exceeded");
519 a52ea5e4 pastith
                                        else
520 409e932c koutsoub
                                                GSS.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());
521 409e932c koutsoub
                                } else
522 409e932c koutsoub
                                        GSS.get().displayError("System error moifying file:" + t.getMessage());
523 14ad7326 pastith
                        }
524 a52ea5e4 pastith
                };
525 a52ea5e4 pastith
                DeferredCommand.addCommand(cf);
526 14ad7326 pastith
        }
527 f46a13ff fstamatelopoulos
528 14ad7326 pastith
}