Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / client / FilePropertiesDialog.java @ 6951c253

History | View | Annotate | Download (18.8 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 d5580e22 koutsoub
                GWT.log("FILE PERMISSIONS:"+file.getPermissions());
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 1016f160 Natasa Kapravelou
                versioned.getElement().setId("filePropertiesDialog.chechBox.versioned");
140 14ad7326 pastith
                inner.add(generalPanel, "General");
141 d74a42f5 fstamatelopoulos
                inner.add(permPanel, "Sharing");
142 14ad7326 pastith
                inner.add(verPanel, "Versions");
143 14ad7326 pastith
                inner.selectTab(0);
144 14ad7326 pastith
145 8b79a1c8 Natasa Kapravelou
                final Label fileNameNote = new Label("Please note that slashes ('/') are not allowed in file names.", true);
146 8b79a1c8 Natasa Kapravelou
                fileNameNote.setVisible(false);
147 8b79a1c8 Natasa Kapravelou
                fileNameNote.setStylePrimaryName("gss-readForAllNote");
148 8b79a1c8 Natasa Kapravelou
149 14ad7326 pastith
                final FlexTable generalTable = new FlexTable();
150 14ad7326 pastith
                generalTable.setText(0, 0, "Name");
151 14ad7326 pastith
                generalTable.setText(1, 0, "Folder");
152 14ad7326 pastith
                generalTable.setText(2, 0, "Owner");
153 e164b7ca Panagiotis Astithas
                generalTable.setText(3, 0, "Last modified");
154 14ad7326 pastith
                generalTable.setText(4, 0, "Tags");
155 6735a2ab Panagiotis Astithas
                name.setWidth("100%");
156 14ad7326 pastith
                name.setText(file.getName());
157 1016f160 Natasa Kapravelou
                name.getElement().setId("filePropertiesDialog.textBox.name");
158 14ad7326 pastith
                generalTable.setWidget(0, 1, name);
159 78729465 Natasa Kapravelou
                name.addChangeHandler(new ChangeHandler() {
160 8b79a1c8 Natasa Kapravelou
161 8b79a1c8 Natasa Kapravelou
                        @Override
162 78729465 Natasa Kapravelou
                        public void onChange(ChangeEvent event) {
163 78729465 Natasa Kapravelou
                                if(name.getText().contains("/"))
164 78729465 Natasa Kapravelou
                                        fileNameNote.setVisible(true);
165 78729465 Natasa Kapravelou
                                else
166 78729465 Natasa Kapravelou
                                        fileNameNote.setVisible(false);
167 8b79a1c8 Natasa Kapravelou
168 8b79a1c8 Natasa Kapravelou
                        }
169 8b79a1c8 Natasa Kapravelou
                });
170 8b79a1c8 Natasa Kapravelou
171 d6ba3052 koutsoub
                if(file.getFolderName() != null)
172 d6ba3052 koutsoub
                        generalTable.setText(1, 1, file.getFolderName());
173 d6ba3052 koutsoub
                else
174 d6ba3052 koutsoub
                        generalTable.setText(1, 1, "-");
175 8b79a1c8 Natasa Kapravelou
                generalTable.setWidget(0, 2, fileNameNote);
176 9ab5db6d Natasa Kapravelou
                generalTable.setText(2, 1,userFullName);
177 9ab5db6d Natasa Kapravelou
178 14ad7326 pastith
                final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
179 e164b7ca Panagiotis Astithas
                generalTable.setText(3, 1, formatter.format(file.getModificationDate()));
180 226e8af7 pastith
                // Get the tags.
181 14ad7326 pastith
                StringBuffer tagsBuffer = new StringBuffer();
182 14ad7326 pastith
                Iterator i = file.getTags().iterator();
183 14ad7326 pastith
                while (i.hasNext()) {
184 14ad7326 pastith
                        String tag = (String) i.next();
185 14ad7326 pastith
                        tagsBuffer.append(tag).append(", ");
186 14ad7326 pastith
                }
187 14ad7326 pastith
                if (tagsBuffer.length() > 1)
188 14ad7326 pastith
                        tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1);
