Statistics
| Branch: | Tag: | Revision:

root / web_client / src / gr / grnet / pithos / web / client / FilePropertiesDialog.java @ 58777026

History | View | Annotate | Download (19.6 kB)

1 ab1eb3f8 Christos Stathis
/*
2 58777026 Christos Stathis
 * Copyright 2011 GRNET S.A. All rights reserved.
3 58777026 Christos Stathis
 *
4 58777026 Christos Stathis
 * Redistribution and use in source and binary forms, with or
5 58777026 Christos Stathis
 * without modification, are permitted provided that the following
6 58777026 Christos Stathis
 * conditions are met:
7 58777026 Christos Stathis
 *
8 58777026 Christos Stathis
 *   1. Redistributions of source code must retain the above
9 58777026 Christos Stathis
 *      copyright notice, this list of conditions and the following
10 58777026 Christos Stathis
 *      disclaimer.
11 58777026 Christos Stathis
 *
12 58777026 Christos Stathis
 *   2. Redistributions in binary form must reproduce the above
13 58777026 Christos Stathis
 *      copyright notice, this list of conditions and the following
14 58777026 Christos Stathis
 *      disclaimer in the documentation and/or other materials
15 58777026 Christos Stathis
 *      provided with the distribution.
16 58777026 Christos Stathis
 *
17 58777026 Christos Stathis
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 58777026 Christos Stathis
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 58777026 Christos Stathis
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 58777026 Christos Stathis
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 58777026 Christos Stathis
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 58777026 Christos Stathis
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 58777026 Christos Stathis
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 58777026 Christos Stathis
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 58777026 Christos Stathis
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 58777026 Christos Stathis
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 58777026 Christos Stathis
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 58777026 Christos Stathis
 * POSSIBILITY OF SUCH DAMAGE.
29 58777026 Christos Stathis
 *
30 58777026 Christos Stathis
 * The views and conclusions contained in the software and
31 58777026 Christos Stathis
 * documentation are those of the authors and should not be
32 58777026 Christos Stathis
 * interpreted as representing official policies, either expressed
33 58777026 Christos Stathis
 * or implied, of GRNET S.A.
34 ab1eb3f8 Christos Stathis
 */
35 ab1eb3f8 Christos Stathis
package gr.grnet.pithos.web.client;
36 ab1eb3f8 Christos Stathis
37 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.PostCommand;
38 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.RestException;
39 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.FileResource;
40 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.GroupResource;
41 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.PermissionHolder;
42 ab1eb3f8 Christos Stathis
43 ab1eb3f8 Christos Stathis
import java.util.Iterator;
44 ab1eb3f8 Christos Stathis
import java.util.List;
45 ab1eb3f8 Christos Stathis
import java.util.Set;
46 ab1eb3f8 Christos Stathis
47 ab1eb3f8 Christos Stathis
import com.google.gwt.core.client.GWT;
48 ab1eb3f8 Christos Stathis
import com.google.gwt.event.dom.client.ChangeEvent;
49 ab1eb3f8 Christos Stathis
import com.google.gwt.event.dom.client.ChangeHandler;
50 ab1eb3f8 Christos Stathis
import com.google.gwt.event.dom.client.ClickEvent;
51 ab1eb3f8 Christos Stathis
import com.google.gwt.event.dom.client.ClickHandler;
52 ab1eb3f8 Christos Stathis
import com.google.gwt.i18n.client.DateTimeFormat;
53 ab1eb3f8 Christos Stathis
import com.google.gwt.json.client.JSONArray;
54 ab1eb3f8 Christos Stathis
import com.google.gwt.json.client.JSONBoolean;
55 ab1eb3f8 Christos Stathis
import com.google.gwt.json.client.JSONObject;
56 ab1eb3f8 Christos Stathis
import com.google.gwt.json.client.JSONString;
57 ab1eb3f8 Christos Stathis
import com.google.gwt.resources.client.ClientBundle;
58 ab1eb3f8 Christos Stathis
import com.google.gwt.resources.client.ImageResource;
59 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.Command;
60 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.DeferredCommand;
61 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.AbstractImagePrototype;
62 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.Button;
63 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.CheckBox;
64 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.DecoratedTabPanel;
65 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.DisclosurePanel;
66 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.FlexTable;
67 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.FlowPanel;
68 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.FocusPanel;
69 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.HTML;
70 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
71 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.HorizontalPanel;
72 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.Label;
73 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.TextBox;
74 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.VerticalPanel;
75 ab1eb3f8 Christos Stathis
76 ab1eb3f8 Christos Stathis
/**
77 ab1eb3f8 Christos Stathis
 * The 'File properties' dialog box implementation.
78 ab1eb3f8 Christos Stathis
 *
79 ab1eb3f8 Christos Stathis
 */
