root / web_client / src / gr / grnet / pithos / web / client / FileList.java @ 0bc032bf
History | View | Annotate | Download (26 kB)
1 |
/*
|
---|---|
2 |
* Copyright (c) 2011 Greek Research and Technology Network
|
3 |
*/
|
4 |
|
5 |
package gr.grnet.pithos.web.client; |
6 |
|
7 |
import static com.google.gwt.query.client.GQuery.$; |
8 |
|
9 |
import gr.grnet.pithos.web.client.commands.UploadFileCommand; |
10 |
import gr.grnet.pithos.web.client.foldertree.File; |
11 |
import gr.grnet.pithos.web.client.foldertree.Folder; |
12 |
import gr.grnet.pithos.web.client.foldertree.FolderTreeView; |
13 |
import gr.grnet.pithos.web.client.rest.GetCommand; |
14 |
import gr.grnet.pithos.web.client.rest.RestCommand; |
15 |
import gr.grnet.pithos.web.client.rest.resource.FileResource; |
16 |
import gr.grnet.pithos.web.client.rest.resource.OtherUserResource; |
17 |
import gr.grnet.pithos.web.client.rest.resource.OthersFolderResource; |
18 |
import gr.grnet.pithos.web.client.rest.resource.OthersResource; |
19 |
import gr.grnet.pithos.web.client.rest.resource.RestResource; |
20 |
import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper; |
21 |
import gr.grnet.pithos.web.client.rest.resource.SharedResource; |
22 |
import gr.grnet.pithos.web.client.rest.resource.TrashFolderResource; |
23 |
import gr.grnet.pithos.web.client.rest.resource.TrashResource; |
24 |
import gr.grnet.pithos.web.client.rest.resource.UserResource; |
25 |
import gwtquery.plugins.draggable.client.DraggableOptions; |
26 |
import gwtquery.plugins.draggable.client.StopDragException; |
27 |
import gwtquery.plugins.draggable.client.DraggableOptions.DragFunction; |
28 |
import gwtquery.plugins.draggable.client.DraggableOptions.RevertOption; |
29 |
import gwtquery.plugins.draggable.client.events.DragContext; |
30 |
import gwtquery.plugins.draggable.client.events.DragStartEvent; |
31 |
import gwtquery.plugins.draggable.client.events.DragStopEvent; |
32 |
import gwtquery.plugins.draggable.client.events.DragStartEvent.DragStartEventHandler; |
33 |
import gwtquery.plugins.draggable.client.events.DragStopEvent.DragStopEventHandler; |
34 |
import gwtquery.plugins.droppable.client.gwt.DragAndDropCellTable; |
35 |
import gwtquery.plugins.droppable.client.gwt.DragAndDropColumn; |
36 |
|
37 |
import java.util.ArrayList; |
38 |
import java.util.Collections; |
39 |
import java.util.Comparator; |
40 |
import java.util.Iterator; |
41 |
import java.util.List; |
42 |
|
43 |
import com.google.gwt.cell.client.AbstractCell; |
44 |
import com.google.gwt.cell.client.ImageResourceCell; |
45 |
import com.google.gwt.cell.client.SafeHtmlCell; |
46 |
import com.google.gwt.cell.client.TextCell; |
47 |
import com.google.gwt.cell.client.ValueUpdater; |
48 |
import com.google.gwt.core.client.GWT; |
49 |
import com.google.gwt.dom.client.Style.Cursor; |
50 |
import com.google.gwt.event.dom.client.ClickEvent; |
51 |
import com.google.gwt.event.dom.client.ClickHandler; |
52 |
import com.google.gwt.i18n.client.DateTimeFormat; |
53 |
import com.google.gwt.resources.client.ClientBundle; |
54 |
import com.google.gwt.resources.client.ImageResource; |
55 |
import com.google.gwt.safehtml.client.SafeHtmlTemplates; |
56 |
import com.google.gwt.safehtml.shared.SafeHtml; |
57 |
import com.google.gwt.safehtml.shared.SafeHtmlBuilder; |
58 |
import com.google.gwt.user.cellview.client.CellTable; |
59 |
import com.google.gwt.user.cellview.client.GssSimplePager; |
60 |
import com.google.gwt.user.client.DOM; |
61 |
import com.google.gwt.user.client.Event; |
62 |
import com.google.gwt.user.client.Window; |
63 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
64 |
import com.google.gwt.user.client.ui.Button; |
65 |
import com.google.gwt.user.client.ui.Composite; |
66 |
import com.google.gwt.user.client.ui.HorizontalPanel; |
67 |
import com.google.gwt.user.client.ui.VerticalPanel; |
68 |
import com.google.gwt.view.client.ListDataProvider; |
69 |
import com.google.gwt.view.client.MultiSelectionModel; |
70 |
import com.google.gwt.view.client.ProvidesKey; |
71 |
import com.google.gwt.view.client.SelectionChangeEvent; |
72 |
import com.google.gwt.view.client.SelectionChangeEvent.Handler; |
73 |
import java.util.Set; |
74 |
|
75 |
/**
|
76 |
* A composite that displays the list of files in a particular folder.
|
77 |
*/
|
78 |
public class FileList extends Composite { |
79 |
|
80 |
ListDataProvider<File> provider = new ListDataProvider<File>(); |
81 |
|
82 |
/**
|
83 |
* The styles applied to the table.
|
84 |
*/
|
85 |
interface TableStyle extends CellTable.Style { |
86 |
} |
87 |
|
88 |
interface TableResources extends DragAndDropCellTable.Resources { |
89 |
@Source({CellTable.Style.DEFAULT_CSS, "GssCellTable.css"}) |
90 |
TableStyle cellTableStyle(); |
91 |
} |
92 |
|
93 |
static interface Templates extends SafeHtmlTemplates { |
94 |
Templates INSTANCE = GWT.create(Templates.class); |
95 |
|
96 |
@Template("<div id='dragHelper' style='border:1px solid black; background-color:#ffffff; color:black; width:150px;z-index:100'></div>") |
97 |
SafeHtml outerHelper(); |
98 |
|
99 |
@Template("<span id='{0}'>{0}</span>") |
100 |
public SafeHtml filenameSpan(String filename); |
101 |
|
102 |
@Template("<a href='{0}' title='{1}' rel='lytebox[mnf]' onclick='myLytebox.start(this, false, false); return false;'>(view)</a>") |
103 |
public SafeHtml viewLink(String link, String title); |
104 |
|
105 |
@Template("<table><tr><td rowspan='3'>{0}</td><td style='font-size:95%;' id='{1}'>{1}</td></tr><tr><td>{2}</td></tr></table>") |
106 |
public SafeHtml rendelContactCell(String imageHtml, String name, String fileSize); |
107 |
|
108 |
@Template("<span id='{0}' class='{1}'>{2}</span>") |
109 |
public SafeHtml spanWithIdAndClass(String id, String cssClass, String content); |
110 |
} |
111 |
|
112 |
private String showingStats = ""; |
113 |
|
114 |
private int startIndex = 0; |
115 |
|
116 |
/**
|
117 |
* A constant that denotes the completion of an IncrementalCommand.
|
118 |
*/
|
119 |
public static final boolean DONE = false; |
120 |
|
121 |
private final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a"); |
122 |
|
123 |
/**
|
124 |
* Specifies that the images available for this composite will be the ones
|
125 |
* available in FileContextMenu.
|
126 |
*/
|
127 |
public interface Images extends ClientBundle,FileContextMenu.Images, CellTreeView.Images { |
128 |
|
129 |
@Source("gr/grnet/pithos/resources/blank.gif") |
130 |
ImageResource blank(); |
131 |
|
132 |
@Source("gr/grnet/pithos/resources/asc.png") |
133 |
ImageResource asc(); |
134 |
|
135 |
@Source("gr/grnet/pithos/resources/desc.png") |
136 |
ImageResource desc(); |
137 |
|
138 |
@Source("gr/grnet/pithos/resources/mimetypes/document_shared.png") |
139 |
ImageResource documentShared(); |
140 |
|
141 |
@Source("gr/grnet/pithos/resources/mimetypes/kcmfontinst.png") |
142 |
ImageResource wordprocessor(); |
143 |
|
144 |
@Source("gr/grnet/pithos/resources/mimetypes/log.png") |
145 |
ImageResource spreadsheet(); |
146 |
|
147 |
@Source("gr/grnet/pithos/resources/mimetypes/kpresenter_kpr.png") |
148 |
ImageResource presentation(); |
149 |
|
150 |
@Source("gr/grnet/pithos/resources/mimetypes/acroread.png") |
151 |
ImageResource pdf(); |
152 |
|
153 |
@Source("gr/grnet/pithos/resources/mimetypes/image.png") |
154 |
ImageResource image(); |
155 |
|
156 |
@Source("gr/grnet/pithos/resources/mimetypes/video2.png") |
157 |
ImageResource video(); |
158 |
|
159 |
@Source("gr/grnet/pithos/resources/mimetypes/knotify.png") |
160 |
ImageResource audio(); |
161 |
|
162 |
@Source("gr/grnet/pithos/resources/mimetypes/html.png") |
163 |
ImageResource html(); |
164 |
|
165 |
@Source("gr/grnet/pithos/resources/mimetypes/txt.png") |
166 |
ImageResource txt(); |
167 |
|
168 |
@Source("gr/grnet/pithos/resources/mimetypes/ark2.png") |
169 |
ImageResource zip(); |
170 |
|
171 |
@Source("gr/grnet/pithos/resources/mimetypes/kcmfontinst_shared.png") |
172 |
ImageResource wordprocessorShared(); |
173 |
|
174 |
@Source("gr/grnet/pithos/resources/mimetypes/log_shared.png") |
175 |
ImageResource spreadsheetShared(); |
176 |
|
177 |
@Source("gr/grnet/pithos/resources/mimetypes/kpresenter_kpr_shared.png") |
178 |
ImageResource presentationShared(); |
179 |
|
180 |
@Source("gr/grnet/pithos/resources/mimetypes/acroread_shared.png") |
181 |
ImageResource pdfShared(); |
182 |
|
183 |
@Source("gr/grnet/pithos/resources/mimetypes/image_shared.png") |
184 |
ImageResource imageShared(); |
185 |
|
186 |
@Source("gr/grnet/pithos/resources/mimetypes/video2_shared.png") |
187 |
ImageResource videoShared(); |
188 |
|
189 |
@Source("gr/grnet/pithos/resources/mimetypes/knotify_shared.png") |
190 |
ImageResource audioShared(); |
191 |
|
192 |
@Source("gr/grnet/pithos/resources/mimetypes/html_shared.png") |
193 |
ImageResource htmlShared(); |
194 |
|
195 |
@Source("gr/grnet/pithos/resources/mimetypes/txt_shared.png") |
196 |
ImageResource txtShared(); |
197 |
|
198 |
@Source("gr/grnet/pithos/resources/mimetypes/ark2_shared.png") |
199 |
ImageResource zipShared(); |
200 |
|
201 |
} |
202 |
|
203 |
/**
|
204 |
* The number of files in this folder.
|
205 |
*/
|
206 |
int folderFileCount;
|
207 |
|
208 |
/**
|
209 |
* Total folder size
|
210 |
*/
|
211 |
long folderTotalSize;
|
212 |
|
213 |
/**
|
214 |
* A cache of the files in the list.
|
215 |
*/
|
216 |
private List<File> files; |
217 |
|
218 |
/**
|
219 |
* The widget's image bundle.
|
220 |
*/
|
221 |
private final Images images; |
222 |
|
223 |
private FileContextMenu menuShowing;
|
224 |
|
225 |
private DragAndDropCellTable<File> celltable; |
226 |
|
227 |
private final MultiSelectionModel<File> selectionModel; |
228 |
|
229 |
private final List<SortableHeader> allHeaders = new ArrayList<SortableHeader>(); |
230 |
|
231 |
SortableHeader nameHeader; |
232 |
|
233 |
GssSimplePager pagerBottom; |
234 |
|
235 |
GssSimplePager pagerTop; |
236 |
|
237 |
Button uploadButtonBottom;
|
238 |
|
239 |
Button uploadButtonTop;
|
240 |
|
241 |
FolderTreeView treeView; |
242 |
|
243 |
/**
|
244 |
* Construct the file list widget. This entails setting up the widget
|
245 |
* layout, fetching the number of files in the current folder from the
|
246 |
* server and filling the local file cache of displayed files with data from
|
247 |
* the server, as well.
|
248 |
*
|
249 |
* @param _images
|
250 |
*/
|
251 |
public FileList(Images _images, FolderTreeView treeView) {
|
252 |
images = _images; |
253 |
this.treeView = treeView;
|
254 |
|
255 |
DragAndDropCellTable.Resources resources = GWT.create(TableResources.class); |
256 |
|
257 |
ProvidesKey<File> keyProvider = new ProvidesKey<File>(){ |
258 |
|
259 |
@Override
|
260 |
public Object getKey(File item) { |
261 |
return item.getUri();
|
262 |
} |
263 |
}; |
264 |
|
265 |
celltable = new DragAndDropCellTable<File>(GSS.VISIBLE_FILE_COUNT, resources, keyProvider); |
266 |
celltable.setWidth("100%");
|
267 |
celltable.setStyleName("pithos-List");
|
268 |
|
269 |
DragAndDropColumn<File, ImageResource> status = new DragAndDropColumn<File, ImageResource>(new ImageResourceCell() { |
270 |
@Override
|
271 |
public boolean handlesSelection() { |
272 |
return false; |
273 |
} |
274 |
}) |
275 |
{ |
276 |
@Override
|
277 |
public ImageResource getValue(File entity) { |
278 |
return getFileIcon(entity);
|
279 |
} |
280 |
}; |
281 |
celltable.addColumn(status,"");
|
282 |
initDragOperation(status); |
283 |
|
284 |
final DragAndDropColumn<File,SafeHtml> nameColumn = new DragAndDropColumn<File,SafeHtml>(new SafeHtmlCell()) { |
285 |
|
286 |
@Override
|
287 |
public SafeHtml getValue(File object) { |
288 |
SafeHtmlBuilder sb = new SafeHtmlBuilder();
|
289 |
sb.append(Templates.INSTANCE.filenameSpan(object.getName()));
|
290 |
if (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg")) { |
291 |
sb.appendHtmlConstant(" ")
|
292 |
.append(Templates.INSTANCE.viewLink(object.getUri(), object.getOwner() + " : " + object.getPath() + object.getName())); |
293 |
} |
294 |
|
295 |
return sb.toSafeHtml();
|
296 |
} |
297 |
|
298 |
}; |
299 |
initDragOperation(nameColumn); |
300 |
celltable.addColumn(nameColumn, nameHeader = new SortableHeader("Name")); |
301 |
allHeaders.add(nameHeader); |
302 |
nameHeader.setUpdater(new FileValueUpdater(nameHeader, "name")); |
303 |
|
304 |
celltable.redrawHeaders(); |
305 |
|
306 |
DragAndDropColumn<File,String> aColumn = new DragAndDropColumn<File, String>(new TextCell()) { |
307 |
@Override
|
308 |
public String getValue(File object) { |
309 |
return object.getOwner();
|
310 |
} |
311 |
}; |
312 |
SortableHeader aheader = new SortableHeader("Owner"); |
313 |
celltable.addColumn(aColumn, aheader); |
314 |
initDragOperation(aColumn); |
315 |
allHeaders.add(aheader); |
316 |
aheader.setUpdater(new FileValueUpdater(aheader, "owner")); |
317 |
|
318 |
aColumn = new DragAndDropColumn<File,String>(new TextCell()) { |
319 |
@Override
|
320 |
public String getValue(File object) { |
321 |
return object.getPath();
|
322 |
} |
323 |
}; |
324 |
aheader = new SortableHeader("Path"); |
325 |
celltable.addColumn(aColumn, aheader); |
326 |
initDragOperation(aColumn); |
327 |
allHeaders.add(aheader); |
328 |
aheader.setUpdater(new FileValueUpdater(aheader, "path")); |
329 |
|
330 |
aColumn = new DragAndDropColumn<File,String>(new TextCell()) { |
331 |
@Override
|
332 |
public String getValue(File object) { |
333 |
return String.valueOf(object.getVersion()); |
334 |
} |
335 |
}; |
336 |
aheader = new SortableHeader("Version"); |
337 |
celltable.addColumn(aColumn, aheader); |
338 |
initDragOperation(aColumn); |
339 |
allHeaders.add(aheader); |
340 |
aheader.setUpdater(new FileValueUpdater(aheader, "version")); |
341 |
|
342 |
aColumn = new DragAndDropColumn<File,String>(new TextCell()) { |
343 |
@Override
|
344 |
public String getValue(File object) { |
345 |
// TODO Auto-generated method stub
|
346 |
return object.getSizeAsString();
|
347 |
} |
348 |
}; |
349 |
aheader = new SortableHeader("Size"); |
350 |
celltable.addColumn(aColumn, aheader); |
351 |
initDragOperation(aColumn); |
352 |
allHeaders.add(aheader); |
353 |
aheader.setUpdater(new FileValueUpdater(aheader, "size")); |
354 |
|
355 |
aColumn = new DragAndDropColumn<File,String>(new TextCell()) { |
356 |
@Override
|
357 |
public String getValue(File object) { |
358 |
return formatter.format(object.getLastModified());
|
359 |
} |
360 |
}; |
361 |
aheader = new SortableHeader("Last Modified"); |
362 |
celltable.addColumn(aColumn, aheader); |
363 |
allHeaders.add(aheader); |
364 |
aheader.setUpdater(new FileValueUpdater(aheader, "date")); |
365 |
|
366 |
provider.addDataDisplay(celltable); |
367 |
|
368 |
celltable.addDragStopHandler(new DragStopEventHandler() {
|
369 |
|
370 |
@Override
|
371 |
public void onDragStop(DragStopEvent event) { |
372 |
GWT.log("DRAG STOPPED");
|
373 |
} |
374 |
}); |
375 |
celltable.addDragStartHandler(new DragStartEventHandler() {
|
376 |
|
377 |
public void onDragStart(DragStartEvent event) { |
378 |
FileResource value = event.getDraggableData(); |
379 |
|
380 |
com.google.gwt.dom.client.Element helper = event.getHelper(); |
381 |
SafeHtmlBuilder sb = new SafeHtmlBuilder();
|
382 |
sb.appendHtmlConstant("<b>");
|
383 |
DisplayHelper.log(value.getName()); |
384 |
if(getSelectedFiles().size()==1) |
385 |
sb.appendEscaped(value.getName()); |
386 |
else
|
387 |
sb.appendEscaped(getSelectedFiles().size()+" files");
|
388 |
sb.appendHtmlConstant("</b>");
|
389 |
helper.setInnerHTML(sb.toSafeHtml().asString()); |
390 |
} |
391 |
}); |
392 |
|
393 |
VerticalPanel vp = new VerticalPanel();
|
394 |
vp.setWidth("100%");
|
395 |
|
396 |
pagerTop = new GssSimplePager(GssSimplePager.TextLocation.CENTER);
|
397 |
pagerTop.setVisible(false);
|
398 |
pagerTop.setDisplay(celltable); |
399 |
uploadButtonTop = new Button("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>"); |
400 |
uploadButtonTop.addClickHandler(new ClickHandler() {
|
401 |
|
402 |
@Override
|
403 |
public void onClick(ClickEvent event) { |
404 |
new UploadFileCommand(null).execute(); |
405 |
} |
406 |
}); |
407 |
HorizontalPanel topPanel = new HorizontalPanel();
|
408 |
topPanel.add(pagerTop); |
409 |
topPanel.add(uploadButtonTop); |
410 |
vp.add(topPanel); |
411 |
|
412 |
vp.add(celltable); |
413 |
|
414 |
pagerBottom = new GssSimplePager(GssSimplePager.TextLocation.CENTER);
|
415 |
pagerBottom.setVisible(false);
|
416 |
pagerBottom.setDisplay(celltable); |
417 |
uploadButtonBottom=new Button("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>"); |
418 |
uploadButtonBottom.addClickHandler(new ClickHandler() {
|
419 |
|
420 |
@Override
|
421 |
public void onClick(ClickEvent event) { |
422 |
new UploadFileCommand(null).execute(); |
423 |
} |
424 |
}); |
425 |
HorizontalPanel bottomPanel = new HorizontalPanel();
|
426 |
bottomPanel.add(pagerBottom); |
427 |
bottomPanel.add(uploadButtonBottom); |
428 |
|
429 |
vp.add(bottomPanel); |
430 |
vp.setCellWidth(celltable, "100%");
|
431 |
initWidget(vp); |
432 |
|
433 |
selectionModel = new MultiSelectionModel<File>(keyProvider); |
434 |
|
435 |
Handler selectionHandler = new SelectionChangeEvent.Handler() { |
436 |
@Override
|
437 |
public void onSelectionChange(SelectionChangeEvent event) { |
438 |
if(getSelectedFiles().size() == 1) |
439 |
GSS.get().setCurrentSelection(getSelectedFiles().get(0));
|
440 |
else
|
441 |
GSS.get().setCurrentSelection(getSelectedFiles()); |
442 |
} |
443 |
}; |
444 |
selectionModel.addSelectionChangeHandler(selectionHandler); |
445 |
|
446 |
celltable.setSelectionModel(selectionModel, GSSSelectionEventManager.<File> createDefaultManager());
|
447 |
celltable.setPageSize(GSS.VISIBLE_FILE_COUNT); |
448 |
|
449 |
sinkEvents(Event.ONCONTEXTMENU);
|
450 |
sinkEvents(Event.ONMOUSEUP);
|
451 |
sinkEvents(Event.ONMOUSEDOWN);
|
452 |
sinkEvents(Event.ONCLICK);
|
453 |
sinkEvents(Event.ONKEYDOWN);
|
454 |
sinkEvents(Event.ONDBLCLICK);
|
455 |
GSS.preventIESelection(); |
456 |
} |
457 |
|
458 |
public List<File> getSelectedFiles() { |
459 |
return new ArrayList<File>(selectionModel.getSelectedSet()); |
460 |
} |
461 |
|
462 |
private void initDragOperation(DragAndDropColumn<?, ?> column) { |
463 |
// retrieve draggableOptions on the column
|
464 |
DraggableOptions draggableOptions = column.getDraggableOptions(); |
465 |
// use template to construct the helper. The content of the div will be set
|
466 |
// after
|
467 |
draggableOptions.setHelper($(Templates.INSTANCE.outerHelper().asString())); |
468 |
//draggableOptions.setZIndex(100);
|
469 |
// opacity of the helper
|
470 |
draggableOptions.setAppendTo("body");
|
471 |
//draggableOptions.setOpacity((float) 0.8);
|
472 |
draggableOptions.setContainment("document");
|
473 |
// cursor to use during the drag operation
|
474 |
draggableOptions.setCursor(Cursor.MOVE);
|
475 |
// set the revert option
|
476 |
draggableOptions.setRevert(RevertOption.ON_INVALID_DROP); |
477 |
// prevents dragging when user click on the category drop-down list
|
478 |
draggableOptions.setCancel("select");
|
479 |
draggableOptions.setOnBeforeDragStart(new DragFunction() {
|
480 |
@Override
|
481 |
public void f(DragContext context) { |
482 |
File value = context.getDraggableData();
|
483 |
if (!selectionModel.isSelected(value)) {
|
484 |
throw new StopDragException(); |
485 |
} |
486 |
} |
487 |
}); |
488 |
} |
489 |
|
490 |
public void showContextMenu(Event event){ |
491 |
menuShowing = new FileContextMenu(images, false, true); |
492 |
menuShowing=menuShowing.onEmptyEvent(event); |
493 |
} |
494 |
@Override
|
495 |
public void onBrowserEvent(Event event) { |
496 |
|
497 |
if (files == null || files.size() == 0) { |
498 |
if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) { |
499 |
menuShowing = new FileContextMenu(images, false, true); |
500 |
menuShowing=menuShowing.onEmptyEvent(event); |
501 |
event.preventDefault(); |
502 |
event.cancelBubble(true);
|
503 |
} |
504 |
return;
|
505 |
} |
506 |
if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() != 0) { |
507 |
GWT.log("*****GOING TO SHOW CONTEXT MENU ****", null); |
508 |
menuShowing = new FileContextMenu(images, false, false); |
509 |
menuShowing=menuShowing.onEvent(event); |
510 |
event.cancelBubble(true);
|
511 |
event.preventDefault(); |
512 |
} else if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) { |
513 |
menuShowing = new FileContextMenu(images, false, true); |
514 |
menuShowing=menuShowing.onEmptyEvent(event); |
515 |
event.cancelBubble(true);
|
516 |
event.preventDefault(); |
517 |
} else if (DOM.eventGetType(event) == Event.ONDBLCLICK) |
518 |
if (getSelectedFiles().size() == 1) { |
519 |
GSS app = GSS.get(); |
520 |
File file = getSelectedFiles().get(0); |
521 |
Window.open(file.getUri(), "_blank", ""); |
522 |
event.preventDefault(); |
523 |
return;
|
524 |
} |
525 |
super.onBrowserEvent(event);
|
526 |
} |
527 |
|
528 |
/**
|
529 |
* Update the display of the file list.
|
530 |
*/
|
531 |
void update(boolean sort) { |
532 |
int count = folderFileCount;
|
533 |
int max = startIndex + GSS.VISIBLE_FILE_COUNT;
|
534 |
if (max > count)
|
535 |
max = count; |
536 |
folderTotalSize = 0;
|
537 |
|
538 |
for(File f : files){ |
539 |
folderTotalSize += f.getBytes(); |
540 |
} |
541 |
if (folderFileCount == 0) { |
542 |
showingStats = "no files";
|
543 |
} else if (folderFileCount < GSS.VISIBLE_FILE_COUNT) { |
544 |
if (folderFileCount == 1) |
545 |
showingStats = "1 file";
|
546 |
else
|
547 |
showingStats = folderFileCount + " files";
|
548 |
showingStats += " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")"; |
549 |
} else {
|
550 |
showingStats = "" + (startIndex + 1) + " - " + max + " of " + count + " files" + " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")"; |
551 |
} |
552 |
showCellTable(); |
553 |
updateCurrentlyShowingStats(); |
554 |
|
555 |
} |
556 |
|
557 |
/**
|
558 |
* Return the proper icon based on the MIME type of the file.
|
559 |
*
|
560 |
* @param file
|
561 |
* @return the icon
|
562 |
*/
|
563 |
private ImageResource getFileIcon(File file) { |
564 |
String mimetype = file.getContentType();
|
565 |
boolean shared = file.isShared();
|
566 |
if (mimetype == null) |
567 |
return shared ? images.documentShared() : images.document();
|
568 |
mimetype = mimetype.toLowerCase(); |
569 |
if (mimetype.startsWith("application/pdf")) |
570 |
return shared ? images.pdfShared() : images.pdf();
|
571 |
else if (mimetype.endsWith("excel")) |
572 |
return shared ? images.spreadsheetShared() : images.spreadsheet();
|
573 |
else if (mimetype.endsWith("msword")) |
574 |
return shared ? images.wordprocessorShared() : images.wordprocessor();
|
575 |
else if (mimetype.endsWith("powerpoint")) |
576 |
return shared ? images.presentationShared() : images.presentation();
|
577 |
else if (mimetype.startsWith("application/zip") || |
578 |
mimetype.startsWith("application/gzip") ||
|
579 |
mimetype.startsWith("application/x-gzip") ||
|
580 |
mimetype.startsWith("application/x-tar") ||
|
581 |
mimetype.startsWith("application/x-gtar"))
|
582 |
return shared ? images.zipShared() : images.zip();
|
583 |
else if (mimetype.startsWith("text/html")) |
584 |
return shared ? images.htmlShared() : images.html();
|
585 |
else if (mimetype.startsWith("text/plain")) |
586 |
return shared ? images.txtShared() : images.txt();
|
587 |
else if (mimetype.startsWith("image/")) |
588 |
return shared ? images.imageShared() : images.image();
|
589 |
else if (mimetype.startsWith("video/")) |
590 |
return shared ? images.videoShared() : images.video();
|
591 |
else if (mimetype.startsWith("audio/")) |
592 |
return shared ? images.audioShared() : images.audio();
|
593 |
return shared ? images.documentShared() : images.document();
|
594 |
} |
595 |
|
596 |
/**
|
597 |
* Update status panel with currently showing file stats.
|
598 |
*/
|
599 |
public void updateCurrentlyShowingStats() { |
600 |
GSS.get().getStatusPanel().updateCurrentlyShowing(showingStats); |
601 |
} |
602 |
|
603 |
/**
|
604 |
* Fill the file cache with data.
|
605 |
*/
|
606 |
public void setFiles(final List<File> _files) { |
607 |
files = new ArrayList<File>(); |
608 |
for (File fres : _files) |
609 |
if (!fres.isInTrash())
|
610 |
files.add(fres); |
611 |
Collections.sort(files, new Comparator<File>() { |
612 |
|
613 |
@Override
|
614 |
public int compare(File arg0, File arg1) { |
615 |
return arg0.getName().compareTo(arg1.getName());
|
616 |
} |
617 |
|
618 |
}); |
619 |
folderFileCount = files.size(); |
620 |
|
621 |
nameHeader.setSorted(true);
|
622 |
nameHeader.toggleReverseSort(); |
623 |
for (SortableHeader otherHeader : allHeaders) {
|
624 |
if (otherHeader != nameHeader) {
|
625 |
otherHeader.setSorted(false);
|
626 |
otherHeader.setReverseSort(true);
|
627 |
} |
628 |
} |
629 |
|
630 |
if(files.size() > GSS.VISIBLE_FILE_COUNT){
|
631 |
pagerBottom.setVisible(true);
|
632 |
pagerTop.setVisible(true);
|
633 |
} |
634 |
else{
|
635 |
pagerTop.setVisible(false);
|
636 |
pagerBottom.setVisible(false);
|
637 |
} |
638 |
Folder selectedItem = treeView.getSelection(); |
639 |
|
640 |
provider.setList(files); |
641 |
} |
642 |
|
643 |
/**
|
644 |
* Does the list contains the requested filename
|
645 |
*
|
646 |
* @param fileName
|
647 |
* @return true/false
|
648 |
*/
|
649 |
public boolean contains(String fileName) { |
650 |
for (int i = 0; i < files.size(); i++) |
651 |
if (files.get(i).getName().equals(fileName))
|
652 |
return true; |
653 |
return false; |
654 |
} |
655 |
|
656 |
public void clearSelectedRows() { |
657 |
Iterator<File> it = selectionModel.getSelectedSet().iterator(); |
658 |
while(it.hasNext()){
|
659 |
selectionModel.setSelected(it.next(),false);
|
660 |
} |
661 |
} |
662 |
|
663 |
|
664 |
/**
|
665 |
*
|
666 |
*/
|
667 |
public void selectAllRows() { |
668 |
Iterator<File> it = provider.getList().iterator(); |
669 |
while(it.hasNext()){
|
670 |
selectionModel.setSelected(it.next(),true);
|
671 |
} |
672 |
|
673 |
|
674 |
} |
675 |
|
676 |
|
677 |
private void sortFiles(final String sortingProperty, final boolean sortingType){ |
678 |
Collections.sort(files, new Comparator<File>() { |
679 |
|
680 |
@Override
|
681 |
public int compare(File arg0, File arg1) { |
682 |
AbstractImagePrototype descPrototype = AbstractImagePrototype.create(images.desc()); |
683 |
AbstractImagePrototype ascPrototype = AbstractImagePrototype.create(images.asc()); |
684 |
if (sortingType){
|
685 |
if (sortingProperty.equals("version")) { |
686 |
return arg0.getVersion() - arg1.getVersion();
|
687 |
} else if (sortingProperty.equals("owner")) { |
688 |
return arg0.getOwner().compareTo(arg1.getOwner());
|
689 |
} else if (sortingProperty.equals("date")) { |
690 |
return arg0.getLastModified().compareTo(arg1.getLastModified());
|
691 |
} else if (sortingProperty.equals("size")) { |
692 |
return (int) (arg0.getBytes() - arg1.getBytes()); |
693 |
} else if (sortingProperty.equals("name")) { |
694 |
return arg0.getName().compareTo(arg1.getName());
|
695 |
} else if (sortingProperty.equals("path")) { |
696 |
return arg0.getUri().compareTo(arg1.getUri());
|
697 |
} else {
|
698 |
return arg0.getName().compareTo(arg1.getName());
|
699 |
} |
700 |
} |
701 |
else if (sortingProperty.equals("version")) { |
702 |
|
703 |
return arg1.getVersion() - arg0.getVersion();
|
704 |
} else if (sortingProperty.equals("owner")) { |
705 |
|
706 |
return arg1.getOwner().compareTo(arg0.getOwner());
|
707 |
} else if (sortingProperty.equals("date")) { |
708 |
|
709 |
return arg1.getLastModified().compareTo(arg0.getLastModified());
|
710 |
} else if (sortingProperty.equals("size")) { |
711 |
return (int) (arg1.getBytes() - arg0.getBytes()); |
712 |
} else if (sortingProperty.equals("name")) { |
713 |
|
714 |
return arg1.getName().compareTo(arg0.getName());
|
715 |
} else if (sortingProperty.equals("path")) { |
716 |
|
717 |
return arg1.getUri().compareTo(arg0.getUri());
|
718 |
} else {
|
719 |
|
720 |
return arg1.getName().compareTo(arg0.getName());
|
721 |
} |
722 |
} |
723 |
|
724 |
}); |
725 |
} |
726 |
|
727 |
final class FileValueUpdater implements ValueUpdater<String>{ |
728 |
private String property; |
729 |
private SortableHeader header;
|
730 |
/**
|
731 |
*
|
732 |
*/
|
733 |
public FileValueUpdater(SortableHeader header,String property) { |
734 |
this.property=property;
|
735 |
this.header=header;
|
736 |
} |
737 |
@Override
|
738 |
public void update(String value) { |
739 |
header.setSorted(true);
|
740 |
header.toggleReverseSort(); |
741 |
|
742 |
for (SortableHeader otherHeader : allHeaders) {
|
743 |
if (otherHeader != header) {
|
744 |
otherHeader.setSorted(false);
|
745 |
otherHeader.setReverseSort(true);
|
746 |
} |
747 |
} |
748 |
celltable.redrawHeaders(); |
749 |
sortFiles(property, header.getReverseSort()); |
750 |
FileList.this.update(true);
|
751 |
} |
752 |
|
753 |
} |
754 |
|
755 |
/**
|
756 |
* Shows the files in the cellTable
|
757 |
*/
|
758 |
private void showCellTable(){ |
759 |
if(files.size()>GSS.VISIBLE_FILE_COUNT){
|
760 |
pagerBottom.setVisible(true);
|
761 |
pagerTop.setVisible(true);
|
762 |
} |
763 |
else{
|
764 |
pagerTop.setVisible(false);
|
765 |
pagerBottom.setVisible(false);
|
766 |
} |
767 |
provider.setList(files); |
768 |
|
769 |
provider.refresh(); |
770 |
|
771 |
//celltable.redraw();
|
772 |
celltable.redrawHeaders(); |
773 |
} |
774 |
} |