189 409e932c koutsoub
                initialTagText = tagsBuffer.toString();
190 6735a2ab Panagiotis Astithas
                tags.setWidth("100%");
191 1016f160 Natasa Kapravelou
                tags.getElement().setId("filePropertiesDialog.textBox.tags");
192 409e932c koutsoub
                tags.setText(initialTagText);
193 14ad7326 pastith
                generalTable.setWidget(4, 1, tags);
194 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
195 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
196 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");
197 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels");
198 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(4, 0, "props-labels");
199 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");
200 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");
201 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");
202 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values");
203 14ad7326 pastith
                generalTable.getFlexCellFormatter().setStyleName(4, 1, "props-values");
204 14ad7326 pastith
                generalTable.setCellSpacing(4);
205 14ad7326 pastith
206 14ad7326 pastith
                // Create the 'OK' button, along with a listener that hides the dialog
207 14ad7326 pastith
                // when the button is clicked.
208 afd3a0ef Giannis Koutsoubos
                final Button ok = new Button("OK", new ClickHandler() {
209 afd3a0ef Giannis Koutsoubos
                        @Override
210 afd3a0ef Giannis Koutsoubos
                        public void onClick(ClickEvent event) {
211 78729465 Natasa Kapravelou
                                if(name.getText().contains("/"))
212 78729465 Natasa Kapravelou
                                        fileNameNote.setVisible(true);
213 78729465 Natasa Kapravelou
                                else{
214 6951c253 fstamatelopoulos
                                        fileNameNote.setVisible(false);
215 78729465 Natasa Kapravelou
                                        accept();
216 78729465 Natasa Kapravelou
                                        closeDialog();
217 78729465 Natasa Kapravelou
                                }                
218 14ad7326 pastith
                        }
219 14ad7326 pastith
                });
220 1016f160 Natasa Kapravelou
                ok.getElement().setId("filePropertiesDialog.button.ok");                
221 14ad7326 pastith
                buttons.add(ok);
222 14ad7326 pastith
                buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
223 14ad7326 pastith
                // Create the 'Cancel' button, along with a listener that hides the
224 226e8af7 pastith
                // dialog when the button is clicked.
225 afd3a0ef Giannis Koutsoubos
                final Button cancel = new Button("Cancel", new ClickHandler() {
226 afd3a0ef Giannis Koutsoubos
                        @Override
227 afd3a0ef Giannis Koutsoubos
                        public void onClick(ClickEvent event) {
228 f46a13ff fstamatelopoulos
                                closeDialog();
229 14ad7326 pastith
                        }
230 14ad7326 pastith
                });
231 1016f160 Natasa Kapravelou
                cancel.getElement().setId("filePropertiesDialog.button.cancel");
232 14ad7326 pastith
                buttons.add(cancel);
233 14ad7326 pastith
                buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
234 14ad7326 pastith
                buttons.setSpacing(8);
235 5c6b2883 Panagiotis Astithas
                buttons.addStyleName("gss-TabPanelBottom");
236 14ad7326 pastith
237 14ad7326 pastith
                generalPanel.add(generalTable);
238 14ad7326 pastith
239 226e8af7 pastith
                // Asynchronously retrieve the tags defined by this user.
240 14ad7326 pastith
                DeferredCommand.addCommand(new Command() {
241 14ad7326 pastith
242 023f6f1e Panagiotis Astithas
                        @Override
243 14ad7326 pastith
                        public void execute() {
244 a52ea5e4 pastith
                                updateTags();
245 14ad7326 pastith
                        }
246 14ad7326 pastith
                });
247 14ad7326 pastith
248 14ad7326 pastith
                DisclosurePanel allTags = new DisclosurePanel("All tags");
249 14ad7326 pastith
                allTagsContent = new FlowPanel();
250 6735a2ab Panagiotis Astithas
                allTagsContent.setWidth("100%");
251 14ad7326 pastith
                allTags.setContent(allTagsContent);
252 14ad7326 pastith
                generalPanel.add(allTags);