80 ab1eb3f8 Christos Stathis
public class FilePropertiesDialog extends AbstractPropertiesDialog {
81 ab1eb3f8 Christos Stathis
82 ab1eb3f8 Christos Stathis
        final PermissionsList permList;
83 ab1eb3f8 Christos Stathis
84 ab1eb3f8 Christos Stathis
        private CheckBox readForAll;
85 ab1eb3f8 Christos Stathis
86 ab1eb3f8 Christos Stathis
        /**
87 ab1eb3f8 Christos Stathis
         * An image bundle for this widgets images.
88 ab1eb3f8 Christos Stathis
         */
89 ab1eb3f8 Christos Stathis
        public interface Images extends ClientBundle,MessagePanel.Images {
90 ab1eb3f8 Christos Stathis
91 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/edit_user.png")
92 ab1eb3f8 Christos Stathis
                ImageResource permUser();
93 ab1eb3f8 Christos Stathis
94 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/groupevent.png")
95 ab1eb3f8 Christos Stathis
                ImageResource permGroup();
96 ab1eb3f8 Christos Stathis
97 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/editdelete.png")
98 ab1eb3f8 Christos Stathis
                ImageResource delete();
99 ab1eb3f8 Christos Stathis
100 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/db_update.png")
101 ab1eb3f8 Christos Stathis
                ImageResource restore();
102 ab1eb3f8 Christos Stathis
103 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/folder_inbox.png")
104 ab1eb3f8 Christos Stathis
                ImageResource download();
105 ab1eb3f8 Christos Stathis
        }
106 ab1eb3f8 Christos Stathis
107 ab1eb3f8 Christos Stathis
        /**
108 ab1eb3f8 Christos Stathis
         * The widget that holds the name of the file.
109 ab1eb3f8 Christos Stathis
         */
110 ab1eb3f8 Christos Stathis
        private TextBox name = new TextBox();
111 ab1eb3f8 Christos Stathis
112 ab1eb3f8 Christos Stathis
        private final CheckBox versioned = new CheckBox();
113 ab1eb3f8 Christos Stathis
114 ab1eb3f8 Christos Stathis
        final FileResource file;
115 ab1eb3f8 Christos Stathis
116 ab1eb3f8 Christos Stathis
        private String userFullName;
117 ab1eb3f8 Christos Stathis
118 ab1eb3f8 Christos Stathis
        /**
119 ab1eb3f8 Christos Stathis
         * The widget's constructor.
120 ab1eb3f8 Christos Stathis
         *
121 ab1eb3f8 Christos Stathis
         * @param images the dialog's ImageBundle
122 ab1eb3f8 Christos Stathis
         * @param groups
123 ab1eb3f8 Christos Stathis
         * @param bodies
124 ab1eb3f8 Christos Stathis
         */
125 ab1eb3f8 Christos Stathis
        public FilePropertiesDialog(final Images images, final List<GroupResource> groups, List<FileResource> bodies, String _userFullName) {
126 ab1eb3f8 Christos Stathis
127 ab1eb3f8 Christos Stathis
                // Set the dialog's caption.
128 ab1eb3f8 Christos Stathis
                setText("File properties");
129 ab1eb3f8 Christos Stathis
130 ab1eb3f8 Christos Stathis
                file = (FileResource) GSS.get().getCurrentSelection();
131 ab1eb3f8 Christos Stathis
                userFullName = _userFullName;
132 ab1eb3f8 Christos Stathis
                permList = new PermissionsList(images, file.getPermissions(), file.getOwner());
133 ab1eb3f8 Christos Stathis
134 ab1eb3f8 Christos Stathis
                GWT.log("FILE PERMISSIONS:"+file.getPermissions());
135 ab1eb3f8 Christos Stathis
                // Outer contains inner and buttons.
136 ab1eb3f8 Christos Stathis
                final VerticalPanel outer = new VerticalPanel();
137 ab1eb3f8 Christos Stathis
                final FocusPanel focusPanel = new FocusPanel(outer);
138 ab1eb3f8 Christos Stathis
                // Inner contains generalPanel and permPanel.
139 ab1eb3f8 Christos Stathis
                inner = new DecoratedTabPanel();
140 ab1eb3f8 Christos Stathis
                inner.setAnimationEnabled(true);
141 ab1eb3f8 Christos Stathis
                final VerticalPanel generalPanel = new VerticalPanel();
142 ab1eb3f8 Christos Stathis
                final VerticalPanel permPanel = new VerticalPanel();
143 ab1eb3f8 Christos Stathis
                final HorizontalPanel buttons = new HorizontalPanel();
144 ab1eb3f8 Christos Stathis
                final HorizontalPanel permButtons = new HorizontalPanel();
145 ab1eb3f8 Christos Stathis
                final HorizontalPanel permForAll = new HorizontalPanel();
146 ab1eb3f8 Christos Stathis
                final HorizontalPanel pathPanel = new HorizontalPanel();
147 ab1eb3f8 Christos Stathis
                final VerticalPanel verPanel = new VerticalPanel();
148 ab1eb3f8 Christos Stathis
                final HorizontalPanel vPanel = new HorizontalPanel();
149 ab1eb3f8 Christos Stathis
                final HorizontalPanel vPanel2 = new HorizontalPanel();
150 ab1eb3f8 Christos Stathis
151 ab1eb3f8 Christos Stathis
                versioned.setValue(file.isVersioned());
152 ab1eb3f8 Christos Stathis
                versioned.getElement().setId("filePropertiesDialog.chechBox.versioned");
153 ab1eb3f8 Christos Stathis
                inner.add(generalPanel, "General");
154 ab1eb3f8 Christos Stathis
                inner.add(permPanel, "Sharing");
155 ab1eb3f8 Christos Stathis
                inner.add(verPanel, "Versions");
156 ab1eb3f8 Christos Stathis
                inner.selectTab(0);
157 ab1eb3f8 Christos Stathis
158 ab1eb3f8 Christos Stathis
                final Label fileNameNote = new Label("Please note that slashes ('/') are not allowed in file names.", true);
159 ab1eb3f8 Christos Stathis
                fileNameNote.setVisible(false);
160 ab1eb3f8 Christos Stathis
                fileNameNote.setStylePrimaryName("pithos-readForAllNote");
161 ab1eb3f8 Christos Stathis
162 ab1eb3f8 Christos Stathis
                final FlexTable generalTable = new FlexTable();
163 ab1eb3f8 Christos Stathis
                generalTable.setText(0, 0, "Name");
164 ab1eb3f8 Christos Stathis
                generalTable.setText(1, 0, "Folder");
165 ab1eb3f8 Christos Stathis
                generalTable.setText(2, 0, "Owner");
166 ab1eb3f8 Christos Stathis
                generalTable.setText(3, 0, "Last modified");
167 ab1eb3f8 Christos Stathis
                generalTable.setText(4, 0, "Tags");
168 ab1eb3f8 Christos Stathis
                name.setWidth("100%");
169 ab1eb3f8 Christos Stathis
                name.setText(file.getName());
170 ab1eb3f8 Christos Stathis
                name.getElement().setId("filePropertiesDialog.textBox.name");
171 ab1eb3f8 Christos Stathis
                generalTable.setWidget(0, 1, name);
172 ab1eb3f8 Christos Stathis
                name.addChangeHandler(new ChangeHandler() {
173 ab1eb3f8 Christos Stathis
174 ab1eb3f8 Christos Stathis
                        @Override
175 ab1eb3f8 Christos Stathis
                        public void onChange(ChangeEvent event) {
176 ab1eb3f8 Christos Stathis
                                if(name.getText().contains("/"))
177 ab1eb3f8 Christos Stathis
                                        fileNameNote.setVisible(true);
178 ab1eb3f8 Christos Stathis
                                else
179 ab1eb3f8 Christos Stathis
                                        fileNameNote.setVisible(false);
180 ab1eb3f8 Christos Stathis
181 ab1eb3f8 Christos Stathis
                        }
182 ab1eb3f8 Christos Stathis
                });
183 ab1eb3f8 Christos Stathis
184 ab1eb3f8 Christos Stathis
                if(file.getFolderName() != null)
185 ab1eb3f8 Christos Stathis
                        generalTable.setText(1, 1, file.getFolderName());
186 ab1eb3f8 Christos Stathis
                else
187 ab1eb3f8 Christos Stathis
                        generalTable.setText(1, 1, "-");
188 ab1eb3f8 Christos Stathis
                generalTable.setWidget(0, 2, fileNameNote);
189 ab1eb3f8 Christos Stathis
                generalTable.setText(2, 1,userFullName);
190 ab1eb3f8 Christos Stathis
191 ab1eb3f8 Christos Stathis
                final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
192 ab1eb3f8 Christos Stathis
                generalTable.setText(3, 1, formatter.format(file.getModificationDate()));
193 ab1eb3f8 Christos Stathis
                // Get the tags.
194 ab1eb3f8 Christos Stathis
                StringBuffer tagsBuffer = new StringBuffer();
195 ab1eb3f8 Christos Stathis
                Iterator i = file.getTags().iterator();
196 ab1eb3f8 Christos Stathis
                while (i.hasNext()) {
197 ab1eb3f8 Christos Stathis
                        String tag = (String) i.next();
198 ab1eb3f8 Christos Stathis
                        tagsBuffer.append(tag).append(", ");
199 ab1eb3f8 Christos Stathis
                }
200 ab1eb3f8 Christos Stathis
                if (tagsBuffer.length() > 1)
201 ab1eb3f8 Christos Stathis
                        tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1);
202 ab1eb3f8 Christos Stathis
                initialTagText = tagsBuffer.toString();
203 ab1eb3f8 Christos Stathis
                tags.setWidth("100%");
204 ab1eb3f8 Christos Stathis
                tags.getElement().setId("filePropertiesDialog.textBox.tags");
205 ab1eb3f8 Christos Stathis
                tags.setText(initialTagText);
206 ab1eb3f8 Christos Stathis
                generalTable.setWidget(4, 1, tags);
207 ab1eb3f8 Christos Stathis
                generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
208 ab1eb3f8 Christos Stathis
                generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
209 ab1eb3f8 Christos Stathis
                generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");
210 ab1eb3f8 Christos Stathis
                generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels");
211 ab1eb3f8 Christos Stathis
                generalTable.getFlexCellFormatter().setStyleName(4, 0, "props-labels");
212 ab1eb3f8 Christos Stathis
                generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");
213 ab1eb3f8 Christos Stathis
                generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");
214 ab1eb3f8 Christos Stathis
                generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");
215 ab1eb3f8 Christos Stathis
                generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values");
216 ab1eb3f8 Christos Stathis
                generalTable.getFlexCellFormatter().setStyleName(4, 1, "props-values");
217 ab1eb3f8 Christos Stathis
                generalTable.setCellSpacing(4);
218 ab1eb3f8 Christos Stathis
219 ab1eb3f8 Christos Stathis
                // Create the 'OK' button, along with a listener that hides the dialog
220 ab1eb3f8 Christos Stathis
                // when the button is clicked.
221 ab1eb3f8 Christos Stathis
                final Button ok = new Button("OK", new ClickHandler() {
222 ab1eb3f8 Christos Stathis
                        @Override
223 ab1eb3f8 Christos Stathis
                        public void onClick(ClickEvent event) {
224 ab1eb3f8 Christos Stathis
                                if(name.getText().contains("/"))
225 ab1eb3f8 Christos Stathis
                                        fileNameNote.setVisible(true);
226 ab1eb3f8 Christos Stathis
                                else{
227 ab1eb3f8 Christos Stathis
                                        fileNameNote.setVisible(false);
228 ab1eb3f8 Christos Stathis
                                        accept();
229 ab1eb3f8 Christos Stathis
                                        closeDialog();
230 ab1eb3f8 Christos Stathis
                                }                
231 ab1eb3f8 Christos Stathis
                        }
232 ab1eb3f8 Christos Stathis
                });
233 ab1eb3f8 Christos Stathis
                ok.getElement().setId("filePropertiesDialog.button.ok");                
234 ab1eb3f8 Christos Stathis
                buttons.add(ok);
235 ab1eb3f8 Christos Stathis
                buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
236 ab1eb3f8 Christos Stathis
                // Create the 'Cancel' button, along with a listener that hides the
237 ab1eb3f8 Christos Stathis
                // dialog when the button is clicked.
238 ab1eb3f8 Christos Stathis
                final Button cancel = new Button("Cancel", new ClickHandler() {
239 ab1eb3f8 Christos Stathis
                        @Override
240 ab1eb3f8 Christos Stathis
                        public void onClick(ClickEvent event) {
241 ab1eb3f8 Christos Stathis
                                closeDialog();
242 ab1eb3f8 Christos Stathis
                        }
243 ab1eb3f8 Christos Stathis
                });
244 ab1eb3f8 Christos Stathis
                cancel.getElement().setId("filePropertiesDialog.button.cancel");
245 ab1eb3f8 Christos Stathis
                buttons.add(cancel);
246 ab1eb3f8 Christos Stathis
                buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
247 ab1eb3f8 Christos Stathis
                buttons.setSpacing(8);
248 ab1eb3f8 Christos Stathis
                buttons.addStyleName("pithos-TabPanelBottom");
249 ab1eb3f8 Christos Stathis
250 ab1eb3f8 Christos Stathis
                generalPanel.add(generalTable);
251 ab1eb3f8 Christos Stathis
252 ab1eb3f8 Christos Stathis
                // Asynchronously retrieve the tags defined by this user.
253 ab1eb3f8 Christos Stathis
                DeferredCommand.addCommand(new Command() {
254 ab1eb3f8 Christos Stathis
255 ab1eb3f8 Christos Stathis
                        @Override
256 ab1eb3f8 Christos Stathis
                        public void execute() {
257 ab1eb3f8 Christos Stathis
                                updateTags();
258 ab1eb3f8 Christos Stathis
                        }
259 ab1eb3f8 Christos Stathis
                });
260 ab1eb3f8 Christos Stathis
261 ab1eb3f8 Christos Stathis
                DisclosurePanel allTags = new DisclosurePanel("All tags");
262 ab1eb3f8 Christos Stathis
                allTagsContent = new FlowPanel();
263 ab1eb3f8 Christos Stathis
                allTagsContent.setWidth("100%");
264 ab1eb3f8 Christos Stathis
                allTags.setContent(allTagsContent);
265 ab1eb3f8 Christos Stathis
                generalPanel.add(allTags);
266 ab1eb3f8 Christos Stathis
                generalPanel.setSpacing(4);
267 ab1eb3f8 Christos Stathis
268 ab1eb3f8 Christos Stathis
                final Button add = new Button("Add Group", new ClickHandler() {
269 ab1eb3f8 Christos Stathis
                        @Override
270 ab1eb3f8 Christos Stathis
                        public void onClick(ClickEvent event) {
271 ab1eb3f8 Christos Stathis
                                PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, false);
272 ab1eb3f8 Christos Stathis
                                dlg.center();
273 ab1eb3f8 Christos Stathis
                        }
274 ab1eb3f8 Christos Stathis
                });
