root / src / gr / ebs / gss / client / GSS.java @ c83883e3
History | View | Annotate | Download (25.3 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2007, 2008, 2009, 2010 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.clipboard.Clipboard; |
22 |
import gr.ebs.gss.client.commands.GetUserCommand; |
23 |
import gr.ebs.gss.client.rest.GetCommand; |
24 |
import gr.ebs.gss.client.rest.RestException; |
25 |
import gr.ebs.gss.client.rest.resource.FileResource; |
26 |
import gr.ebs.gss.client.rest.resource.FolderResource; |
27 |
import gr.ebs.gss.client.rest.resource.OtherUserResource; |
28 |
import gr.ebs.gss.client.rest.resource.OthersResource; |
29 |
import gr.ebs.gss.client.rest.resource.RestResource; |
30 |
import gr.ebs.gss.client.rest.resource.RestResourceWrapper; |
31 |
import gr.ebs.gss.client.rest.resource.TrashResource; |
32 |
import gr.ebs.gss.client.rest.resource.UserResource; |
33 |
|
34 |
import java.util.ArrayList; |
35 |
import java.util.Arrays; |
36 |
import java.util.Date; |
37 |
import java.util.HashMap; |
38 |
import java.util.List; |
39 |
|
40 |
import com.google.gwt.core.client.EntryPoint; |
41 |
import com.google.gwt.core.client.GWT; |
42 |
import com.google.gwt.event.logical.shared.ResizeEvent; |
43 |
import com.google.gwt.event.logical.shared.ResizeHandler; |
44 |
import com.google.gwt.event.logical.shared.SelectionEvent; |
45 |
import com.google.gwt.event.logical.shared.SelectionHandler; |
46 |
import com.google.gwt.event.logical.shared.ValueChangeEvent; |
47 |
import com.google.gwt.event.logical.shared.ValueChangeHandler; |
48 |
import com.google.gwt.i18n.client.DateTimeFormat; |
49 |
import com.google.gwt.resources.client.ClientBundle; |
50 |
import com.google.gwt.resources.client.ImageResource; |
51 |
import com.google.gwt.user.client.Command; |
52 |
import com.google.gwt.user.client.Cookies; |
53 |
import com.google.gwt.user.client.DOM; |
54 |
import com.google.gwt.user.client.DeferredCommand; |
55 |
import com.google.gwt.user.client.Event; |
56 |
import com.google.gwt.user.client.History; |
57 |
import com.google.gwt.user.client.Window; |
58 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
59 |
import com.google.gwt.user.client.ui.DecoratedTabPanel; |
60 |
import com.google.gwt.user.client.ui.DockPanel; |
61 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
62 |
import com.google.gwt.user.client.ui.HasVerticalAlignment; |
63 |
import com.google.gwt.user.client.ui.HorizontalSplitPanel; |
64 |
import com.google.gwt.user.client.ui.RootPanel; |
65 |
import com.google.gwt.user.client.ui.TabPanel; |
66 |
import com.google.gwt.user.client.ui.VerticalPanel; |
67 |
/**
|
68 |
* Entry point classes define <code>onModuleLoad()</code>.
|
69 |
*/
|
70 |
public class GSS implements EntryPoint, ResizeHandler { |
71 |
|
72 |
/**
|
73 |
* A constant that denotes the completion of an IncrementalCommand.
|
74 |
*/
|
75 |
public static final boolean DONE = false; |
76 |
|
77 |
public static final int VISIBLE_FILE_COUNT = 100; |
78 |
|
79 |
/**
|
80 |
* Instantiate an application-level image bundle. This object will provide
|
81 |
* programmatic access to all the images needed by widgets.
|
82 |
*/
|
83 |
private static Images images = (Images) GWT.create(Images.class); |
84 |
|
85 |
private GlassPanel glassPanel = new GlassPanel(); |
86 |
|
87 |
/**
|
88 |
* An aggregate image bundle that pulls together all the images for this
|
89 |
* application into a single bundle.
|
90 |
*/
|
91 |
public interface Images extends ClientBundle, TopPanel.Images, StatusPanel.Images, FileMenu.Images, EditMenu.Images, SettingsMenu.Images, GroupMenu.Images, FilePropertiesDialog.Images, MessagePanel.Images, FileList.Images, SearchResults.Images, Search.Images, Groups.Images, CellTreeView.Images { |
92 |
|
93 |
@Source("gr/ebs/gss/resources/document.png") |
94 |
ImageResource folders(); |
95 |
|
96 |
@Source("gr/ebs/gss/resources/edit_group_22.png") |
97 |
ImageResource groups(); |
98 |
|
99 |
@Source("gr/ebs/gss/resources/search.png") |
100 |
ImageResource search(); |
101 |
} |
102 |
|
103 |
/**
|
104 |
* The single GSS instance.
|
105 |
*/
|
106 |
private static GSS singleton; |
107 |
|
108 |
/**
|
109 |
* Gets the singleton GSS instance.
|
110 |
*
|
111 |
* @return the GSS object
|
112 |
*/
|
113 |
public static GSS get() { |
114 |
if (GSS.singleton == null) |
115 |
GSS.singleton = new GSS();
|
116 |
return GSS.singleton;
|
117 |
} |
118 |
|
119 |
/**
|
120 |
* The Application Clipboard implementation;
|
121 |
*/
|
122 |
private Clipboard clipboard = new Clipboard(); |
123 |
|
124 |
private UserResource currentUserResource;
|
125 |
|
126 |
/**
|
127 |
* The top panel that contains the menu bar.
|
128 |
*/
|
129 |
private TopPanel topPanel;
|
130 |
|
131 |
/**
|
132 |
* The panel that contains the various system messages.
|
133 |
*/
|
134 |
private MessagePanel messagePanel = new MessagePanel(GSS.images); |
135 |
|
136 |
/**
|
137 |
* The bottom panel that contains the status bar.
|
138 |
*/
|
139 |
private StatusPanel statusPanel = new StatusPanel(GSS.images); |
140 |
|
141 |
/**
|
142 |
* The top right panel that displays the logged in user details
|
143 |
*/
|
144 |
private UserDetailsPanel userDetailsPanel = new UserDetailsPanel(); |
145 |
|
146 |
/**
|
147 |
* The file list widget.
|
148 |
*/
|
149 |
private FileList fileList;
|
150 |
|
151 |
/**
|
152 |
* The group list widget.
|
153 |
*/
|
154 |
private Groups groups = new Groups(images); |
155 |
|
156 |
/**
|
157 |
* The search result widget.
|
158 |
*/
|
159 |
private SearchResults searchResults;
|
160 |
|
161 |
/**
|
162 |
* The tab panel that occupies the right side of the screen.
|
163 |
*/
|
164 |
private TabPanel inner = new DecoratedTabPanel(){ |
165 |
|
166 |
public void onBrowserEvent(com.google.gwt.user.client.Event event) { |
167 |
if (DOM.eventGetType(event) == Event.ONCONTEXTMENU){ |
168 |
if(isFileListShowing()){
|
169 |
getFileList().showContextMenu(event); |
170 |
} |
171 |
} |
172 |
}; |
173 |
}; |
174 |
|
175 |
/**
|
176 |
* The split panel that will contain the left and right panels.
|
177 |
*/
|
178 |
private HorizontalSplitPanel splitPanel = new HorizontalSplitPanel(); |
179 |
|
180 |
/**
|
181 |
* The horizontal panel that will contain the search and status panels.
|
182 |
*/
|
183 |
private DockPanel searchStatus = new DockPanel(); |
184 |
|
185 |
/**
|
186 |
* The search widget.
|
187 |
*/
|
188 |
private Search search;
|
189 |
|
190 |
/**
|
191 |
* The widget that displays the tree of folders.
|
192 |
*/
|
193 |
|
194 |
private CellTreeView treeView = new CellTreeView(images); |
195 |
/**
|
196 |
* The currently selected item in the application, for use by the Edit menu
|
197 |
* commands. Potential types are Folder, File, User and Group.
|
198 |
*/
|
199 |
private Object currentSelection; |
200 |
|
201 |
/**
|
202 |
* The authentication token of the current user.
|
203 |
*/
|
204 |
private String token; |
205 |
|
206 |
/**
|
207 |
* The WebDAV password of the current user
|
208 |
*/
|
209 |
private String webDAVPassword; |
210 |
|
211 |
|
212 |
|
213 |
public HashMap<String, String> userFullNameMap = new HashMap<String, String>(); |
214 |
|
215 |
@Override
|
216 |
public void onModuleLoad() { |
217 |
// Initialize the singleton before calling the constructors of the
|
218 |
// various widgets that might call GSS.get().
|
219 |
singleton = this;
|
220 |
RootPanel.get().add(glassPanel, 0, 0); |
221 |
parseUserCredentials(); |
222 |
|
223 |
topPanel = new TopPanel(GSS.images);
|
224 |
topPanel.setWidth("100%");
|
225 |
|
226 |
messagePanel.setWidth("100%");
|
227 |
messagePanel.setVisible(false);
|
228 |
|
229 |
search = new Search(images);
|
230 |
searchStatus.add(search, DockPanel.WEST); |
231 |
searchStatus.add(userDetailsPanel, DockPanel.EAST); |
232 |
searchStatus.setCellHorizontalAlignment(userDetailsPanel, HasHorizontalAlignment.ALIGN_RIGHT); |
233 |
searchStatus.setCellVerticalAlignment(search, HasVerticalAlignment.ALIGN_MIDDLE); |
234 |
searchStatus.setCellVerticalAlignment(userDetailsPanel, HasVerticalAlignment.ALIGN_MIDDLE); |
235 |
searchStatus.setWidth("100%");
|
236 |
|
237 |
fileList = new FileList(images);
|
238 |
|
239 |
searchResults = new SearchResults(images);
|
240 |
|
241 |
// Inner contains the various lists.
|
242 |
inner.sinkEvents(Event.ONCONTEXTMENU);
|
243 |
inner.setAnimationEnabled(true);
|
244 |
inner.getTabBar().addStyleName("gss-MainTabBar");
|
245 |
inner.getDeckPanel().addStyleName("gss-MainTabPanelBottom");
|
246 |
inner.add(fileList, createHeaderHTML(AbstractImagePrototype.create(images.folders()), "Files"), true); |
247 |
|
248 |
inner.add(groups, createHeaderHTML(AbstractImagePrototype.create(images.groups()), "Groups"), true); |
249 |
inner.add(searchResults, createHeaderHTML(AbstractImagePrototype.create(images.search()), "Search Results"), true); |
250 |
//inner.add(new CellTreeView(images), createHeaderHTML(AbstractImagePrototype.create(images.search()), "Cell tree sample"), true);
|
251 |
inner.setWidth("100%");
|
252 |
inner.selectTab(0);
|
253 |
|
254 |
inner.addSelectionHandler(new SelectionHandler<Integer>() { |
255 |
|
256 |
@Override
|
257 |
public void onSelection(SelectionEvent<Integer> event) { |
258 |
int tabIndex = event.getSelectedItem();
|
259 |
// TreeItem treeItem = GSS.get().getFolders().getCurrent();
|
260 |
switch (tabIndex) {
|
261 |
case 0: |
262 |
// Files tab selected
|
263 |
fileList.clearSelectedRows(); |
264 |
fileList.updateCurrentlyShowingStats(); |
265 |
break;
|
266 |
case 1: |
267 |
// Groups tab selected
|
268 |
groups.updateCurrentlyShowingStats(); |
269 |
updateHistory("Groups");
|
270 |
break;
|
271 |
case 2: |
272 |
// Search tab selected
|
273 |
searchResults.clearSelectedRows(); |
274 |
searchResults.updateCurrentlyShowingStats(); |
275 |
updateHistory("Search");
|
276 |
break;
|
277 |
} |
278 |
} |
279 |
}); |
280 |
// If the application starts with no history token, redirect to a new "Files" state
|
281 |
String initToken = History.getToken();
|
282 |
if(initToken.length() == 0) |
283 |
History.newItem("Files");
|
284 |
// Add history listener to handle any history events
|
285 |
History.addValueChangeHandler(new ValueChangeHandler<String>() { |
286 |
@Override
|
287 |
public void onValueChange(ValueChangeEvent<String> event) { |
288 |
String tokenInput = event.getValue();
|
289 |
String historyToken = handleSpecialFolderNames(tokenInput);
|
290 |
try {
|
291 |
if(historyToken.equals("Search")) |
292 |
inner.selectTab(2);
|
293 |
else if(historyToken.equals("Groups")) |
294 |
inner.selectTab(1);
|
295 |
else if(historyToken.equals("Files")|| historyToken.length()==0) |
296 |
inner.selectTab(0);
|
297 |
else {
|
298 |
/*TODO: CELLTREE
|
299 |
PopupTree popupTree = GSS.get().getFolders().getPopupTree();
|
300 |
TreeItem treeObj = GSS.get().getFolders().getPopupTree().getTreeItem(historyToken);
|
301 |
SelectionEvent.fire(popupTree, treeObj);
|
302 |
*/
|
303 |
} |
304 |
} catch (IndexOutOfBoundsException e) { |
305 |
inner.selectTab(0);
|
306 |
} |
307 |
} |
308 |
}); |
309 |
|
310 |
// Add the left and right panels to the split panel.
|
311 |
splitPanel.setLeftWidget(treeView); |
312 |
splitPanel.setRightWidget(inner); |
313 |
splitPanel.setSplitPosition("25%");
|
314 |
splitPanel.setSize("100%", "100%"); |
315 |
splitPanel.addStyleName("gss-splitPanel");
|
316 |
|
317 |
// Create a dock panel that will contain the menu bar at the top,
|
318 |
// the shortcuts to the left, the status bar at the bottom and the
|
319 |
// right panel taking the rest.
|
320 |
VerticalPanel outer = new VerticalPanel();
|
321 |
outer.add(topPanel); |
322 |
outer.add(searchStatus); |
323 |
outer.add(messagePanel); |
324 |
outer.add(splitPanel); |
325 |
outer.add(statusPanel); |
326 |
outer.setWidth("100%");
|
327 |
outer.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER); |
328 |
|
329 |
outer.setSpacing(4);
|
330 |
|
331 |
// Hook the window resize event, so that we can adjust the UI.
|
332 |
Window.addResizeHandler(this); |
333 |
// Clear out the window's built-in margin, because we want to take
|
334 |
// advantage of the entire client area.
|
335 |
Window.setMargin("0px"); |
336 |
// Finally, add the outer panel to the RootPanel, so that it will be
|
337 |
// displayed.
|
338 |
RootPanel.get().add(outer); |
339 |
// Call the window resized handler to get the initial sizes setup. Doing
|
340 |
// this in a deferred command causes it to occur after all widgets'
|
341 |
// sizes have been computed by the browser.
|
342 |
DeferredCommand.addCommand(new Command() {
|
343 |
|
344 |
@Override
|
345 |
public void execute() { |
346 |
onWindowResized(Window.getClientHeight());
|
347 |
} |
348 |
}); |
349 |
} |
350 |
|
351 |
/**
|
352 |
* Fetches the User object for the specified username.
|
353 |
*
|
354 |
* @param username the username of the user
|
355 |
*/
|
356 |
private void fetchUser(final String username) { |
357 |
String path = getApiPath() + username + "/"; |
358 |
GetCommand<UserResource> getUserCommand = new GetCommand<UserResource>(UserResource.class, username, path, null) { |
359 |
|
360 |
@Override
|
361 |
public void onComplete() { |
362 |
|
363 |
currentUserResource = getResult(); |
364 |
final String announcement = currentUserResource.getAnnouncement(); |
365 |
if (announcement != null) |
366 |
DeferredCommand.addCommand(new Command() {
|
367 |
|
368 |
@Override
|
369 |
public void execute() { |
370 |
displayInformation(announcement); |
371 |
} |
372 |
}); |
373 |
} |
374 |
|
375 |
@Override
|
376 |
public void onError(Throwable t) { |
377 |
GWT.log("Fetching user error", t);
|
378 |
if (t instanceof RestException) |
379 |
GSS.get().displayError("No user found:" + ((RestException) t).getHttpStatusText());
|
380 |
else
|
381 |
GSS.get().displayError("System error fetching user data:" + t.getMessage());
|
382 |
authenticateUser(); |
383 |
} |
384 |
}; |
385 |
DeferredCommand.addCommand(getUserCommand); |
386 |
} |
387 |
|
388 |
/**
|
389 |
* Parse and store the user credentials to the appropriate fields.
|
390 |
*/
|
391 |
private void parseUserCredentials() { |
392 |
Configuration conf = (Configuration) GWT.create(Configuration.class); |
393 |
String cookie = conf.authCookie();
|
394 |
String auth = Cookies.getCookie(cookie);
|
395 |
if (auth == null) { |
396 |
authenticateUser(); |
397 |
// Redundant, but silences warnings about possible auth NPE, below.
|
398 |
return;
|
399 |
} |
400 |
int sepIndex = auth.indexOf(conf.cookieSeparator());
|
401 |
if (sepIndex == -1) |
402 |
authenticateUser(); |
403 |
token = auth.substring(sepIndex + 1);
|
404 |
final String username = auth.substring(0, sepIndex); |
405 |
if (username == null) |
406 |
authenticateUser(); |
407 |
|
408 |
refreshWebDAVPassword(); |
409 |
|
410 |
DeferredCommand.addCommand(new Command() {
|
411 |
|
412 |
@Override
|
413 |
public void execute() { |
414 |
fetchUser(username); |
415 |
} |
416 |
}); |
417 |
} |
418 |
|
419 |
/**
|
420 |
* Redirect the user to the login page for authentication.
|
421 |
*/
|
422 |
protected void authenticateUser() { |
423 |
Configuration conf = (Configuration) GWT.create(Configuration.class); |
424 |
Window.Location.assign(conf.loginUrl() + "?next=" + GWT.getModuleBaseURL()); |
425 |
} |
426 |
|
427 |
/**
|
428 |
* Clear the cookie and redirect the user to the logout page.
|
429 |
*/
|
430 |
void logout() {
|
431 |
Configuration conf = (Configuration) GWT.create(Configuration.class); |
432 |
String cookie = conf.authCookie();
|
433 |
String domain = Window.Location.getHostName(); |
434 |
String path = Window.Location.getPath(); |
435 |
Cookies.setCookie(cookie, "", null, domain, path, false); |
436 |
Window.Location.assign(conf.logoutUrl());
|
437 |
} |
438 |
|
439 |
/**
|
440 |
* Creates an HTML fragment that places an image & caption together, for use
|
441 |
* in a group header.
|
442 |
*
|
443 |
* @param imageProto an image prototype for an image
|
444 |
* @param caption the group caption
|
445 |
* @return the header HTML fragment
|
446 |
*/
|
447 |
private String createHeaderHTML(AbstractImagePrototype imageProto, String caption) { |
448 |
String captionHTML = "<table class='caption' cellpadding='0' " |
449 |
+ "cellspacing='0'>" + "<tr><td class='lcaption'>" + imageProto.getHTML() |
450 |
+ "</td><td id =" + caption +" class='rcaption'><b style='white-space:nowrap'> " |
451 |
+ caption + "</b></td></tr></table>";
|
452 |
return captionHTML;
|
453 |
} |
454 |
|
455 |
private void onWindowResized(int height) { |
456 |
// Adjust the split panel to take up the available room in the window.
|
457 |
int newHeight = height - splitPanel.getAbsoluteTop() - 44; |
458 |
if (newHeight < 1) |
459 |
newHeight = 1;
|
460 |
splitPanel.setHeight("" + newHeight);
|
461 |
inner.setHeight("" + newHeight);
|
462 |
/*if(isFileListShowing()){
|
463 |
getFileList().setHeight("" + (newHeight-50));
|
464 |
}*/
|
465 |
} |
466 |
|
467 |
@Override
|
468 |
public void onResize(ResizeEvent event) { |
469 |
int height = event.getHeight();
|
470 |
onWindowResized(height); |
471 |
} |
472 |
|
473 |
public boolean isFileListShowing() { |
474 |
int tab = inner.getTabBar().getSelectedTab();
|
475 |
if (tab == 0) |
476 |
return true; |
477 |
return false; |
478 |
} |
479 |
|
480 |
public boolean isSearchResultsShowing() { |
481 |
int tab = inner.getTabBar().getSelectedTab();
|
482 |
if (tab == 2) |
483 |
return true; |
484 |
return false; |
485 |
} |
486 |
|
487 |
/**
|
488 |
* Make the user list visible.
|
489 |
*/
|
490 |
public void showUserList() { |
491 |
inner.selectTab(1);
|
492 |
} |
493 |
|
494 |
/**
|
495 |
* Make the file list visible.
|
496 |
*/
|
497 |
public void showFileList() { |
498 |
fileList.updateFileCache(false, true /*clear selection*/); |
499 |
inner.selectTab(0);
|
500 |
} |
501 |
|
502 |
/**
|
503 |
* Make the file list visible.
|
504 |
*
|
505 |
* @param update
|
506 |
*/
|
507 |
public void showFileList(boolean update) { |
508 |
/*TreeItem currentFolder = getFolders().getCurrent();
|
509 |
if (currentFolder != null) {
|
510 |
List<FileResource> files = null;
|
511 |
Object cachedObject = currentFolder.getUserObject();
|
512 |
if (cachedObject instanceof FolderResource) {
|
513 |
FolderResource folder = (FolderResource) cachedObject;
|
514 |
files = folder.getFiles();
|
515 |
} else if (cachedObject instanceof TrashResource) {
|
516 |
TrashResource folder = (TrashResource) cachedObject;
|
517 |
files = folder.getFiles();
|
518 |
}
|
519 |
if (files != null)
|
520 |
getFileList().setFiles(files);
|
521 |
}*/
|
522 |
RestResource currentFolder = getTreeView().getSelection(); |
523 |
GWT.log("SELECTED:"+currentFolder);
|
524 |
if(currentFolder!=null){ |
525 |
GWT.log("SELECTED:"+currentFolder.getClass());
|
526 |
List<FileResource> files = null; |
527 |
if (currentFolder instanceof RestResourceWrapper) { |
528 |
RestResourceWrapper folder = (RestResourceWrapper) currentFolder; |
529 |
files = folder.getResource().getFiles(); |
530 |
} else if (currentFolder instanceof TrashResource) { |
531 |
TrashResource folder = (TrashResource) currentFolder; |
532 |
files = folder.getFiles(); |
533 |
} |
534 |
else if(currentFolder instanceof OthersResource){ |
535 |
files = new ArrayList<FileResource>(); |
536 |
} |
537 |
else if(currentFolder instanceof OtherUserResource){ |
538 |
files = ((OtherUserResource)currentFolder).getFiles(); |
539 |
} |
540 |
if (files != null) |
541 |
getFileList().setFiles(files); |
542 |
} |
543 |
fileList.updateFileCache(update, true /*clear selection*/); |
544 |
inner.selectTab(0);
|
545 |
} |
546 |
|
547 |
public void showFileList(RestResource r,boolean update) { |
548 |
/*TreeItem currentFolder = getFolders().getCurrent();
|
549 |
if (currentFolder != null) {
|
550 |
List<FileResource> files = null;
|
551 |
Object cachedObject = currentFolder.getUserObject();
|
552 |
if (cachedObject instanceof FolderResource) {
|
553 |
FolderResource folder = (FolderResource) cachedObject;
|
554 |
files = folder.getFiles();
|
555 |
} else if (cachedObject instanceof TrashResource) {
|
556 |
TrashResource folder = (TrashResource) cachedObject;
|
557 |
files = folder.getFiles();
|
558 |
}
|
559 |
if (files != null)
|
560 |
getFileList().setFiles(files);
|
561 |
}*/
|
562 |
RestResource currentFolder = r; |
563 |
GWT.log("SELECTED:"+currentFolder);
|
564 |
if(currentFolder!=null){ |
565 |
List<FileResource> files = null; |
566 |
if (currentFolder instanceof RestResourceWrapper) { |
567 |
RestResourceWrapper folder = (RestResourceWrapper) currentFolder; |
568 |
files = folder.getResource().getFiles(); |
569 |
} else if (currentFolder instanceof TrashResource) { |
570 |
TrashResource folder = (TrashResource) currentFolder; |
571 |
files = folder.getFiles(); |
572 |
} |
573 |
else if (currentFolder instanceof OtherUserResource) { |
574 |
OtherUserResource folder = (OtherUserResource) currentFolder; |
575 |
files = folder.getFiles(); |
576 |
} |
577 |
if (files != null) |
578 |
getFileList().setFiles(files); |
579 |
} |
580 |
fileList.updateFileCache(update, true /*clear selection*/); |
581 |
inner.selectTab(0);
|
582 |
} |
583 |
|
584 |
/**
|
585 |
* Make the search results visible.
|
586 |
*
|
587 |
* @param query the search query string
|
588 |
*/
|
589 |
public void showSearchResults(String query) { |
590 |
searchResults.updateFileCache(query); |
591 |
searchResults.updateCurrentlyShowingStats(); |
592 |
inner.selectTab(2);
|
593 |
} |
594 |
|
595 |
/**
|
596 |
* Display the 'loading' indicator.
|
597 |
*/
|
598 |
public void showLoadingIndicator() { |
599 |
topPanel.getLoading().setVisible(true);
|
600 |
} |
601 |
|
602 |
/**
|
603 |
* Hide the 'loading' indicator.
|
604 |
*/
|
605 |
public void hideLoadingIndicator() { |
606 |
topPanel.getLoading().setVisible(false);
|
607 |
} |
608 |
|
609 |
/**
|
610 |
* A native JavaScript method to reach out to the browser's window and
|
611 |
* invoke its resizeTo() method.
|
612 |
*
|
613 |
* @param x the new width
|
614 |
* @param y the new height
|
615 |
*/
|
616 |
public static native void resizeTo(int x, int y) /*-{ |
617 |
$wnd.resizeTo(x,y);
|
618 |
}-*/;
|
619 |
|
620 |
/**
|
621 |
* A helper method that returns true if the user's list is currently visible
|
622 |
* and false if it is hidden.
|
623 |
*
|
624 |
* @return true if the user list is visible
|
625 |
*/
|
626 |
public boolean isUserListVisible() { |
627 |
return inner.getTabBar().getSelectedTab() == 1; |
628 |
} |
629 |
|
630 |
/**
|
631 |
* Display an error message.
|
632 |
*
|
633 |
* @param msg the message to display
|
634 |
*/
|
635 |
public void displayError(String msg) { |
636 |
messagePanel.displayError(msg); |
637 |
} |
638 |
|
639 |
/**
|
640 |
* Display a warning message.
|
641 |
*
|
642 |
* @param msg the message to display
|
643 |
*/
|
644 |
public void displayWarning(String msg) { |
645 |
messagePanel.displayWarning(msg); |
646 |
} |
647 |
|
648 |
/**
|
649 |
* Display an informational message.
|
650 |
*
|
651 |
* @param msg the message to display
|
652 |
*/
|
653 |
public void displayInformation(String msg) { |
654 |
messagePanel.displayInformation(msg); |
655 |
} |
656 |
|
657 |
/**
|
658 |
* Retrieve the folders.
|
659 |
*
|
660 |
* @return the folders
|
661 |
|
662 |
public Folders getFolders() {
|
663 |
return folders;
|
664 |
}*/
|
665 |
|
666 |
/**
|
667 |
* Retrieve the search.
|
668 |
*
|
669 |
* @return the search
|
670 |
*/
|
671 |
Search getSearch() { |
672 |
return search;
|
673 |
} |
674 |
|
675 |
/**
|
676 |
* Retrieve the currentSelection.
|
677 |
*
|
678 |
* @return the currentSelection
|
679 |
*/
|
680 |
public Object getCurrentSelection() { |
681 |
return currentSelection;
|
682 |
} |
683 |
|
684 |
/**
|
685 |
* Modify the currentSelection.
|
686 |
*
|
687 |
* @param newCurrentSelection the currentSelection to set
|
688 |
*/
|
689 |
public void setCurrentSelection(Object newCurrentSelection) { |
690 |
currentSelection = newCurrentSelection; |
691 |
} |
692 |
|
693 |
/**
|
694 |
* Retrieve the groups.
|
695 |
*
|
696 |
* @return the groups
|
697 |
*/
|
698 |
public Groups getGroups() {
|
699 |
return groups;
|
700 |
} |
701 |
|
702 |
/**
|
703 |
* Retrieve the fileList.
|
704 |
*
|
705 |
* @return the fileList
|
706 |
*/
|
707 |
public FileList getFileList() {
|
708 |
return fileList;
|
709 |
} |
710 |
|
711 |
public SearchResults getSearchResults() {
|
712 |
return searchResults;
|
713 |
} |
714 |
|
715 |
/**
|
716 |
* Retrieve the topPanel.
|
717 |
*
|
718 |
* @return the topPanel
|
719 |
*/
|
720 |
TopPanel getTopPanel() { |
721 |
return topPanel;
|
722 |
} |
723 |
|
724 |
/**
|
725 |
* Retrieve the clipboard.
|
726 |
*
|
727 |
* @return the clipboard
|
728 |
*/
|
729 |
public Clipboard getClipboard() { |
730 |
return clipboard;
|
731 |
} |
732 |
|
733 |
public StatusPanel getStatusPanel() {
|
734 |
return statusPanel;
|
735 |
} |
736 |
|
737 |
/**
|
738 |
* Retrieve the userDetailsPanel.
|
739 |
*
|
740 |
* @return the userDetailsPanel
|
741 |
*/
|
742 |
public UserDetailsPanel getUserDetailsPanel() {
|
743 |
return userDetailsPanel;
|
744 |
} |
745 |
|
746 |
|
747 |
|
748 |
public String getToken() { |
749 |
return token;
|
750 |
} |
751 |
|
752 |
public String getWebDAVPassword() { |
753 |
return webDAVPassword;
|
754 |
} |
755 |
|
756 |
public void removeGlassPanel() { |
757 |
glassPanel.removeFromParent(); |
758 |
} |
759 |
|
760 |
/**
|
761 |
* Retrieve the currentUserResource.
|
762 |
*
|
763 |
* @return the currentUserResource
|
764 |
*/
|
765 |
public UserResource getCurrentUserResource() {
|
766 |
return currentUserResource;
|
767 |
} |
768 |
|
769 |
/**
|
770 |
* Modify the currentUserResource.
|
771 |
*
|
772 |
* @param newUser the new currentUserResource
|
773 |
*/
|
774 |
public void setCurrentUserResource(UserResource newUser) { |
775 |
currentUserResource = newUser; |
776 |
} |
777 |
|
778 |
public static native void preventIESelection() /*-{ |
779 |
$doc.body.onselectstart = function () { return false; };
|
780 |
}-*/;
|
781 |
|
782 |
public static native void enableIESelection() /*-{ |
783 |
if ($doc.body.onselectstart != null)
|
784 |
$doc.body.onselectstart = null;
|
785 |
}-*/;
|
786 |
|
787 |
/**
|
788 |
* @return the absolute path of the API root URL
|
789 |
*/
|
790 |
public String getApiPath() { |
791 |
Configuration conf = (Configuration) GWT.create(Configuration.class); |
792 |
return GWT.getModuleBaseURL() + conf.apiPath();
|
793 |
} |
794 |
|
795 |
public void refreshWebDAVPassword() { |
796 |
Configuration conf = (Configuration) GWT.create(Configuration.class); |
797 |
String domain = Window.Location.getHostName(); |
798 |
String path = Window.Location.getPath(); |
799 |
String cookie = conf.webdavCookie();
|
800 |
webDAVPassword = Cookies.getCookie(cookie); |
801 |
Cookies.setCookie(cookie, "", null, domain, path, false); |
802 |
} |
803 |
|
804 |
/**
|
805 |
* Convert server date to local time according to browser timezone
|
806 |
* and format it according to localized pattern.
|
807 |
* Time is always formatted to 24hr format.
|
808 |
* NB: This assumes that server runs in UTC timezone. Otherwise
|
809 |
* we would need to adjust for server time offset as well.
|
810 |
*
|
811 |
* @param date
|
812 |
* @return String
|
813 |
*/
|
814 |
public static String formatLocalDateTime(Date date) { |
815 |
Date convertedDate = new Date(date.getTime() - date.getTimezoneOffset()); |
816 |
final DateTimeFormat dateFormatter = DateTimeFormat.getShortDateFormat();
|
817 |
final DateTimeFormat timeFormatter = DateTimeFormat.getFormat("HH:mm"); |
818 |
String datePart = dateFormatter.format(convertedDate);
|
819 |
String timePart = timeFormatter.format(convertedDate);
|
820 |
return datePart + " " + timePart; |
821 |
} |
822 |
|
823 |
/**
|
824 |
* History support for folder navigation
|
825 |
* adds a new browser history entry
|
826 |
*
|
827 |
* @param key
|
828 |
*/
|
829 |
public void updateHistory(String key){ |
830 |
// Replace any whitespace of the initial string to "+"
|
831 |
// String result = key.replaceAll("\\s","+");
|
832 |
// Add a new browser history entry.
|
833 |
// History.newItem(result);
|
834 |
History.newItem(key); |
835 |
} |
836 |
|
837 |
/**
|
838 |
* This method examines the token input and add a "/" at the end in case it's omitted.
|
839 |
* This happens only in Files/trash/, Files/shared/, Files/others.
|
840 |
*
|
841 |
* @param tokenInput
|
842 |
* @return the formated token with a "/" at the end or the same tokenInput parameter
|
843 |
*/
|
844 |
|
845 |
private String handleSpecialFolderNames(String tokenInput){ |
846 |
List<String> pathsToCheck = Arrays.asList("Files/trash", "Files/shared", "Files/others"); |
847 |
if(pathsToCheck.contains(tokenInput))
|
848 |
return tokenInput + "/"; |
849 |
return tokenInput;
|
850 |
|
851 |
} |
852 |
|
853 |
/**
|
854 |
* Reject illegal resource names, like '.' or '..' or slashes '/'.
|
855 |
*/
|
856 |
static boolean isValidResourceName(String name) { |
857 |
if (".".equals(name) || "..".equals(name) || name.contains("/")) |
858 |
return false; |
859 |
return true; |
860 |
} |
861 |
|
862 |
public void putUserToMap(String _userName, String _userFullName){ |
863 |
userFullNameMap.put(_userName, _userFullName); |
864 |
} |
865 |
|
866 |
public String findUserFullName(String _userName){ |
867 |
return userFullNameMap.get(_userName);
|
868 |
} |
869 |
public String getUserFullName(String _userName) { |
870 |
|
871 |
if (GSS.get().findUserFullName(_userName) == null) |
872 |
//if there is no userFullName found then the map fills with the given _userName,
|
873 |
//so userFullName = _userName
|
874 |
GSS.get().putUserToMap(_userName, _userName); |
875 |
else if(GSS.get().findUserFullName(_userName).indexOf('@') != -1){ |
876 |
//if the userFullName = _userName the GetUserCommand updates the userFullName in the map
|
877 |
GetUserCommand guc = new GetUserCommand(_userName);
|
878 |
guc.execute(); |
879 |
} |
880 |
return GSS.get().findUserFullName(_userName);
|
881 |
} |
882 |
/**
|
883 |
* Retrieve the treeView.
|
884 |
*
|
885 |
* @return the treeView
|
886 |
*/
|
887 |
public CellTreeView getTreeView() {
|
888 |
return treeView;
|
889 |
} |
890 |
|
891 |
public void onResourceUpdate(RestResource resource){ |
892 |
if(resource instanceof RestResourceWrapper || resource instanceof OtherUserResource){ |
893 |
if(getTreeView().getSelection()!=null&&getTreeView().getSelection().getUri().equals(resource.getUri())) |
894 |
showFileList(resource,true);
|
895 |
} |
896 |
|
897 |
} |
898 |
|
899 |
|
900 |
} |