Revision 50326f36 web_client/src/gr/grnet/pithos/web/client/commands/PropertiesCommand.java
b/web_client/src/gr/grnet/pithos/web/client/commands/PropertiesCommand.java | ||
---|---|---|
40 | 40 |
import gr.grnet.pithos.web.client.FolderPropertiesDialog; |
41 | 41 |
import gr.grnet.pithos.web.client.GSS; |
42 | 42 |
import gr.grnet.pithos.web.client.FileMenu.Images; |
43 |
import gr.grnet.pithos.web.client.foldertree.File; |
|
44 |
import gr.grnet.pithos.web.client.foldertree.Folder; |
|
43 | 45 |
import gr.grnet.pithos.web.client.rest.GetCommand; |
44 | 46 |
import gr.grnet.pithos.web.client.rest.HeadCommand; |
45 | 47 |
import gr.grnet.pithos.web.client.rest.MultipleGetCommand; |
... | ... | |
60 | 62 |
import com.google.gwt.user.client.DeferredCommand; |
61 | 63 |
import com.google.gwt.user.client.IncrementalCommand; |
62 | 64 |
import com.google.gwt.user.client.ui.PopupPanel; |
65 |
import org.w3c.css.sac.ElementSelector; |
|
63 | 66 |
|
64 | 67 |
/** |
65 | 68 |
* The command that displays the appropriate Properties dialog, according to the |
... | ... | |
80 | 83 |
|
81 | 84 |
private String userName; |
82 | 85 |
|
86 |
private Object resource; |
|
87 |
|
|
88 |
private GSS app; |
|
89 |
|
|
83 | 90 |
/** |
84 | 91 |
* @param _containerPanel |
85 | 92 |
* @param _newImages the images of all the possible delete dialogs |
86 | 93 |
* @param _tab the tab to switch to |
87 | 94 |
*/ |
88 |
public PropertiesCommand(PopupPanel _containerPanel, final FileMenu.Images _newImages, int _tab) {
|
|
95 |
public PropertiesCommand(GSS _app, PopupPanel _containerPanel, Object _resource, final FileMenu.Images _newImages, int _tab) {
|
|
89 | 96 |
containerPanel = _containerPanel; |
90 | 97 |
newImages = _newImages; |
91 | 98 |
tabToShow = _tab; |
99 |
resource = _resource; |
|
100 |
app = _app; |
|
92 | 101 |
} |
93 | 102 |
|
94 | 103 |
@Override |
95 | 104 |
public void execute() { |
96 |
containerPanel.hide(); |
|
97 |
if (GSS.get().getCurrentSelection() instanceof RestResourceWrapper) { |
|
98 |
GetCommand<FolderResource> eg = new GetCommand<FolderResource>(FolderResource.class, ((RestResourceWrapper) GSS.get().getCurrentSelection()).getUri(),((RestResourceWrapper) GSS.get().getCurrentSelection()).getResource()) { |
|
99 |
|
|
100 |
@Override |
|
101 |
public void onComplete() { |
|
102 |
((RestResourceWrapper) GSS.get().getCurrentSelection()).setResource(getResult()); |
|
103 |
initialize(); |
|
104 |
} |
|
105 |
|
|
106 |
@Override |
|
107 |
public void onError(Throwable t) { |
|
108 |
|
|
109 |
} |
|
110 |
|
|
111 |
}; |
|
112 |
DeferredCommand.addCommand(eg); |
|
113 |
} |
|
114 |
else if (GSS.get().getCurrentSelection() instanceof FileResource) { |
|
115 |
final String path = ((FileResource) GSS.get().getCurrentSelection()).getUri(); |
|
116 |
// Needed because firefox caches head requests. |
|
117 |
HeadCommand<FileResource> eg = new HeadCommand<FileResource>(FileResource.class, path+"?"+Math.random(), null ) { |
|
118 |
|
|
119 |
@Override |
|
120 |
public void onComplete() { |
|
121 |
FileResource res = getResult(); |
|
122 |
GSS.get().setCurrentSelection(res); |
|
123 |
initialize(); |
|
124 |
} |
|
125 |
|
|
126 |
@Override |
|
127 |
public void onError(Throwable t) { |
|
128 |
if(t instanceof RestException) |
|
129 |
GSS.get().displayError("Unable to retrieve file details:"+((RestException)t).getHttpStatusText()); |
|
130 |
} |
|
131 |
|
|
132 |
}; |
|
133 |
DeferredCommand.addCommand(eg); |
|
134 |
} |
|
135 |
else if (GSS.get().getCurrentSelection() instanceof List) { |
|
136 |
List<String> paths = new ArrayList<String>(); |
|
137 |
for (FileResource fr : (List<FileResource>) GSS.get().getCurrentSelection()) |
|
138 |
paths.add(fr.getUri()+"?"+Math.random()); |
|
139 |
Cached[] cached = new Cached[paths.size()]; |
|
140 |
int i=0; |
|
141 |
for (FileResource fr : (List<FileResource>) GSS.get().getCurrentSelection()){ |
|
142 |
Cached c = new Cached(); |
|
143 |
c.uri=fr.getUri()+"?"+Math.random(); |
|
144 |
c.cache=fr; |
|
145 |
cached[i]=c; |
|
146 |
i++; |
|
147 |
} |
|
148 |
MultipleHeadCommand<FileResource> gv = new MultipleHeadCommand<FileResource>(FileResource.class, paths.toArray(new String[] {}),cached) { |
|
149 |
|
|
150 |
@Override |
|
151 |
public void onComplete() { |
|
152 |
List<FileResource> res = getResult(); |
|
153 |
GSS.get().setCurrentSelection(res); |
|
154 |
FilesPropertiesDialog dlg = new FilesPropertiesDialog(res); |
|
155 |
dlg.selectTab(tabToShow); |
|
156 |
dlg.center(); |
|
157 |
} |
|
158 |
|
|
159 |
@Override |
|
160 |
public void onError(Throwable t) { |
|
161 |
GWT.log("", t); |
|
162 |
GSS.get().displayError("Unable to fetch files details"); |
|
163 |
} |
|
164 |
|
|
165 |
@Override |
|
166 |
public void onError(String p, Throwable throwable) { |
|
167 |
GWT.log("Path:" + p, throwable); |
|
168 |
} |
|
169 |
}; |
|
170 |
DeferredCommand.addCommand(gv); |
|
171 |
} |
|
172 |
} |
|
173 |
|
|
174 |
private void initialize(){ |
|
175 |
getGroups(); |
|
176 |
getVersions(); |
|
177 |
getOwnerFullName(); |
|
178 |
DeferredCommand.addCommand(new IncrementalCommand() { |
|
179 |
|
|
180 |
@Override |
|
181 |
public boolean execute() { |
|
182 |
boolean res = canContinue(); |
|
183 |
if (res) { |
|
184 |
displayProperties(newImages, GSS.get().findUserFullName(userName)); |
|
185 |
return false; |
|
186 |
} |
|
187 |
return true; |
|
188 |
} |
|
189 |
|
|
190 |
}); |
|
191 |
|
|
105 |
if (containerPanel != null) |
|
106 |
containerPanel.hide(); |
|
107 |
|
|
108 |
if (resource instanceof Folder) { |
|
109 |
Folder folder = (Folder) resource; |
|
110 |
FolderPropertiesDialog dlg = new FolderPropertiesDialog(app, false, folder); |
|
111 |
dlg.selectTab(tabToShow); |
|
112 |
dlg.center(); |
|
113 |
} |
|
114 |
else if (resource instanceof List) { |
|
115 |
List<File> files = (List<File>) resource; |
|
116 |
if (files.size() > 1) { |
|
117 |
// FilesPropertiesDialog dlg = new FilesPropertiesDialog(files); |
|
118 |
// dlg.selectTab(tabToShow); |
|
119 |
// dlg.center(); |
|
120 |
} |
|
121 |
else { |
|
122 |
FilePropertiesDialog dlg = new FilePropertiesDialog(app, files.get(0)); |
|
123 |
dlg.selectTab(tabToShow); |
|
124 |
dlg.center(); |
|
125 |
} |
|
126 |
} |
|
192 | 127 |
} |
193 |
|
|
194 |
private boolean canContinue() { |
|
195 |
String userFullNameFromMap = GSS.get().findUserFullName(userName); |
|
196 |
if(groups == null || versions == null || userFullNameFromMap == null) |
|
197 |
return false; |
|
198 |
return true; |
|
199 |
} |
|
200 |
|
|
201 |
/** |
|
202 |
* Display the appropriate Properties dialog, according to the selected |
|
203 |
* object in the application. |
|
204 |
* |
|
205 |
* @param propImages the images of all the possible properties dialogs |
|
206 |
*/ |
|
207 |
void displayProperties(final Images propImages, final String _userName) { |
|
208 |
if (GSS.get().getCurrentSelection() instanceof RestResourceWrapper) { |
|
209 |
// FolderPropertiesDialog dlg = new FolderPropertiesDialog(propImages, false, groups); |
|
210 |
// dlg.selectTab(tabToShow); |
|
211 |
// dlg.center(); |
|
212 |
} else if (GSS.get().getCurrentSelection() instanceof FileResource) { |
|
213 |
FilePropertiesDialog dlg = new FilePropertiesDialog(propImages, groups, versions, _userName); |
|
214 |
dlg.selectTab(tabToShow); |
|
215 |
dlg.center(); |
|
216 |
} |
|
217 |
} |
|
218 |
|
|
219 |
private void getGroups() { |
|
220 |
GetCommand<GroupsResource> gg = new GetCommand<GroupsResource>(GroupsResource.class, GSS.get().getCurrentUserResource().getGroupsPath(), null) { |
|
221 |
|
|
222 |
@Override |
|
223 |
public void onComplete() { |
|
224 |
GroupsResource res = getResult(); |
|
225 |
MultipleGetCommand<GroupResource> ga = new MultipleGetCommand<GroupResource>(GroupResource.class, res.getGroupPaths().toArray(new String[] {}), null) { |
|
226 |
|
|
227 |
@Override |
|
228 |
public void onComplete() { |
|
229 |
List<GroupResource> groupList = getResult(); |
|
230 |
groups = groupList; |
|
231 |
} |
|
232 |
|
|
233 |
@Override |
|
234 |
public void onError(Throwable t) { |
|
235 |
GWT.log("", t); |
|
236 |
GSS.get().displayError("Unable to fetch groups"); |
|
237 |
groups = new ArrayList<GroupResource>(); |
|
238 |
} |
|
239 |
|
|
240 |
@Override |
|
241 |
public void onError(String p, Throwable throwable) { |
|
242 |
GWT.log("Path:" + p, throwable); |
|
243 |
} |
|
244 |
}; |
|
245 |
DeferredCommand.addCommand(ga); |
|
246 |
} |
|
247 |
|
|
248 |
@Override |
|
249 |
public void onError(Throwable t) { |
|
250 |
GWT.log("", t); |
|
251 |
GSS.get().displayError("Unable to fetch groups"); |
|
252 |
groups = new ArrayList<GroupResource>(); |
|
253 |
} |
|
254 |
}; |
|
255 |
DeferredCommand.addCommand(gg); |
|
256 |
} |
|
257 |
|
|
258 |
private void getVersions() { |
|
259 |
if (GSS.get().getCurrentSelection() instanceof FileResource) { |
|
260 |
FileResource afile = (FileResource) GSS.get().getCurrentSelection(); |
|
261 |
GWT.log("File is versioned:" + afile.isVersioned(), null); |
|
262 |
if (afile.isVersioned()) { |
|
263 |
List<String> paths = new ArrayList<String>(); |
|
264 |
for (int i = 1; i <= afile.getVersion(); i++) |
|
265 |
paths.add(afile.getUri() + "?version=" + i); |
|
266 |
MultipleHeadCommand<FileResource> gv = new MultipleHeadCommand<FileResource>(FileResource.class, paths.toArray(new String[] {}), null) { |
|
267 |
|
|
268 |
@Override |
|
269 |
public void onComplete() { |
|
270 |
versions = getResult(); |
|
271 |
} |
|
272 |
|
|
273 |
@Override |
|
274 |
public void onError(Throwable t) { |
|
275 |
GWT.log("", t); |
|
276 |
GSS.get().displayError("Unable to fetch versions"); |
|
277 |
versions = new ArrayList<FileResource>(); |
|
278 |
} |
|
279 |
|
|
280 |
@Override |
|
281 |
public void onError(String p, Throwable throwable) { |
|
282 |
GWT.log("Path:" + p, throwable); |
|
283 |
} |
|
284 |
}; |
|
285 |
DeferredCommand.addCommand(gv); |
|
286 |
} else |
|
287 |
versions = new ArrayList<FileResource>(); |
|
288 |
} else |
|
289 |
versions = new ArrayList<FileResource>(); |
|
290 |
} |
|
291 |
|
|
292 |
private void getOwnerFullName() { |
|
293 |
if(GSS.get().getCurrentSelection() instanceof FileResource){ |
|
294 |
FileResource fileResource = (FileResource) GSS.get().getCurrentSelection(); |
|
295 |
userName = fileResource.getOwner(); |
|
296 |
if(GSS.get().findUserFullName(userName) == null){ |
|
297 |
GetUserCommand gu = new GetUserCommand(userName); |
|
298 |
gu.execute(); |
|
299 |
} |
|
300 |
}else{ |
|
301 |
FolderResource resource = ((RestResourceWrapper) GSS.get().getCurrentSelection()).getResource(); |
|
302 |
userName = resource.getOwner(); |
|
303 |
if(GSS.get().findUserFullName(userName) == null){ |
|
304 |
GetUserCommand gu = new GetUserCommand(userName); |
|
305 |
gu.execute(); |
|
306 |
} |
|
307 |
} |
|
308 |
} |
|
309 |
|
|
310 |
|
|
311 | 128 |
} |
Also available in: Unified diff