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