253 14ad7326 pastith
                generalPanel.setSpacing(4);
254 14ad7326 pastith
255 afd3a0ef Giannis Koutsoubos
                final Button add = new Button("Add Group", new ClickHandler() {
256 afd3a0ef Giannis Koutsoubos
                        @Override
257 afd3a0ef Giannis Koutsoubos
                        public void onClick(ClickEvent event) {
258 41d05cc8 pastith
                                PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, false);
259 14ad7326 pastith
                                dlg.center();
260 14ad7326 pastith
                        }
261 14ad7326 pastith
                });
262 1016f160 Natasa Kapravelou
                add.getElement().setId("filePropertiesDialog.button.addGroup");
263 14ad7326 pastith
                permButtons.add(add);
264 14ad7326 pastith
                permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER);
265 14ad7326 pastith
266 afd3a0ef Giannis Koutsoubos
                final Button addUser = new Button("Add User", new ClickHandler() {
267 afd3a0ef Giannis Koutsoubos
                        @Override
268 afd3a0ef Giannis Koutsoubos
                        public void onClick(ClickEvent event) {
269 41d05cc8 pastith
                                PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, true);
270 14ad7326 pastith
                                dlg.center();
271 14ad7326 pastith
                        }
272 14ad7326 pastith
                });
273 1016f160 Natasa Kapravelou
                add.getElement().setId("filePropertiesDialog.button.addUser");
274 14ad7326 pastith
                permButtons.add(addUser);
275 14ad7326 pastith
                permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER);
276 14ad7326 pastith
277 14ad7326 pastith
                permButtons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
278 14ad7326 pastith
                permButtons.setSpacing(8);
279 5c6b2883 Panagiotis Astithas
                permButtons.addStyleName("gss-TabPanelBottom");
280 14ad7326 pastith
281 226e8af7 pastith
                final Label readForAllNote = new Label("When this option is enabled, the file will be readable" +
282 226e8af7 pastith
                                        " by everyone. By checking this option, you are certifying that you have the right to " +
283 226e8af7 pastith
                                        "distribute this file and that it does not violate the Terms of Use.", true);
284 220675e1 pastith
                readForAllNote.setVisible(false);
285 220675e1 pastith
                readForAllNote.setStylePrimaryName("gss-readForAllNote");
286 220675e1 pastith
287 14ad7326 pastith
                readForAll = new CheckBox();
288 1016f160 Natasa Kapravelou
                readForAll.getElement().setId("filePropertiesDialog.checkBox.public");
289 afd3a0ef Giannis Koutsoubos
                readForAll.setValue(file.isReadForAll());
290 afd3a0ef Giannis Koutsoubos
                readForAll.addClickHandler(new ClickHandler() {
291 afd3a0ef Giannis Koutsoubos
                        @Override
292 afd3a0ef Giannis Koutsoubos
                        public void onClick(ClickEvent event) {
293 f841ed5b Panagiotis Astithas
                                readForAllNote.setVisible(readForAll.getValue());
294 220675e1 pastith
                        }
295 220675e1 pastith
296 220675e1 pastith
                });
297 d74a42f5 fstamatelopoulos
298 14ad7326 pastith
                permPanel.add(permList);
299 14ad7326 pastith
                permPanel.add(permButtons);
300 226e8af7 pastith
                // Only show the read for all permission if the user is the owner.
301 52938043 fstamatelopoulos
                if (file.getOwner().equals(GSS.get().getCurrentUserResource().getUsername())) {
302 afcd9a21 Panagiotis Astithas
                        permForAll.add(new Label("Public"));
303 52938043 fstamatelopoulos
                        permForAll.add(readForAll);
304 52938043 fstamatelopoulos
                        permForAll.setSpacing(8);
305 5c6b2883 Panagiotis Astithas
                        permForAll.addStyleName("gss-TabPanelBottom");
306 8960233b Fotis Stamatelopoulos
                        permForAll.add(readForAllNote);
307 52938043 fstamatelopoulos
                        permPanel.add(permForAll);
308 52938043 fstamatelopoulos
                }
