root / src / gr / ebs / gss / client / FilesPropertiesDialog.java @ 4856bcbf
History | View | Annotate | Download (9.1 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.components.TristateCheckBox; |
22 |
import gr.ebs.gss.client.rest.MultiplePostCommand; |
23 |
import gr.ebs.gss.client.rest.RestException; |
24 |
import gr.ebs.gss.client.rest.resource.FileResource; |
25 |
|
26 |
import java.util.ArrayList; |
27 |
import java.util.Iterator; |
28 |
import java.util.List; |
29 |
|
30 |
import com.google.gwt.core.client.GWT; |
31 |
import com.google.gwt.event.dom.client.ClickEvent; |
32 |
import com.google.gwt.event.dom.client.ClickHandler; |
33 |
import com.google.gwt.event.dom.client.FocusEvent; |
34 |
import com.google.gwt.event.dom.client.FocusHandler; |
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.user.client.Command; |
40 |
import com.google.gwt.user.client.DeferredCommand; |
41 |
import com.google.gwt.user.client.ui.Button; |
42 |
import com.google.gwt.user.client.ui.DecoratedTabPanel; |
43 |
import com.google.gwt.user.client.ui.DisclosurePanel; |
44 |
import com.google.gwt.user.client.ui.FlexTable; |
45 |
import com.google.gwt.user.client.ui.FlowPanel; |
46 |
import com.google.gwt.user.client.ui.FocusPanel; |
47 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
48 |
import com.google.gwt.user.client.ui.HorizontalPanel; |
49 |
import com.google.gwt.user.client.ui.Label; |
50 |
import com.google.gwt.user.client.ui.VerticalPanel; |
51 |
|
52 |
/**
|
53 |
* The 'Multiple file properties' dialog box implementation.
|
54 |
*
|
55 |
* @author droutsis
|
56 |
*/
|
57 |
public class FilesPropertiesDialog extends AbstractPropertiesDialog { |
58 |
|
59 |
private final TristateCheckBox versionedCheck; |
60 |
|
61 |
private final List<FileResource> files; |
62 |
|
63 |
private Boolean initialVersioned; |
64 |
|
65 |
|
66 |
/**
|
67 |
* The widget's constructor.
|
68 |
*
|
69 |
* @param _files
|
70 |
*/
|
71 |
public FilesPropertiesDialog(final List<FileResource> _files) { |
72 |
super();
|
73 |
|
74 |
files = _files; |
75 |
int versionedNum = 0; |
76 |
for (FileResource fr : files)
|
77 |
if (fr.isVersioned()) versionedNum++;
|
78 |
Boolean versioned = null; |
79 |
if (versionedNum==0) versioned = false; |
80 |
if (versionedNum==files.size()) versioned = true; |
81 |
initialVersioned = versioned; |
82 |
versionedCheck = new TristateCheckBox(versioned);
|
83 |
|
84 |
// Set the dialog's caption.
|
85 |
setText("Files properties");
|
86 |
|
87 |
// Outer contains inner and buttons.
|
88 |
final VerticalPanel outer = new VerticalPanel(); |
89 |
final FocusPanel focusPanel = new FocusPanel(outer); |
90 |
// Inner contains generalPanel and permPanel.
|
91 |
inner = new DecoratedTabPanel();
|
92 |
inner.setAnimationEnabled(true);
|
93 |
final VerticalPanel generalPanel = new VerticalPanel(); |
94 |
final HorizontalPanel buttons = new HorizontalPanel(); |
95 |
final VerticalPanel verPanel = new VerticalPanel(); |
96 |
final HorizontalPanel vPanel = new HorizontalPanel(); |
97 |
|
98 |
inner.add(generalPanel, "General");
|
99 |
inner.add(verPanel, "Versions");
|
100 |
inner.selectTab(0);
|
101 |
|
102 |
final FlexTable generalTable = new FlexTable(); |
103 |
generalTable.setText(0, 0, String.valueOf(files.size())+" files selected"); |
104 |
generalTable.setText(1, 0, "Folder"); |
105 |
generalTable.setText(2, 0, "Tags"); |
106 |
FileResource firstFile = files.get(0);
|
107 |
if(firstFile.getFolderName() != null) |
108 |
generalTable.setText(1, 1, firstFile.getFolderName()); |
109 |
else
|
110 |
generalTable.setText(1, 1, "-"); |
111 |
|
112 |
// Find if tags are identical
|
113 |
List<String> tagsList = files.get(0).getTags(); |
114 |
List<String> tagss; |
115 |
for (int i=1; i<files.size(); i++) { |
116 |
tagss = files.get(i).getTags(); |
117 |
if (tagsList.size() != tagss.size() || !tagsList.containsAll(tagss)) {
|
118 |
tagsList = null;
|
119 |
break;
|
120 |
} |
121 |
} |
122 |
// Get the tags.
|
123 |
StringBuffer tagsBuffer = new StringBuffer(); |
124 |
if (tagsList==null) |
125 |
tagsBuffer.append(MULTIPLE_VALUES_TEXT); |
126 |
else {
|
127 |
Iterator i = tagsList.iterator();
|
128 |
while (i.hasNext()) {
|
129 |
String tag = (String) i.next(); |
130 |
tagsBuffer.append(tag).append(", ");
|
131 |
} |
132 |
if (tagsBuffer.length() > 1) |
133 |
tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1); |
134 |
} |
135 |
initialTagText = tagsBuffer.toString(); |
136 |
tags.setText(initialTagText); |
137 |
tags.addFocusHandler(new FocusHandler() {
|
138 |
@Override
|
139 |
public void onFocus(FocusEvent event) { |
140 |
if (MULTIPLE_VALUES_TEXT.equals(tags.getText()))
|
141 |
tags.setText("");
|
142 |
} |
143 |
} |
144 |
); |
145 |
|
146 |
generalTable.setWidget(2, 1, tags); |
147 |
generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels"); |
148 |
generalTable.getFlexCellFormatter().setColSpan(0, 0, 2); |
149 |
generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels"); |
150 |
generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels"); |
151 |
generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values"); |
152 |
generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values"); |
153 |
generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values"); |
154 |
generalTable.setCellSpacing(4);
|
155 |
|
156 |
// Create the 'OK' button, along with a listener that hides the dialog
|
157 |
// when the button is clicked.
|
158 |
final Button ok = new Button("OK", new ClickHandler() { |
159 |
@Override
|
160 |
public void onClick(ClickEvent event) { |
161 |
accept(); |
162 |
closeDialog(); |
163 |
} |
164 |
}); |
165 |
buttons.add(ok); |
166 |
buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER); |
167 |
// Create the 'Cancel' button, along with a listener that hides the
|
168 |
// dialog when the button is clicked.
|
169 |
final Button cancel = new Button("Cancel", new ClickHandler() { |
170 |
@Override
|
171 |
public void onClick(ClickEvent event) { |
172 |
closeDialog(); |
173 |
} |
174 |
}); |
175 |
buttons.add(cancel); |
176 |
buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); |
177 |
buttons.setSpacing(8);
|
178 |
buttons.addStyleName("gss-TabPanelBottom");
|
179 |
|
180 |
generalPanel.add(generalTable); |
181 |
|
182 |
// Asynchronously retrieve the tags defined by this user.
|
183 |
DeferredCommand.addCommand(new Command() {
|
184 |
|
185 |
@Override
|
186 |
public void execute() { |
187 |
updateTags(); |
188 |
} |
189 |
}); |
190 |
|
191 |
DisclosurePanel allTags = new DisclosurePanel("All tags"); |
192 |
allTagsContent = new FlowPanel();
|
193 |
allTags.setContent(allTagsContent); |
194 |
generalPanel.add(allTags); |
195 |
generalPanel.setSpacing(4);
|
196 |
|
197 |
|
198 |
vPanel.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); |
199 |
vPanel.setSpacing(8);
|
200 |
vPanel.addStyleName("gss-TabPanelBottom");
|
201 |
vPanel.add(new Label("Versioned")); |
202 |
|
203 |
vPanel.add(versionedCheck); |
204 |
verPanel.add(vPanel); |
205 |
outer.add(inner); |
206 |
outer.add(buttons); |
207 |
outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); |
208 |
outer.addStyleName("gss-TabPanelBottom");
|
209 |
|
210 |
focusPanel.setFocus(true);
|
211 |
setWidget(outer); |
212 |
} |
213 |
|
214 |
|
215 |
/**
|
216 |
* Accepts any change and updates the file
|
217 |
*
|
218 |
*/
|
219 |
@Override
|
220 |
protected void accept() { |
221 |
JSONObject json = new JSONObject();
|
222 |
if ( versionedCheck.getState()!=null && !versionedCheck.getState().equals(initialVersioned) ) |
223 |
json.put("versioned", JSONBoolean.getInstance(versionedCheck.getState()));
|
224 |
|
225 |
JSONArray taga = new JSONArray();
|
226 |
int i = 0; |
227 |
String tagText = tags.getText();
|
228 |
if (!MULTIPLE_VALUES_TEXT.equals(tagText) && !initialTagText.equals(tagText)) {
|
229 |
String[] tagset = tagText.split(","); |
230 |
for (String t : tagset) { |
231 |
JSONString to = new JSONString(t);
|
232 |
taga.set(i, to); |
233 |
i++; |
234 |
} |
235 |
json.put("tags", taga);
|
236 |
} |
237 |
String jsonString = json.toString();
|
238 |
if(jsonString.equals("{}")){ |
239 |
GWT.log("NO CHANGES", null); |
240 |
return;
|
241 |
} |
242 |
final List<String> fileIds = new ArrayList<String>(); |
243 |
for(FileResource f : files)
|
244 |
fileIds.add(f.getUri()+"?update=");
|
245 |
MultiplePostCommand rt = new MultiplePostCommand(fileIds.toArray(new String[0]), jsonString, 200){ |
246 |
|
247 |
@Override
|
248 |
public void onComplete() { |
249 |
GSS.get().getFileList().updateFileCache(true, false /* do not clear selected file*/); |
250 |
} |
251 |
|
252 |
@Override
|
253 |
public void onError(String p, Throwable t) { |
254 |
GWT.log("", t);
|
255 |
if(t instanceof RestException){ |
256 |
int statusCode = ((RestException)t).getHttpStatusCode();
|
257 |
if(statusCode == 405) |
258 |
GSS.get().displayError("You don't have the necessary permissions");
|
259 |
else if(statusCode == 404) |
260 |
GSS.get().displayError("File does not exist");
|
261 |
else if(statusCode == 409) |
262 |
GSS.get().displayError("A file with the same name already exists");
|
263 |
else if(statusCode == 413) |
264 |
GSS.get().displayError("Your quota has been exceeded");
|
265 |
else
|
266 |
GSS.get().displayError("Unable to modify file::"+((RestException)t).getHttpStatusText());
|
267 |
} |
268 |
else
|
269 |
GSS.get().displayError("System error modifying file:"+t.getMessage());
|
270 |
} |
271 |
}; |
272 |
DeferredCommand.addCommand(rt); |
273 |
} |
274 |
|
275 |
|
276 |
} |