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