309 14ad7326 pastith
310 d74a42f5 fstamatelopoulos
                TextBox path = new TextBox();
311 8960233b Fotis Stamatelopoulos
                path.setWidth("100%");
312 afd3a0ef Giannis Koutsoubos
                path.addClickHandler(new ClickHandler() {
313 afd3a0ef Giannis Koutsoubos
                        @Override
314 afd3a0ef Giannis Koutsoubos
                        public void onClick(ClickEvent event) {
315 18cd8128 fstamatelopoulos
                                GSS.enableIESelection();
316 afd3a0ef Giannis Koutsoubos
                                ((TextBox) event.getSource()).selectAll();
317 18cd8128 fstamatelopoulos
                                GSS.preventIESelection();
318 d74a42f5 fstamatelopoulos
                        }
319 d0dd62e3 fstamatelopoulos
320 d74a42f5 fstamatelopoulos
                });
321 555e8e59 pastith
                path.setText(file.getUri());
322 1016f160 Natasa Kapravelou
                path.getElement().setId("filePropertiesDialog.textBox.link");
323 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)");
324 8960233b Fotis Stamatelopoulos
                path.setWidth("100%");
325 d74a42f5 fstamatelopoulos
                path.setReadOnly(true);
326 8960233b Fotis Stamatelopoulos
                pathPanel.setWidth("100%");
327 8960233b Fotis Stamatelopoulos
                pathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
328 f841ed5b Panagiotis Astithas
                pathPanel.add(new Label("Link"));
329 d74a42f5 fstamatelopoulos
                pathPanel.setSpacing(8);
330 5c6b2883 Panagiotis Astithas
                pathPanel.addStyleName("gss-TabPanelBottom");
331 d74a42f5 fstamatelopoulos
                pathPanel.add(path);
332 d74a42f5 fstamatelopoulos
                permPanel.add(pathPanel);
333 d74a42f5 fstamatelopoulos
334 14ad7326 pastith
                VersionsList verList = new VersionsList(this, images, bodies);
335 14ad7326 pastith
                verPanel.add(verList);
336 14ad7326 pastith
337 14ad7326 pastith
                vPanel.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
338 14ad7326 pastith
                vPanel.setSpacing(8);
339 5c6b2883 Panagiotis Astithas
                vPanel.addStyleName("gss-TabPanelBottom");
340 226e8af7 pastith
                vPanel.add(new Label("Versioned"));
341 14ad7326 pastith
342 14ad7326 pastith
                vPanel.add(versioned);
343 14ad7326 pastith
                verPanel.add(vPanel);
344 14ad7326 pastith
                vPanel2.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
345 14ad7326 pastith
                vPanel2.setSpacing(8);
346 5c6b2883 Panagiotis Astithas
                vPanel2.addStyleName("gss-TabPanelBottom");
347 afd3a0ef Giannis Koutsoubos
                Button removeVersionsButton = new Button(AbstractImagePrototype.create(images.delete()).getHTML(), new ClickHandler() {
348 afd3a0ef Giannis Koutsoubos
                        @Override
349 afd3a0ef Giannis Koutsoubos
                        public void onClick(ClickEvent event) {
350 5c6b4b2c Panagiotis Astithas
                                ConfirmationDialog confirm = new ConfirmationDialog("Really " +
351 5c6b4b2c Panagiotis Astithas
                                                "remove all previous versions?", "Remove") {
352 14ad7326 pastith
353 5c6b4b2c Panagiotis Astithas
                                        @Override
354 f98f18c2 koutsoub
                                        public void cancel() {
355 f98f18c2 koutsoub
                                        }
356 f98f18c2 koutsoub
357 5c6b4b2c Panagiotis Astithas
                                        @Override
358 f98f18c2 koutsoub
                                        public void confirm() {
359 f46a13ff fstamatelopoulos
                                                FilePropertiesDialog.this.closeDialog();
360 f98f18c2 koutsoub
                                                removeAllOldVersions();
361 f98f18c2 koutsoub
                                        }
362 f98f18c2 koutsoub
363 f98f18c2 koutsoub
                                };
364 f98f18c2 koutsoub
                                confirm.center();
365 14ad7326 pastith
                        }
366 14ad7326 pastith
367 14ad7326 pastith
                });