275 ab1eb3f8 Christos Stathis
                add.getElement().setId("filePropertiesDialog.button.addGroup");
276 ab1eb3f8 Christos Stathis
                permButtons.add(add);
277 ab1eb3f8 Christos Stathis
                permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER);
278 ab1eb3f8 Christos Stathis
279 ab1eb3f8 Christos Stathis
                final Button addUser = new Button("Add User", new ClickHandler() {
280 ab1eb3f8 Christos Stathis
                        @Override
281 ab1eb3f8 Christos Stathis
                        public void onClick(ClickEvent event) {
282 ab1eb3f8 Christos Stathis
                                PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, true);
283 ab1eb3f8 Christos Stathis
                                dlg.center();
284 ab1eb3f8 Christos Stathis
                        }
285 ab1eb3f8 Christos Stathis
                });
286 ab1eb3f8 Christos Stathis
                add.getElement().setId("filePropertiesDialog.button.addUser");
287 ab1eb3f8 Christos Stathis
                permButtons.add(addUser);
288 ab1eb3f8 Christos Stathis
                permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER);
289 ab1eb3f8 Christos Stathis
290 ab1eb3f8 Christos Stathis
                permButtons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
291 ab1eb3f8 Christos Stathis
                permButtons.setSpacing(8);
