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