Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / client / FilePropertiesDialog.java @ b75f55ce

History | View | Annotate | Download (17.3 kB)

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