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