root / src / gr / ebs / gss / client / FileList.java @ ce2716a9
History | View | Annotate | Download (38.7 kB)
1 | 023f6f1e | Panagiotis Astithas | /*
|
---|---|---|---|
2 | 023f6f1e | Panagiotis Astithas | * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
|
3 | 023f6f1e | Panagiotis Astithas | *
|
4 | 023f6f1e | Panagiotis Astithas | * This file is part of GSS.
|
5 | 023f6f1e | Panagiotis Astithas | *
|
6 | 023f6f1e | Panagiotis Astithas | * GSS is free software: you can redistribute it and/or modify
|
7 | 023f6f1e | Panagiotis Astithas | * it under the terms of the GNU General Public License as published by
|
8 | 023f6f1e | Panagiotis Astithas | * the Free Software Foundation, either version 3 of the License, or
|
9 | 023f6f1e | Panagiotis Astithas | * (at your option) any later version.
|
10 | 023f6f1e | Panagiotis Astithas | *
|
11 | 023f6f1e | Panagiotis Astithas | * GSS is distributed in the hope that it will be useful,
|
12 | 023f6f1e | Panagiotis Astithas | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 023f6f1e | Panagiotis Astithas | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 023f6f1e | Panagiotis Astithas | * GNU General Public License for more details.
|
15 | 023f6f1e | Panagiotis Astithas | *
|
16 | 023f6f1e | Panagiotis Astithas | * You should have received a copy of the GNU General Public License
|
17 | 023f6f1e | Panagiotis Astithas | * along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 | 023f6f1e | Panagiotis Astithas | */
|
19 | 023f6f1e | Panagiotis Astithas | package gr.ebs.gss.client; |
20 | ce2716a9 | Natasa Kapravelou | import gr.ebs.gss.client.commands.GetUserCommand; |
21 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.dnd.DnDSimpleFocusPanel; |
22 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.dnd.DnDTreeItem; |
23 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.rest.GetCommand; |
24 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.rest.MultipleHeadCommand; |
25 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.rest.RestCommand; |
26 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.rest.RestException; |
27 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.rest.resource.FileResource; |
28 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.rest.resource.FolderResource; |
29 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.rest.resource.OtherUserResource; |
30 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.rest.resource.SharedResource; |
31 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.rest.resource.TrashResource; |
32 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.rest.resource.UserResource; |
33 | 023f6f1e | Panagiotis Astithas | |
34 | 023f6f1e | Panagiotis Astithas | import java.util.ArrayList; |
35 | 023f6f1e | Panagiotis Astithas | import java.util.Collections; |
36 | 023f6f1e | Panagiotis Astithas | import java.util.Comparator; |
37 | 023f6f1e | Panagiotis Astithas | import java.util.List; |
38 | 023f6f1e | Panagiotis Astithas | |
39 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.core.client.GWT; |
40 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.dom.client.NativeEvent; |
41 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.event.dom.client.ClickEvent; |
42 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.event.dom.client.ClickHandler; |
43 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.http.client.URL; |
44 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.i18n.client.DateTimeFormat; |
45 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.resources.client.ClientBundle; |
46 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.resources.client.ImageResource; |
47 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.DOM; |
48 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.DeferredCommand; |
49 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.Event; |
50 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.IncrementalCommand; |
51 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.Window; |
52 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
53 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.ui.Composite; |
54 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.ui.Grid; |
55 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.ui.HTML; |
56 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
57 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.ui.HorizontalPanel; |
58 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.ui.TreeItem; |
59 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.ui.Widget; |
60 | 9ab5db6d | Natasa Kapravelou | import com.google.gwt.user.client.ui.HTMLTable.Cell; |
61 | 023f6f1e | Panagiotis Astithas | |
62 | 023f6f1e | Panagiotis Astithas | /**
|
63 | 023f6f1e | Panagiotis Astithas | * A composite that displays the list of files in a particular folder.
|
64 | 023f6f1e | Panagiotis Astithas | */
|
65 | 023f6f1e | Panagiotis Astithas | public class FileList extends Composite implements ClickHandler { |
66 | 023f6f1e | Panagiotis Astithas | |
67 | 023f6f1e | Panagiotis Astithas | private HTML prevButton = new HTML("<a href='javascript:;'>< Previous</a>", true); |
68 | 023f6f1e | Panagiotis Astithas | |
69 | 023f6f1e | Panagiotis Astithas | private HTML nextButton = new HTML("<a href='javascript:;'>Next ></a>", true); |
70 | 023f6f1e | Panagiotis Astithas | |
71 | 023f6f1e | Panagiotis Astithas | private String showingStats = ""; |
72 | 023f6f1e | Panagiotis Astithas | |
73 | 023f6f1e | Panagiotis Astithas | private int startIndex = 0; |
74 | 023f6f1e | Panagiotis Astithas | |
75 | 023f6f1e | Panagiotis Astithas | /**
|
76 | 023f6f1e | Panagiotis Astithas | * A constant that denotes the completion of an IncrementalCommand.
|
77 | 023f6f1e | Panagiotis Astithas | */
|
78 | 023f6f1e | Panagiotis Astithas | public static final boolean DONE = false; |
79 | 023f6f1e | Panagiotis Astithas | |
80 | 023f6f1e | Panagiotis Astithas | private boolean clickControl = false; |
81 | 023f6f1e | Panagiotis Astithas | |
82 | 023f6f1e | Panagiotis Astithas | private boolean clickShift = false; |
83 | 023f6f1e | Panagiotis Astithas | |
84 | 023f6f1e | Panagiotis Astithas | private int firstShift = -1; |
85 | 023f6f1e | Panagiotis Astithas | |
86 | 023f6f1e | Panagiotis Astithas | private ArrayList<Integer> selectedRows = new ArrayList<Integer>(); |
87 | 023f6f1e | Panagiotis Astithas | |
88 | 023f6f1e | Panagiotis Astithas | /**
|
89 | 023f6f1e | Panagiotis Astithas | * The context menu for the selected file.
|
90 | 023f6f1e | Panagiotis Astithas | */
|
91 | 023f6f1e | Panagiotis Astithas | final DnDSimpleFocusPanel contextMenu;
|
92 | 023f6f1e | Panagiotis Astithas | |
93 | 023f6f1e | Panagiotis Astithas | /**
|
94 | 023f6f1e | Panagiotis Astithas | * Specifies that the images available for this composite will be the ones
|
95 | 023f6f1e | Panagiotis Astithas | * available in FileContextMenu.
|
96 | 023f6f1e | Panagiotis Astithas | */
|
97 | 023f6f1e | Panagiotis Astithas | public interface Images extends ClientBundle,FileContextMenu.Images, Folders.Images { |
98 | 023f6f1e | Panagiotis Astithas | |
99 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/blank.gif") |
100 | 023f6f1e | Panagiotis Astithas | ImageResource blank(); |
101 | 023f6f1e | Panagiotis Astithas | |
102 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/asc.png") |
103 | 023f6f1e | Panagiotis Astithas | ImageResource asc(); |
104 | 023f6f1e | Panagiotis Astithas | |
105 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/desc.png") |
106 | 023f6f1e | Panagiotis Astithas | ImageResource desc(); |
107 | 023f6f1e | Panagiotis Astithas | |
108 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/document_shared.png") |
109 | 023f6f1e | Panagiotis Astithas | ImageResource documentShared(); |
110 | 023f6f1e | Panagiotis Astithas | |
111 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/kcmfontinst.png") |
112 | 023f6f1e | Panagiotis Astithas | ImageResource wordprocessor(); |
113 | 023f6f1e | Panagiotis Astithas | |
114 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/log.png") |
115 | 023f6f1e | Panagiotis Astithas | ImageResource spreadsheet(); |
116 | 023f6f1e | Panagiotis Astithas | |
117 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/kpresenter_kpr.png") |
118 | 023f6f1e | Panagiotis Astithas | ImageResource presentation(); |
119 | 023f6f1e | Panagiotis Astithas | |
120 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/acroread.png") |
121 | 023f6f1e | Panagiotis Astithas | ImageResource pdf(); |
122 | 023f6f1e | Panagiotis Astithas | |
123 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/image.png") |
124 | 023f6f1e | Panagiotis Astithas | ImageResource image(); |
125 | 023f6f1e | Panagiotis Astithas | |
126 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/video2.png") |
127 | 023f6f1e | Panagiotis Astithas | ImageResource video(); |
128 | 023f6f1e | Panagiotis Astithas | |
129 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/knotify.png") |
130 | 023f6f1e | Panagiotis Astithas | ImageResource audio(); |
131 | 023f6f1e | Panagiotis Astithas | |
132 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/html.png") |
133 | 023f6f1e | Panagiotis Astithas | ImageResource html(); |
134 | 023f6f1e | Panagiotis Astithas | |
135 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/txt.png") |
136 | 023f6f1e | Panagiotis Astithas | ImageResource txt(); |
137 | 023f6f1e | Panagiotis Astithas | |
138 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/ark2.png") |
139 | 023f6f1e | Panagiotis Astithas | ImageResource zip(); |
140 | 023f6f1e | Panagiotis Astithas | |
141 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/kcmfontinst_shared.png") |
142 | 023f6f1e | Panagiotis Astithas | ImageResource wordprocessorShared(); |
143 | 023f6f1e | Panagiotis Astithas | |
144 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/log_shared.png") |
145 | 023f6f1e | Panagiotis Astithas | ImageResource spreadsheetShared(); |
146 | 023f6f1e | Panagiotis Astithas | |
147 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/kpresenter_kpr_shared.png") |
148 | 023f6f1e | Panagiotis Astithas | ImageResource presentationShared(); |
149 | 023f6f1e | Panagiotis Astithas | |
150 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/acroread_shared.png") |
151 | 023f6f1e | Panagiotis Astithas | ImageResource pdfShared(); |
152 | 023f6f1e | Panagiotis Astithas | |
153 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/image_shared.png") |
154 | 023f6f1e | Panagiotis Astithas | ImageResource imageShared(); |
155 | 023f6f1e | Panagiotis Astithas | |
156 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/video2_shared.png") |
157 | 023f6f1e | Panagiotis Astithas | ImageResource videoShared(); |
158 | 023f6f1e | Panagiotis Astithas | |
159 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/knotify_shared.png") |
160 | 023f6f1e | Panagiotis Astithas | ImageResource audioShared(); |
161 | 023f6f1e | Panagiotis Astithas | |
162 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/html_shared.png") |
163 | 023f6f1e | Panagiotis Astithas | ImageResource htmlShared(); |
164 | 023f6f1e | Panagiotis Astithas | |
165 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/txt_shared.png") |
166 | 023f6f1e | Panagiotis Astithas | ImageResource txtShared(); |
167 | 023f6f1e | Panagiotis Astithas | |
168 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/mimetypes/ark2_shared.png") |
169 | 023f6f1e | Panagiotis Astithas | ImageResource zipShared(); |
170 | 023f6f1e | Panagiotis Astithas | |
171 | 023f6f1e | Panagiotis Astithas | } |
172 | 023f6f1e | Panagiotis Astithas | |
173 | 023f6f1e | Panagiotis Astithas | /**
|
174 | 023f6f1e | Panagiotis Astithas | * A label with the number of files in this folder.
|
175 | 023f6f1e | Panagiotis Astithas | */
|
176 | 023f6f1e | Panagiotis Astithas | private HTML countLabel = new HTML(); |
177 | 023f6f1e | Panagiotis Astithas | |
178 | 023f6f1e | Panagiotis Astithas | /**
|
179 | 023f6f1e | Panagiotis Astithas | * The table widget with the file list.
|
180 | 023f6f1e | Panagiotis Astithas | */
|
181 | 023f6f1e | Panagiotis Astithas | private FileTable table = new FileTable(GSS.VISIBLE_FILE_COUNT + 1, 8); |
182 | 023f6f1e | Panagiotis Astithas | |
183 | 023f6f1e | Panagiotis Astithas | /**
|
184 | 023f6f1e | Panagiotis Astithas | * The navigation bar for paginating the results.
|
185 | 023f6f1e | Panagiotis Astithas | */
|
186 | 023f6f1e | Panagiotis Astithas | private HorizontalPanel navBar = new HorizontalPanel(); |
187 | 023f6f1e | Panagiotis Astithas | |
188 | 023f6f1e | Panagiotis Astithas | /**
|
189 | 023f6f1e | Panagiotis Astithas | * The number of files in this folder.
|
190 | 023f6f1e | Panagiotis Astithas | */
|
191 | 023f6f1e | Panagiotis Astithas | int folderFileCount;
|
192 | 023f6f1e | Panagiotis Astithas | |
193 | 023f6f1e | Panagiotis Astithas | /**
|
194 | 023f6f1e | Panagiotis Astithas | * Total folder size
|
195 | 023f6f1e | Panagiotis Astithas | */
|
196 | 023f6f1e | Panagiotis Astithas | long folderTotalSize;
|
197 | 023f6f1e | Panagiotis Astithas | |
198 | 023f6f1e | Panagiotis Astithas | /**
|
199 | 023f6f1e | Panagiotis Astithas | * A cache of the files in the list.
|
200 | 023f6f1e | Panagiotis Astithas | */
|
201 | 023f6f1e | Panagiotis Astithas | private List<FileResource> files; |
202 | 023f6f1e | Panagiotis Astithas | |
203 | 023f6f1e | Panagiotis Astithas | /**
|
204 | 023f6f1e | Panagiotis Astithas | * The widget's image bundle.
|
205 | 023f6f1e | Panagiotis Astithas | */
|
206 | 023f6f1e | Panagiotis Astithas | private final Images images; |
207 | 023f6f1e | Panagiotis Astithas | |
208 | 023f6f1e | Panagiotis Astithas | private String sortingProperty = "name"; |
209 | 023f6f1e | Panagiotis Astithas | |
210 | 023f6f1e | Panagiotis Astithas | private boolean sortingType = true; |
211 | 023f6f1e | Panagiotis Astithas | |
212 | 023f6f1e | Panagiotis Astithas | private HTML nameLabel; |
213 | 023f6f1e | Panagiotis Astithas | |
214 | 023f6f1e | Panagiotis Astithas | private HTML versionLabel; |
215 | 023f6f1e | Panagiotis Astithas | |
216 | 023f6f1e | Panagiotis Astithas | private HTML sizeLabel; |
217 | 023f6f1e | Panagiotis Astithas | |
218 | 023f6f1e | Panagiotis Astithas | private HTML dateLabel; |
219 | 023f6f1e | Panagiotis Astithas | |
220 | 023f6f1e | Panagiotis Astithas | private HTML ownerLabel; |
221 | 023f6f1e | Panagiotis Astithas | |
222 | 023f6f1e | Panagiotis Astithas | private HTML pathLabel; |
223 | 023f6f1e | Panagiotis Astithas | |
224 | 023f6f1e | Panagiotis Astithas | /**
|
225 | 023f6f1e | Panagiotis Astithas | * Construct the file list widget. This entails setting up the widget
|
226 | 023f6f1e | Panagiotis Astithas | * layout, fetching the number of files in the current folder from the
|
227 | 023f6f1e | Panagiotis Astithas | * server and filling the local file cache of displayed files with data from
|
228 | 023f6f1e | Panagiotis Astithas | * the server, as well.
|
229 | 023f6f1e | Panagiotis Astithas | *
|
230 | 023f6f1e | Panagiotis Astithas | * @param _images
|
231 | 023f6f1e | Panagiotis Astithas | */
|
232 | 023f6f1e | Panagiotis Astithas | public FileList(Images _images) {
|
233 | 023f6f1e | Panagiotis Astithas | images = _images; |
234 | 023f6f1e | Panagiotis Astithas | |
235 | 023f6f1e | Panagiotis Astithas | prevButton.addClickHandler(this);
|
236 | 023f6f1e | Panagiotis Astithas | nextButton.addClickHandler(this);
|
237 | 023f6f1e | Panagiotis Astithas | |
238 | 023f6f1e | Panagiotis Astithas | contextMenu = new DnDSimpleFocusPanel(new HTML(AbstractImagePrototype.create(images.fileContextMenu()).getHTML())); |
239 | 023f6f1e | Panagiotis Astithas | GSS.get().getDragController().makeDraggable(contextMenu); |
240 | 023f6f1e | Panagiotis Astithas | |
241 | 023f6f1e | Panagiotis Astithas | // Setup the table.
|
242 | 023f6f1e | Panagiotis Astithas | table.setCellSpacing(0);
|
243 | 023f6f1e | Panagiotis Astithas | table.setCellPadding(2);
|
244 | 023f6f1e | Panagiotis Astithas | table.setWidth("100%");
|
245 | 023f6f1e | Panagiotis Astithas | table.addClickHandler(new ClickHandler() {
|
246 | 023f6f1e | Panagiotis Astithas | |
247 | 023f6f1e | Panagiotis Astithas | @Override
|
248 | 023f6f1e | Panagiotis Astithas | public void onClick(ClickEvent event) { |
249 | 023f6f1e | Panagiotis Astithas | Cell cell = table.getCellForEvent(event); |
250 | 023f6f1e | Panagiotis Astithas | GWT.log("row clicked:"+cell.getRowIndex(), null); |
251 | 023f6f1e | Panagiotis Astithas | onRowClicked(cell.getRowIndex(), true);
|
252 | 023f6f1e | Panagiotis Astithas | } |
253 | 023f6f1e | Panagiotis Astithas | }); |
254 | 023f6f1e | Panagiotis Astithas | // Create the 'navigation' bar at the upper-right.
|
255 | 023f6f1e | Panagiotis Astithas | HorizontalPanel innerNavBar = new HorizontalPanel();
|
256 | 023f6f1e | Panagiotis Astithas | innerNavBar.setStyleName("gss-ListNavBar");
|
257 | 023f6f1e | Panagiotis Astithas | innerNavBar.setSpacing(8);
|
258 | 023f6f1e | Panagiotis Astithas | innerNavBar.add(prevButton); |
259 | 023f6f1e | Panagiotis Astithas | innerNavBar.add(countLabel); |
260 | 023f6f1e | Panagiotis Astithas | innerNavBar.add(nextButton); |
261 | 023f6f1e | Panagiotis Astithas | navBar.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); |
262 | 023f6f1e | Panagiotis Astithas | navBar.add(innerNavBar); |
263 | 023f6f1e | Panagiotis Astithas | navBar.setWidth("100%");
|
264 | 023f6f1e | Panagiotis Astithas | |
265 | 023f6f1e | Panagiotis Astithas | initWidget(table); |
266 | 023f6f1e | Panagiotis Astithas | setStyleName("gss-List");
|
267 | 023f6f1e | Panagiotis Astithas | |
268 | 023f6f1e | Panagiotis Astithas | initTable(); |
269 | 023f6f1e | Panagiotis Astithas | DeferredCommand.addCommand(new IncrementalCommand() {
|
270 | 023f6f1e | Panagiotis Astithas | |
271 | 023f6f1e | Panagiotis Astithas | @Override
|
272 | 023f6f1e | Panagiotis Astithas | public boolean execute() { |
273 | 023f6f1e | Panagiotis Astithas | return fetchRootFolder();
|
274 | 023f6f1e | Panagiotis Astithas | } |
275 | 023f6f1e | Panagiotis Astithas | }); |
276 | 023f6f1e | Panagiotis Astithas | sinkEvents(Event.ONCONTEXTMENU);
|
277 | 023f6f1e | Panagiotis Astithas | sinkEvents(Event.ONMOUSEUP);
|
278 | 023f6f1e | Panagiotis Astithas | sinkEvents(Event.ONMOUSEDOWN);
|
279 | 023f6f1e | Panagiotis Astithas | sinkEvents(Event.ONCLICK);
|
280 | 023f6f1e | Panagiotis Astithas | sinkEvents(Event.ONKEYDOWN);
|
281 | 023f6f1e | Panagiotis Astithas | sinkEvents(Event.ONDBLCLICK);
|
282 | 023f6f1e | Panagiotis Astithas | GSS.preventIESelection(); |
283 | 023f6f1e | Panagiotis Astithas | } |
284 | 023f6f1e | Panagiotis Astithas | |
285 | 023f6f1e | Panagiotis Astithas | @Override
|
286 | 023f6f1e | Panagiotis Astithas | public void onClick(ClickEvent event) { |
287 | 023f6f1e | Panagiotis Astithas | if(event.getSource() == nextButton){
|
288 | 023f6f1e | Panagiotis Astithas | // Move forward a page.
|
289 | 023f6f1e | Panagiotis Astithas | clearSelectedRows(); |
290 | 023f6f1e | Panagiotis Astithas | startIndex += GSS.VISIBLE_FILE_COUNT; |
291 | 023f6f1e | Panagiotis Astithas | if (startIndex >= folderFileCount)
|
292 | 023f6f1e | Panagiotis Astithas | startIndex -= GSS.VISIBLE_FILE_COUNT; |
293 | 023f6f1e | Panagiotis Astithas | else
|
294 | 023f6f1e | Panagiotis Astithas | update(false);
|
295 | 023f6f1e | Panagiotis Astithas | } else if (event.getSource() == prevButton) { |
296 | 023f6f1e | Panagiotis Astithas | clearSelectedRows(); |
297 | 023f6f1e | Panagiotis Astithas | // Move back a page.
|
298 | 023f6f1e | Panagiotis Astithas | startIndex -= GSS.VISIBLE_FILE_COUNT; |
299 | 023f6f1e | Panagiotis Astithas | if (startIndex < 0) |
300 | 023f6f1e | Panagiotis Astithas | startIndex = 0;
|
301 | 023f6f1e | Panagiotis Astithas | else
|
302 | 023f6f1e | Panagiotis Astithas | update(false);
|
303 | 023f6f1e | Panagiotis Astithas | } |
304 | 023f6f1e | Panagiotis Astithas | } |
305 | 023f6f1e | Panagiotis Astithas | |
306 | 023f6f1e | Panagiotis Astithas | |
307 | 023f6f1e | Panagiotis Astithas | @Override
|
308 | 023f6f1e | Panagiotis Astithas | public void onBrowserEvent(Event event) { |
309 | 023f6f1e | Panagiotis Astithas | if (DOM.eventGetType(event) == Event.ONMOUSEDOWN && DOM.eventGetButton(event) == NativeEvent.BUTTON_RIGHT){ |
310 | 023f6f1e | Panagiotis Astithas | if (DOM.eventGetCtrlKey(event))
|
311 | 023f6f1e | Panagiotis Astithas | clickControl = true;
|
312 | 023f6f1e | Panagiotis Astithas | else
|
313 | 023f6f1e | Panagiotis Astithas | clickControl = false;
|
314 | 023f6f1e | Panagiotis Astithas | if (DOM.eventGetShiftKey(event)) {
|
315 | 023f6f1e | Panagiotis Astithas | clickShift = true;
|
316 | 023f6f1e | Panagiotis Astithas | if (selectedRows.size() == 1) |
317 | 023f6f1e | Panagiotis Astithas | firstShift = selectedRows.get(0) - startIndex;
|
318 | 023f6f1e | Panagiotis Astithas | //event.preventDefault();
|
319 | 023f6f1e | Panagiotis Astithas | } else {
|
320 | 023f6f1e | Panagiotis Astithas | clickShift = false;
|
321 | 023f6f1e | Panagiotis Astithas | firstShift = -1;
|
322 | 023f6f1e | Panagiotis Astithas | //event.preventDefault();
|
323 | 023f6f1e | Panagiotis Astithas | } |
324 | 023f6f1e | Panagiotis Astithas | int ri = table.getRowForEvent2(event);
|
325 | 023f6f1e | Panagiotis Astithas | if(ri != -1) |
326 | 023f6f1e | Panagiotis Astithas | if(!selectedRows.contains(ri-1)) |
327 | 023f6f1e | Panagiotis Astithas | onRowClicked(ri, false);
|
328 | 023f6f1e | Panagiotis Astithas | } |
329 | 023f6f1e | Panagiotis Astithas | |
330 | 023f6f1e | Panagiotis Astithas | if (files == null || files.size() == 0) { |
331 | 023f6f1e | Panagiotis Astithas | if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && selectedRows.size() == 0) { |
332 | 023f6f1e | Panagiotis Astithas | FileContextMenu fm = new FileContextMenu(images, false, true); |
333 | 023f6f1e | Panagiotis Astithas | fm.onEmptyEvent(event); |
334 | 023f6f1e | Panagiotis Astithas | } |
335 | 023f6f1e | Panagiotis Astithas | return;
|
336 | 023f6f1e | Panagiotis Astithas | } |
337 | 023f6f1e | Panagiotis Astithas | if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && selectedRows.size() != 0) { |
338 | 023f6f1e | Panagiotis Astithas | FileContextMenu fm = new FileContextMenu(images, false, false); |
339 | 023f6f1e | Panagiotis Astithas | fm.onEvent(event); |
340 | 023f6f1e | Panagiotis Astithas | } else if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && selectedRows.size() == 0) { |
341 | 023f6f1e | Panagiotis Astithas | FileContextMenu fm = new FileContextMenu(images, false, true); |
342 | 023f6f1e | Panagiotis Astithas | fm.onEmptyEvent(event); |
343 | 023f6f1e | Panagiotis Astithas | } else if (DOM.eventGetType(event) == Event.ONDBLCLICK) |
344 | 023f6f1e | Panagiotis Astithas | if (getSelectedFiles().size() == 1) { |
345 | 023f6f1e | Panagiotis Astithas | GSS app = GSS.get(); |
346 | 023f6f1e | Panagiotis Astithas | FileResource file = getSelectedFiles().get(0);
|
347 | 023f6f1e | Panagiotis Astithas | String dateString = RestCommand.getDate();
|
348 | 023f6f1e | Panagiotis Astithas | String resource = file.getUri().substring(app.getApiPath().length() - 1, file.getUri().length()); |
349 | 023f6f1e | Panagiotis Astithas | String sig = app.getCurrentUserResource().getUsername() + " " + |
350 | 023f6f1e | Panagiotis Astithas | RestCommand.calculateSig("GET", dateString, resource,
|
351 | 023f6f1e | Panagiotis Astithas | RestCommand.base64decode(app.getToken())); |
352 | 023f6f1e | Panagiotis Astithas | Window.open(file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date=" + URL.encodeComponent(dateString), "_blank", ""); |
353 | 023f6f1e | Panagiotis Astithas | event.preventDefault(); |
354 | 023f6f1e | Panagiotis Astithas | return;
|
355 | 023f6f1e | Panagiotis Astithas | } |
356 | 023f6f1e | Panagiotis Astithas | if (DOM.eventGetType(event) == Event.ONCLICK) { |
357 | 023f6f1e | Panagiotis Astithas | if (DOM.eventGetCtrlKey(event))
|
358 | 023f6f1e | Panagiotis Astithas | clickControl = true;
|
359 | 023f6f1e | Panagiotis Astithas | else
|
360 | 023f6f1e | Panagiotis Astithas | clickControl = false;
|
361 | 023f6f1e | Panagiotis Astithas | if (DOM.eventGetShiftKey(event)) {
|
362 | 023f6f1e | Panagiotis Astithas | clickShift = true;
|
363 | 023f6f1e | Panagiotis Astithas | if (selectedRows.size() == 1) |
364 | 023f6f1e | Panagiotis Astithas | firstShift = selectedRows.get(0) - startIndex;
|
365 | 023f6f1e | Panagiotis Astithas | //event.preventDefault();
|
366 | 023f6f1e | Panagiotis Astithas | } else {
|
367 | 023f6f1e | Panagiotis Astithas | clickShift = false;
|
368 | 023f6f1e | Panagiotis Astithas | firstShift = -1;
|
369 | 023f6f1e | Panagiotis Astithas | //event.preventDefault();
|
370 | 023f6f1e | Panagiotis Astithas | } |
371 | 023f6f1e | Panagiotis Astithas | } |
372 | 023f6f1e | Panagiotis Astithas | super.onBrowserEvent(event);
|
373 | 023f6f1e | Panagiotis Astithas | } |
374 | 023f6f1e | Panagiotis Astithas | |
375 | 023f6f1e | Panagiotis Astithas | /**
|
376 | 023f6f1e | Panagiotis Astithas | * Retrieve the root folder for the current user.
|
377 | 023f6f1e | Panagiotis Astithas | *
|
378 | 023f6f1e | Panagiotis Astithas | * @return true if the retrieval was successful
|
379 | 023f6f1e | Panagiotis Astithas | */
|
380 | 023f6f1e | Panagiotis Astithas | protected boolean fetchRootFolder() { |
381 | 023f6f1e | Panagiotis Astithas | UserResource user = GSS.get().getCurrentUserResource(); |
382 | 023f6f1e | Panagiotis Astithas | if (user == null) |
383 | 023f6f1e | Panagiotis Astithas | return !DONE;
|
384 | 023f6f1e | Panagiotis Astithas | // Update cache and clear selection.
|
385 | 023f6f1e | Panagiotis Astithas | updateFileCache(true);
|
386 | 023f6f1e | Panagiotis Astithas | return DONE;
|
387 | 023f6f1e | Panagiotis Astithas | } |
388 | 023f6f1e | Panagiotis Astithas | |
389 | 023f6f1e | Panagiotis Astithas | private void onRowClicked(int row, boolean toggleSelection) { |
390 | 023f6f1e | Panagiotis Astithas | // Select the row that was clicked (-1 to account for header row).
|
391 | 023f6f1e | Panagiotis Astithas | if (row > folderFileCount)
|
392 | 023f6f1e | Panagiotis Astithas | return;
|
393 | 023f6f1e | Panagiotis Astithas | if (clickShift) {
|
394 | 023f6f1e | Panagiotis Astithas | GWT.log("Row is: " + row + " fs: " + firstShift, null); |
395 | 023f6f1e | Panagiotis Astithas | if (firstShift == -1) |
396 | 023f6f1e | Panagiotis Astithas | firstShift = row; |
397 | 023f6f1e | Panagiotis Astithas | else if (row > firstShift) { |
398 | 023f6f1e | Panagiotis Astithas | clearSelectedRows(); |
399 | 023f6f1e | Panagiotis Astithas | for (int i = firstShift; i < row; i++) { |
400 | 023f6f1e | Panagiotis Astithas | selectedRows.add(startIndex + i); |
401 | 023f6f1e | Panagiotis Astithas | styleRow(i, true);
|
402 | 023f6f1e | Panagiotis Astithas | } |
403 | 023f6f1e | Panagiotis Astithas | GSS.get().setCurrentSelection(getSelectedFiles()); |
404 | 023f6f1e | Panagiotis Astithas | contextMenu.setFiles(getSelectedFiles()); |
405 | 023f6f1e | Panagiotis Astithas | makeRowDraggable(row); |
406 | 023f6f1e | Panagiotis Astithas | } else if (row != -1 && row == firstShift) { |
407 | 023f6f1e | Panagiotis Astithas | selectedRows.add(row - 1);
|
408 | 023f6f1e | Panagiotis Astithas | styleRow(row, true);
|
409 | 023f6f1e | Panagiotis Astithas | styleRow(row - 1, true); |
410 | 023f6f1e | Panagiotis Astithas | GSS.get().setCurrentSelection(getSelectedFiles()); |
411 | 023f6f1e | Panagiotis Astithas | contextMenu.setFiles(getSelectedFiles()); |
412 | 023f6f1e | Panagiotis Astithas | makeRowDraggable(row); |
413 | 023f6f1e | Panagiotis Astithas | } else if (row < firstShift) { |
414 | 023f6f1e | Panagiotis Astithas | GWT.log("Row is:" + row + " fs:" + firstShift, null); |
415 | 023f6f1e | Panagiotis Astithas | clearSelectedRows(); |
416 | 023f6f1e | Panagiotis Astithas | |
417 | 023f6f1e | Panagiotis Astithas | for (int i = firstShift; i >= row - 1; i--) { |
418 | 023f6f1e | Panagiotis Astithas | selectedRows.add(startIndex + i); |
419 | 023f6f1e | Panagiotis Astithas | styleRow(i, true);
|
420 | 023f6f1e | Panagiotis Astithas | } |
421 | 023f6f1e | Panagiotis Astithas | GSS.get().setCurrentSelection(getSelectedFiles()); |
422 | 023f6f1e | Panagiotis Astithas | makeRowDraggable(row); |
423 | 023f6f1e | Panagiotis Astithas | contextMenu.setFiles(getSelectedFiles()); |
424 | 023f6f1e | Panagiotis Astithas | } |
425 | 023f6f1e | Panagiotis Astithas | } else if (row > 0) |
426 | 023f6f1e | Panagiotis Astithas | selectRow(row - 1, toggleSelection);
|
427 | 023f6f1e | Panagiotis Astithas | } |
428 | 023f6f1e | Panagiotis Astithas | |
429 | 023f6f1e | Panagiotis Astithas | /**
|
430 | 023f6f1e | Panagiotis Astithas | * Initializes the table so that it contains enough rows for a full page of
|
431 | 023f6f1e | Panagiotis Astithas | * files.
|
432 | 023f6f1e | Panagiotis Astithas | */
|
433 | 023f6f1e | Panagiotis Astithas | private void initTable() { |
434 | 023f6f1e | Panagiotis Astithas | nameLabel = new HTML("Name"); |
435 | 023f6f1e | Panagiotis Astithas | nameLabel.addClickHandler(new ClickHandler() {
|
436 | 023f6f1e | Panagiotis Astithas | |
437 | 023f6f1e | Panagiotis Astithas | @Override
|
438 | 023f6f1e | Panagiotis Astithas | public void onClick(ClickEvent event) { |
439 | 023f6f1e | Panagiotis Astithas | sortFiles("name");
|
440 | 023f6f1e | Panagiotis Astithas | |
441 | 023f6f1e | Panagiotis Astithas | } |
442 | 023f6f1e | Panagiotis Astithas | |
443 | 023f6f1e | Panagiotis Astithas | }); |
444 | 023f6f1e | Panagiotis Astithas | versionLabel = new HTML("Version"); |
445 | 023f6f1e | Panagiotis Astithas | versionLabel.addClickHandler(new ClickHandler() {
|
446 | 023f6f1e | Panagiotis Astithas | |
447 | 023f6f1e | Panagiotis Astithas | @Override
|
448 | 023f6f1e | Panagiotis Astithas | public void onClick(ClickEvent event) { |
449 | 023f6f1e | Panagiotis Astithas | sortFiles("version");
|
450 | 023f6f1e | Panagiotis Astithas | } |
451 | 023f6f1e | Panagiotis Astithas | |
452 | 023f6f1e | Panagiotis Astithas | }); |
453 | 023f6f1e | Panagiotis Astithas | sizeLabel = new HTML("Size"); |
454 | 023f6f1e | Panagiotis Astithas | sizeLabel.addClickHandler(new ClickHandler() {
|
455 | 023f6f1e | Panagiotis Astithas | |
456 | 023f6f1e | Panagiotis Astithas | @Override
|
457 | 023f6f1e | Panagiotis Astithas | public void onClick(ClickEvent event) { |
458 | 023f6f1e | Panagiotis Astithas | sortFiles("size");
|
459 | 023f6f1e | Panagiotis Astithas | } |
460 | 023f6f1e | Panagiotis Astithas | |
461 | 023f6f1e | Panagiotis Astithas | }); |
462 | 023f6f1e | Panagiotis Astithas | dateLabel = new HTML("Last modified"); |
463 | 023f6f1e | Panagiotis Astithas | dateLabel.addClickHandler(new ClickHandler() {
|
464 | 023f6f1e | Panagiotis Astithas | |
465 | 023f6f1e | Panagiotis Astithas | @Override
|
466 | 023f6f1e | Panagiotis Astithas | public void onClick(ClickEvent event) { |
467 | 023f6f1e | Panagiotis Astithas | sortFiles("date");
|
468 | 023f6f1e | Panagiotis Astithas | } |
469 | 023f6f1e | Panagiotis Astithas | |
470 | 023f6f1e | Panagiotis Astithas | }); |
471 | 023f6f1e | Panagiotis Astithas | ownerLabel = new HTML("Owner"); |
472 | 023f6f1e | Panagiotis Astithas | ownerLabel.addClickHandler(new ClickHandler() {
|
473 | 023f6f1e | Panagiotis Astithas | |
474 | 023f6f1e | Panagiotis Astithas | @Override
|
475 | 023f6f1e | Panagiotis Astithas | public void onClick(ClickEvent event) { |
476 | 023f6f1e | Panagiotis Astithas | sortFiles("owner");
|
477 | 023f6f1e | Panagiotis Astithas | } |
478 | 023f6f1e | Panagiotis Astithas | |
479 | 023f6f1e | Panagiotis Astithas | }); |
480 | 023f6f1e | Panagiotis Astithas | pathLabel = new HTML("Path"); |
481 | 023f6f1e | Panagiotis Astithas | pathLabel.addClickHandler(new ClickHandler() {
|
482 | 023f6f1e | Panagiotis Astithas | |
483 | 023f6f1e | Panagiotis Astithas | @Override
|
484 | 023f6f1e | Panagiotis Astithas | public void onClick(ClickEvent event) { |
485 | 023f6f1e | Panagiotis Astithas | sortFiles("path");
|
486 | 023f6f1e | Panagiotis Astithas | } |
487 | 023f6f1e | Panagiotis Astithas | |
488 | 023f6f1e | Panagiotis Astithas | }); |
489 | 023f6f1e | Panagiotis Astithas | // Create the header row.
|
490 | 023f6f1e | Panagiotis Astithas | table.setText(0, 0, ""); |
491 | 023f6f1e | Panagiotis Astithas | table.setWidget(0, 1, nameLabel); |
492 | 023f6f1e | Panagiotis Astithas | table.setWidget(0, 2, ownerLabel); |
493 | 023f6f1e | Panagiotis Astithas | table.setWidget(0, 3, pathLabel); |
494 | 023f6f1e | Panagiotis Astithas | table.setWidget(0, 4, versionLabel); |
495 | 023f6f1e | Panagiotis Astithas | table.setWidget(0, 5, sizeLabel); |
496 | 023f6f1e | Panagiotis Astithas | table.setWidget(0, 6, dateLabel); |
497 | 023f6f1e | Panagiotis Astithas | table.setWidget(0, 7, navBar); |
498 | 023f6f1e | Panagiotis Astithas | table.getRowFormatter().setStyleName(0, "gss-ListHeader"); |
499 | 023f6f1e | Panagiotis Astithas | |
500 | 023f6f1e | Panagiotis Astithas | // Initialize the rest of the rows.
|
501 | 023f6f1e | Panagiotis Astithas | for (int i = 1; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) { |
502 | 023f6f1e | Panagiotis Astithas | table.setText(i, 0, ""); |
503 | 023f6f1e | Panagiotis Astithas | table.setText(i, 1, ""); |
504 | 023f6f1e | Panagiotis Astithas | table.setText(i, 2, ""); |
505 | 023f6f1e | Panagiotis Astithas | table.setText(i, 3, ""); |
506 | 023f6f1e | Panagiotis Astithas | table.setText(i, 4, ""); |
507 | 023f6f1e | Panagiotis Astithas | table.setText(i, 5, ""); |
508 | 023f6f1e | Panagiotis Astithas | table.setText(i, 6, ""); |
509 | 023f6f1e | Panagiotis Astithas | table.setText(i, 7, ""); |
510 | 023f6f1e | Panagiotis Astithas | table.getCellFormatter().setWordWrap(i, 0, false); |
511 | 023f6f1e | Panagiotis Astithas | table.getCellFormatter().setWordWrap(i, 1, false); |
512 | 023f6f1e | Panagiotis Astithas | table.getCellFormatter().setWordWrap(i, 2, false); |
513 | 023f6f1e | Panagiotis Astithas | table.getCellFormatter().setWordWrap(i, 3, false); |
514 | 023f6f1e | Panagiotis Astithas | table.getCellFormatter().setWordWrap(i, 4, false); |
515 | 023f6f1e | Panagiotis Astithas | table.getCellFormatter().setWordWrap(i, 5, false); |
516 | 023f6f1e | Panagiotis Astithas | table.getCellFormatter().setWordWrap(i, 6, false); |
517 | 023f6f1e | Panagiotis Astithas | table.getCellFormatter().setWordWrap(i, 7, false); |
518 | 023f6f1e | Panagiotis Astithas | table.getCellFormatter().setHorizontalAlignment(i, 4, HasHorizontalAlignment.ALIGN_CENTER);
|
519 | 023f6f1e | Panagiotis Astithas | } |
520 | 023f6f1e | Panagiotis Astithas | prevButton.setVisible(false);
|
521 | 023f6f1e | Panagiotis Astithas | nextButton.setVisible(false);
|
522 | 023f6f1e | Panagiotis Astithas | } |
523 | 023f6f1e | Panagiotis Astithas | |
524 | 023f6f1e | Panagiotis Astithas | /**
|
525 | 023f6f1e | Panagiotis Astithas | * Selects the given row (relative to the current page).
|
526 | 023f6f1e | Panagiotis Astithas | *
|
527 | 023f6f1e | Panagiotis Astithas | * @param row the row to be selected
|
528 | 023f6f1e | Panagiotis Astithas | */
|
529 | 023f6f1e | Panagiotis Astithas | private void selectRow(final int row, boolean toggleSelection) { |
530 | 023f6f1e | Panagiotis Astithas | if (row < folderFileCount) {
|
531 | 023f6f1e | Panagiotis Astithas | if (clickControl)
|
532 | 023f6f1e | Panagiotis Astithas | if (selectedRows.contains(row) && toggleSelection) {
|
533 | 023f6f1e | Panagiotis Astithas | int i = selectedRows.indexOf(startIndex + row);
|
534 | 023f6f1e | Panagiotis Astithas | selectedRows.remove(i); |
535 | 023f6f1e | Panagiotis Astithas | styleRow(row, false);
|
536 | 023f6f1e | Panagiotis Astithas | } else {
|
537 | 023f6f1e | Panagiotis Astithas | selectedRows.add(startIndex + row); |
538 | 023f6f1e | Panagiotis Astithas | styleRow(row, true);
|
539 | 023f6f1e | Panagiotis Astithas | } |
540 | 023f6f1e | Panagiotis Astithas | else if (selectedRows.size() == 1 && selectedRows.contains(row) && toggleSelection){ |
541 | 023f6f1e | Panagiotis Astithas | clearSelectedRows(); |
542 | 023f6f1e | Panagiotis Astithas | return;
|
543 | 023f6f1e | Panagiotis Astithas | } |
544 | 023f6f1e | Panagiotis Astithas | else {
|
545 | 023f6f1e | Panagiotis Astithas | clearSelectedRows(); |
546 | 023f6f1e | Panagiotis Astithas | selectedRows.add(startIndex + row); |
547 | 023f6f1e | Panagiotis Astithas | styleRow(row, true);
|
548 | 023f6f1e | Panagiotis Astithas | } |
549 | 023f6f1e | Panagiotis Astithas | if (selectedRows.size() == 1) |
550 | 023f6f1e | Panagiotis Astithas | GSS.get().setCurrentSelection(files.get(selectedRows.get(0)));
|
551 | 023f6f1e | Panagiotis Astithas | else if(selectedRows.size() == 0) |
552 | 023f6f1e | Panagiotis Astithas | GSS.get().setCurrentSelection(null);
|
553 | 023f6f1e | Panagiotis Astithas | else
|
554 | 023f6f1e | Panagiotis Astithas | GSS.get().setCurrentSelection(getSelectedFiles()); |
555 | 023f6f1e | Panagiotis Astithas | contextMenu.setFiles(getSelectedFiles()); |
556 | 023f6f1e | Panagiotis Astithas | makeRowDraggable(row+1);
|
557 | 023f6f1e | Panagiotis Astithas | } |
558 | 023f6f1e | Panagiotis Astithas | } |
559 | 023f6f1e | Panagiotis Astithas | |
560 | 023f6f1e | Panagiotis Astithas | public List<FileResource> getSelectedFiles() { |
561 | 023f6f1e | Panagiotis Astithas | List<FileResource> result = new ArrayList(); |
562 | 023f6f1e | Panagiotis Astithas | for (int i : selectedRows) |
563 | 023f6f1e | Panagiotis Astithas | result.add(files.get(i)); |
564 | 023f6f1e | Panagiotis Astithas | return result;
|
565 | 023f6f1e | Panagiotis Astithas | } |
566 | 023f6f1e | Panagiotis Astithas | |
567 | 023f6f1e | Panagiotis Astithas | /**
|
568 | 023f6f1e | Panagiotis Astithas | * Make the specified row look like selected or not, according to the
|
569 | 023f6f1e | Panagiotis Astithas | * <code>selected</code> flag.
|
570 | 023f6f1e | Panagiotis Astithas | *
|
571 | 023f6f1e | Panagiotis Astithas | * @param row
|
572 | 023f6f1e | Panagiotis Astithas | * @param selected
|
573 | 023f6f1e | Panagiotis Astithas | */
|
574 | 023f6f1e | Panagiotis Astithas | void styleRow(final int row, final boolean selected) { |
575 | 023f6f1e | Panagiotis Astithas | if (row != -1 && row >= 0) |
576 | 023f6f1e | Panagiotis Astithas | if (selected)
|
577 | 023f6f1e | Panagiotis Astithas | table.getRowFormatter().addStyleName(row + 1, "gss-SelectedRow"); |
578 | 023f6f1e | Panagiotis Astithas | else
|
579 | 023f6f1e | Panagiotis Astithas | table.getRowFormatter().removeStyleName(row + 1, "gss-SelectedRow"); |
580 | 023f6f1e | Panagiotis Astithas | } |
581 | 023f6f1e | Panagiotis Astithas | |
582 | 023f6f1e | Panagiotis Astithas | /**
|
583 | 023f6f1e | Panagiotis Astithas | * Update the display of the file list.
|
584 | 023f6f1e | Panagiotis Astithas | */
|
585 | 023f6f1e | Panagiotis Astithas | void update(boolean sort) { |
586 | 023f6f1e | Panagiotis Astithas | int count = folderFileCount;
|
587 | 023f6f1e | Panagiotis Astithas | int max = startIndex + GSS.VISIBLE_FILE_COUNT;
|
588 | 023f6f1e | Panagiotis Astithas | if (max > count)
|
589 | 023f6f1e | Panagiotis Astithas | max = count; |
590 | 023f6f1e | Panagiotis Astithas | folderTotalSize = 0;
|
591 | 023f6f1e | Panagiotis Astithas | |
592 | 023f6f1e | Panagiotis Astithas | if (sort && files != null && files.size() != 0) { |
593 | 023f6f1e | Panagiotis Astithas | clearLabels(); |
594 | 023f6f1e | Panagiotis Astithas | clearSelectedRows(); |
595 | 023f6f1e | Panagiotis Astithas | |
596 | 023f6f1e | Panagiotis Astithas | Collections.sort(files, new Comparator<FileResource>() { |
597 | 023f6f1e | Panagiotis Astithas | |
598 | 023f6f1e | Panagiotis Astithas | @Override
|
599 | 023f6f1e | Panagiotis Astithas | public int compare(FileResource arg0, FileResource arg1) { |
600 | 023f6f1e | Panagiotis Astithas | AbstractImagePrototype descPrototype = AbstractImagePrototype.create(images.desc()); |
601 | 023f6f1e | Panagiotis Astithas | AbstractImagePrototype ascPrototype = AbstractImagePrototype.create(images.asc()); |
602 | 023f6f1e | Panagiotis Astithas | if (sortingType)
|
603 | 023f6f1e | Panagiotis Astithas | if (sortingProperty.equals("version")) { |
604 | 023f6f1e | Panagiotis Astithas | versionLabel.setHTML("Version " + descPrototype.getHTML());
|
605 | 023f6f1e | Panagiotis Astithas | return arg0.getVersion().compareTo(arg1.getVersion());
|
606 | 023f6f1e | Panagiotis Astithas | } else if (sortingProperty.equals("owner")) { |
607 | 023f6f1e | Panagiotis Astithas | ownerLabel.setHTML("Owner " + descPrototype.getHTML());
|
608 | 023f6f1e | Panagiotis Astithas | return arg0.getOwner().compareTo(arg1.getOwner());
|
609 | 023f6f1e | Panagiotis Astithas | } else if (sortingProperty.equals("date")) { |
610 | 023f6f1e | Panagiotis Astithas | dateLabel.setHTML("Date modified " + descPrototype.getHTML());
|
611 | 023f6f1e | Panagiotis Astithas | return arg0.getModificationDate().compareTo(arg1.getModificationDate());
|
612 | 023f6f1e | Panagiotis Astithas | } else if (sortingProperty.equals("size")) { |
613 | 023f6f1e | Panagiotis Astithas | sizeLabel.setHTML("Size " + descPrototype.getHTML());
|
614 | 023f6f1e | Panagiotis Astithas | return arg0.getContentLength().compareTo(arg1.getContentLength());
|
615 | 023f6f1e | Panagiotis Astithas | } else if (sortingProperty.equals("name")) { |
616 | 023f6f1e | Panagiotis Astithas | nameLabel.setHTML("Name " + descPrototype.getHTML());
|
617 | 023f6f1e | Panagiotis Astithas | return arg0.getName().compareTo(arg1.getName());
|
618 | 023f6f1e | Panagiotis Astithas | } else if (sortingProperty.equals("path")) { |
619 | 023f6f1e | Panagiotis Astithas | pathLabel.setHTML("Path " + descPrototype.getHTML());
|
620 | 023f6f1e | Panagiotis Astithas | return arg0.getUri().compareTo(arg1.getUri());
|
621 | 023f6f1e | Panagiotis Astithas | } else {
|
622 | 023f6f1e | Panagiotis Astithas | nameLabel.setHTML("Name " + descPrototype.getHTML());
|
623 | 023f6f1e | Panagiotis Astithas | return arg0.getName().compareTo(arg1.getName());
|
624 | 023f6f1e | Panagiotis Astithas | } |
625 | 023f6f1e | Panagiotis Astithas | else if (sortingProperty.equals("version")) { |
626 | 023f6f1e | Panagiotis Astithas | versionLabel.setHTML("Version " + ascPrototype.getHTML());
|
627 | 023f6f1e | Panagiotis Astithas | return arg1.getVersion().compareTo(arg0.getVersion());
|
628 | 023f6f1e | Panagiotis Astithas | } else if (sortingProperty.equals("owner")) { |
629 | 023f6f1e | Panagiotis Astithas | ownerLabel.setHTML("Owner " + ascPrototype.getHTML());
|
630 | 023f6f1e | Panagiotis Astithas | return arg1.getOwner().compareTo(arg0.getOwner());
|
631 | 023f6f1e | Panagiotis Astithas | } else if (sortingProperty.equals("date")) { |
632 | 023f6f1e | Panagiotis Astithas | dateLabel.setHTML("Date modified " + ascPrototype.getHTML());
|
633 | 023f6f1e | Panagiotis Astithas | return arg1.getModificationDate().compareTo(arg0.getModificationDate());
|
634 | 023f6f1e | Panagiotis Astithas | } else if (sortingProperty.equals("size")) { |
635 | 023f6f1e | Panagiotis Astithas | sizeLabel.setHTML("Size " + ascPrototype.getHTML());
|
636 | 023f6f1e | Panagiotis Astithas | return arg1.getContentLength().compareTo(arg0.getContentLength());
|
637 | 023f6f1e | Panagiotis Astithas | } else if (sortingProperty.equals("name")) { |
638 | 023f6f1e | Panagiotis Astithas | nameLabel.setHTML("Name " + ascPrototype.getHTML());
|
639 | 023f6f1e | Panagiotis Astithas | return arg1.getName().compareTo(arg0.getName());
|
640 | 023f6f1e | Panagiotis Astithas | } else if (sortingProperty.equals("path")) { |
641 | 023f6f1e | Panagiotis Astithas | pathLabel.setHTML("Path " + ascPrototype.getHTML());
|
642 | 023f6f1e | Panagiotis Astithas | return arg1.getUri().compareTo(arg0.getUri());
|
643 | 023f6f1e | Panagiotis Astithas | } else {
|
644 | 023f6f1e | Panagiotis Astithas | nameLabel.setHTML("Name " + ascPrototype.getHTML());
|
645 | 023f6f1e | Panagiotis Astithas | return arg1.getName().compareTo(arg0.getName());
|
646 | 023f6f1e | Panagiotis Astithas | } |
647 | 023f6f1e | Panagiotis Astithas | } |
648 | 023f6f1e | Panagiotis Astithas | |
649 | 023f6f1e | Panagiotis Astithas | }); |
650 | 023f6f1e | Panagiotis Astithas | } |
651 | 023f6f1e | Panagiotis Astithas | |
652 | 023f6f1e | Panagiotis Astithas | |
653 | 023f6f1e | Panagiotis Astithas | // Show the selected files.
|
654 | 023f6f1e | Panagiotis Astithas | int i = 1; |
655 | 023f6f1e | Panagiotis Astithas | for (; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) { |
656 | 023f6f1e | Panagiotis Astithas | // Don't read past the end.
|
657 | 023f6f1e | Panagiotis Astithas | // if (i > folderFileCount)
|
658 | 023f6f1e | Panagiotis Astithas | // break;
|
659 | 023f6f1e | Panagiotis Astithas | if (startIndex + i > folderFileCount)
|
660 | 023f6f1e | Panagiotis Astithas | break;
|
661 | 023f6f1e | Panagiotis Astithas | // Add a new row to the table, then set each of its columns to the
|
662 | 023f6f1e | Panagiotis Astithas | // proper values.
|
663 | 023f6f1e | Panagiotis Astithas | FileResource file = files.get(startIndex + i - 1);
|
664 | 023f6f1e | Panagiotis Astithas | table.setWidget(i, 0, getFileIcon(file).createImage());
|
665 | 023f6f1e | Panagiotis Astithas | table.getRowFormatter().addStyleName(i, "gss-fileRow");
|
666 | 023f6f1e | Panagiotis Astithas | |
667 | 023f6f1e | Panagiotis Astithas | //add view image link for image files
|
668 | 023f6f1e | Panagiotis Astithas | String contentType = file.getContentType();
|
669 | 023f6f1e | Panagiotis Astithas | if (contentType.endsWith("png") || contentType.endsWith("gif") || contentType.endsWith("jpeg") ) |
670 | 023f6f1e | Panagiotis Astithas | table.setHTML(i, 1, file.getName() + " <a href='" + |
671 | 023f6f1e | Panagiotis Astithas | GSS.get().getTopPanel().getFileMenu().getDownloadURL(file) + |
672 | 023f6f1e | Panagiotis Astithas | "' title='" + file.getName() + "' rel='lytebox[p]' " + |
673 | 023f6f1e | Panagiotis Astithas | "onclick='myLytebox.start(this, false, false)'>" +
|
674 | 023f6f1e | Panagiotis Astithas | "(view)" + "</a>"); |
675 | 023f6f1e | Panagiotis Astithas | else
|
676 | 023f6f1e | Panagiotis Astithas | table.setHTML(i, 1, file.getName());
|
677 | ce2716a9 | Natasa Kapravelou | |
678 | ce2716a9 | Natasa Kapravelou | if(GSS.get().findUserFullName(file.getOwner()) == null){ |
679 | ce2716a9 | Natasa Kapravelou | GetUserCommand guc = new GetUserCommand(file.getOwner());
|
680 | ce2716a9 | Natasa Kapravelou | guc.execute(); |
681 | ce2716a9 | Natasa Kapravelou | GSS.get().putUserToMap(file.getOwner(), file.getOwner()); |
682 | ce2716a9 | Natasa Kapravelou | } |
683 | ce2716a9 | Natasa Kapravelou | table.setText(i, 2, GSS.get().findUserFullName(file.getOwner()));
|
684 | 023f6f1e | Panagiotis Astithas | table.setText(i, 3, file.getPath());
|
685 | 023f6f1e | Panagiotis Astithas | table.setText(i, 4, String.valueOf(file.getVersion())); |
686 | 023f6f1e | Panagiotis Astithas | table.setText(i, 5, String.valueOf(file.getFileSizeAsString())); |
687 | 023f6f1e | Panagiotis Astithas | final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a"); |
688 | 023f6f1e | Panagiotis Astithas | table.setText(i, 6, formatter.format(file.getModificationDate()));
|
689 | 023f6f1e | Panagiotis Astithas | folderTotalSize += file.getContentLength(); |
690 | 023f6f1e | Panagiotis Astithas | } |
691 | 023f6f1e | Panagiotis Astithas | |
692 | 023f6f1e | Panagiotis Astithas | // Clear any remaining slots.
|
693 | 023f6f1e | Panagiotis Astithas | for (; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) { |
694 | 023f6f1e | Panagiotis Astithas | table.setHTML(i, 0, " "); |
695 | 023f6f1e | Panagiotis Astithas | table.setHTML(i, 1, " "); |
696 | 023f6f1e | Panagiotis Astithas | table.setHTML(i, 2, " "); |
697 | 023f6f1e | Panagiotis Astithas | table.setHTML(i, 3, " "); |
698 | 023f6f1e | Panagiotis Astithas | table.setHTML(i, 4, " "); |
699 | 023f6f1e | Panagiotis Astithas | table.setHTML(i, 5, " "); |
700 | 023f6f1e | Panagiotis Astithas | table.setHTML(i, 6, " "); |
701 | 023f6f1e | Panagiotis Astithas | table.setHTML(i, 7, " "); |
702 | 023f6f1e | Panagiotis Astithas | } |
703 | 023f6f1e | Panagiotis Astithas | |
704 | 023f6f1e | Panagiotis Astithas | if (folderFileCount == 0) { |
705 | 023f6f1e | Panagiotis Astithas | showingStats = "no files";
|
706 | 023f6f1e | Panagiotis Astithas | prevButton.setVisible(false);
|
707 | 023f6f1e | Panagiotis Astithas | nextButton.setVisible(false);
|
708 | 023f6f1e | Panagiotis Astithas | } else if (folderFileCount < GSS.VISIBLE_FILE_COUNT) { |
709 | 023f6f1e | Panagiotis Astithas | if (folderFileCount == 1) |
710 | 023f6f1e | Panagiotis Astithas | showingStats = "1 file";
|
711 | 023f6f1e | Panagiotis Astithas | else
|
712 | 023f6f1e | Panagiotis Astithas | showingStats = folderFileCount + " files";
|
713 | 023f6f1e | Panagiotis Astithas | showingStats += " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")"; |
714 | 023f6f1e | Panagiotis Astithas | prevButton.setVisible(false);
|
715 | 023f6f1e | Panagiotis Astithas | nextButton.setVisible(false);
|
716 | 023f6f1e | Panagiotis Astithas | } else {
|
717 | 023f6f1e | Panagiotis Astithas | showingStats = "" + (startIndex + 1) + " - " + max + " of " + count + " files" + " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")"; |
718 | 023f6f1e | Panagiotis Astithas | prevButton.setVisible(startIndex != 0);
|
719 | 023f6f1e | Panagiotis Astithas | nextButton.setVisible(startIndex + GSS.VISIBLE_FILE_COUNT < count); |
720 | 023f6f1e | Panagiotis Astithas | } |
721 | 023f6f1e | Panagiotis Astithas | updateCurrentlyShowingStats(); |
722 | 023f6f1e | Panagiotis Astithas | |
723 | 023f6f1e | Panagiotis Astithas | } |
724 | 023f6f1e | Panagiotis Astithas | |
725 | 023f6f1e | Panagiotis Astithas | /**
|
726 | 023f6f1e | Panagiotis Astithas | * Return the proper icon based on the MIME type of the file.
|
727 | 023f6f1e | Panagiotis Astithas | *
|
728 | 023f6f1e | Panagiotis Astithas | * @param file
|
729 | 023f6f1e | Panagiotis Astithas | * @return the icon
|
730 | 023f6f1e | Panagiotis Astithas | */
|
731 | 023f6f1e | Panagiotis Astithas | private AbstractImagePrototype getFileIcon(FileResource file) {
|
732 | 023f6f1e | Panagiotis Astithas | String mimetype = file.getContentType();
|
733 | 023f6f1e | Panagiotis Astithas | boolean shared=false; |
734 | 023f6f1e | Panagiotis Astithas | Folders folders = GSS.get().getFolders(); |
735 | 023f6f1e | Panagiotis Astithas | if(folders.getCurrent() != null && folders.isOthersSharedItem(folders.getCurrent())){ |
736 | 023f6f1e | Panagiotis Astithas | DnDTreeItem otherUser = (DnDTreeItem) folders.getUserOfSharedItem(folders.getCurrent()); |
737 | 023f6f1e | Panagiotis Astithas | if(otherUser==null) |
738 | 023f6f1e | Panagiotis Astithas | shared = false;
|
739 | 023f6f1e | Panagiotis Astithas | else{
|
740 | 023f6f1e | Panagiotis Astithas | String uname = otherUser.getOtherUserResource().getUsername();
|
741 | 023f6f1e | Panagiotis Astithas | if(uname==null) |
742 | 023f6f1e | Panagiotis Astithas | uname = ((DnDTreeItem)folders.getSharesItem()).getOthersResource().getUsernameOfUri(otherUser.getOtherUserResource().getUri()); |
743 | 023f6f1e | Panagiotis Astithas | if(uname != null) |
744 | 023f6f1e | Panagiotis Astithas | shared = file.isShared(); |
745 | 023f6f1e | Panagiotis Astithas | } |
746 | 023f6f1e | Panagiotis Astithas | } |
747 | 023f6f1e | Panagiotis Astithas | else
|
748 | 023f6f1e | Panagiotis Astithas | shared = file.isShared(); |
749 | 023f6f1e | Panagiotis Astithas | if (mimetype == null) |
750 | 023f6f1e | Panagiotis Astithas | return shared ? AbstractImagePrototype.create(images.documentShared()) : AbstractImagePrototype.create(images.document());
|
751 | 023f6f1e | Panagiotis Astithas | mimetype = mimetype.toLowerCase(); |
752 | 023f6f1e | Panagiotis Astithas | if (mimetype.startsWith("application/pdf")) |
753 | 023f6f1e | Panagiotis Astithas | return shared ? AbstractImagePrototype.create(images.pdfShared()) : AbstractImagePrototype.create(images.pdf());
|
754 | 023f6f1e | Panagiotis Astithas | else if (mimetype.endsWith("excel")) |
755 | 023f6f1e | Panagiotis Astithas | return shared ? AbstractImagePrototype.create(images.spreadsheetShared()) : AbstractImagePrototype.create(images.spreadsheet());
|
756 | 023f6f1e | Panagiotis Astithas | else if (mimetype.endsWith("msword")) |
757 | 023f6f1e | Panagiotis Astithas | return shared ? AbstractImagePrototype.create(images.wordprocessorShared()) : AbstractImagePrototype.create(images.wordprocessor());
|
758 | 023f6f1e | Panagiotis Astithas | else if (mimetype.endsWith("powerpoint")) |
759 | 023f6f1e | Panagiotis Astithas | return shared ? AbstractImagePrototype.create(images.presentationShared()) : AbstractImagePrototype.create(images.presentation());
|
760 | 023f6f1e | Panagiotis Astithas | else if (mimetype.startsWith("application/zip") || |
761 | 023f6f1e | Panagiotis Astithas | mimetype.startsWith("application/gzip") ||
|
762 | 023f6f1e | Panagiotis Astithas | mimetype.startsWith("application/x-gzip") ||
|
763 | 023f6f1e | Panagiotis Astithas | mimetype.startsWith("application/x-tar") ||
|
764 | 023f6f1e | Panagiotis Astithas | mimetype.startsWith("application/x-gtar"))
|
765 | 023f6f1e | Panagiotis Astithas | return shared ? AbstractImagePrototype.create(images.zipShared()) : AbstractImagePrototype.create(images.zip());
|
766 | 023f6f1e | Panagiotis Astithas | else if (mimetype.startsWith("text/html")) |
767 | 023f6f1e | Panagiotis Astithas | return shared ? AbstractImagePrototype.create(images.htmlShared()) : AbstractImagePrototype.create(images.html());
|
768 | 023f6f1e | Panagiotis Astithas | else if (mimetype.startsWith("text/plain")) |
769 | 023f6f1e | Panagiotis Astithas | return shared ? AbstractImagePrototype.create(images.txtShared()) : AbstractImagePrototype.create(images.txt());
|
770 | 023f6f1e | Panagiotis Astithas | else if (mimetype.startsWith("image/")) |
771 | 023f6f1e | Panagiotis Astithas | return shared ? AbstractImagePrototype.create(images.imageShared()) : AbstractImagePrototype.create(images.image());
|
772 | 023f6f1e | Panagiotis Astithas | else if (mimetype.startsWith("video/")) |
773 | 023f6f1e | Panagiotis Astithas | return shared ? AbstractImagePrototype.create(images.videoShared()) : AbstractImagePrototype.create(images.video());
|
774 | 023f6f1e | Panagiotis Astithas | else if (mimetype.startsWith("audio/")) |
775 | 023f6f1e | Panagiotis Astithas | return shared ? AbstractImagePrototype.create(images.audioShared()) : AbstractImagePrototype.create(images.audio());
|
776 | 023f6f1e | Panagiotis Astithas | return shared ? AbstractImagePrototype.create(images.documentShared()) : AbstractImagePrototype.create(images.document());
|
777 | 023f6f1e | Panagiotis Astithas | } |
778 | 023f6f1e | Panagiotis Astithas | |
779 | 023f6f1e | Panagiotis Astithas | /**
|
780 | 023f6f1e | Panagiotis Astithas | * Update status panel with currently showing file stats.
|
781 | 023f6f1e | Panagiotis Astithas | */
|
782 | 023f6f1e | Panagiotis Astithas | public void updateCurrentlyShowingStats() { |
783 | 023f6f1e | Panagiotis Astithas | GSS.get().getStatusPanel().updateCurrentlyShowing(showingStats); |
784 | 023f6f1e | Panagiotis Astithas | } |
785 | 023f6f1e | Panagiotis Astithas | |
786 | 023f6f1e | Panagiotis Astithas | /**
|
787 | 023f6f1e | Panagiotis Astithas | * Adjust the height of the table by adding and removing rows as necessary.
|
788 | 023f6f1e | Panagiotis Astithas | *
|
789 | 023f6f1e | Panagiotis Astithas | * @param newHeight the new height to reach
|
790 | 023f6f1e | Panagiotis Astithas | */
|
791 | 023f6f1e | Panagiotis Astithas | void resizeTableHeight(final int newHeight) { |
792 | 023f6f1e | Panagiotis Astithas | GWT.log("Panel: " + newHeight + ", parent: " + table.getParent().getOffsetHeight(), null); |
793 | 023f6f1e | Panagiotis Astithas | // Fill the rest with empty slots.
|
794 | 023f6f1e | Panagiotis Astithas | if (newHeight > table.getOffsetHeight())
|
795 | 023f6f1e | Panagiotis Astithas | while (newHeight > table.getOffsetHeight()) {
|
796 | 023f6f1e | Panagiotis Astithas | table.resizeRows(table.getRowCount() + 1);
|
797 | 023f6f1e | Panagiotis Astithas | GWT.log("Table: " + table.getOffsetHeight() + ", rows: " + table.getRowCount(), null); |
798 | 023f6f1e | Panagiotis Astithas | } |
799 | 023f6f1e | Panagiotis Astithas | else
|
800 | 023f6f1e | Panagiotis Astithas | while (newHeight < table.getOffsetHeight()) {
|
801 | 023f6f1e | Panagiotis Astithas | table.resizeRows(table.getRowCount() - 1);
|
802 | 023f6f1e | Panagiotis Astithas | GWT.log("Table: " + table.getOffsetHeight() + ", rows: " + table.getRowCount(), null); |
803 | 023f6f1e | Panagiotis Astithas | } |
804 | 023f6f1e | Panagiotis Astithas | } |
805 | 023f6f1e | Panagiotis Astithas | |
806 | 023f6f1e | Panagiotis Astithas | public void updateFileCache(boolean updateSelectedFolder, final boolean clearSelection) { |
807 | 023f6f1e | Panagiotis Astithas | updateFileCache(updateSelectedFolder, clearSelection, null);
|
808 | 023f6f1e | Panagiotis Astithas | } |
809 | 023f6f1e | Panagiotis Astithas | |
810 | 023f6f1e | Panagiotis Astithas | public void updateFileCache(boolean updateSelectedFolder, final boolean clearSelection, final String newFilename) { |
811 | 023f6f1e | Panagiotis Astithas | if (!updateSelectedFolder && !GSS.get().getFolders().getTrashItem().equals(GSS.get().getFolders().getCurrent()))
|
812 | 023f6f1e | Panagiotis Astithas | updateFileCache(clearSelection); |
813 | 023f6f1e | Panagiotis Astithas | else if (GSS.get().getFolders().getCurrent() != null) { |
814 | 023f6f1e | Panagiotis Astithas | final DnDTreeItem folderItem = (DnDTreeItem) GSS.get().getFolders().getCurrent();
|
815 | 023f6f1e | Panagiotis Astithas | if( folderItem.getFolderResource()!= null){ |
816 | 023f6f1e | Panagiotis Astithas | if(GSS.get().getFolders().isFileItem(folderItem) || GSS.get().getFolders().isMySharedItem(folderItem) || GSS.get().getFolders().isOthersSharedItem(folderItem) ){
|
817 | 023f6f1e | Panagiotis Astithas | update(true);
|
818 | 023f6f1e | Panagiotis Astithas | GetCommand<FolderResource> gf = new GetCommand<FolderResource>(FolderResource.class, folderItem.getFolderResource().getUri(),folderItem.getFolderResource()) {
|
819 | 023f6f1e | Panagiotis Astithas | |
820 | 023f6f1e | Panagiotis Astithas | @Override
|
821 | 023f6f1e | Panagiotis Astithas | public void onComplete() { |
822 | 023f6f1e | Panagiotis Astithas | folderItem.setUserObject(getResult()); |
823 | 023f6f1e | Panagiotis Astithas | if(GSS.get().getFolders().isFileItem(folderItem)){
|
824 | 023f6f1e | Panagiotis Astithas | String[] filePaths = new String[folderItem.getFolderResource().getFilePaths().size()]; |
825 | 023f6f1e | Panagiotis Astithas | int c=0; |
826 | 023f6f1e | Panagiotis Astithas | for(String fpath : folderItem.getFolderResource().getFilePaths()){ |
827 | 023f6f1e | Panagiotis Astithas | filePaths[c] = fpath + "?" + Math.random(); |
828 | 023f6f1e | Panagiotis Astithas | c++; |
829 | 023f6f1e | Panagiotis Astithas | } |
830 | 023f6f1e | Panagiotis Astithas | MultipleHeadCommand<FileResource> getFiles = new MultipleHeadCommand<FileResource>(FileResource.class, filePaths, folderItem.getFolderResource().getFileCache()){
|
831 | 023f6f1e | Panagiotis Astithas | |
832 | 023f6f1e | Panagiotis Astithas | @Override
|
833 | 023f6f1e | Panagiotis Astithas | public void onComplete(){ |
834 | 023f6f1e | Panagiotis Astithas | List<FileResource> result = getResult();
|
835 | 023f6f1e | Panagiotis Astithas | //remove random from path
|
836 | 023f6f1e | Panagiotis Astithas | for(FileResource r : result){
|
837 | 023f6f1e | Panagiotis Astithas | String p = r.getUri();
|
838 | 023f6f1e | Panagiotis Astithas | int indexOfQuestionMark = p.lastIndexOf('?'); |
839 | 023f6f1e | Panagiotis Astithas | if(indexOfQuestionMark>0) |
840 | 023f6f1e | Panagiotis Astithas | r.setUri(p.substring(0, indexOfQuestionMark));
|
841 | 023f6f1e | Panagiotis Astithas | GWT.log("FETCHED:"+r.getLastModifiedSince(), null); |
842 | 023f6f1e | Panagiotis Astithas | } |
843 | 023f6f1e | Panagiotis Astithas | folderItem.getFolderResource().setFiles(result); |
844 | 023f6f1e | Panagiotis Astithas | folderItem.getFolderResource().setFilesExpanded(true);
|
845 | 023f6f1e | Panagiotis Astithas | updateFileCache(clearSelection, newFilename); |
846 | 023f6f1e | Panagiotis Astithas | } |
847 | 023f6f1e | Panagiotis Astithas | |
848 | 023f6f1e | Panagiotis Astithas | @Override
|
849 | 023f6f1e | Panagiotis Astithas | public void onError(String p, Throwable throwable) { |
850 | 023f6f1e | Panagiotis Astithas | if(throwable instanceof RestException) |
851 | 023f6f1e | Panagiotis Astithas | GSS.get().displayError("Unable to retrieve file details:"+((RestException)throwable).getHttpStatusText());
|
852 | 023f6f1e | Panagiotis Astithas | } |
853 | 023f6f1e | Panagiotis Astithas | |
854 | 023f6f1e | Panagiotis Astithas | @Override
|
855 | 023f6f1e | Panagiotis Astithas | public void onError(Throwable t) { |
856 | 023f6f1e | Panagiotis Astithas | GWT.log("", t);
|
857 | 023f6f1e | Panagiotis Astithas | GSS.get().displayError("Unable to fetch files for folder " + folderItem.getFolderResource().getName());
|
858 | 023f6f1e | Panagiotis Astithas | } |
859 | 023f6f1e | Panagiotis Astithas | |
860 | 023f6f1e | Panagiotis Astithas | }; |
861 | 023f6f1e | Panagiotis Astithas | DeferredCommand.addCommand(getFiles); |
862 | 023f6f1e | Panagiotis Astithas | } |
863 | 023f6f1e | Panagiotis Astithas | else
|
864 | 023f6f1e | Panagiotis Astithas | updateFileCache(clearSelection, newFilename); |
865 | 023f6f1e | Panagiotis Astithas | } |
866 | 023f6f1e | Panagiotis Astithas | |
867 | 023f6f1e | Panagiotis Astithas | @Override
|
868 | 023f6f1e | Panagiotis Astithas | public void onError(Throwable t) { |
869 | 023f6f1e | Panagiotis Astithas | GWT.log("", t);
|
870 | 023f6f1e | Panagiotis Astithas | GSS.get().displayError("Unable to fetch folder " + folderItem.getFolderResource().getName());
|
871 | 023f6f1e | Panagiotis Astithas | } |
872 | 023f6f1e | Panagiotis Astithas | }; |
873 | 023f6f1e | Panagiotis Astithas | DeferredCommand.addCommand(gf); |
874 | 023f6f1e | Panagiotis Astithas | } |
875 | 023f6f1e | Panagiotis Astithas | } |
876 | 023f6f1e | Panagiotis Astithas | else if (folderItem.getTrashResource() != null) { |
877 | 023f6f1e | Panagiotis Astithas | GetCommand<TrashResource> gt = new GetCommand<TrashResource>(TrashResource.class, folderItem.getTrashResource().getUri(), null) { |
878 | 023f6f1e | Panagiotis Astithas | |
879 | 023f6f1e | Panagiotis Astithas | @Override
|
880 | 023f6f1e | Panagiotis Astithas | public void onComplete() { |
881 | 023f6f1e | Panagiotis Astithas | folderItem.setUserObject(getResult()); |
882 | 023f6f1e | Panagiotis Astithas | updateFileCache(clearSelection); |
883 | 023f6f1e | Panagiotis Astithas | } |
884 | 023f6f1e | Panagiotis Astithas | |
885 | 023f6f1e | Panagiotis Astithas | @Override
|
886 | 023f6f1e | Panagiotis Astithas | public void onError(Throwable t) { |
887 | 023f6f1e | Panagiotis Astithas | if (t instanceof RestException && (((RestException) t).getHttpStatusCode() == 204 || ((RestException) t).getHttpStatusCode() == 1223)) { |
888 | 023f6f1e | Panagiotis Astithas | folderItem.setUserObject(new TrashResource(folderItem.getTrashResource().getUri()));
|
889 | 023f6f1e | Panagiotis Astithas | updateFileCache(clearSelection); |
890 | 023f6f1e | Panagiotis Astithas | } else {
|
891 | 023f6f1e | Panagiotis Astithas | GWT.log("", t);
|
892 | 023f6f1e | Panagiotis Astithas | GSS.get().displayError("Unable to fetch trash resource");
|
893 | 023f6f1e | Panagiotis Astithas | } |
894 | 023f6f1e | Panagiotis Astithas | } |
895 | 023f6f1e | Panagiotis Astithas | }; |
896 | 023f6f1e | Panagiotis Astithas | DeferredCommand.addCommand(gt); |
897 | 023f6f1e | Panagiotis Astithas | } else if (folderItem.getSharedResource() != null) { |
898 | 023f6f1e | Panagiotis Astithas | GetCommand<SharedResource> gt = new GetCommand<SharedResource>(SharedResource.class, folderItem.getSharedResource().getUri(), null) { |
899 | 023f6f1e | Panagiotis Astithas | |
900 | 023f6f1e | Panagiotis Astithas | @Override
|
901 | 023f6f1e | Panagiotis Astithas | public void onComplete() { |
902 | 023f6f1e | Panagiotis Astithas | folderItem.setUserObject(getResult()); |
903 | 023f6f1e | Panagiotis Astithas | updateFileCache(clearSelection, newFilename); |
904 | 023f6f1e | Panagiotis Astithas | String[] filePaths = new String[folderItem.getSharedResource().getFilePaths().size()]; |
905 | 023f6f1e | Panagiotis Astithas | int c=0; |
906 | 023f6f1e | Panagiotis Astithas | for(String fpath : folderItem.getSharedResource().getFilePaths()){ |
907 | 023f6f1e | Panagiotis Astithas | filePaths[c] = fpath + "?" + Math.random(); |
908 | 023f6f1e | Panagiotis Astithas | c++; |
909 | 023f6f1e | Panagiotis Astithas | } |
910 | 023f6f1e | Panagiotis Astithas | MultipleHeadCommand<FileResource> getFiles = new MultipleHeadCommand<FileResource>(FileResource.class, filePaths, folderItem.getSharedResource().getFileCache()){
|
911 | 023f6f1e | Panagiotis Astithas | |
912 | 023f6f1e | Panagiotis Astithas | @Override
|
913 | 023f6f1e | Panagiotis Astithas | public void onComplete(){ |
914 | 023f6f1e | Panagiotis Astithas | List<FileResource> result = getResult();
|
915 | 023f6f1e | Panagiotis Astithas | //remove random from path
|
916 | 023f6f1e | Panagiotis Astithas | for(FileResource r : result){
|
917 | 023f6f1e | Panagiotis Astithas | String p = r.getUri();
|
918 | 023f6f1e | Panagiotis Astithas | int indexOfQuestionMark = p.lastIndexOf('?'); |
919 | 023f6f1e | Panagiotis Astithas | if(indexOfQuestionMark>0) |
920 | 023f6f1e | Panagiotis Astithas | r.setUri(p.substring(0, indexOfQuestionMark));
|
921 | 023f6f1e | Panagiotis Astithas | GWT.log("FETCHED:"+r.getLastModifiedSince(), null); |
922 | 023f6f1e | Panagiotis Astithas | } |
923 | 023f6f1e | Panagiotis Astithas | folderItem.getSharedResource().setFiles(result); |
924 | 023f6f1e | Panagiotis Astithas | folderItem.getSharedResource().setFilesExpanded(true);
|
925 | 023f6f1e | Panagiotis Astithas | updateFileCache(clearSelection, newFilename); |
926 | 023f6f1e | Panagiotis Astithas | } |
927 | 023f6f1e | Panagiotis Astithas | |
928 | 023f6f1e | Panagiotis Astithas | @Override
|
929 | 023f6f1e | Panagiotis Astithas | public void onError(String p, Throwable throwable) { |
930 | 023f6f1e | Panagiotis Astithas | if(throwable instanceof RestException) |
931 | 023f6f1e | Panagiotis Astithas | GSS.get().displayError("Unable to retrieve file details:"+((RestException)throwable).getHttpStatusText());
|
932 | 023f6f1e | Panagiotis Astithas | } |
933 | 023f6f1e | Panagiotis Astithas | |
934 | 023f6f1e | Panagiotis Astithas | @Override
|
935 | 023f6f1e | Panagiotis Astithas | public void onError(Throwable t) { |
936 | 023f6f1e | Panagiotis Astithas | GWT.log("", t);
|
937 | 023f6f1e | Panagiotis Astithas | GSS.get().displayError("Unable to fetch files for folder " + folderItem.getFolderResource().getName());
|
938 | 023f6f1e | Panagiotis Astithas | } |
939 | 023f6f1e | Panagiotis Astithas | |
940 | 023f6f1e | Panagiotis Astithas | }; |
941 | 023f6f1e | Panagiotis Astithas | DeferredCommand.addCommand(getFiles); |
942 | 023f6f1e | Panagiotis Astithas | } |
943 | 023f6f1e | Panagiotis Astithas | |
944 | 023f6f1e | Panagiotis Astithas | @Override
|
945 | 023f6f1e | Panagiotis Astithas | public void onError(Throwable t) { |
946 | 023f6f1e | Panagiotis Astithas | GWT.log("", t);
|
947 | 023f6f1e | Panagiotis Astithas | GSS.get().displayError("Unable to fetch My Shares resource");
|
948 | 023f6f1e | Panagiotis Astithas | } |
949 | 023f6f1e | Panagiotis Astithas | }; |
950 | 023f6f1e | Panagiotis Astithas | DeferredCommand.addCommand(gt); |
951 | 023f6f1e | Panagiotis Astithas | } else if (folderItem.getOtherUserResource() != null) { |
952 | 023f6f1e | Panagiotis Astithas | GetCommand<OtherUserResource> gt = new GetCommand<OtherUserResource>(OtherUserResource.class, folderItem.getOtherUserResource().getUri(), null) { |
953 | 023f6f1e | Panagiotis Astithas | |
954 | 023f6f1e | Panagiotis Astithas | @Override
|
955 | 023f6f1e | Panagiotis Astithas | public void onComplete() { |
956 | 023f6f1e | Panagiotis Astithas | folderItem.setUserObject(getResult()); |
957 | 023f6f1e | Panagiotis Astithas | updateFileCache(clearSelection, newFilename); |
958 | 023f6f1e | Panagiotis Astithas | String[] filePaths = new String[folderItem.getOtherUserResource().getFilePaths().size()]; |
959 | 023f6f1e | Panagiotis Astithas | int c=0; |
960 | 023f6f1e | Panagiotis Astithas | for(String fpath : folderItem.getOtherUserResource().getFilePaths()){ |
961 | 023f6f1e | Panagiotis Astithas | filePaths[c] = fpath + "?" + Math.random(); |
962 | 023f6f1e | Panagiotis Astithas | c++; |
963 | 023f6f1e | Panagiotis Astithas | } |
964 | 023f6f1e | Panagiotis Astithas | MultipleHeadCommand<FileResource> getFiles = new MultipleHeadCommand<FileResource>(FileResource.class, filePaths, folderItem.getOtherUserResource().getFileCache()){
|
965 | 023f6f1e | Panagiotis Astithas | |
966 | 023f6f1e | Panagiotis Astithas | @Override
|
967 | 023f6f1e | Panagiotis Astithas | public void onComplete(){ |
968 | 023f6f1e | Panagiotis Astithas | List<FileResource> result = getResult();
|
969 | 023f6f1e | Panagiotis Astithas | //remove random from path
|
970 | 023f6f1e | Panagiotis Astithas | for(FileResource r : result){
|
971 | 023f6f1e | Panagiotis Astithas | String p = r.getUri();
|
972 | 023f6f1e | Panagiotis Astithas | int indexOfQuestionMark = p.lastIndexOf('?'); |
973 | 023f6f1e | Panagiotis Astithas | if(indexOfQuestionMark>0) |
974 | 023f6f1e | Panagiotis Astithas | r.setUri(p.substring(0, indexOfQuestionMark));
|
975 | 023f6f1e | Panagiotis Astithas | GWT.log("FETCHED:"+r.getLastModifiedSince(), null); |
976 | 023f6f1e | Panagiotis Astithas | } |
977 | 023f6f1e | Panagiotis Astithas | folderItem.getOtherUserResource().setFiles(result); |
978 | 023f6f1e | Panagiotis Astithas | folderItem.getOtherUserResource().setFilesExpanded(true);
|
979 | 023f6f1e | Panagiotis Astithas | updateFileCache(clearSelection, newFilename); |
980 | 023f6f1e | Panagiotis Astithas | } |
981 | 023f6f1e | Panagiotis Astithas | |
982 | 023f6f1e | Panagiotis Astithas | @Override
|
983 | 023f6f1e | Panagiotis Astithas | public void onError(String p, Throwable throwable) { |
984 | 023f6f1e | Panagiotis Astithas | if(throwable instanceof RestException) |
985 | 023f6f1e | Panagiotis Astithas | GSS.get().displayError("Unable to retrieve file details:"+((RestException)throwable).getHttpStatusText());
|
986 | 023f6f1e | Panagiotis Astithas | } |
987 | 023f6f1e | Panagiotis Astithas | |
988 | 023f6f1e | Panagiotis Astithas | @Override
|
989 | 023f6f1e | Panagiotis Astithas | public void onError(Throwable t) { |
990 | 023f6f1e | Panagiotis Astithas | GWT.log("", t);
|
991 | 023f6f1e | Panagiotis Astithas | GSS.get().displayError("Unable to fetch files for folder " + folderItem.getFolderResource().getName());
|
992 | 023f6f1e | Panagiotis Astithas | } |
993 | 023f6f1e | Panagiotis Astithas | |
994 | 023f6f1e | Panagiotis Astithas | }; |
995 | 023f6f1e | Panagiotis Astithas | DeferredCommand.addCommand(getFiles); |
996 | 023f6f1e | Panagiotis Astithas | } |
997 | 023f6f1e | Panagiotis Astithas | |
998 | 023f6f1e | Panagiotis Astithas | @Override
|
999 | 023f6f1e | Panagiotis Astithas | public void onError(Throwable t) { |
1000 | 023f6f1e | Panagiotis Astithas | GWT.log("", t);
|
1001 | 023f6f1e | Panagiotis Astithas | GSS.get().displayError("Unable to fetch My Shares resource");
|
1002 | 023f6f1e | Panagiotis Astithas | } |
1003 | 023f6f1e | Panagiotis Astithas | }; |
1004 | 023f6f1e | Panagiotis Astithas | DeferredCommand.addCommand(gt); |
1005 | 023f6f1e | Panagiotis Astithas | } |
1006 | 023f6f1e | Panagiotis Astithas | } else
|
1007 | 023f6f1e | Panagiotis Astithas | updateFileCache(clearSelection); |
1008 | 023f6f1e | Panagiotis Astithas | } |
1009 | 023f6f1e | Panagiotis Astithas | |
1010 | 023f6f1e | Panagiotis Astithas | private void updateFileCache(boolean clearSelection) { |
1011 | 023f6f1e | Panagiotis Astithas | updateFileCache(clearSelection, null);
|
1012 | 023f6f1e | Panagiotis Astithas | } |
1013 | 023f6f1e | Panagiotis Astithas | |
1014 | 023f6f1e | Panagiotis Astithas | /**
|
1015 | 023f6f1e | Panagiotis Astithas | * Update the file cache with data from the server.
|
1016 | 023f6f1e | Panagiotis Astithas | *
|
1017 | 023f6f1e | Panagiotis Astithas | * @param userId the ID of the current user
|
1018 | 023f6f1e | Panagiotis Astithas | * @param newFilename the new name of the previously selected file,
|
1019 | 023f6f1e | Panagiotis Astithas | * if a rename operation has taken place
|
1020 | 023f6f1e | Panagiotis Astithas | */
|
1021 | 023f6f1e | Panagiotis Astithas | private void updateFileCache(boolean clearSelection, String newFilename) { |
1022 | 023f6f1e | Panagiotis Astithas | if (clearSelection)
|
1023 | 023f6f1e | Panagiotis Astithas | clearSelectedRows(); |
1024 | 023f6f1e | Panagiotis Astithas | clearLabels(); |
1025 | 023f6f1e | Panagiotis Astithas | startIndex = 0;
|
1026 | 023f6f1e | Panagiotis Astithas | final TreeItem folderItem = GSS.get().getFolders().getCurrent();
|
1027 | 023f6f1e | Panagiotis Astithas | // Validation.
|
1028 | 023f6f1e | Panagiotis Astithas | if (folderItem == null || GSS.get().getFolders().isOthersShared(folderItem)) { |
1029 | 023f6f1e | Panagiotis Astithas | setFiles(new ArrayList<FileResource>()); |
1030 | 023f6f1e | Panagiotis Astithas | update(true);
|
1031 | 023f6f1e | Panagiotis Astithas | return;
|
1032 | 023f6f1e | Panagiotis Astithas | } |
1033 | 023f6f1e | Panagiotis Astithas | if (folderItem instanceof DnDTreeItem) { |
1034 | 023f6f1e | Panagiotis Astithas | DnDTreeItem dnd = (DnDTreeItem) folderItem; |
1035 | 023f6f1e | Panagiotis Astithas | if (dnd.getFolderResource() != null) { |
1036 | 023f6f1e | Panagiotis Astithas | if (GSS.get().getFolders().isTrashItem(dnd))
|
1037 | 023f6f1e | Panagiotis Astithas | setFiles(new ArrayList<FileResource>()); |
1038 | 023f6f1e | Panagiotis Astithas | else
|
1039 | 023f6f1e | Panagiotis Astithas | setFiles(dnd.getFolderResource().getFiles()); |
1040 | 023f6f1e | Panagiotis Astithas | |
1041 | 023f6f1e | Panagiotis Astithas | } else if (dnd.getTrashResource() != null) |
1042 | 023f6f1e | Panagiotis Astithas | setFiles(dnd.getTrashResource().getFiles()); |
1043 | 023f6f1e | Panagiotis Astithas | else if (dnd.getSharedResource() != null) |
1044 | 023f6f1e | Panagiotis Astithas | setFiles(dnd.getSharedResource().getFiles()); |
1045 | 023f6f1e | Panagiotis Astithas | else if (dnd.getOtherUserResource() != null) |
1046 | 023f6f1e | Panagiotis Astithas | setFiles(dnd.getOtherUserResource().getFiles()); |
1047 | 023f6f1e | Panagiotis Astithas | else
|
1048 | 023f6f1e | Panagiotis Astithas | setFiles(dnd.getFolderResource().getFiles()); |
1049 | 023f6f1e | Panagiotis Astithas | update(true);
|
1050 | 023f6f1e | Panagiotis Astithas | |
1051 | 023f6f1e | Panagiotis Astithas | if (!clearSelection && selectedRows.size()==1 && newFilename!=null) { |
1052 | 023f6f1e | Panagiotis Astithas | int row = -1; |
1053 | 023f6f1e | Panagiotis Astithas | for (int i=1; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) { |
1054 | 023f6f1e | Panagiotis Astithas | if (startIndex + i > folderFileCount)
|
1055 | 023f6f1e | Panagiotis Astithas | break;
|
1056 | 023f6f1e | Panagiotis Astithas | FileResource file = files.get(startIndex + i - 1);
|
1057 | 023f6f1e | Panagiotis Astithas | if (newFilename.equals(file.getName())) {
|
1058 | 023f6f1e | Panagiotis Astithas | row = i-1;
|
1059 | 023f6f1e | Panagiotis Astithas | break;
|
1060 | 023f6f1e | Panagiotis Astithas | } |
1061 | 023f6f1e | Panagiotis Astithas | } |
1062 | 023f6f1e | Panagiotis Astithas | clearSelectedRows(); |
1063 | 023f6f1e | Panagiotis Astithas | if (row!=-1) |
1064 | 023f6f1e | Panagiotis Astithas | selectRow(row, true);
|
1065 | 023f6f1e | Panagiotis Astithas | } |
1066 | 023f6f1e | Panagiotis Astithas | } |
1067 | 023f6f1e | Panagiotis Astithas | } |
1068 | 023f6f1e | Panagiotis Astithas | |
1069 | 023f6f1e | Panagiotis Astithas | /**
|
1070 | 023f6f1e | Panagiotis Astithas | * Fill the file cache with data.
|
1071 | 023f6f1e | Panagiotis Astithas | */
|
1072 | 023f6f1e | Panagiotis Astithas | public void setFiles(final List<FileResource> _files) { |
1073 | 023f6f1e | Panagiotis Astithas | if (_files.size() > 0 && !GSS.get().getFolders().isTrash(GSS.get().getFolders().getCurrent())) { |
1074 | 023f6f1e | Panagiotis Astithas | files = new ArrayList<FileResource>(); |
1075 | 023f6f1e | Panagiotis Astithas | for (FileResource fres : _files)
|
1076 | 023f6f1e | Panagiotis Astithas | if (!fres.isDeleted())
|
1077 | 023f6f1e | Panagiotis Astithas | files.add(fres); |
1078 | 023f6f1e | Panagiotis Astithas | } else
|
1079 | 023f6f1e | Panagiotis Astithas | files = _files; |
1080 | 023f6f1e | Panagiotis Astithas | Collections.sort(files, new Comparator<FileResource>() { |
1081 | 023f6f1e | Panagiotis Astithas | |
1082 | 023f6f1e | Panagiotis Astithas | @Override
|
1083 | 023f6f1e | Panagiotis Astithas | public int compare(FileResource arg0, FileResource arg1) { |
1084 | 023f6f1e | Panagiotis Astithas | return arg0.getName().compareTo(arg1.getName());
|
1085 | 023f6f1e | Panagiotis Astithas | } |
1086 | 023f6f1e | Panagiotis Astithas | |
1087 | 023f6f1e | Panagiotis Astithas | }); |
1088 | 023f6f1e | Panagiotis Astithas | folderFileCount = files.size(); |
1089 | 023f6f1e | Panagiotis Astithas | } |
1090 | 023f6f1e | Panagiotis Astithas | |
1091 | 023f6f1e | Panagiotis Astithas | private void sortFiles(final String sortProperty) { |
1092 | 023f6f1e | Panagiotis Astithas | if (sortProperty.equals(sortingProperty))
|
1093 | 023f6f1e | Panagiotis Astithas | sortingType = !sortingType; |
1094 | 023f6f1e | Panagiotis Astithas | else {
|
1095 | 023f6f1e | Panagiotis Astithas | sortingProperty = sortProperty; |
1096 | 023f6f1e | Panagiotis Astithas | sortingType = true;
|
1097 | 023f6f1e | Panagiotis Astithas | } |
1098 | 023f6f1e | Panagiotis Astithas | update(true);
|
1099 | 023f6f1e | Panagiotis Astithas | } |
1100 | 023f6f1e | Panagiotis Astithas | |
1101 | 023f6f1e | Panagiotis Astithas | private void clearLabels() { |
1102 | 023f6f1e | Panagiotis Astithas | nameLabel.setText("Name");
|
1103 | 023f6f1e | Panagiotis Astithas | versionLabel.setText("Version");
|
1104 | 023f6f1e | Panagiotis Astithas | sizeLabel.setText("Size");
|
1105 | 023f6f1e | Panagiotis Astithas | dateLabel.setText("Last modified");
|
1106 | 023f6f1e | Panagiotis Astithas | ownerLabel.setText("Owner");
|
1107 | 023f6f1e | Panagiotis Astithas | pathLabel.setText("Path");
|
1108 | 023f6f1e | Panagiotis Astithas | } |
1109 | 023f6f1e | Panagiotis Astithas | |
1110 | 023f6f1e | Panagiotis Astithas | /**
|
1111 | 023f6f1e | Panagiotis Astithas | * Retrieve the table.
|
1112 | 023f6f1e | Panagiotis Astithas | *
|
1113 | 023f6f1e | Panagiotis Astithas | * @return the table
|
1114 | 023f6f1e | Panagiotis Astithas | */
|
1115 | 023f6f1e | Panagiotis Astithas | Grid getTable() { |
1116 | 023f6f1e | Panagiotis Astithas | return table;
|
1117 | 023f6f1e | Panagiotis Astithas | } |
1118 | 023f6f1e | Panagiotis Astithas | |
1119 | 023f6f1e | Panagiotis Astithas | /**
|
1120 | 023f6f1e | Panagiotis Astithas | * Does the list contains the requested filename
|
1121 | 023f6f1e | Panagiotis Astithas | *
|
1122 | 023f6f1e | Panagiotis Astithas | * @param fileName
|
1123 | 023f6f1e | Panagiotis Astithas | * @return true/false
|
1124 | 023f6f1e | Panagiotis Astithas | */
|
1125 | 023f6f1e | Panagiotis Astithas | public boolean contains(String fileName) { |
1126 | 023f6f1e | Panagiotis Astithas | for (int i = 0; i < files.size(); i++) |
1127 | 023f6f1e | Panagiotis Astithas | if (files.get(i).getName().equals(fileName))
|
1128 | 023f6f1e | Panagiotis Astithas | return true; |
1129 | 023f6f1e | Panagiotis Astithas | return false; |
1130 | 023f6f1e | Panagiotis Astithas | } |
1131 | 023f6f1e | Panagiotis Astithas | |
1132 | 023f6f1e | Panagiotis Astithas | public void clearSelectedRows() { |
1133 | 023f6f1e | Panagiotis Astithas | for (int r : selectedRows) { |
1134 | 023f6f1e | Panagiotis Astithas | int row = r - startIndex;
|
1135 | 023f6f1e | Panagiotis Astithas | styleRow(row, false);
|
1136 | 023f6f1e | Panagiotis Astithas | } |
1137 | 023f6f1e | Panagiotis Astithas | selectedRows.clear(); |
1138 | 023f6f1e | Panagiotis Astithas | Object sel = GSS.get().getCurrentSelection();
|
1139 | 023f6f1e | Panagiotis Astithas | if (sel instanceof FileResource || sel instanceof List) |
1140 | 023f6f1e | Panagiotis Astithas | GSS.get().setCurrentSelection(null);
|
1141 | 023f6f1e | Panagiotis Astithas | } |
1142 | 023f6f1e | Panagiotis Astithas | |
1143 | 023f6f1e | Panagiotis Astithas | /**
|
1144 | 023f6f1e | Panagiotis Astithas | *
|
1145 | 023f6f1e | Panagiotis Astithas | */
|
1146 | 023f6f1e | Panagiotis Astithas | public void selectAllRows() { |
1147 | 023f6f1e | Panagiotis Astithas | clearSelectedRows(); |
1148 | 023f6f1e | Panagiotis Astithas | int count = folderFileCount;
|
1149 | 023f6f1e | Panagiotis Astithas | if (count == 0) |
1150 | 023f6f1e | Panagiotis Astithas | return;
|
1151 | 023f6f1e | Panagiotis Astithas | int max = startIndex + GSS.VISIBLE_FILE_COUNT;
|
1152 | 023f6f1e | Panagiotis Astithas | if (max > count)
|
1153 | 023f6f1e | Panagiotis Astithas | max = count; |
1154 | 023f6f1e | Panagiotis Astithas | int i = 1; |
1155 | 023f6f1e | Panagiotis Astithas | for (; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) { |
1156 | 023f6f1e | Panagiotis Astithas | // Don't read past the end.
|
1157 | 023f6f1e | Panagiotis Astithas | // if (i > folderFileCount)
|
1158 | 023f6f1e | Panagiotis Astithas | // break;
|
1159 | 023f6f1e | Panagiotis Astithas | if (startIndex + i > folderFileCount)
|
1160 | 023f6f1e | Panagiotis Astithas | break;
|
1161 | 023f6f1e | Panagiotis Astithas | selectedRows.add(startIndex + i - 1);
|
1162 | 023f6f1e | Panagiotis Astithas | styleRow(i - 1, true); |
1163 | 023f6f1e | Panagiotis Astithas | } |
1164 | 023f6f1e | Panagiotis Astithas | GSS.get().setCurrentSelection(getSelectedFiles()); |
1165 | 023f6f1e | Panagiotis Astithas | contextMenu.setFiles(getSelectedFiles()); |
1166 | 023f6f1e | Panagiotis Astithas | makeRowDraggable(i-1);
|
1167 | 023f6f1e | Panagiotis Astithas | |
1168 | 023f6f1e | Panagiotis Astithas | } |
1169 | 023f6f1e | Panagiotis Astithas | |
1170 | 023f6f1e | Panagiotis Astithas | private void makeRowDraggable(int row){ |
1171 | 023f6f1e | Panagiotis Astithas | int contextRow = getWidgetRow(contextMenu, table);
|
1172 | 023f6f1e | Panagiotis Astithas | if (contextRow != -1) |
1173 | 023f6f1e | Panagiotis Astithas | table.setWidget(contextRow, 0, getFileIcon(files.get(contextRow - 1)).createImage()); |
1174 | 023f6f1e | Panagiotis Astithas | contextMenu.setWidget(new HTML(getFileIcon(files.get(row - 1)).getHTML())); |
1175 | 023f6f1e | Panagiotis Astithas | table.setWidget(row, 0, contextMenu);
|
1176 | 023f6f1e | Panagiotis Astithas | } |
1177 | 023f6f1e | Panagiotis Astithas | |
1178 | 023f6f1e | Panagiotis Astithas | private int getWidgetRow(Widget widget, Grid grid) { |
1179 | 023f6f1e | Panagiotis Astithas | for (int row = 0; row < grid.getRowCount(); row++) |
1180 | 023f6f1e | Panagiotis Astithas | for (int col = 0; col < grid.getCellCount(row); col++) { |
1181 | 023f6f1e | Panagiotis Astithas | Widget w = table.getWidget(row, col); |
1182 | 023f6f1e | Panagiotis Astithas | if (w == widget)
|
1183 | 023f6f1e | Panagiotis Astithas | return row;
|
1184 | 023f6f1e | Panagiotis Astithas | } |
1185 | 023f6f1e | Panagiotis Astithas | return -1; |
1186 | 023f6f1e | Panagiotis Astithas | } |
1187 | 023f6f1e | Panagiotis Astithas | |
1188 | 023f6f1e | Panagiotis Astithas | |
1189 | 023f6f1e | Panagiotis Astithas | |
1190 | 023f6f1e | Panagiotis Astithas | } |