368 14ad7326 pastith
                HTML removeAllVersion = new HTML("<span>Remove all previous versions?</span>");
369 14ad7326 pastith
                vPanel2.add(removeAllVersion);
370 14ad7326 pastith
                vPanel2.add(removeVersionsButton);
371 14ad7326 pastith
                verPanel.add(vPanel2);
372 f98f18c2 koutsoub
                if(!file.isVersioned())
373 f98f18c2 koutsoub
                        vPanel2.setVisible(false);
374 14ad7326 pastith
                outer.add(inner);
375 14ad7326 pastith
                outer.add(buttons);
376 14ad7326 pastith
                outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
377 5c6b2883 Panagiotis Astithas
                outer.addStyleName("gss-TabPanelBottom");
378 14ad7326 pastith
379 14ad7326 pastith
                focusPanel.setFocus(true);
380 14ad7326 pastith
                setWidget(outer);
381 14ad7326 pastith
        }
382 14ad7326 pastith
383 14ad7326 pastith
384 14ad7326 pastith
        /**
385 14ad7326 pastith
         * Accepts any change and updates the file
386 14ad7326 pastith
         *
387 14ad7326 pastith
         */
388 2002c1dc Dimitris Routsis
        @Override
389 2002c1dc Dimitris Routsis
        protected void accept() {
390 5e9d7683 Dimitris Routsis
                String newFilename = null;
391 14ad7326 pastith
                permList.updatePermissionsAccordingToInput();
392 a52ea5e4 pastith
                Set<PermissionHolder> perms = permList.getPermissions();
393 a52ea5e4 pastith
                JSONObject json = new JSONObject();
394 5e9d7683 Dimitris Routsis
                if (!name.getText().equals(file.getName())) {
395 5e9d7683 Dimitris Routsis
                        newFilename = name.getText();
396 5e9d7683 Dimitris Routsis
                        json.put("name", new JSONString(newFilename));
397 5e9d7683 Dimitris Routsis
                }
398 afd3a0ef Giannis Koutsoubos
                if (versioned.getValue() != file.isVersioned())
399 afd3a0ef Giannis Koutsoubos
                        json.put("versioned", JSONBoolean.getInstance(versioned.getValue()));
400 52938043 fstamatelopoulos
                //only update the read for all perm if the user is the owner
401 afd3a0ef Giannis Koutsoubos
                if (readForAll.getValue() != file.isReadForAll())
402 409e932c koutsoub
                        if (file.getOwner().equals(GSS.get().getCurrentUserResource().getUsername()))
403 afd3a0ef Giannis Koutsoubos
                                json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue()));
404 409e932c koutsoub
                int i = 0;
405 409e932c koutsoub
                if (permList.hasChanges()) {
406 409e932c koutsoub
                        GWT.log("Permissions change", null);
407 409e932c koutsoub
                        JSONArray perma = new JSONArray();
408 409e932c koutsoub
409 409e932c koutsoub
                        for (PermissionHolder p : perms) {
410 409e932c koutsoub
                                JSONObject po = new JSONObject();
411 409e932c koutsoub
                                if (p.getUser() != null)
412 409e932c koutsoub
                                        po.put("user", new JSONString(p.getUser()));
413 409e932c koutsoub
                                if (p.getGroup() != null)
414 409e932c koutsoub
                                        po.put("group", new JSONString(p.getGroup()));
415 409e932c koutsoub
                                po.put("read", JSONBoolean.getInstance(p.isRead()));
416 409e932c koutsoub
                                po.put("write", JSONBoolean.getInstance(p.isWrite()));
417 409e932c koutsoub
                                po.put("modifyACL", JSONBoolean.getInstance(p.isModifyACL()));
418 409e932c koutsoub
                                perma.set(i, po);
419 409e932c koutsoub
                                i++;
420 409e932c koutsoub
                        }
421 409e932c koutsoub
                        json.put("permissions", perma);
422 14ad7326 pastith
                }
