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