292 ab1eb3f8 Christos Stathis
                permButtons.addStyleName("pithos-TabPanelBottom");
293 ab1eb3f8 Christos Stathis
294 ab1eb3f8 Christos Stathis
                final Label readForAllNote = new Label("When this option is enabled, the file will be readable" +
295 ab1eb3f8 Christos Stathis
                                        " by everyone. By checking this option, you are certifying that you have the right to " +
296 ab1eb3f8 Christos Stathis
                                        "distribute this file and that it does not violate the Terms of Use.", true);
297 ab1eb3f8 Christos Stathis
                readForAllNote.setVisible(false);
298 ab1eb3f8 Christos Stathis
                readForAllNote.setStylePrimaryName("pithos-readForAllNote");
299 ab1eb3f8 Christos Stathis
300 ab1eb3f8 Christos Stathis
                readForAll = new CheckBox();
301 ab1eb3f8 Christos Stathis
                readForAll.getElement().setId("filePropertiesDialog.checkBox.public");
302 ab1eb3f8 Christos Stathis
                readForAll.setValue(file.isReadForAll());
303 ab1eb3f8 Christos Stathis
                readForAll.addClickHandler(new ClickHandler() {
304 ab1eb3f8 Christos Stathis
                        @Override
305 ab1eb3f8 Christos Stathis
                        public void onClick(ClickEvent event) {
306 ab1eb3f8 Christos Stathis
                                readForAllNote.setVisible(readForAll.getValue());
307 ab1eb3f8 Christos Stathis
                        }
308 ab1eb3f8 Christos Stathis
309 ab1eb3f8 Christos Stathis
                });