423 a52ea5e4 pastith
                JSONArray taga = new JSONArray();
424 409e932c koutsoub
                i = 0;
425 409e932c koutsoub
                if (!tags.getText().equals(initialTagText)) {
426 409e932c koutsoub
                        String[] tagset = tags.getText().split(",");
427 409e932c koutsoub
                        for (String t : tagset) {
428 409e932c koutsoub
                                JSONString to = new JSONString(t);
429 409e932c koutsoub
                                taga.set(i, to);
430 409e932c koutsoub
                                i++;
431 409e932c koutsoub
                        }
432 409e932c koutsoub
                        json.put("tags", taga);
433 a52ea5e4 pastith
                }
434 409e932c koutsoub
                String jsonString = json.toString();
435 409e932c koutsoub
                if(jsonString.equals("{}")){
436 409e932c koutsoub
                        GWT.log("NO CHANGES", null);
437 409e932c koutsoub
                        return;
438 409e932c koutsoub
                }
439 5e9d7683 Dimitris Routsis
                final String newFilenameFinal = newFilename;
440 895035a2 pastith
                PostCommand cf = new PostCommand(file.getUri() + "?update=", jsonString, 200) {
441 409e932c koutsoub
442 5c6b4b2c Panagiotis Astithas
                        @Override
443 a52ea5e4 pastith
                        public void onComplete() {
444 d5580e22 koutsoub
                                GSS.get().getTreeView().refreshCurrentNode(false);
445 14ad7326 pastith
                        }
446 14ad7326 pastith
447 5c6b4b2c Panagiotis Astithas
                        @Override
448 a52ea5e4 pastith
                        public void onError(Throwable t) {
449 a52ea5e4 pastith
                                GWT.log("", t);
450 409e932c koutsoub
                                if (t instanceof RestException) {
451 409e932c koutsoub
                                        int statusCode = ((RestException) t).getHttpStatusCode();
452 409e932c koutsoub
                                        if (statusCode == 405)
453 a52ea5e4 pastith
                                                GSS.get().displayError("You don't have the necessary permissions");
454 409e932c koutsoub
                                        else if (statusCode == 404)
455 a52ea5e4 pastith
                                                GSS.get().displayError("User in permissions does not exist");
456 409e932c koutsoub
                                        else if (statusCode == 409)
457 a52ea5e4 pastith
                                                GSS.get().displayError("A file with the same name already exists");
458 409e932c koutsoub
                                        else if (statusCode == 413)
459 a52ea5e4 pastith
                                                GSS.get().displayError("Your quota has been exceeded");
460 a52ea5e4 pastith
                                        else
461 409e932c koutsoub
                                                GSS.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());
462 409e932c koutsoub
                                } else
463 409e932c koutsoub
                                        GSS.get().displayError("System error modifying file:" + t.getMessage());
464 14ad7326 pastith
                        }
465 14ad7326 pastith
466 a52ea5e4 pastith
                };
467 a52ea5e4 pastith
                DeferredCommand.addCommand(cf);
468 14ad7326 pastith
469 a52ea5e4 pastith
        }
