root / src / gr / ebs / gss / client / SearchResults.java @ fa556159
History | View | Annotate | Download (23.4 kB)
1 | 14ad7326 | pastith | /*
|
---|---|---|---|
2 | 14ad7326 | pastith | * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
|
3 | 14ad7326 | pastith | *
|
4 | 14ad7326 | pastith | * This file is part of GSS.
|
5 | 14ad7326 | pastith | *
|
6 | 14ad7326 | pastith | * GSS is free software: you can redistribute it and/or modify
|
7 | 14ad7326 | pastith | * it under the terms of the GNU General Public License as published by
|
8 | 14ad7326 | pastith | * the Free Software Foundation, either version 3 of the License, or
|
9 | 14ad7326 | pastith | * (at your option) any later version.
|
10 | 14ad7326 | pastith | *
|
11 | 14ad7326 | pastith | * GSS is distributed in the hope that it will be useful,
|
12 | 14ad7326 | pastith | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 14ad7326 | pastith | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 14ad7326 | pastith | * GNU General Public License for more details.
|
15 | 14ad7326 | pastith | *
|
16 | 14ad7326 | pastith | * You should have received a copy of the GNU General Public License
|
17 | 14ad7326 | pastith | * along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 | 14ad7326 | pastith | */
|
19 | 14ad7326 | pastith | package gr.ebs.gss.client; |
20 | 14ad7326 | pastith | |
21 | 14ad7326 | pastith | import gr.ebs.gss.client.dnd.DnDFocusPanel; |
22 | 895035a2 | pastith | import gr.ebs.gss.client.rest.GetCommand; |
23 | bbad17b4 | pastith | import gr.ebs.gss.client.rest.RestCommand; |
24 | e08c358f | koutsoub | import gr.ebs.gss.client.rest.RestException; |
25 | a52ea5e4 | pastith | import gr.ebs.gss.client.rest.resource.FileResource; |
26 | a52ea5e4 | pastith | import gr.ebs.gss.client.rest.resource.SearchResource; |
27 | a52ea5e4 | pastith | import gr.ebs.gss.client.rest.resource.UserResource; |
28 | 14ad7326 | pastith | |
29 | 14ad7326 | pastith | import java.util.ArrayList; |
30 | 14ad7326 | pastith | import java.util.Collections; |
31 | 14ad7326 | pastith | import java.util.Comparator; |
32 | 14ad7326 | pastith | import java.util.List; |
33 | 14ad7326 | pastith | |
34 | 14ad7326 | pastith | import com.google.gwt.core.client.GWT; |
35 | a52ea5e4 | pastith | import com.google.gwt.http.client.URL; |
36 | 14ad7326 | pastith | import com.google.gwt.i18n.client.DateTimeFormat; |
37 | 14ad7326 | pastith | import com.google.gwt.user.client.DOM; |
38 | 14ad7326 | pastith | import com.google.gwt.user.client.DeferredCommand; |
39 | 14ad7326 | pastith | import com.google.gwt.user.client.Event; |
40 | 14ad7326 | pastith | import com.google.gwt.user.client.IncrementalCommand; |
41 | eaf8a7cb | koutsoub | import com.google.gwt.user.client.Window; |
42 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
43 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.ClickListener; |
44 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.Composite; |
45 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.Grid; |
46 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.HTML; |
47 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
48 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.HorizontalPanel; |
49 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.SourcesTableEvents; |
50 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.TableListener; |
51 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.VerticalPanel; |
52 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.Widget; |
53 | 14ad7326 | pastith | |
54 | 14ad7326 | pastith | /**
|
55 | 14ad7326 | pastith | * A composite that displays a list of search results for a particular query on
|
56 | 14ad7326 | pastith | * files.
|
57 | 14ad7326 | pastith | */
|
58 | 14ad7326 | pastith | public class SearchResults extends Composite implements TableListener, ClickListener { |
59 | 14ad7326 | pastith | |
60 | 14ad7326 | pastith | private HTML prevButton = new HTML("<a href='javascript:;'>< Previous</a>", true); |
61 | 14ad7326 | pastith | |
62 | 14ad7326 | pastith | private HTML nextButton = new HTML("<a href='javascript:;'>Next ></a>", true); |
63 | 14ad7326 | pastith | |
64 | b3c6d52e | fstamatelopoulos | private String showingStats = ""; |
65 | b3c6d52e | fstamatelopoulos | |
66 | 14ad7326 | pastith | private int startIndex = 0; |
67 | 14ad7326 | pastith | |
68 | 14ad7326 | pastith | /**
|
69 | 14ad7326 | pastith | * A constant that denotes the completion of an IncrementalCommand.
|
70 | 14ad7326 | pastith | */
|
71 | 14ad7326 | pastith | public static final boolean DONE = false; |
72 | 14ad7326 | pastith | |
73 | 14ad7326 | pastith | private boolean clickControl = false; |
74 | 14ad7326 | pastith | |
75 | 14ad7326 | pastith | private boolean clickShift = false; |
76 | 14ad7326 | pastith | |
77 | 14ad7326 | pastith | private int firstShift = -1; |
78 | 14ad7326 | pastith | |
79 | 14ad7326 | pastith | private ArrayList<Integer> selectedRows = new ArrayList<Integer>(); |
80 | 14ad7326 | pastith | |
81 | 14ad7326 | pastith | /**
|
82 | 14ad7326 | pastith | * The context menu for the selected file.
|
83 | 14ad7326 | pastith | */
|
84 | 14ad7326 | pastith | final DnDFocusPanel contextMenu;
|
85 | 14ad7326 | pastith | |
86 | 14ad7326 | pastith | /**
|
87 | 14ad7326 | pastith | * Specifies that the images available for this composite will be the ones
|
88 | 14ad7326 | pastith | * available in FileContextMenu.
|
89 | 14ad7326 | pastith | */
|
90 | 14ad7326 | pastith | public interface Images extends FileContextMenu.Images, Folders.Images { |
91 | 14ad7326 | pastith | |
92 | 14ad7326 | pastith | @Resource("gr/ebs/gss/resources/blank.gif") |
93 | 14ad7326 | pastith | AbstractImagePrototype blank(); |
94 | 14ad7326 | pastith | |
95 | 14ad7326 | pastith | @Resource("gr/ebs/gss/resources/asc.png") |
96 | 14ad7326 | pastith | AbstractImagePrototype asc(); |
97 | 14ad7326 | pastith | |
98 | 14ad7326 | pastith | @Resource("gr/ebs/gss/resources/desc.png") |
99 | 14ad7326 | pastith | AbstractImagePrototype desc(); |
100 | 14ad7326 | pastith | } |
101 | 14ad7326 | pastith | |
102 | 14ad7326 | pastith | /**
|
103 | 14ad7326 | pastith | * A label with the number of files in this folder.
|
104 | 14ad7326 | pastith | */
|
105 | 14ad7326 | pastith | private HTML countLabel = new HTML(); |
106 | 14ad7326 | pastith | |
107 | 14ad7326 | pastith | /**
|
108 | 14ad7326 | pastith | * The table widget with the file list.
|
109 | 14ad7326 | pastith | */
|
110 | 780606ca | pastith | private Grid table;
|
111 | 14ad7326 | pastith | |
112 | 14ad7326 | pastith | /**
|
113 | 14ad7326 | pastith | * The navigation bar for paginating the results.
|
114 | 14ad7326 | pastith | */
|
115 | 14ad7326 | pastith | private HorizontalPanel navBar = new HorizontalPanel(); |
116 | 14ad7326 | pastith | |
117 | 14ad7326 | pastith | /**
|
118 | 4b29a3ca | fstamatelopoulos | * The number of files in the search results
|
119 | 14ad7326 | pastith | */
|
120 | 780606ca | pastith | private int folderFileCount; |
121 | 14ad7326 | pastith | |
122 | 14ad7326 | pastith | /**
|
123 | 4b29a3ca | fstamatelopoulos | * Total search results size
|
124 | 4b29a3ca | fstamatelopoulos | */
|
125 | 780606ca | pastith | private long folderTotalSize; |
126 | 4b29a3ca | fstamatelopoulos | |
127 | 4b29a3ca | fstamatelopoulos | /**
|
128 | 14ad7326 | pastith | * A cache of the files in the list.
|
129 | 14ad7326 | pastith | */
|
130 | a52ea5e4 | pastith | private List<FileResource> files; |
131 | 14ad7326 | pastith | |
132 | 14ad7326 | pastith | /**
|
133 | 14ad7326 | pastith | * The widget's image bundle.
|
134 | 14ad7326 | pastith | */
|
135 | 14ad7326 | pastith | private final Images images; |
136 | 14ad7326 | pastith | |
137 | 14ad7326 | pastith | private String sortingProperty = "name"; |
138 | 14ad7326 | pastith | |
139 | 14ad7326 | pastith | private boolean sortingType = true; |
140 | 14ad7326 | pastith | |
141 | 14ad7326 | pastith | private HTML nameLabel; |
142 | 14ad7326 | pastith | |
143 | 14ad7326 | pastith | private HTML versionLabel; |
144 | 14ad7326 | pastith | |
145 | 14ad7326 | pastith | private HTML sizeLabel; |
146 | 14ad7326 | pastith | |
147 | 14ad7326 | pastith | private HTML dateLabel; |
148 | 14ad7326 | pastith | |
149 | 14ad7326 | pastith | private HTML ownerLabel; |
150 | 14ad7326 | pastith | |
151 | 14ad7326 | pastith | private HTML pathLabel; |
152 | 14ad7326 | pastith | |
153 | 14ad7326 | pastith | private HTML searchResults = new HTML("Results for search:"); |
154 | 14ad7326 | pastith | |
155 | 14ad7326 | pastith | /**
|
156 | 14ad7326 | pastith | * Construct the file list widget. This entails setting up the widget
|
157 | 14ad7326 | pastith | * layout, fetching the number of files in the current folder from the
|
158 | 14ad7326 | pastith | * server and filling the local file cache of displayed files with data from
|
159 | 14ad7326 | pastith | * the server, as well.
|
160 | 14ad7326 | pastith | *
|
161 | 14ad7326 | pastith | * @param _images
|
162 | 14ad7326 | pastith | */
|
163 | 14ad7326 | pastith | public SearchResults(final Images _images) { |
164 | 14ad7326 | pastith | images = _images; |
165 | bbad17b4 | pastith | final GSS app = GSS.get();
|
166 | bbad17b4 | pastith | table = new Grid(GSS.VISIBLE_FILE_COUNT + 1, 8) { |
167 | 780606ca | pastith | |
168 | 780606ca | pastith | @Override
|
169 | 14ad7326 | pastith | public void onBrowserEvent(Event event) { |
170 | 14ad7326 | pastith | if (files == null || files.size() == 0) |
171 | 14ad7326 | pastith | return;
|
172 | 14ad7326 | pastith | if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && selectedRows.size() != 0) { |
173 | b4b188fe | koutsoub | FileContextMenu fm = new FileContextMenu(images, false, false); |
174 | 14ad7326 | pastith | fm.onClick(contextMenu); |
175 | 14ad7326 | pastith | } |
176 | eaf8a7cb | koutsoub | else if (DOM.eventGetType(event) == Event.ONDBLCLICK) |
177 | eaf8a7cb | koutsoub | if(getSelectedFiles().size() == 1){ |
178 | eaf8a7cb | koutsoub | FileResource file = getSelectedFiles().get(0);
|
179 | 895035a2 | pastith | String dateString = RestCommand.getDate();
|
180 | bbad17b4 | pastith | String resource = file.getUri().substring(app.getApiPath().length()-1,file.getUri().length()); |
181 | bbad17b4 | pastith | String sig = app.getCurrentUserResource().getUsername()+" "+RestCommand.calculateSig("GET", dateString, resource, RestCommand.base64decode(GSS.get().getToken())); |
182 | 555e8e59 | pastith | Window.open(file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date="+URL.encodeComponent(dateString), "_blank", ""); |
183 | eaf8a7cb | koutsoub | } |
184 | fa6bdefa | koutsoub | if (DOM.eventGetType(event) == Event.ONCLICK) { |
185 | 14ad7326 | pastith | if (DOM.eventGetCtrlKey(event))
|
186 | 14ad7326 | pastith | clickControl = true;
|
187 | 14ad7326 | pastith | else
|
188 | 14ad7326 | pastith | clickControl = false;
|
189 | 14ad7326 | pastith | if (DOM.eventGetShiftKey(event)) {
|
190 | 14ad7326 | pastith | clickShift = true;
|
191 | 14ad7326 | pastith | if (selectedRows.size() == 1) |
192 | 14ad7326 | pastith | firstShift = selectedRows.get(0) - startIndex;
|
193 | 14ad7326 | pastith | //event.preventDefault();
|
194 | 14ad7326 | pastith | } else {
|
195 | 14ad7326 | pastith | clickShift = false;
|
196 | 14ad7326 | pastith | firstShift = -1;
|
197 | 14ad7326 | pastith | //event.preventDefault();
|
198 | 14ad7326 | pastith | } |
199 | 14ad7326 | pastith | } |
200 | 14ad7326 | pastith | |
201 | 14ad7326 | pastith | super.onBrowserEvent(event);
|
202 | 14ad7326 | pastith | } |
203 | 14ad7326 | pastith | }; |
204 | 14ad7326 | pastith | prevButton.addClickListener(this);
|
205 | 14ad7326 | pastith | nextButton.addClickListener(this);
|
206 | 14ad7326 | pastith | |
207 | 14ad7326 | pastith | contextMenu = new DnDFocusPanel(new HTML(images.fileContextMenu().getHTML())); |
208 | b4b188fe | koutsoub | contextMenu.addClickListener(new FileContextMenu(images, false, false)); |
209 | bbad17b4 | pastith | app.getDragController().makeDraggable(contextMenu); |
210 | 14ad7326 | pastith | |
211 | 14ad7326 | pastith | // Setup the table.
|
212 | 14ad7326 | pastith | table.setCellSpacing(0);
|
213 | 14ad7326 | pastith | table.setCellPadding(2);
|
214 | 14ad7326 | pastith | table.setWidth("100%");
|
215 | 14ad7326 | pastith | |
216 | 14ad7326 | pastith | // Hook up events.
|
217 | 14ad7326 | pastith | table.addTableListener(this);
|
218 | 14ad7326 | pastith | |
219 | 14ad7326 | pastith | // Create the 'navigation' bar at the upper-right.
|
220 | 780606ca | pastith | HorizontalPanel innerNavBar = new HorizontalPanel();
|
221 | 14ad7326 | pastith | innerNavBar.setStyleName("gss-ListNavBar");
|
222 | 14ad7326 | pastith | innerNavBar.setSpacing(8);
|
223 | 14ad7326 | pastith | innerNavBar.add(prevButton); |
224 | 14ad7326 | pastith | innerNavBar.add(countLabel); |
225 | 14ad7326 | pastith | innerNavBar.add(nextButton); |
226 | 14ad7326 | pastith | navBar.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); |
227 | 14ad7326 | pastith | navBar.add(innerNavBar); |
228 | 14ad7326 | pastith | navBar.setWidth("100%");
|
229 | 14ad7326 | pastith | VerticalPanel vp = new VerticalPanel();
|
230 | 14ad7326 | pastith | vp.add(searchResults); |
231 | 14ad7326 | pastith | searchResults.addStyleName("gss-searchlabel");
|
232 | 14ad7326 | pastith | vp.add(table); |
233 | 14ad7326 | pastith | initWidget(vp); |
234 | 14ad7326 | pastith | table.setStyleName("gss-List");
|
235 | 14ad7326 | pastith | initTable(); |
236 | 14ad7326 | pastith | DeferredCommand.addCommand(new IncrementalCommand() {
|
237 | 14ad7326 | pastith | |
238 | 14ad7326 | pastith | public boolean execute() { |
239 | 14ad7326 | pastith | return fetchRootFolder();
|
240 | 14ad7326 | pastith | } |
241 | 14ad7326 | pastith | }); |
242 | 14ad7326 | pastith | table.sinkEvents(Event.ONCONTEXTMENU);
|
243 | 14ad7326 | pastith | table.sinkEvents(Event.ONMOUSEUP);
|
244 | 14ad7326 | pastith | table.sinkEvents(Event.ONCLICK);
|
245 | 14ad7326 | pastith | table.sinkEvents(Event.ONKEYDOWN);
|
246 | eaf8a7cb | koutsoub | table.sinkEvents(Event.ONDBLCLICK);
|
247 | 14ad7326 | pastith | preventIESelection(); |
248 | 14ad7326 | pastith | } |
249 | 14ad7326 | pastith | |
250 | 14ad7326 | pastith | public void onClick(Widget sender) { |
251 | 14ad7326 | pastith | if (sender == nextButton) {
|
252 | 14ad7326 | pastith | // Move forward a page.
|
253 | 14ad7326 | pastith | clearSelectedRows(); |
254 | a52ea5e4 | pastith | startIndex += GSS.VISIBLE_FILE_COUNT; |
255 | 14ad7326 | pastith | if (startIndex >= folderFileCount)
|
256 | a52ea5e4 | pastith | startIndex -= GSS.VISIBLE_FILE_COUNT; |
257 | 14ad7326 | pastith | else
|
258 | ba8a1aff | Fotis Stamatelopoulos | update(false);
|
259 | 14ad7326 | pastith | } else if (sender == prevButton) { |
260 | 14ad7326 | pastith | clearSelectedRows(); |
261 | 14ad7326 | pastith | // Move back a page.
|
262 | a52ea5e4 | pastith | startIndex -= GSS.VISIBLE_FILE_COUNT; |
263 | 14ad7326 | pastith | if (startIndex < 0) |
264 | 14ad7326 | pastith | startIndex = 0;
|
265 | 14ad7326 | pastith | else
|
266 | ba8a1aff | Fotis Stamatelopoulos | update(false);
|
267 | 14ad7326 | pastith | } |
268 | 14ad7326 | pastith | } |
269 | 14ad7326 | pastith | |
270 | 14ad7326 | pastith | /**
|
271 | 14ad7326 | pastith | * Retrieve the root folder for the current user.
|
272 | 14ad7326 | pastith | *
|
273 | 14ad7326 | pastith | * @return true if the retrieval was successful
|
274 | 14ad7326 | pastith | */
|
275 | 14ad7326 | pastith | protected boolean fetchRootFolder() { |
276 | a52ea5e4 | pastith | UserResource user = GSS.get().getCurrentUserResource(); |
277 | 14ad7326 | pastith | if (user == null) |
278 | 14ad7326 | pastith | return !DONE;
|
279 | a52ea5e4 | pastith | updateFileCache("");
|
280 | 14ad7326 | pastith | return DONE;
|
281 | 14ad7326 | pastith | } |
282 | 14ad7326 | pastith | |
283 | 780606ca | pastith | public void onCellClicked(SourcesTableEvents sender, int row, int cell) { |
284 | 14ad7326 | pastith | // Select the row that was clicked (-1 to account for header row).
|
285 | 14ad7326 | pastith | if (row > folderFileCount)
|
286 | 14ad7326 | pastith | return;
|
287 | 14ad7326 | pastith | if (clickShift) {
|
288 | 14ad7326 | pastith | GWT.log("ROW is:" + row + " fs:" + firstShift, null); |
289 | 14ad7326 | pastith | if (firstShift == -1) |
290 | 14ad7326 | pastith | firstShift = row; |
291 | 14ad7326 | pastith | else if (row > firstShift) { |
292 | 14ad7326 | pastith | clearSelectedRows(); |
293 | 14ad7326 | pastith | for (int i = firstShift; i < row; i++) { |
294 | 14ad7326 | pastith | selectedRows.add(startIndex + i); |
295 | 14ad7326 | pastith | styleRow(i, true);
|
296 | 14ad7326 | pastith | } |
297 | 14ad7326 | pastith | GSS.get().setCurrentSelection(getSelectedFiles()); |
298 | a52ea5e4 | pastith | //contextMenu.setFiles(getSelectedFiles());
|
299 | 14ad7326 | pastith | table.setWidget(row, 0, contextMenu);
|
300 | 14ad7326 | pastith | } else if (row != -1 && row == firstShift) { |
301 | 14ad7326 | pastith | selectedRows.add(row); |
302 | 14ad7326 | pastith | selectedRows.add(row - 1);
|
303 | 14ad7326 | pastith | styleRow(row, true);
|
304 | 14ad7326 | pastith | styleRow(row - 1, true); |
305 | 14ad7326 | pastith | } else if (row < firstShift) { |
306 | 14ad7326 | pastith | GWT.log("ROW is:" + row + " fs:" + firstShift, null); |
307 | 14ad7326 | pastith | clearSelectedRows(); |
308 | 14ad7326 | pastith | |
309 | 14ad7326 | pastith | for (int i = firstShift; i >= row - 1; i--) { |
310 | 14ad7326 | pastith | selectedRows.add(startIndex + i); |
311 | 14ad7326 | pastith | styleRow(i, true);
|
312 | 14ad7326 | pastith | } |
313 | 14ad7326 | pastith | GSS.get().setCurrentSelection(getSelectedFiles()); |
314 | 14ad7326 | pastith | table.setWidget(row, 0, contextMenu);
|
315 | a52ea5e4 | pastith | //contextMenu.setFiles(getSelectedFiles());
|
316 | 14ad7326 | pastith | } |
317 | 14ad7326 | pastith | |
318 | 14ad7326 | pastith | } else if (row > 0) |
319 | 14ad7326 | pastith | selectRow(row - 1);
|
320 | 14ad7326 | pastith | |
321 | 14ad7326 | pastith | } |
322 | 14ad7326 | pastith | |
323 | 14ad7326 | pastith | /**
|
324 | 14ad7326 | pastith | * Initializes the table so that it contains enough rows for a full page of
|
325 | 14ad7326 | pastith | * files.
|
326 | 14ad7326 | pastith | */
|
327 | 14ad7326 | pastith | private void initTable() { |
328 | 14ad7326 | pastith | |
329 | 14ad7326 | pastith | nameLabel = new HTML("Name"); |
330 | 14ad7326 | pastith | nameLabel.addClickListener(new ClickListener() {
|
331 | 14ad7326 | pastith | |
332 | 14ad7326 | pastith | public void onClick(Widget sender) { |
333 | 14ad7326 | pastith | sortFiles("name");
|
334 | 14ad7326 | pastith | } |
335 | 14ad7326 | pastith | |
336 | 14ad7326 | pastith | }); |
337 | 14ad7326 | pastith | versionLabel = new HTML("Version"); |
338 | 14ad7326 | pastith | versionLabel.addClickListener(new ClickListener() {
|
339 | 14ad7326 | pastith | |
340 | 14ad7326 | pastith | public void onClick(Widget sender) { |
341 | 14ad7326 | pastith | sortFiles("version");
|
342 | 14ad7326 | pastith | } |
343 | 14ad7326 | pastith | |
344 | 14ad7326 | pastith | }); |
345 | 14ad7326 | pastith | sizeLabel = new HTML("Size"); |
346 | 14ad7326 | pastith | sizeLabel.addClickListener(new ClickListener() {
|
347 | 14ad7326 | pastith | |
348 | 14ad7326 | pastith | public void onClick(Widget sender) { |
349 | 14ad7326 | pastith | sortFiles("size");
|
350 | 14ad7326 | pastith | } |
351 | 14ad7326 | pastith | |
352 | 14ad7326 | pastith | }); |
353 | 10786b3c | Panagiotis Astithas | dateLabel = new HTML("Last modified"); |
354 | 14ad7326 | pastith | dateLabel.addClickListener(new ClickListener() {
|
355 | 14ad7326 | pastith | |
356 | 14ad7326 | pastith | public void onClick(Widget sender) { |
357 | 14ad7326 | pastith | sortFiles("date");
|
358 | 14ad7326 | pastith | } |
359 | 14ad7326 | pastith | |
360 | 14ad7326 | pastith | }); |
361 | 14ad7326 | pastith | ownerLabel = new HTML("Owner"); |
362 | 14ad7326 | pastith | ownerLabel.addClickListener(new ClickListener() {
|
363 | 14ad7326 | pastith | |
364 | 14ad7326 | pastith | public void onClick(Widget sender) { |
365 | 14ad7326 | pastith | sortFiles("owner");
|
366 | 14ad7326 | pastith | } |
367 | 14ad7326 | pastith | |
368 | 14ad7326 | pastith | }); |
369 | 14ad7326 | pastith | |
370 | 14ad7326 | pastith | pathLabel = new HTML("Path"); |
371 | 14ad7326 | pastith | pathLabel.addClickListener(new ClickListener() {
|
372 | 14ad7326 | pastith | |
373 | 14ad7326 | pastith | public void onClick(Widget sender) { |
374 | 14ad7326 | pastith | sortFiles("path");
|
375 | 14ad7326 | pastith | } |
376 | 14ad7326 | pastith | |
377 | 14ad7326 | pastith | }); |
378 | 14ad7326 | pastith | // Create the header row.
|
379 | 14ad7326 | pastith | table.setText(0, 0, ""); |
380 | 14ad7326 | pastith | // table.setText(0, 1, "Name");
|
381 | 14ad7326 | pastith | table.setWidget(0, 1, nameLabel); |
382 | 14ad7326 | pastith | table.setWidget(0, 2, ownerLabel); |
383 | 14ad7326 | pastith | // table.setText(0, 3, "Version");
|
384 | 14ad7326 | pastith | table.setWidget(0, 3, pathLabel); |
385 | 14ad7326 | pastith | table.setWidget(0, 4, versionLabel); |
386 | 14ad7326 | pastith | // table.setText(0, 4, "Size");
|
387 | 14ad7326 | pastith | table.setWidget(0, 5, sizeLabel); |
388 | 10786b3c | Panagiotis Astithas | // table.setText(0, 5, "Last modified");
|
389 | 14ad7326 | pastith | table.setWidget(0, 6, dateLabel); |
390 | 14ad7326 | pastith | table.setWidget(0, 7, navBar); |
391 | 14ad7326 | pastith | table.getRowFormatter().setStyleName(0, "gss-ListHeader"); |
392 | 14ad7326 | pastith | |
393 | 14ad7326 | pastith | // Initialize the rest of the rows.
|
394 | a52ea5e4 | pastith | for (int i = 1; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) { |
395 | 14ad7326 | pastith | table.setText(i, 0, ""); |
396 | 14ad7326 | pastith | table.setText(i, 1, ""); |
397 | 14ad7326 | pastith | table.setText(i, 2, ""); |
398 | 14ad7326 | pastith | table.setText(i, 3, ""); |
399 | 14ad7326 | pastith | table.setText(i, 4, ""); |
400 | 14ad7326 | pastith | table.setText(i, 5, ""); |
401 | 14ad7326 | pastith | table.setText(i, 6, ""); |
402 | 14ad7326 | pastith | table.getCellFormatter().setWordWrap(i, 0, false); |
403 | 14ad7326 | pastith | table.getCellFormatter().setWordWrap(i, 1, false); |
404 | 14ad7326 | pastith | table.getCellFormatter().setWordWrap(i, 2, false); |
405 | 14ad7326 | pastith | table.getCellFormatter().setWordWrap(i, 3, false); |
406 | 14ad7326 | pastith | table.getCellFormatter().setWordWrap(i, 4, false); |
407 | 14ad7326 | pastith | table.getCellFormatter().setWordWrap(i, 5, false); |
408 | 14ad7326 | pastith | table.getCellFormatter().setWordWrap(i, 6, false); |
409 | 31fe3066 | fstamatelopoulos | table.getCellFormatter().setHorizontalAlignment(i, 4, HasHorizontalAlignment.ALIGN_CENTER);
|
410 | 14ad7326 | pastith | } |
411 | 14ad7326 | pastith | prevButton.setVisible(false);
|
412 | 14ad7326 | pastith | nextButton.setVisible(false);
|
413 | 14ad7326 | pastith | } |
414 | 14ad7326 | pastith | |
415 | 14ad7326 | pastith | /**
|
416 | 14ad7326 | pastith | * Selects the given row (relative to the current page).
|
417 | 14ad7326 | pastith | *
|
418 | 14ad7326 | pastith | * @param row the row to be selected
|
419 | 14ad7326 | pastith | */
|
420 | 14ad7326 | pastith | private void selectRow(final int row) { |
421 | 14ad7326 | pastith | if (row < folderFileCount) {
|
422 | 14ad7326 | pastith | if (clickControl)
|
423 | 14ad7326 | pastith | if (selectedRows.contains(row)) {
|
424 | 14ad7326 | pastith | int i = selectedRows.indexOf(startIndex + row);
|
425 | 14ad7326 | pastith | selectedRows.remove(i); |
426 | 14ad7326 | pastith | styleRow(row, false);
|
427 | 14ad7326 | pastith | } else {
|
428 | 14ad7326 | pastith | for (int r : selectedRows) { |
429 | 14ad7326 | pastith | int prow = r - startIndex;
|
430 | 14ad7326 | pastith | table.setWidget(prow + 1, 0, images.document().createImage()); |
431 | 14ad7326 | pastith | } |
432 | 14ad7326 | pastith | selectedRows.add(startIndex + row); |
433 | 14ad7326 | pastith | styleRow(row, true);
|
434 | 14ad7326 | pastith | } |
435 | 14ad7326 | pastith | else {
|
436 | 14ad7326 | pastith | clearSelectedRows(); |
437 | 14ad7326 | pastith | selectedRows.add(startIndex + row); |
438 | 14ad7326 | pastith | styleRow(row, true);
|
439 | 14ad7326 | pastith | } |
440 | 14ad7326 | pastith | if (selectedRows.size() == 1) |
441 | 14ad7326 | pastith | GSS.get().setCurrentSelection(files.get(selectedRows.get(0)));
|
442 | 14ad7326 | pastith | else
|
443 | 14ad7326 | pastith | GSS.get().setCurrentSelection(getSelectedFiles()); |
444 | a52ea5e4 | pastith | //contextMenu.setFiles(getSelectedFiles());
|
445 | 14ad7326 | pastith | table.setWidget(row + 1, 0, contextMenu); |
446 | 14ad7326 | pastith | } |
447 | 14ad7326 | pastith | } |
448 | 14ad7326 | pastith | |
449 | a52ea5e4 | pastith | public List<FileResource> getSelectedFiles() { |
450 | a52ea5e4 | pastith | List<FileResource> result = new ArrayList(); |
451 | 14ad7326 | pastith | for (int i : selectedRows) |
452 | 14ad7326 | pastith | result.add(files.get(i)); |
453 | 14ad7326 | pastith | return result;
|
454 | 14ad7326 | pastith | } |
455 | 14ad7326 | pastith | |
456 | 14ad7326 | pastith | /**
|
457 | 14ad7326 | pastith | * Make the specified row look like selected or not, according to the
|
458 | 14ad7326 | pastith | * <code>selected</code> flag.
|
459 | 14ad7326 | pastith | *
|
460 | 14ad7326 | pastith | * @param row
|
461 | 14ad7326 | pastith | * @param selected
|
462 | 14ad7326 | pastith | */
|
463 | 14ad7326 | pastith | void styleRow(final int row, final boolean selected) { |
464 | 14ad7326 | pastith | if (row != -1 && row >= 0) |
465 | 14ad7326 | pastith | if (selected)
|
466 | 14ad7326 | pastith | table.getRowFormatter().addStyleName(row + 1, "gss-SelectedRow"); |
467 | 14ad7326 | pastith | else
|
468 | 14ad7326 | pastith | table.getRowFormatter().removeStyleName(row + 1, "gss-SelectedRow"); |
469 | 14ad7326 | pastith | } |
470 | 14ad7326 | pastith | |
471 | 14ad7326 | pastith | /**
|
472 | 14ad7326 | pastith | * Update the display of the file list.
|
473 | 14ad7326 | pastith | */
|
474 | ba8a1aff | Fotis Stamatelopoulos | void update(boolean sort) { |
475 | 14ad7326 | pastith | int count = folderFileCount;
|
476 | a52ea5e4 | pastith | int max = startIndex + GSS.VISIBLE_FILE_COUNT;
|
477 | 14ad7326 | pastith | if (max > count)
|
478 | 14ad7326 | pastith | max = count; |
479 | 4b29a3ca | fstamatelopoulos | folderTotalSize = 0;
|
480 | 14ad7326 | pastith | |
481 | ba8a1aff | Fotis Stamatelopoulos | if (sort && files != null && files.size() != 0) { |
482 | ba8a1aff | Fotis Stamatelopoulos | clearLabels(); |
483 | ba8a1aff | Fotis Stamatelopoulos | clearSelectedRows(); |
484 | ba8a1aff | Fotis Stamatelopoulos | |
485 | ba8a1aff | Fotis Stamatelopoulos | Collections.sort(files, new Comparator<FileResource>() { |
486 | ba8a1aff | Fotis Stamatelopoulos | |
487 | ba8a1aff | Fotis Stamatelopoulos | public int compare(FileResource arg0, FileResource arg1) { |
488 | ba8a1aff | Fotis Stamatelopoulos | if (sortingType)
|
489 | ba8a1aff | Fotis Stamatelopoulos | if (sortingProperty.equals("version")) { |
490 | ba8a1aff | Fotis Stamatelopoulos | versionLabel.setHTML("Version " + images.desc().getHTML());
|
491 | ba8a1aff | Fotis Stamatelopoulos | return arg0.getVersion().compareTo(arg1.getVersion());
|
492 | ba8a1aff | Fotis Stamatelopoulos | } else if (sortingProperty.equals("owner")) { |
493 | ba8a1aff | Fotis Stamatelopoulos | ownerLabel.setHTML("Owner " + images.desc().getHTML());
|
494 | ba8a1aff | Fotis Stamatelopoulos | return arg0.getOwner().compareTo(arg1.getOwner());
|
495 | ba8a1aff | Fotis Stamatelopoulos | } else if (sortingProperty.equals("date")) { |
496 | ba8a1aff | Fotis Stamatelopoulos | dateLabel.setHTML("Last modified " + images.desc().getHTML());
|
497 | ba8a1aff | Fotis Stamatelopoulos | return arg0.getModificationDate().compareTo(arg1.getModificationDate());
|
498 | ba8a1aff | Fotis Stamatelopoulos | } else if (sortingProperty.equals("size")) { |
499 | ba8a1aff | Fotis Stamatelopoulos | sizeLabel.setHTML("Size " + images.desc().getHTML());
|
500 | ba8a1aff | Fotis Stamatelopoulos | return arg0.getContentLength().compareTo(arg1.getContentLength());
|
501 | ba8a1aff | Fotis Stamatelopoulos | } else if (sortingProperty.equals("name")) { |
502 | ba8a1aff | Fotis Stamatelopoulos | nameLabel.setHTML("Name " + images.desc().getHTML());
|
503 | ba8a1aff | Fotis Stamatelopoulos | return arg0.getName().compareTo(arg1.getName());
|
504 | ba8a1aff | Fotis Stamatelopoulos | } else if (sortingProperty.equals("path")) { |
505 | ba8a1aff | Fotis Stamatelopoulos | pathLabel.setHTML("Path " + images.desc().getHTML());
|
506 | ba8a1aff | Fotis Stamatelopoulos | return arg0.getUri().compareTo(arg1.getUri());
|
507 | ba8a1aff | Fotis Stamatelopoulos | } else {
|
508 | ba8a1aff | Fotis Stamatelopoulos | nameLabel.setHTML("Name " + images.desc().getHTML());
|
509 | ba8a1aff | Fotis Stamatelopoulos | return arg0.getName().compareTo(arg1.getName());
|
510 | ba8a1aff | Fotis Stamatelopoulos | } |
511 | ba8a1aff | Fotis Stamatelopoulos | else if (sortingProperty.equals("version")) { |
512 | ba8a1aff | Fotis Stamatelopoulos | versionLabel.setHTML("Version " + images.asc().getHTML());
|
513 | ba8a1aff | Fotis Stamatelopoulos | return arg1.getVersion().compareTo(arg0.getVersion());
|
514 | ba8a1aff | Fotis Stamatelopoulos | } else if (sortingProperty.equals("owner")) { |
515 | ba8a1aff | Fotis Stamatelopoulos | ownerLabel.setHTML("Owner " + images.asc().getHTML());
|
516 | ba8a1aff | Fotis Stamatelopoulos | return arg1.getOwner().compareTo(arg0.getOwner());
|
517 | ba8a1aff | Fotis Stamatelopoulos | } else if (sortingProperty.equals("date")) { |
518 | ba8a1aff | Fotis Stamatelopoulos | dateLabel.setHTML("Last modified " + images.asc().getHTML());
|
519 | ba8a1aff | Fotis Stamatelopoulos | return arg1.getModificationDate().compareTo(arg0.getModificationDate());
|
520 | ba8a1aff | Fotis Stamatelopoulos | } else if (sortingProperty.equals("size")) { |
521 | ba8a1aff | Fotis Stamatelopoulos | sizeLabel.setHTML("Size " + images.asc().getHTML());
|
522 | ba8a1aff | Fotis Stamatelopoulos | return arg1.getContentLength().compareTo(arg0.getContentLength());
|
523 | ba8a1aff | Fotis Stamatelopoulos | } else if (sortingProperty.equals("name")) { |
524 | ba8a1aff | Fotis Stamatelopoulos | nameLabel.setHTML("Name " + images.asc().getHTML());
|
525 | ba8a1aff | Fotis Stamatelopoulos | return arg1.getName().compareTo(arg0.getName());
|
526 | ba8a1aff | Fotis Stamatelopoulos | } else if (sortingProperty.equals("path")) { |
527 | ba8a1aff | Fotis Stamatelopoulos | pathLabel.setHTML("Path " + images.asc().getHTML());
|
528 | ba8a1aff | Fotis Stamatelopoulos | return arg1.getUri().compareTo(arg0.getUri());
|
529 | ba8a1aff | Fotis Stamatelopoulos | } else {
|
530 | ba8a1aff | Fotis Stamatelopoulos | nameLabel.setHTML("Name " + images.asc().getHTML());
|
531 | ba8a1aff | Fotis Stamatelopoulos | return arg1.getName().compareTo(arg0.getName());
|
532 | ba8a1aff | Fotis Stamatelopoulos | } |
533 | ba8a1aff | Fotis Stamatelopoulos | } |
534 | ba8a1aff | Fotis Stamatelopoulos | |
535 | ba8a1aff | Fotis Stamatelopoulos | }); |
536 | ba8a1aff | Fotis Stamatelopoulos | |
537 | ba8a1aff | Fotis Stamatelopoulos | } |
538 | 14ad7326 | pastith | // Show the selected files.
|
539 | 14ad7326 | pastith | int i = 1; |
540 | a52ea5e4 | pastith | for (; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) { |
541 | 14ad7326 | pastith | // Don't read past the end.
|
542 | 14ad7326 | pastith | // if (i > folderFileCount)
|
543 | 14ad7326 | pastith | // break;
|
544 | 14ad7326 | pastith | if (startIndex + i > folderFileCount)
|
545 | 14ad7326 | pastith | break;
|
546 | 14ad7326 | pastith | // Add a new row to the table, then set each of its columns to the
|
547 | 14ad7326 | pastith | // proper values.
|
548 | 14ad7326 | pastith | table.setWidget(i, 0, images.document().createImage());
|
549 | a52ea5e4 | pastith | FileResource fileHeader = files.get(startIndex + i - 1);
|
550 | 14ad7326 | pastith | table.getRowFormatter().addStyleName(i, "gss-fileRow");
|
551 | 14ad7326 | pastith | table.setHTML(i, 1, fileHeader.getName());
|
552 | a52ea5e4 | pastith | table.setText(i, 2, fileHeader.getOwner());
|
553 | 555e8e59 | pastith | table.setText(i, 3, fileHeader.getPath());
|
554 | 14ad7326 | pastith | table.setText(i, 4, String.valueOf(fileHeader.getVersion())); |
555 | 14ad7326 | pastith | table.setText(i, 5, String.valueOf(fileHeader.getFileSizeAsString())); |
556 | 31fe3066 | fstamatelopoulos | final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a"); |
557 | 10786b3c | Panagiotis Astithas | table.setText(i, 6, formatter.format(fileHeader.getModificationDate()));
|
558 | 4b29a3ca | fstamatelopoulos | folderTotalSize += fileHeader.getContentLength(); |
559 | 14ad7326 | pastith | } |
560 | 14ad7326 | pastith | |
561 | 14ad7326 | pastith | // Clear any remaining slots.
|
562 | a52ea5e4 | pastith | for (; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) { |
563 | 14ad7326 | pastith | table.setHTML(i, 0, " "); |
564 | 14ad7326 | pastith | table.setHTML(i, 1, " "); |
565 | 14ad7326 | pastith | table.setHTML(i, 2, " "); |
566 | 14ad7326 | pastith | table.setHTML(i, 3, " "); |
567 | 14ad7326 | pastith | table.setHTML(i, 4, " "); |
568 | 14ad7326 | pastith | table.setHTML(i, 5, " "); |
569 | 14ad7326 | pastith | table.setHTML(i, 6, " "); |
570 | 14ad7326 | pastith | table.setHTML(i, 7, " "); |
571 | 14ad7326 | pastith | } |
572 | 14ad7326 | pastith | |
573 | 4b29a3ca | fstamatelopoulos | if (folderFileCount == 0) { |
574 | b3c6d52e | fstamatelopoulos | showingStats = "no files";
|
575 | 4b29a3ca | fstamatelopoulos | prevButton.setVisible(false);
|
576 | 4b29a3ca | fstamatelopoulos | nextButton.setVisible(false);
|
577 | 4b29a3ca | fstamatelopoulos | } else if (folderFileCount < GSS.VISIBLE_FILE_COUNT) { |
578 | 2bc32810 | fstamatelopoulos | if (folderFileCount == 1) |
579 | 2bc32810 | fstamatelopoulos | showingStats = "1 file";
|
580 | 2bc32810 | fstamatelopoulos | else
|
581 | 2bc32810 | fstamatelopoulos | showingStats = folderFileCount + " files";
|
582 | 2bc32810 | fstamatelopoulos | showingStats += " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")"; |
583 | 4b29a3ca | fstamatelopoulos | prevButton.setVisible(false);
|
584 | 4b29a3ca | fstamatelopoulos | nextButton.setVisible(false);
|
585 | 4b29a3ca | fstamatelopoulos | } else {
|
586 | b3c6d52e | fstamatelopoulos | showingStats = "" + (startIndex + 1) + " - " + max + " of " + count + " files" + " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")"; |
587 | 4b29a3ca | fstamatelopoulos | prevButton.setVisible(startIndex != 0);
|
588 | 4b29a3ca | fstamatelopoulos | nextButton.setVisible(startIndex + GSS.VISIBLE_FILE_COUNT < count); |
589 | 4b29a3ca | fstamatelopoulos | } |
590 | b3c6d52e | fstamatelopoulos | updateCurrentlyShowingStats(); |
591 | 14ad7326 | pastith | } |
592 | 14ad7326 | pastith | |
593 | 14ad7326 | pastith | /**
|
594 | b3c6d52e | fstamatelopoulos | * update status panel with currently showing file stats
|
595 | b3c6d52e | fstamatelopoulos | */
|
596 | b3c6d52e | fstamatelopoulos | public void updateCurrentlyShowingStats() { |
597 | b3c6d52e | fstamatelopoulos | GSS.get().getStatusPanel().updateCurrentlyShowing(showingStats); |
598 | b3c6d52e | fstamatelopoulos | } |
599 | b3c6d52e | fstamatelopoulos | |
600 | b3c6d52e | fstamatelopoulos | /**
|
601 | 14ad7326 | pastith | * Adjust the height of the table by adding and removing rows as necessary.
|
602 | 14ad7326 | pastith | *
|
603 | 14ad7326 | pastith | * @param newHeight the new height to reach
|
604 | 14ad7326 | pastith | */
|
605 | 14ad7326 | pastith | void resizeTableHeight(final int newHeight) { |
606 | 14ad7326 | pastith | GWT.log("Panel: " + newHeight + ", parent: " + table.getParent().getOffsetHeight(), null); |
607 | 14ad7326 | pastith | // Fill the rest with empty slots.
|
608 | 14ad7326 | pastith | if (newHeight > table.getOffsetHeight())
|
609 | 14ad7326 | pastith | while (newHeight > table.getOffsetHeight()) {
|
610 | 14ad7326 | pastith | // table.setHTML(table.getRowCount(), 5, " ");
|
611 | 14ad7326 | pastith | table.resizeRows(table.getRowCount() + 1);
|
612 | 14ad7326 | pastith | GWT.log("Table: " + table.getOffsetHeight() + ", rows: " + table.getRowCount(), null); |
613 | 14ad7326 | pastith | } |
614 | 14ad7326 | pastith | else
|
615 | 14ad7326 | pastith | while (newHeight < table.getOffsetHeight()) {
|
616 | 14ad7326 | pastith | // table.setHTML(table.getRowCount(), 5, " ");
|
617 | 14ad7326 | pastith | table.resizeRows(table.getRowCount() - 1);
|
618 | 14ad7326 | pastith | GWT.log("Table: " + table.getOffsetHeight() + ", rows: " + table.getRowCount(), null); |
619 | 14ad7326 | pastith | } |
620 | 14ad7326 | pastith | } |
621 | 14ad7326 | pastith | |
622 | 14ad7326 | pastith | /**
|
623 | 14ad7326 | pastith | * Update the file cache with data from the server.
|
624 | 14ad7326 | pastith | */
|
625 | 780606ca | pastith | public void updateFileCache(String query) { |
626 | bbad17b4 | pastith | final GSS app = GSS.get();
|
627 | 14ad7326 | pastith | clearSelectedRows(); |
628 | 4bb05581 | koutsoub | clearLabels(); |
629 | 14ad7326 | pastith | startIndex = 0;
|
630 | bbad17b4 | pastith | app.showLoadingIndicator(); |
631 | 14ad7326 | pastith | if (query == null || query.trim().equals("")) { |
632 | 14ad7326 | pastith | searchResults.setHTML("You must specify a query");
|
633 | 14ad7326 | pastith | setFiles(new ArrayList()); |
634 | ba8a1aff | Fotis Stamatelopoulos | update(true);
|
635 | bbad17b4 | pastith | app.hideLoadingIndicator(); |
636 | 14ad7326 | pastith | } else{
|
637 | 14ad7326 | pastith | searchResults.setHTML("Search results for " + query);
|
638 | 3c793c5c | koutsoub | |
639 | 895035a2 | pastith | GetCommand<SearchResource> eg = new GetCommand<SearchResource>(SearchResource.class,
|
640 | bbad17b4 | pastith | app.getApiPath() + "search/" + URL.encodeComponent(query)) { |
641 | a52ea5e4 | pastith | |
642 | a52ea5e4 | pastith | @Override
|
643 | a52ea5e4 | pastith | public void onComplete() { |
644 | a52ea5e4 | pastith | SearchResource s = getResult(); |
645 | 3c793c5c | koutsoub | setFiles(s.getFiles()); |
646 | ba8a1aff | Fotis Stamatelopoulos | update(true);
|
647 | a52ea5e4 | pastith | } |
648 | a52ea5e4 | pastith | |
649 | 780606ca | pastith | @Override
|
650 | a52ea5e4 | pastith | public void onError(Throwable t) { |
651 | e08c358f | koutsoub | if(t instanceof RestException) |
652 | bbad17b4 | pastith | app.displayError("Unable to perform search:"+((RestException)t).getHttpStatusText());
|
653 | e08c358f | koutsoub | else
|
654 | bbad17b4 | pastith | app.displayError("System error performing search:"+t.getMessage());
|
655 | a52ea5e4 | pastith | updateFileCache("");
|
656 | a52ea5e4 | pastith | } |
657 | a52ea5e4 | pastith | |
658 | a52ea5e4 | pastith | }; |
659 | a52ea5e4 | pastith | DeferredCommand.addCommand(eg); |
660 | a52ea5e4 | pastith | } |
661 | 14ad7326 | pastith | } |
662 | 14ad7326 | pastith | |
663 | 14ad7326 | pastith | /**
|
664 | 14ad7326 | pastith | * Fill the file cache with data.
|
665 | 14ad7326 | pastith | *
|
666 | 14ad7326 | pastith | * @param _files
|
667 | a52ea5e4 | pastith | * @param filePaths the files to set
|
668 | 14ad7326 | pastith | */
|
669 | 780606ca | pastith | private void setFiles(List<FileResource> _files) { |
670 | 14ad7326 | pastith | files = _files; |
671 | a52ea5e4 | pastith | Collections.sort(files, new Comparator<FileResource>() { |
672 | 14ad7326 | pastith | |
673 | a52ea5e4 | pastith | public int compare(FileResource arg0, FileResource arg1) { |
674 | 14ad7326 | pastith | return arg0.getName().compareTo(arg1.getName());
|
675 | 14ad7326 | pastith | } |
676 | 14ad7326 | pastith | |
677 | 14ad7326 | pastith | }); |
678 | 14ad7326 | pastith | folderFileCount = files.size(); |
679 | 14ad7326 | pastith | GWT.log("File count:" + folderFileCount, null); |
680 | 14ad7326 | pastith | } |
681 | 14ad7326 | pastith | |
682 | 14ad7326 | pastith | private void sortFiles(final String sortProperty) { |
683 | 14ad7326 | pastith | if (sortProperty.equals(sortingProperty))
|
684 | 14ad7326 | pastith | sortingType = !sortingType; |
685 | 14ad7326 | pastith | else {
|
686 | 14ad7326 | pastith | sortingProperty = sortProperty; |
687 | 14ad7326 | pastith | sortingType = true;
|
688 | 14ad7326 | pastith | } |
689 | ba8a1aff | Fotis Stamatelopoulos | update(true);
|
690 | 14ad7326 | pastith | } |
691 | 14ad7326 | pastith | |
692 | 14ad7326 | pastith | private void clearLabels() { |
693 | 14ad7326 | pastith | nameLabel.setText("Name");
|
694 | 14ad7326 | pastith | versionLabel.setText("Version");
|
695 | 14ad7326 | pastith | sizeLabel.setText("Size");
|
696 | 10786b3c | Panagiotis Astithas | dateLabel.setText("Last modified");
|
697 | 14ad7326 | pastith | ownerLabel.setText("Owner");
|
698 | 14ad7326 | pastith | pathLabel.setText("Path");
|
699 | 14ad7326 | pastith | } |
700 | 14ad7326 | pastith | |
701 | 14ad7326 | pastith | /**
|
702 | 14ad7326 | pastith | * Retrieve the table.
|
703 | 14ad7326 | pastith | *
|
704 | 14ad7326 | pastith | * @return the table
|
705 | 14ad7326 | pastith | */
|
706 | 14ad7326 | pastith | Grid getTable() { |
707 | 14ad7326 | pastith | return table;
|
708 | 14ad7326 | pastith | } |
709 | 14ad7326 | pastith | |
710 | 14ad7326 | pastith | /**
|
711 | 14ad7326 | pastith | * Does the list contains the requested filename
|
712 | 14ad7326 | pastith | *
|
713 | 14ad7326 | pastith | * @param fileName
|
714 | 14ad7326 | pastith | * @return true/false
|
715 | 14ad7326 | pastith | */
|
716 | 14ad7326 | pastith | public boolean contains(String fileName) { |
717 | 14ad7326 | pastith | for (int i = 0; i < files.size(); i++) |
718 | 14ad7326 | pastith | if (files.get(i).getName().equals(fileName))
|
719 | 14ad7326 | pastith | return true; |
720 | 14ad7326 | pastith | return false; |
721 | 14ad7326 | pastith | } |
722 | 14ad7326 | pastith | |
723 | 14ad7326 | pastith | public void clearSelectedRows() { |
724 | 14ad7326 | pastith | for (int r : selectedRows) { |
725 | 14ad7326 | pastith | int row = r - startIndex;
|
726 | 14ad7326 | pastith | styleRow(row, false);
|
727 | 14ad7326 | pastith | table.setWidget(row + 1, 0, images.document().createImage()); |
728 | 14ad7326 | pastith | } |
729 | 14ad7326 | pastith | selectedRows.clear(); |
730 | 14ad7326 | pastith | Object sel = GSS.get().getCurrentSelection();
|
731 | a52ea5e4 | pastith | if (sel instanceof FileResource || sel instanceof List) |
732 | 14ad7326 | pastith | GSS.get().setCurrentSelection(null);
|
733 | 14ad7326 | pastith | } |
734 | 14ad7326 | pastith | |
735 | 14ad7326 | pastith | public static native void preventIESelection() /*-{ |
736 | 14ad7326 | pastith | $doc.body.onselectstart = function () { return false; };
|
737 | 14ad7326 | pastith | }-*/;
|
738 | 14ad7326 | pastith | |
739 | 14ad7326 | pastith | public static native void enableIESelection() /*-{ |
740 | 14ad7326 | pastith | if ($doc.body.onselectstart != null)
|
741 | 14ad7326 | pastith | $doc.body.onselectstart = null;
|
742 | 14ad7326 | pastith | }-*/;
|
743 | 14ad7326 | pastith | |
744 | 14ad7326 | pastith | public void selectAllRows() { |
745 | 14ad7326 | pastith | clearSelectedRows(); |
746 | 14ad7326 | pastith | int count = folderFileCount;
|
747 | 14ad7326 | pastith | if (count == 0) |
748 | 14ad7326 | pastith | return;
|
749 | a52ea5e4 | pastith | int max = startIndex + GSS.VISIBLE_FILE_COUNT;
|
750 | 14ad7326 | pastith | if (max > count)
|
751 | 14ad7326 | pastith | max = count; |
752 | 14ad7326 | pastith | int i = 1; |
753 | a52ea5e4 | pastith | for (; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) { |
754 | 14ad7326 | pastith | // Don't read past the end.
|
755 | 14ad7326 | pastith | // if (i > folderFileCount)
|
756 | 14ad7326 | pastith | // break;
|
757 | 14ad7326 | pastith | if (startIndex + i > folderFileCount)
|
758 | 14ad7326 | pastith | break;
|
759 | 14ad7326 | pastith | selectedRows.add(startIndex + i - 1);
|
760 | 14ad7326 | pastith | styleRow(i - 1, true); |
761 | 14ad7326 | pastith | } |
762 | 14ad7326 | pastith | GSS.get().setCurrentSelection(getSelectedFiles()); |
763 | a52ea5e4 | pastith | //contextMenu.setFiles(getSelectedFiles());
|
764 | 14ad7326 | pastith | table.setWidget(i - 1, 0, contextMenu); |
765 | 14ad7326 | pastith | } |
766 | 14ad7326 | pastith | |
767 | 14ad7326 | pastith | } |