310 ab1eb3f8 Christos Stathis
311 ab1eb3f8 Christos Stathis
                permPanel.add(permList);
312 ab1eb3f8 Christos Stathis
                permPanel.add(permButtons);
313 ab1eb3f8 Christos Stathis
                // Only show the read for all permission if the user is the owner.
314 ab1eb3f8 Christos Stathis
                if (file.getOwner().equals(GSS.get().getCurrentUserResource().getUsername())) {
315 ab1eb3f8 Christos Stathis
                        permForAll.add(new Label("Public"));
316 ab1eb3f8 Christos Stathis
                        permForAll.add(readForAll);
317 ab1eb3f8 Christos Stathis
                        permForAll.setSpacing(8);
318 ab1eb3f8 Christos Stathis
                        permForAll.addStyleName("pithos-TabPanelBottom");
319 ab1eb3f8 Christos Stathis
                        permForAll.add(readForAllNote);
320 ab1eb3f8 Christos Stathis
                        permPanel.add(permForAll);
321 ab1eb3f8 Christos Stathis
                }
322 ab1eb3f8 Christos Stathis
323 ab1eb3f8 Christos Stathis
                TextBox path = new TextBox();
324 ab1eb3f8 Christos Stathis
                path.setWidth("100%");
325 ab1eb3f8 Christos Stathis
                path.addClickHandler(new ClickHandler() {
326 ab1eb3f8 Christos Stathis
                        @Override
327 ab1eb3f8 Christos Stathis
                        public void onClick(ClickEvent event) {
328 ab1eb3f8 Christos Stathis
                                GSS.enableIESelection();
329 ab1eb3f8 Christos Stathis
                                ((TextBox) event.getSource()).selectAll();
330 ab1eb3f8 Christos Stathis
                                GSS.preventIESelection();
331 ab1eb3f8 Christos Stathis
                        }
332 ab1eb3f8 Christos Stathis
333 ab1eb3f8 Christos Stathis
                });
334 ab1eb3f8 Christos Stathis
                path.setText(file.getUri());
335 ab1eb3f8 Christos Stathis
                path.getElement().setId("filePropertiesDialog.textBox.link");
336 ab1eb3f8 Christos Stathis
                path.setTitle("Use this link for sharing the file via e-mail, IM, etc. (crtl-C/cmd-C to copy to system clipboard)");
337 ab1eb3f8 Christos Stathis
                path.setWidth("100%");
338 ab1eb3f8 Christos Stathis
                path.setReadOnly(true);
339 ab1eb3f8 Christos Stathis
                pathPanel.setWidth("100%");
340 ab1eb3f8 Christos Stathis
                pathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
341 ab1eb3f8 Christos Stathis
                pathPanel.add(new Label("Link"));
342 ab1eb3f8 Christos Stathis
                pathPanel.setSpacing(8);
343 ab1eb3f8 Christos Stathis
                pathPanel.addStyleName("pithos-TabPanelBottom");
344 ab1eb3f8 Christos Stathis
                pathPanel.add(path);
345 ab1eb3f8 Christos Stathis
                permPanel.add(pathPanel);
346 ab1eb3f8 Christos Stathis
347 ab1eb3f8 Christos Stathis
                VersionsList verList = new VersionsList(this, images, bodies);
348 ab1eb3f8 Christos Stathis
                verPanel.add(verList);
349 ab1eb3f8 Christos Stathis
350 ab1eb3f8 Christos Stathis
                vPanel.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
351 ab1eb3f8 Christos Stathis
                vPanel.setSpacing(8);
352 ab1eb3f8 Christos Stathis
                vPanel.addStyleName("pithos-TabPanelBottom");
353 ab1eb3f8 Christos Stathis
                vPanel.add(new Label("Versioned"));