470 14ad7326 pastith
471 a52ea5e4 pastith
        private void removeAllOldVersions() {
472 f98f18c2 koutsoub
                JSONObject json = new JSONObject();
473 f98f18c2 koutsoub
                json.put("versioned", JSONBoolean.getInstance(false));
474 f98f18c2 koutsoub
                GWT.log(json.toString(), null);
475 895035a2 pastith
                PostCommand cf = new PostCommand(file.getUri() + "?update=", json.toString(), 200) {
476 f98f18c2 koutsoub
477 5c6b4b2c Panagiotis Astithas
                        @Override
478 f98f18c2 koutsoub
                        public void onComplete() {
479 f98f18c2 koutsoub
                                toggleVersioned(true);
480 f98f18c2 koutsoub
                        }
481 f98f18c2 koutsoub
482 5c6b4b2c Panagiotis Astithas
                        @Override
483 f98f18c2 koutsoub
                        public void onError(Throwable t) {
484 f98f18c2 koutsoub
                                GWT.log("", t);
485 f98f18c2 koutsoub
                                if (t instanceof RestException) {
486 f98f18c2 koutsoub
                                        int statusCode = ((RestException) t).getHttpStatusCode();
487 f98f18c2 koutsoub
                                        if (statusCode == 405)
488 f98f18c2 koutsoub
                                                GSS.get().displayError("You don't have the necessary permissions");
489 f98f18c2 koutsoub
                                        else if (statusCode == 404)
490 f98f18c2 koutsoub
                                                GSS.get().displayError("User in permissions does not exist");
491 f98f18c2 koutsoub
                                        else if (statusCode == 409)
492 f98f18c2 koutsoub
                                                GSS.get().displayError("A folder with the same name already exists");
493 f98f18c2 koutsoub
                                        else if (statusCode == 413)
494 f98f18c2 koutsoub
                                                GSS.get().displayError("Your quota has been exceeded");
495 f98f18c2 koutsoub
                                        else
496 f98f18c2 koutsoub
                                                GSS.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());
497 f98f18c2 koutsoub
                                } else
498 f98f18c2 koutsoub
                                        GSS.get().displayError("System error moifying file:" + t.getMessage());
499 f98f18c2 koutsoub
                        }
500 f98f18c2 koutsoub
                };
501 f98f18c2 koutsoub
                DeferredCommand.addCommand(cf);
502 14ad7326 pastith
        }
503 14ad7326 pastith
504 409e932c koutsoub
        private void toggleVersioned(boolean versionedValue) {
505 a52ea5e4 pastith
                JSONObject json = new JSONObject();
506 a52ea5e4 pastith
                json.put("versioned", JSONBoolean.getInstance(versionedValue));
507 a52ea5e4 pastith
                GWT.log(json.toString(), null);
508 895035a2 pastith
                PostCommand cf = new PostCommand(file.getUri() + "?update=", json.toString(), 200) {
509 409e932c koutsoub
510 5c6b4b2c Panagiotis Astithas
                        @Override
511 a52ea5e4 pastith
                        public void onComplete() {
512 d5580e22 koutsoub
                                GSS.get().getTreeView().refreshCurrentNode(false);
513 14ad7326 pastith
                        }
514 14ad7326 pastith
515 5c6b4b2c Panagiotis Astithas
                        @Override
516 a52ea5e4 pastith
                        public void onError(Throwable t) {
517 a52ea5e4 pastith
                                GWT.log("", t);
518 409e932c koutsoub
                                if (t instanceof RestException) {
519 409e932c koutsoub
                                        int statusCode = ((RestException) t).getHttpStatusCode();
520 409e932c koutsoub
                                        if (statusCode == 405)
521 a52ea5e4 pastith
                                                GSS.get().displayError("You don't have the necessary permissions");
522 409e932c koutsoub
                                        else if (statusCode == 404)
523 a52ea5e4 pastith
                                                GSS.get().displayError("User in permissions does not exist");
524 409e932c koutsoub
                                        else if (statusCode == 409)
525 a52ea5e4 pastith
                                                GSS.get().displayError("A folder with the same name already exists");
526 409e932c koutsoub
                                        else if (statusCode == 413)
527 a52ea5e4 pastith
                                                GSS.get().displayError("Your quota has been exceeded");
528 a52ea5e4 pastith
                                        else
529 409e932c koutsoub
                                                GSS.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());
530 409e932c koutsoub
                                } else
531 409e932c koutsoub
                                        GSS.get().displayError("System error moifying file:" + t.getMessage());
532 14ad7326 pastith
                        }
533 a52ea5e4 pastith
                };
534 a52ea5e4 pastith
                DeferredCommand.addCommand(cf);
535 14ad7326 pastith
        }
536 f46a13ff fstamatelopoulos
537 14ad7326 pastith
}