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