354 ab1eb3f8 Christos Stathis
355 ab1eb3f8 Christos Stathis
                vPanel.add(versioned);
356 ab1eb3f8 Christos Stathis
                verPanel.add(vPanel);
357 ab1eb3f8 Christos Stathis
                vPanel2.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
358 ab1eb3f8 Christos Stathis
                vPanel2.setSpacing(8);
359 ab1eb3f8 Christos Stathis
                vPanel2.addStyleName("pithos-TabPanelBottom");
360 ab1eb3f8 Christos Stathis
                Button removeVersionsButton = new Button(AbstractImagePrototype.create(images.delete()).getHTML(), new ClickHandler() {
361 ab1eb3f8 Christos Stathis
                        @Override
362 ab1eb3f8 Christos Stathis
                        public void onClick(ClickEvent event) {
363 ab1eb3f8 Christos Stathis
                                ConfirmationDialog confirm = new ConfirmationDialog("Really " +
364 ab1eb3f8 Christos Stathis
                                                "remove all previous versions?", "Remove") {
365 ab1eb3f8 Christos Stathis
366 ab1eb3f8 Christos Stathis
                                        @Override
367 ab1eb3f8 Christos Stathis
                                        public void cancel() {
368 ab1eb3f8 Christos Stathis
                                        }
369 ab1eb3f8 Christos Stathis
370 ab1eb3f8 Christos Stathis
                                        @Override
371 ab1eb3f8 Christos Stathis
                                        public void confirm() {
372 ab1eb3f8 Christos Stathis
                                                FilePropertiesDialog.this.closeDialog();
373 ab1eb3f8 Christos Stathis
                                                removeAllOldVersions();
374 ab1eb3f8 Christos Stathis
                                        }
375 ab1eb3f8 Christos Stathis
376 ab1eb3f8 Christos Stathis
                                };
377 ab1eb3f8 Christos Stathis
                                confirm.center();
378 ab1eb3f8 Christos Stathis
                        }
379 ab1eb3f8 Christos Stathis
380 ab1eb3f8 Christos Stathis
                });
381 ab1eb3f8 Christos Stathis
                HTML removeAllVersion = new HTML("<span>Remove all previous versions?</span>");
382 ab1eb3f8 Christos Stathis
                vPanel2.add(removeAllVersion);
383 ab1eb3f8 Christos Stathis
                vPanel2.add(removeVersionsButton);
384 ab1eb3f8 Christos Stathis
                verPanel.add(vPanel2);
385 ab1eb3f8 Christos Stathis
                if(!file.isVersioned())
386 ab1eb3f8 Christos Stathis
                        vPanel2.setVisible(false);
387 ab1eb3f8 Christos Stathis
                outer.add(inner);
388 ab1eb3f8 Christos Stathis
                outer.add(buttons);
389 ab1eb3f8 Christos Stathis
                outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
390 ab1eb3f8 Christos Stathis
                outer.addStyleName("pithos-TabPanelBottom");
391 ab1eb3f8 Christos Stathis
392 ab1eb3f8 Christos Stathis
                focusPanel.setFocus(true);
393 ab1eb3f8 Christos Stathis
                setWidget(outer);
394 ab1eb3f8 Christos Stathis
        }
395 ab1eb3f8 Christos Stathis
396 ab1eb3f8 Christos Stathis
397 ab1eb3f8 Christos Stathis
        /**
398 ab1eb3f8 Christos Stathis
         * Accepts any change and updates the file
399 ab1eb3f8 Christos Stathis
         *
400 ab1eb3f8 Christos Stathis
         */
401 ab1eb3f8 Christos Stathis
        @Override
402 ab1eb3f8 Christos Stathis
        protected void accept() {
403 ab1eb3f8 Christos Stathis
                String newFilename = null;
404 ab1eb3f8 Christos Stathis
                permList.updatePermissionsAccordingToInput();
405 ab1eb3f8 Christos Stathis
                Set<PermissionHolder> perms = permList.getPermissions();
406 ab1eb3f8 Christos Stathis
                JSONObject json = new JSONObject();
407 ab1eb3f8 Christos Stathis
                if (!name.getText().equals(file.getName())) {
408 ab1eb3f8 Christos Stathis
                        newFilename = name.getText();
409 ab1eb3f8 Christos Stathis
                        json.put("name", new JSONString(newFilename));
410 ab1eb3f8 Christos Stathis
                }
411 ab1eb3f8 Christos Stathis
                if (versioned.getValue() != file.isVersioned())
412 ab1eb3f8 Christos Stathis
                        json.put("versioned", JSONBoolean.getInstance(versioned.getValue()));
413 ab1eb3f8 Christos Stathis
                //only update the read for all perm if the user is the owner
414 ab1eb3f8 Christos Stathis
                if (readForAll.getValue() != file.isReadForAll())
415 ab1eb3f8 Christos Stathis
                        if (file.getOwner().equals(GSS.get().getCurrentUserResource().getUsername()))
416 ab1eb3f8 Christos Stathis
                                json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue()));
417 ab1eb3f8 Christos Stathis
                int i = 0;
