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