418 ab1eb3f8 Christos Stathis
                if (permList.hasChanges()) {
419 ab1eb3f8 Christos Stathis
                        GWT.log("Permissions change", null);
420 ab1eb3f8 Christos Stathis
                        JSONArray perma = new JSONArray();
421 ab1eb3f8 Christos Stathis
422 ab1eb3f8 Christos Stathis
                        for (PermissionHolder p : perms) {
423 ab1eb3f8 Christos Stathis
                                JSONObject po = new JSONObject();
424 ab1eb3f8 Christos Stathis
                                if (p.getUser() != null)
425 ab1eb3f8 Christos Stathis
                                        po.put("user", new JSONString(p.getUser()));
426 ab1eb3f8 Christos Stathis
                                if (p.getGroup() != null)
427 ab1eb3f8 Christos Stathis
                                        po.put("group", new JSONString(p.getGroup()));
428 ab1eb3f8 Christos Stathis
                                po.put("read", JSONBoolean.getInstance(p.isRead()));
429 ab1eb3f8 Christos Stathis
                                po.put("write", JSONBoolean.getInstance(p.isWrite()));
430 ab1eb3f8 Christos Stathis
                                po.put("modifyACL", JSONBoolean.getInstance(p.isModifyACL()));
431 ab1eb3f8 Christos Stathis
                                perma.set(i, po);
432 ab1eb3f8 Christos Stathis
                                i++;
433 ab1eb3f8 Christos Stathis
                        }
434 ab1eb3f8 Christos Stathis
                        json.put("permissions", perma);
435 ab1eb3f8 Christos Stathis
                }
436 ab1eb3f8 Christos Stathis
                JSONArray taga = new JSONArray();
437 ab1eb3f8 Christos Stathis
                i = 0;
438 ab1eb3f8 Christos Stathis
                if (!tags.getText().equals(initialTagText)) {
439 ab1eb3f8 Christos Stathis
                        String[] tagset = tags.getText().split(",");
440 ab1eb3f8 Christos Stathis
                        for (String t : tagset) {
441 ab1eb3f8 Christos Stathis
                                JSONString to = new JSONString(t);
442 ab1eb3f8 Christos Stathis
                                taga.set(i, to);
443 ab1eb3f8 Christos Stathis
                                i++;
444 ab1eb3f8 Christos Stathis
                        }
445 ab1eb3f8 Christos Stathis
                        json.put("tags", taga);
446 ab1eb3f8 Christos Stathis
                }
447 ab1eb3f8 Christos Stathis
                String jsonString = json.toString();
448 ab1eb3f8 Christos Stathis
                if(jsonString.equals("{}")){
449 ab1eb3f8 Christos Stathis
                        GWT.log("NO CHANGES", null);
450 ab1eb3f8 Christos Stathis
                        return;
451 ab1eb3f8 Christos Stathis
                }
452 ab1eb3f8 Christos Stathis
                final String newFilenameFinal = newFilename;
453 ab1eb3f8 Christos Stathis
                PostCommand cf = new PostCommand(file.getUri() + "?update=", jsonString, 200) {
454 ab1eb3f8 Christos Stathis
455 ab1eb3f8 Christos Stathis
                        @Override
456 ab1eb3f8 Christos Stathis
                        public void onComplete() {
457 ab1eb3f8 Christos Stathis
                                GSS.get().getTreeView().refreshCurrentNode(false);
458 ab1eb3f8 Christos Stathis
                        }
459 ab1eb3f8 Christos Stathis
460 ab1eb3f8 Christos Stathis
                        @Override
461 ab1eb3f8 Christos Stathis
                        public void onError(Throwable t) {
462 ab1eb3f8 Christos Stathis
                                GWT.log("", t);
463 ab1eb3f8 Christos Stathis
                                if (t instanceof RestException) {
464 ab1eb3f8 Christos Stathis
                                        int statusCode = ((RestException) t).getHttpStatusCode();
465 ab1eb3f8 Christos Stathis
                                        if (statusCode == 405)
466 ab1eb3f8 Christos Stathis
                                                GSS.get().displayError("You don't have the necessary permissions");
467 ab1eb3f8 Christos Stathis
                                        else if (statusCode == 404)
468 ab1eb3f8 Christos Stathis
                                                GSS.get().displayError("User in permissions does not exist");
469 ab1eb3f8 Christos Stathis
                                        else if (statusCode == 409)
470 ab1eb3f8 Christos Stathis
                                                GSS.get().displayError("A file with the same name already exists");
471 ab1eb3f8 Christos Stathis
                                        else if (statusCode == 413)
472 ab1eb3f8 Christos Stathis
                                                GSS.get().displayError("Your quota has been exceeded");
473 ab1eb3f8 Christos Stathis
                                        else
474 ab1eb3f8 Christos Stathis
                                                GSS.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());
475 ab1eb3f8 Christos Stathis
                                } else
476 ab1eb3f8 Christos Stathis
                                        GSS.get().displayError("System error modifying file:" + t.getMessage());
477 ab1eb3f8 Christos Stathis
                        }
478 ab1eb3f8 Christos Stathis
479 ab1eb3f8 Christos Stathis
                };
480 ab1eb3f8 Christos Stathis
                DeferredCommand.addCommand(cf);
481 ab1eb3f8 Christos Stathis
482 ab1eb3f8 Christos Stathis
        }
483 ab1eb3f8 Christos Stathis
484 ab1eb3f8 Christos Stathis
        private void removeAllOldVersions() {
485 ab1eb3f8 Christos Stathis
                JSONObject json = new JSONObject();
486 ab1eb3f8 Christos Stathis
                json.put("versioned", JSONBoolean.getInstance(false));
487 ab1eb3f8 Christos Stathis
                GWT.log(json.toString(), null);
488 ab1eb3f8 Christos Stathis
                PostCommand cf = new PostCommand(file.getUri() + "?update=", json.toString(), 200) {
489 ab1eb3f8 Christos Stathis
490 ab1eb3f8 Christos Stathis
                        @Override
491 ab1eb3f8 Christos Stathis
                        public void onComplete() {
492 ab1eb3f8 Christos Stathis
                                toggleVersioned(true);
493 ab1eb3f8 Christos Stathis
                        }
494 ab1eb3f8 Christos Stathis
495 ab1eb3f8 Christos Stathis
                        @Override
496 ab1eb3f8 Christos Stathis
                        public void onError(Throwable t) {
497 ab1eb3f8 Christos Stathis
                                GWT.log("", t);
498 ab1eb3f8 Christos Stathis
                                if (t instanceof RestException) {
499 ab1eb3f8 Christos Stathis
                                        int statusCode = ((RestException) t).getHttpStatusCode();
500 ab1eb3f8 Christos Stathis
                                        if (statusCode == 405)
501 ab1eb3f8 Christos Stathis
                                                GSS.get().displayError("You don't have the necessary permissions");
502 ab1eb3f8 Christos Stathis
                                        else if (statusCode == 404)
503 ab1eb3f8 Christos Stathis
                                                GSS.get().displayError("User in permissions does not exist");
504 ab1eb3f8 Christos Stathis
                                        else if (statusCode == 409)
505 ab1eb3f8 Christos Stathis
                                                GSS.get().displayError("A folder with the same name already exists");
506 ab1eb3f8 Christos Stathis
                                        else if (statusCode == 413)
507 ab1eb3f8 Christos Stathis
                                                GSS.get().displayError("Your quota has been exceeded");
508 ab1eb3f8 Christos Stathis
                                        else
509 ab1eb3f8 Christos Stathis
                                                GSS.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());
510 ab1eb3f8 Christos Stathis
                                } else
511 ab1eb3f8 Christos Stathis
                                        GSS.get().displayError("System error moifying file:" + t.getMessage());
512 ab1eb3f8 Christos Stathis
                        }
513 ab1eb3f8 Christos Stathis
                };
514 ab1eb3f8 Christos Stathis
                DeferredCommand.addCommand(cf);
515 ab1eb3f8 Christos Stathis
        }
516 ab1eb3f8 Christos Stathis
517 ab1eb3f8 Christos Stathis
        private void toggleVersioned(boolean versionedValue) {
518 ab1eb3f8 Christos Stathis
                JSONObject json = new JSONObject();
519 ab1eb3f8 Christos Stathis
                json.put("versioned", JSONBoolean.getInstance(versionedValue));
520 ab1eb3f8 Christos Stathis
                GWT.log(json.toString(), null);
521 ab1eb3f8 Christos Stathis
                PostCommand cf = new PostCommand(file.getUri() + "?update=", json.toString(), 200) {
522 ab1eb3f8 Christos Stathis
523 ab1eb3f8 Christos Stathis
                        @Override
524 ab1eb3f8 Christos Stathis
                        public void onComplete() {
525 ab1eb3f8 Christos Stathis
                                GSS.get().getTreeView().refreshCurrentNode(false);
526 ab1eb3f8 Christos Stathis
                        }
527 ab1eb3f8 Christos Stathis
528 ab1eb3f8 Christos Stathis
                        @Override
529 ab1eb3f8 Christos Stathis
                        public void onError(Throwable t) {
530 ab1eb3f8 Christos Stathis
                                GWT.log("", t);
531 ab1eb3f8 Christos Stathis
                                if (t instanceof RestException) {
532 ab1eb3f8 Christos Stathis
                                        int statusCode = ((RestException) t).getHttpStatusCode();
533 ab1eb3f8 Christos Stathis
                                        if (statusCode == 405)
534 ab1eb3f8 Christos Stathis
                                                GSS.get().displayError("You don't have the necessary permissions");
535 ab1eb3f8 Christos Stathis
                                        else if (statusCode == 404)
536 ab1eb3f8 Christos Stathis
                                                GSS.get().displayError("User in permissions does not exist");
537 ab1eb3f8 Christos Stathis
                                        else if (statusCode == 409)
538 ab1eb3f8 Christos Stathis
                                                GSS.get().displayError("A folder with the same name already exists");
539 ab1eb3f8 Christos Stathis
                                        else if (statusCode == 413)
540 ab1eb3f8 Christos Stathis
                                                GSS.get().displayError("Your quota has been exceeded");
541 ab1eb3f8 Christos Stathis
                                        else
542 ab1eb3f8 Christos Stathis
                                                GSS.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());
543 ab1eb3f8 Christos Stathis
                                } else
544 ab1eb3f8 Christos Stathis
                                        GSS.get().displayError("System error moifying file:" + t.getMessage());
545 ab1eb3f8 Christos Stathis
                        }
546 ab1eb3f8 Christos Stathis
                };
547 ab1eb3f8 Christos Stathis
                DeferredCommand.addCommand(cf);
548 ab1eb3f8 Christos Stathis
        }
549 ab1eb3f8 Christos Stathis
550 ab1eb3f8 Christos Stathis
}