Revision 08880e98 src/gr/ebs/gss/client/SearchResults.java
b/src/gr/ebs/gss/client/SearchResults.java | ||
---|---|---|
19 | 19 |
package gr.ebs.gss.client; |
20 | 20 |
|
21 | 21 |
|
22 |
import static com.google.gwt.query.client.GQuery.$; |
|
23 |
import gr.ebs.gss.client.FileList.FileValueUpdater; |
|
24 |
import gr.ebs.gss.client.FileList.Images; |
|
25 |
import gr.ebs.gss.client.FileList.TableResources; |
|
26 |
import gr.ebs.gss.client.FileList.TableStyle; |
|
27 |
import gr.ebs.gss.client.FileList.Templates; |
|
22 | 28 |
import gr.ebs.gss.client.rest.GetCommand; |
23 | 29 |
import gr.ebs.gss.client.rest.RestCommand; |
24 | 30 |
import gr.ebs.gss.client.rest.RestException; |
25 | 31 |
import gr.ebs.gss.client.rest.resource.FileResource; |
32 |
import gr.ebs.gss.client.rest.resource.RestResource; |
|
33 |
import gr.ebs.gss.client.rest.resource.RestResourceWrapper; |
|
26 | 34 |
import gr.ebs.gss.client.rest.resource.SearchResource; |
35 |
import gr.ebs.gss.client.rest.resource.SharedResource; |
|
36 |
import gr.ebs.gss.client.rest.resource.TrashResource; |
|
27 | 37 |
import gr.ebs.gss.client.rest.resource.UserResource; |
38 |
import gr.ebs.gss.client.rest.resource.UserSearchResource; |
|
39 |
import gwtquery.plugins.draggable.client.DraggableOptions; |
|
40 |
import gwtquery.plugins.draggable.client.StopDragException; |
|
41 |
import gwtquery.plugins.draggable.client.DraggableOptions.DragFunction; |
|
42 |
import gwtquery.plugins.draggable.client.DraggableOptions.RevertOption; |
|
43 |
import gwtquery.plugins.draggable.client.events.DragContext; |
|
44 |
import gwtquery.plugins.draggable.client.events.DragStartEvent; |
|
45 |
import gwtquery.plugins.draggable.client.events.DragStopEvent; |
|
46 |
import gwtquery.plugins.draggable.client.events.DragStartEvent.DragStartEventHandler; |
|
47 |
import gwtquery.plugins.draggable.client.events.DragStopEvent.DragStopEventHandler; |
|
48 |
import gwtquery.plugins.droppable.client.gwt.DragAndDropCellTable; |
|
49 |
import gwtquery.plugins.droppable.client.gwt.DragAndDropColumn; |
|
28 | 50 |
|
29 | 51 |
import java.util.ArrayList; |
30 | 52 |
import java.util.Collections; |
31 | 53 |
import java.util.Comparator; |
54 |
import java.util.Iterator; |
|
32 | 55 |
import java.util.List; |
33 | 56 |
|
57 |
import com.google.gwt.cell.client.AbstractCell; |
|
58 |
import com.google.gwt.cell.client.ImageResourceCell; |
|
59 |
import com.google.gwt.cell.client.SafeHtmlCell; |
|
60 |
import com.google.gwt.cell.client.ValueUpdater; |
|
61 |
import com.google.gwt.cell.client.Cell.Context; |
|
34 | 62 |
import com.google.gwt.core.client.GWT; |
63 |
import com.google.gwt.core.client.Scheduler; |
|
64 |
import com.google.gwt.core.client.Scheduler.RepeatingCommand; |
|
35 | 65 |
import com.google.gwt.dom.client.NativeEvent; |
66 |
import com.google.gwt.dom.client.Style.Cursor; |
|
36 | 67 |
import com.google.gwt.event.dom.client.ClickEvent; |
37 | 68 |
import com.google.gwt.event.dom.client.ClickHandler; |
38 | 69 |
import com.google.gwt.http.client.URL; |
39 | 70 |
import com.google.gwt.i18n.client.DateTimeFormat; |
40 | 71 |
import com.google.gwt.resources.client.ClientBundle; |
41 | 72 |
import com.google.gwt.resources.client.ImageResource; |
73 |
import com.google.gwt.resources.client.ClientBundle.Source; |
|
74 |
import com.google.gwt.safehtml.client.SafeHtmlTemplates; |
|
75 |
import com.google.gwt.safehtml.client.SafeHtmlTemplates.Template; |
|
76 |
import com.google.gwt.safehtml.shared.SafeHtml; |
|
77 |
import com.google.gwt.safehtml.shared.SafeHtmlBuilder; |
|
78 |
import com.google.gwt.user.cellview.client.CellTable; |
|
79 |
import com.google.gwt.user.cellview.client.Column; |
|
80 |
import com.google.gwt.user.cellview.client.SimplePager; |
|
81 |
import com.google.gwt.user.cellview.client.TextColumn; |
|
82 |
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy; |
|
42 | 83 |
import com.google.gwt.user.client.DOM; |
43 | 84 |
import com.google.gwt.user.client.DeferredCommand; |
44 | 85 |
import com.google.gwt.user.client.Event; |
... | ... | |
52 | 93 |
import com.google.gwt.user.client.ui.HorizontalPanel; |
53 | 94 |
import com.google.gwt.user.client.ui.VerticalPanel; |
54 | 95 |
import com.google.gwt.user.client.ui.HTMLTable.Cell; |
96 |
import com.google.gwt.view.client.ListDataProvider; |
|
97 |
import com.google.gwt.view.client.MultiSelectionModel; |
|
98 |
import com.google.gwt.view.client.ProvidesKey; |
|
99 |
import com.google.gwt.view.client.SelectionChangeEvent; |
|
100 |
import com.google.gwt.view.client.SelectionChangeEvent.Handler; |
|
55 | 101 |
|
56 | 102 |
/** |
57 | 103 |
* A composite that displays a list of search results for a particular query on |
58 | 104 |
* files. |
59 | 105 |
*/ |
60 |
public class SearchResults extends Composite implements ClickHandler { |
|
106 |
public class SearchResults extends Composite{ |
|
107 |
private HTML searchResults = new HTML("Results for search:"); |
|
108 |
/** |
|
109 |
* Specifies that the images available for this composite will be the ones |
|
110 |
* available in FileContextMenu. |
|
111 |
*/ |
|
112 |
public interface Images extends ClientBundle,FileContextMenu.Images, CellTreeView.Images, FileList.Images { |
|
113 |
|
|
114 |
@Source("gr/ebs/gss/resources/blank.gif") |
|
115 |
ImageResource blank(); |
|
61 | 116 |
|
62 |
private HTML prevButton = new HTML("<a href='javascript:;'>< Previous</a>", true); |
|
117 |
@Source("gr/ebs/gss/resources/asc.png") |
|
118 |
ImageResource asc(); |
|
119 |
|
|
120 |
@Source("gr/ebs/gss/resources/desc.png") |
|
121 |
ImageResource desc(); |
|
122 |
} |
|
123 |
|
|
124 |
ListDataProvider<FileResource> provider = new ListDataProvider<FileResource>(); |
|
125 |
interface TableResources extends DragAndDropCellTable.Resources { |
|
126 |
@Source({CellTable.Style.DEFAULT_CSS, "GssCellTable.css"}) |
|
127 |
TableStyle cellTableStyle(); |
|
128 |
} |
|
129 |
|
|
130 |
static interface Templates extends SafeHtmlTemplates { |
|
131 |
Templates INSTANCE = GWT.create(Templates.class); |
|
63 | 132 |
|
64 |
private HTML nextButton = new HTML("<a href='javascript:;'>Next ></a>", true); |
|
133 |
@Template("<div id='dragHelper' style='border:1px solid black; background-color:#ffffff; color:black; width:150px;z-index:100'></div>") |
|
134 |
SafeHtml outerHelper(); |
|
135 |
} |
|
136 |
|
|
137 |
|
|
138 |
/** |
|
139 |
* The styles applied to the table. |
|
140 |
*/ |
|
141 |
interface TableStyle extends CellTable.Style { |
|
142 |
} |
|
65 | 143 |
|
66 | 144 |
private String showingStats = ""; |
67 | 145 |
|
... | ... | |
72 | 150 |
*/ |
73 | 151 |
public static final boolean DONE = false; |
74 | 152 |
|
75 |
private boolean clickControl = false; |
|
153 |
|
|
154 |
|
|
155 |
private final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a"); |
|
76 | 156 |
|
77 |
private boolean clickShift = false; |
|
157 |
|
|
158 |
|
|
159 |
DragStopEventHandler dragStop = new DragStopEventHandler() { |
|
160 |
|
|
161 |
@Override |
|
162 |
public void onDragStop(DragStopEvent event) { |
|
163 |
GWT.log("DRAG STOPPED"); |
|
164 |
|
|
165 |
} |
|
166 |
}; |
|
167 |
|
|
168 |
private static class ContactCell extends AbstractCell<gr.ebs.gss.client.rest.resource.FileResource> { |
|
78 | 169 |
|
79 |
private int firstShift = -1; |
|
170 |
/** |
|
171 |
* The html of the image used for contacts. |
|
172 |
* |
|
173 |
*/ |
|
174 |
private final String imageHtml; |
|
80 | 175 |
|
81 |
private ArrayList<Integer> selectedRows = new ArrayList<Integer>(); |
|
176 |
public ContactCell(ImageResource image) { |
|
177 |
this.imageHtml = AbstractImagePrototype.create(image).getHTML(); |
|
178 |
} |
|
82 | 179 |
|
83 |
|
|
180 |
|
|
84 | 181 |
|
85 |
/** |
|
86 |
* Specifies that the images available for this composite will be the ones |
|
87 |
* available in FileContextMenu. |
|
88 |
*/ |
|
89 |
public interface Images extends ClientBundle,FileContextMenu.Images, CellTreeView.Images { |
|
182 |
|
|
90 | 183 |
|
91 |
@Source("gr/ebs/gss/resources/blank.gif") |
|
92 |
ImageResource blank(); |
|
184 |
@Override |
|
185 |
public void render(Context context, FileResource value, SafeHtmlBuilder sb) { |
|
186 |
// Value can be null, so do a null check.. |
|
187 |
if (value == null) { |
|
188 |
return; |
|
189 |
} |
|
93 | 190 |
|
94 |
@Source("gr/ebs/gss/resources/asc.png") |
|
95 |
ImageResource asc(); |
|
191 |
sb.appendHtmlConstant("<table>"); |
|
96 | 192 |
|
97 |
@Source("gr/ebs/gss/resources/desc.png") |
|
98 |
ImageResource desc(); |
|
99 |
} |
|
193 |
// Add the contact image. |
|
194 |
sb.appendHtmlConstant("<tr><td rowspan='3'>"); |
|
195 |
sb.appendHtmlConstant(imageHtml); |
|
196 |
sb.appendHtmlConstant("</td>"); |
|
100 | 197 |
|
101 |
/** |
|
102 |
* A label with the number of files in this folder. |
|
103 |
*/ |
|
104 |
private HTML countLabel = new HTML(); |
|
198 |
// Add the name and address. |
|
199 |
DisplayHelper.log("value.getName()"); |
|
200 |
sb.appendHtmlConstant("<td style='font-size:95%;' id='"+value.getName()+"'>"); |
|
201 |
sb.appendEscaped(value.getName()); |
|
202 |
sb.appendHtmlConstant("</td></tr><tr><td>"); |
|
203 |
sb.appendEscaped(value.getFileSizeAsString()); |
|
204 |
sb.appendHtmlConstant("</td></tr></table>"); |
|
205 |
} |
|
105 | 206 |
|
106 |
/** |
|
107 |
* The table widget with the file list. |
|
108 |
*/ |
|
109 |
private FileTable table; |
|
110 | 207 |
|
208 |
} |
|
111 | 209 |
/** |
112 |
* The navigation bar for paginating the results. |
|
210 |
* Retrieve the celltable. |
|
211 |
* |
|
212 |
* @return the celltable |
|
113 | 213 |
*/ |
114 |
private HorizontalPanel navBar = new HorizontalPanel(); |
|
214 |
public DragAndDropCellTable<FileResource> getCelltable() { |
|
215 |
return celltable; |
|
216 |
} |
|
217 |
|
|
115 | 218 |
|
219 |
|
|
116 | 220 |
/** |
117 |
* The number of files in the search results
|
|
221 |
* The number of files in this folder.
|
|
118 | 222 |
*/ |
119 |
private int folderFileCount;
|
|
223 |
int folderFileCount; |
|
120 | 224 |
|
121 | 225 |
/** |
122 |
* Total search results size
|
|
226 |
* Total folder size
|
|
123 | 227 |
*/ |
124 |
private long folderTotalSize;
|
|
228 |
long folderTotalSize; |
|
125 | 229 |
|
126 | 230 |
/** |
127 | 231 |
* A cache of the files in the list. |
... | ... | |
132 | 236 |
* The widget's image bundle. |
133 | 237 |
*/ |
134 | 238 |
private final Images images; |
135 |
|
|
136 |
private String sortingProperty = "name"; |
|
137 |
|
|
138 |
private boolean sortingType = true; |
|
139 |
|
|
140 |
private HTML nameLabel; |
|
141 |
|
|
142 |
private HTML versionLabel; |
|
143 |
|
|
144 |
private HTML sizeLabel; |
|
145 |
|
|
146 |
private HTML dateLabel; |
|
147 |
|
|
148 |
private HTML ownerLabel; |
|
149 |
|
|
150 |
private HTML pathLabel; |
|
151 |
|
|
152 |
private HTML searchResults = new HTML("Results for search:"); |
|
153 |
|
|
239 |
|
|
240 |
private FileContextMenu menuShowing; |
|
241 |
private DragAndDropCellTable<FileResource> celltable; |
|
242 |
private final MultiSelectionModel<FileResource> selectionModel; |
|
243 |
private final List<SortableHeader> allHeaders = new ArrayList<SortableHeader>(); |
|
244 |
SortableHeader nameHeader; |
|
245 |
SimplePager pager; |
|
154 | 246 |
/** |
155 | 247 |
* Construct the file list widget. This entails setting up the widget |
156 | 248 |
* layout, fetching the number of files in the current folder from the |
... | ... | |
159 | 251 |
* |
160 | 252 |
* @param _images |
161 | 253 |
*/ |
162 |
public SearchResults(final Images _images) {
|
|
254 |
public SearchResults(Images _images) { |
|
163 | 255 |
images = _images; |
164 |
final GSS app = GSS.get();
|
|
165 |
table = new FileTable(GSS.VISIBLE_FILE_COUNT + 1, 8) {
|
|
256 |
DragAndDropCellTable.Resources resources = GWT.create(TableResources.class);
|
|
257 |
ProvidesKey<FileResource> keyProvider = new ProvidesKey<FileResource>(){
|
|
166 | 258 |
|
167 | 259 |
@Override |
168 |
public void onBrowserEvent(Event event) { |
|
169 |
if (DOM.eventGetType(event) == Event.ONMOUSEDOWN && DOM.eventGetButton(event) == NativeEvent.BUTTON_RIGHT){ |
|
170 |
if (DOM.eventGetCtrlKey(event)) |
|
171 |
clickControl = true; |
|
172 |
else |
|
173 |
clickControl = false; |
|
174 |
if (DOM.eventGetShiftKey(event)) { |
|
175 |
clickShift = true; |
|
176 |
if (selectedRows.size() == 1) |
|
177 |
firstShift = selectedRows.get(0) - startIndex; |
|
178 |
//event.preventDefault(); |
|
179 |
} else { |
|
180 |
clickShift = false; |
|
181 |
firstShift = -1; |
|
182 |
//event.preventDefault(); |
|
183 |
} |
|
184 |
int ri = table.getRowForEvent2(event); |
|
185 |
if(ri != -1) |
|
186 |
if(!selectedRows.contains(ri-1)) |
|
187 |
onRowClicked(ri, false); |
|
188 |
} |
|
260 |
public Object getKey(FileResource item) { |
|
261 |
return item.getUri(); |
|
262 |
} |
|
263 |
|
|
264 |
}; |
|
265 |
final DragAndDropColumn<FileResource,SafeHtml> nameColumn = new DragAndDropColumn<FileResource,SafeHtml>(new SafeHtmlCell()) { |
|
266 |
|
|
189 | 267 |
|
190 |
if (files == null || files.size() == 0) { |
|
191 |
if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && selectedRows.size() == 0) { |
|
192 |
FileContextMenu fm = new FileContextMenu(images, false, true); |
|
193 |
fm.onEmptyEvent(event); |
|
194 |
} |
|
195 |
return; |
|
268 |
@Override |
|
269 |
public SafeHtml getValue(FileResource object) { |
|
270 |
SafeHtmlBuilder sb = new SafeHtmlBuilder(); |
|
271 |
if (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg") ){ |
|
272 |
sb.appendHtmlConstant("<span id='fileList."+ object.getName() +"'>"); |
|
273 |
sb.appendEscaped(object.getName()); |
|
274 |
sb.appendHtmlConstant("</span>"); |
|
275 |
sb.appendHtmlConstant(" <a href='" + |
|
276 |
GSS.get().getTopPanel().getFileMenu().getDownloadURL(object) + |
|
277 |
"' title='" + object.getOwner() + " : " + object.getPath() + object.getName() + |
|
278 |
"' rel='lytebox[mnf]' " + |
|
279 |
"onclick='myLytebox.start(this, false, false); return false;'>" + |
|
280 |
"(view)" + "</a>"); |
|
281 |
|
|
282 |
|
|
196 | 283 |
} |
197 |
if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && selectedRows.size() != 0) { |
|
198 |
FileContextMenu fm = new FileContextMenu(images, false, false); |
|
199 |
fm.onEvent(event); |
|
200 |
} else if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && selectedRows.size() == 0) { |
|
201 |
FileContextMenu fm = new FileContextMenu(images, false, true); |
|
202 |
fm.onEmptyEvent(event); |
|
203 |
} else if (DOM.eventGetType(event) == Event.ONDBLCLICK) |
|
204 |
if (getSelectedFiles().size() == 1) { |
|
205 |
FileResource file = getSelectedFiles().get(0); |
|
206 |
String dateString = RestCommand.getDate(); |
|
207 |
String resource = file.getUri().substring(app.getApiPath().length() - 1, file.getUri().length()); |
|
208 |
String sig = app.getCurrentUserResource().getUsername() + " " + |
|
209 |
RestCommand.calculateSig("GET", dateString, resource, |
|
210 |
RestCommand.base64decode(app.getToken())); |
|
211 |
Window.open(file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date=" + URL.encodeComponent(dateString), "_blank", ""); |
|
212 |
event.preventDefault(); |
|
213 |
return; |
|
214 |
} |
|
215 |
if (DOM.eventGetType(event) == Event.ONCLICK) { |
|
216 |
if (DOM.eventGetCtrlKey(event)) |
|
217 |
clickControl = true; |
|
218 |
else |
|
219 |
clickControl = false; |
|
220 |
if (DOM.eventGetShiftKey(event)) { |
|
221 |
clickShift = true; |
|
222 |
if (selectedRows.size() == 1) |
|
223 |
firstShift = selectedRows.get(0) - startIndex; |
|
224 |
//event.preventDefault(); |
|
225 |
} else { |
|
226 |
clickShift = false; |
|
227 |
firstShift = -1; |
|
228 |
//event.preventDefault(); |
|
229 |
} |
|
284 |
else{ |
|
285 |
sb.appendHtmlConstant("<span id='fileList."+ object.getName() +"'>"); |
|
286 |
sb.appendEscaped(object.getName()); |
|
287 |
sb.appendHtmlConstant("</span>"); |
|
230 | 288 |
} |
231 |
super.onBrowserEvent(event);
|
|
289 |
return sb.toSafeHtml();
|
|
232 | 290 |
} |
291 |
|
|
292 |
|
|
233 | 293 |
}; |
234 |
prevButton.addClickHandler(this); |
|
235 |
nextButton.addClickHandler(this); |
|
236 |
|
|
237 |
|
|
238 |
// Setup the table. |
|
239 |
table.setCellSpacing(0); |
|
240 |
table.setCellPadding(2); |
|
241 |
table.setWidth("100%"); |
|
242 |
|
|
243 |
// Hook up events. |
|
244 |
table.addClickHandler(new ClickHandler() { |
|
245 |
|
|
294 |
initDragOperation(nameColumn); |
|
295 |
celltable = new DragAndDropCellTable<FileResource>(GSS.VISIBLE_FILE_COUNT,resources,keyProvider){ |
|
246 | 296 |
@Override |
247 |
public void onClick(ClickEvent event) { |
|
248 |
Cell cell = table.getCellForEvent(event); |
|
249 |
onRowClicked(cell.getRowIndex(),true); |
|
297 |
protected void onBrowserEvent2(Event event) { |
|
298 |
/*if (DOM.eventGetType((Event) event) == Event.ONMOUSEDOWN && DOM.eventGetButton((Event) event) == NativeEvent.BUTTON_RIGHT){ |
|
299 |
fireClickEvent((Element) event.getEventTarget().cast()); |
|
300 |
}*/ |
|
301 |
super.onBrowserEvent2(event); |
|
250 | 302 |
} |
251 |
}); |
|
252 |
|
|
253 |
// Create the 'navigation' bar at the upper-right. |
|
254 |
HorizontalPanel innerNavBar = new HorizontalPanel(); |
|
255 |
innerNavBar.setStyleName("gss-ListNavBar"); |
|
256 |
innerNavBar.setSpacing(8); |
|
257 |
innerNavBar.add(prevButton); |
|
258 |
innerNavBar.add(countLabel); |
|
259 |
innerNavBar.add(nextButton); |
|
260 |
navBar.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); |
|
261 |
navBar.add(innerNavBar); |
|
262 |
navBar.setWidth("100%"); |
|
303 |
}; |
|
304 |
provider.addDataDisplay(celltable); |
|
305 |
celltable.addDragStopHandler(dragStop); |
|
306 |
celltable.addDragStartHandler(new DragStartEventHandler() { |
|
307 |
|
|
308 |
public void onDragStart(DragStartEvent event) { |
|
309 |
FileResource value = event.getDraggableData(); |
|
310 |
com.google.gwt.dom.client.Element helper = event.getHelper(); |
|
311 |
SafeHtmlBuilder sb = new SafeHtmlBuilder(); |
|
312 |
sb.appendHtmlConstant("<b>"); |
|
313 |
DisplayHelper.log(value.getName()); |
|
314 |
sb.appendEscaped(value.getName()); |
|
315 |
sb.appendHtmlConstant("</b>"); |
|
316 |
helper.setInnerHTML(sb.toSafeHtml().asString()); |
|
317 |
|
|
318 |
} |
|
319 |
}); |
|
320 |
Column<FileResource, ImageResource> status = new Column<FileResource, ImageResource>(new ImageResourceCell()) { |
|
321 |
@Override |
|
322 |
public ImageResource getValue(FileResource entity) { |
|
323 |
return getFileIcon(entity); |
|
324 |
} |
|
325 |
}; |
|
326 |
celltable.addColumn(status,""); |
|
327 |
|
|
328 |
|
|
329 |
celltable.addColumn(nameColumn,nameHeader = new SortableHeader("Name")); |
|
330 |
allHeaders.add(nameHeader); |
|
331 |
nameHeader.setSorted(true); |
|
332 |
nameHeader.toggleReverseSort(); |
|
333 |
nameHeader.setUpdater(new FileValueUpdater(nameHeader, "name")); |
|
334 |
celltable.redrawHeaders(); |
|
335 |
SortableHeader aheader; |
|
336 |
celltable.addColumn(new TextColumn<FileResource>() { |
|
337 |
@Override |
|
338 |
public String getValue(FileResource object) { |
|
339 |
return GSS.get().findUserFullName(object.getOwner()); |
|
340 |
} |
|
341 |
},aheader = new SortableHeader("Owner")); |
|
342 |
allHeaders.add(aheader); |
|
343 |
aheader.setUpdater(new FileValueUpdater(aheader, "owner")); |
|
344 |
celltable.addColumn(new TextColumn<FileResource>() { |
|
345 |
@Override |
|
346 |
public String getValue(FileResource object) { |
|
347 |
// TODO Auto-generated method stub |
|
348 |
if(object.isDeleted()) |
|
349 |
return object.getPath()+" (In Trash)"; |
|
350 |
return object.getPath(); |
|
351 |
} |
|
352 |
},aheader = new SortableHeader("Path")); |
|
353 |
allHeaders.add(aheader); |
|
354 |
aheader.setUpdater(new FileValueUpdater(aheader, "path")); |
|
355 |
celltable.addColumn(new TextColumn<FileResource>() { |
|
356 |
@Override |
|
357 |
public String getValue(FileResource object) { |
|
358 |
// TODO Auto-generated method stub |
|
359 |
return object.getVersion().toString(); |
|
360 |
} |
|
361 |
},aheader = new SortableHeader("Version")); |
|
362 |
allHeaders.add(aheader); |
|
363 |
aheader.setUpdater(new FileValueUpdater(aheader, "version")); |
|
364 |
celltable.addColumn(new TextColumn<FileResource>() { |
|
365 |
@Override |
|
366 |
public String getValue(FileResource object) { |
|
367 |
// TODO Auto-generated method stub |
|
368 |
return object.getFileSizeAsString(); |
|
369 |
} |
|
370 |
},aheader = new SortableHeader("Size")); |
|
371 |
allHeaders.add(aheader); |
|
372 |
aheader.setUpdater(new FileValueUpdater(aheader, "size")); |
|
373 |
celltable.addColumn(new TextColumn<FileResource>() { |
|
374 |
@Override |
|
375 |
public String getValue(FileResource object) { |
|
376 |
return formatter.format(object.getModificationDate()); |
|
377 |
} |
|
378 |
},aheader = new SortableHeader("Last Modified")); |
|
379 |
allHeaders.add(aheader); |
|
380 |
aheader.setUpdater(new FileValueUpdater(aheader, "date")); |
|
263 | 381 |
VerticalPanel vp = new VerticalPanel(); |
382 |
vp.setWidth("100%"); |
|
383 |
celltable.setWidth("100%"); |
|
264 | 384 |
vp.add(searchResults); |
265 | 385 |
searchResults.addStyleName("gss-searchLabel"); |
266 |
vp.add(table); |
|
386 |
vp.add(celltable); |
|
387 |
pager = new SimplePager(SimplePager.TextLocation.CENTER); |
|
388 |
pager.setDisplay(celltable); |
|
389 |
//celltable.setPageSize(2); |
|
390 |
|
|
391 |
vp.add(pager); |
|
392 |
vp.setCellWidth(celltable, "100%"); |
|
393 |
|
|
267 | 394 |
initWidget(vp); |
268 |
table.setStyleName("gss-List"); |
|
269 |
initTable(); |
|
270 |
DeferredCommand.addCommand(new IncrementalCommand() { |
|
395 |
|
|
396 |
//initWidget(celltable); |
|
397 |
celltable.setStyleName("gss-List"); |
|
398 |
selectionModel = new MultiSelectionModel<FileResource>(); |
|
399 |
|
|
400 |
|
|
401 |
Handler selectionHandler = new SelectionChangeEvent.Handler() { |
|
402 |
@Override |
|
403 |
public void onSelectionChange(com.google.gwt.view.client.SelectionChangeEvent event) { |
|
404 |
if(getSelectedFiles().size()==1) |
|
405 |
GSS.get().setCurrentSelection(getSelectedFiles().get(0)); |
|
406 |
else |
|
407 |
GSS.get().setCurrentSelection(getSelectedFiles()); |
|
408 |
//contextMenu.setFiles(getSelectedFiles()); |
|
409 |
} |
|
410 |
}; |
|
411 |
selectionModel.addSelectionChangeHandler(selectionHandler); |
|
412 |
|
|
413 |
celltable.setSelectionModel(selectionModel,GSSSelectionEventManager.<FileResource>createDefaultManager()); |
|
414 |
celltable.setPageSize(GSS.VISIBLE_FILE_COUNT); |
|
415 |
celltable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); |
|
416 |
Scheduler.get().scheduleIncremental(new RepeatingCommand() { |
|
271 | 417 |
|
272 | 418 |
@Override |
273 | 419 |
public boolean execute() { |
274 | 420 |
return fetchRootFolder(); |
275 | 421 |
} |
276 | 422 |
}); |
277 |
table.sinkEvents(Event.ONCONTEXTMENU);
|
|
278 |
table.sinkEvents(Event.ONMOUSEUP);
|
|
279 |
table.sinkEvents(Event.ONMOUSEDOWN);
|
|
280 |
table.sinkEvents(Event.ONCLICK);
|
|
281 |
table.sinkEvents(Event.ONKEYDOWN);
|
|
282 |
table.sinkEvents(Event.ONDBLCLICK);
|
|
283 |
preventIESelection(); |
|
423 |
sinkEvents(Event.ONCONTEXTMENU); |
|
424 |
sinkEvents(Event.ONMOUSEUP); |
|
425 |
sinkEvents(Event.ONMOUSEDOWN); |
|
426 |
sinkEvents(Event.ONCLICK); |
|
427 |
sinkEvents(Event.ONKEYDOWN); |
|
428 |
sinkEvents(Event.ONDBLCLICK); |
|
429 |
GSS.preventIESelection();
|
|
284 | 430 |
} |
285 |
|
|
431 |
|
|
432 |
//public native void fireClickEvent(Element element) /*-{ |
|
433 |
// var evObj = $doc.createEvent('MouseEvents'); |
|
434 |
//evObj.initEvent('click', true, true); |
|
435 |
//element.dispatchEvent(evObj); |
|
436 |
//}-*/; |
|
437 |
|
|
438 |
public List<FileResource> getSelectedFiles() { |
|
439 |
return new ArrayList<FileResource>(selectionModel.getSelectedSet()); |
|
440 |
} |
|
441 |
|
|
442 |
private void initDragOperation(DragAndDropColumn<?, ?> column) { |
|
443 |
|
|
444 |
// retrieve draggableOptions on the column |
|
445 |
DraggableOptions draggableOptions = column.getDraggableOptions(); |
|
446 |
// use template to construct the helper. The content of the div will be set |
|
447 |
// after |
|
448 |
draggableOptions.setHelper($(Templates.INSTANCE.outerHelper().asString())); |
|
449 |
//draggableOptions.setZIndex(100); |
|
450 |
// opacity of the helper |
|
451 |
draggableOptions.setAppendTo("body"); |
|
452 |
//draggableOptions.setOpacity((float) 0.8); |
|
453 |
draggableOptions.setContainment("document"); |
|
454 |
// cursor to use during the drag operation |
|
455 |
draggableOptions.setCursor(Cursor.MOVE); |
|
456 |
// set the revert option |
|
457 |
draggableOptions.setRevert(RevertOption.ON_INVALID_DROP); |
|
458 |
// prevents dragging when user click on the category drop-down list |
|
459 |
draggableOptions.setCancel("select"); |
|
460 |
|
|
461 |
draggableOptions.setOnBeforeDragStart(new DragFunction() { |
|
462 |
|
|
463 |
@Override |
|
464 |
public void f(DragContext context) { |
|
465 |
FileResource value = context.getDraggableData(); |
|
466 |
if(!selectionModel.isSelected(value)){ |
|
467 |
throw new StopDragException(); |
|
468 |
} |
|
469 |
|
|
470 |
} |
|
471 |
}); |
|
472 |
} |
|
473 |
|
|
474 |
public void showContextMenu(Event event){ |
|
475 |
menuShowing = new FileContextMenu(images, false, true); |
|
476 |
menuShowing=menuShowing.onEmptyEvent(event); |
|
477 |
} |
|
286 | 478 |
@Override |
287 |
public void onClick(ClickEvent event) { |
|
288 |
if (event.getSource() == nextButton) { |
|
289 |
// Move forward a page. |
|
290 |
clearSelectedRows(); |
|
291 |
startIndex += GSS.VISIBLE_FILE_COUNT; |
|
292 |
if (startIndex >= folderFileCount) |
|
293 |
startIndex -= GSS.VISIBLE_FILE_COUNT; |
|
294 |
else |
|
295 |
update(false); |
|
296 |
} else if (event.getSource() == prevButton) { |
|
297 |
clearSelectedRows(); |
|
298 |
// Move back a page. |
|
299 |
startIndex -= GSS.VISIBLE_FILE_COUNT; |
|
300 |
if (startIndex < 0) |
|
301 |
startIndex = 0; |
|
302 |
else |
|
303 |
update(false); |
|
479 |
public void onBrowserEvent(Event event) { |
|
480 |
|
|
481 |
if (files == null || files.size() == 0) { |
|
482 |
if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) { |
|
483 |
menuShowing = new FileContextMenu(images, false, true); |
|
484 |
menuShowing=menuShowing.onEmptyEvent(event); |
|
485 |
event.preventDefault(); |
|
486 |
event.cancelBubble(true); |
|
487 |
} |
|
488 |
return; |
|
304 | 489 |
} |
490 |
if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() != 0) { |
|
491 |
GWT.log("*****GOING TO SHOW CONTEXT MENU ****", null); |
|
492 |
menuShowing = new FileContextMenu(images, false, false); |
|
493 |
menuShowing=menuShowing.onEvent(event); |
|
494 |
event.cancelBubble(true); |
|
495 |
event.preventDefault(); |
|
496 |
} else if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) { |
|
497 |
menuShowing = new FileContextMenu(images, false, true); |
|
498 |
menuShowing=menuShowing.onEmptyEvent(event); |
|
499 |
event.cancelBubble(true); |
|
500 |
event.preventDefault(); |
|
501 |
} else if (DOM.eventGetType(event) == Event.ONDBLCLICK) |
|
502 |
if (getSelectedFiles().size() == 1) { |
|
503 |
GSS app = GSS.get(); |
|
504 |
FileResource file = getSelectedFiles().get(0); |
|
505 |
String dateString = RestCommand.getDate(); |
|
506 |
String resource = file.getUri().substring(app.getApiPath().length() - 1, file.getUri().length()); |
|
507 |
String sig = app.getCurrentUserResource().getUsername() + " " + |
|
508 |
RestCommand.calculateSig("GET", dateString, resource, |
|
509 |
RestCommand.base64decode(app.getToken())); |
|
510 |
Window.open(file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date=" + URL.encodeComponent(dateString), "_blank", ""); |
|
511 |
event.preventDefault(); |
|
512 |
return; |
|
513 |
} |
|
514 |
super.onBrowserEvent(event); |
|
305 | 515 |
} |
306 | 516 |
|
307 | 517 |
/** |
... | ... | |
313 | 523 |
UserResource user = GSS.get().getCurrentUserResource(); |
314 | 524 |
if (user == null) |
315 | 525 |
return !DONE; |
316 |
updateFileCache(""); |
|
526 |
// Update cache and clear selection. |
|
527 |
updateFileCache(null); |
|
317 | 528 |
return DONE; |
318 | 529 |
} |
319 | 530 |
|
320 |
public void onRowClicked(int row, boolean toggleSelection) { |
|
321 |
// Select the row that was clicked (-1 to account for header row). |
|
322 |
if (row > folderFileCount) |
|
323 |
return; |
|
324 |
if (clickShift) { |
|
325 |
GWT.log("ROW is:" + row + " fs:" + firstShift, null); |
|
326 |
if (firstShift == -1) |
|
327 |
firstShift = row; |
|
328 |
else if (row > firstShift) { |
|
329 |
clearSelectedRows(); |
|
330 |
for (int i = firstShift; i < row; i++) { |
|
331 |
selectedRows.add(startIndex + i); |
|
332 |
styleRow(i, true); |
|
333 |
} |
|
334 |
GSS.get().setCurrentSelection(getSelectedFiles()); |
|
335 |
//contextMenu.setFiles(getSelectedFiles()); |
|
336 |
//table.setWidget(row, 0, contextMenu); |
|
337 |
} else if (row != -1 && row == firstShift) { |
|
338 |
selectedRows.add(row); |
|
339 |
selectedRows.add(row - 1); |
|
340 |
styleRow(row, true); |
|
341 |
styleRow(row - 1, true); |
|
342 |
} else if (row < firstShift) { |
|
343 |
GWT.log("ROW is:" + row + " fs:" + firstShift, null); |
|
344 |
clearSelectedRows(); |
|
345 |
|
|
346 |
for (int i = firstShift; i >= row - 1; i--) { |
|
347 |
selectedRows.add(startIndex + i); |
|
348 |
styleRow(i, true); |
|
349 |
} |
|
350 |
GSS.get().setCurrentSelection(getSelectedFiles()); |
|
351 |
//table.setWidget(row, 0, contextMenu); |
|
352 |
//contextMenu.setFiles(getSelectedFiles()); |
|
353 |
} |
|
354 |
|
|
355 |
} else if (row > 0) |
|
356 |
selectRow(row - 1, toggleSelection); |
|
357 |
|
|
358 |
} |
|
359 |
|
|
360 |
/** |
|
361 |
* Initializes the table so that it contains enough rows for a full page of |
|
362 |
* files. |
|
363 |
*/ |
|
364 |
private void initTable() { |
|
365 |
|
|
366 |
nameLabel = new HTML("Name"); |
|
367 |
nameLabel.addClickHandler(new ClickHandler() { |
|
368 |
@Override |
|
369 |
public void onClick(ClickEvent event) { |
|
370 |
sortFiles("name"); |
|
371 |
} |
|
372 |
|
|
373 |
}); |
|
374 |
versionLabel = new HTML("Version"); |
|
375 |
versionLabel.addClickHandler(new ClickHandler() { |
|
376 |
@Override |
|
377 |
public void onClick(ClickEvent event) { |
|
378 |
sortFiles("version"); |
|
379 |
} |
|
380 |
|
|
381 |
}); |
|
382 |
sizeLabel = new HTML("Size"); |
|
383 |
sizeLabel.addClickHandler(new ClickHandler() { |
|
384 |
@Override |
|
385 |
public void onClick(ClickEvent event) { |
|
386 |
sortFiles("size"); |
|
387 |
} |
|
388 |
|
|
389 |
}); |
|
390 |
dateLabel = new HTML("Last modified"); |
|
391 |
dateLabel.addClickHandler(new ClickHandler() { |
|
392 |
@Override |
|
393 |
public void onClick(ClickEvent event) { |
|
394 |
sortFiles("date"); |
|
395 |
} |
|
396 |
|
|
397 |
}); |
|
398 |
ownerLabel = new HTML("Owner"); |
|
399 |
ownerLabel.addClickHandler(new ClickHandler() { |
|
400 |
@Override |
|
401 |
public void onClick(ClickEvent event) { |
|
402 |
sortFiles("owner"); |
|
403 |
} |
|
404 |
|
|
405 |
}); |
|
406 |
|
|
407 |
pathLabel = new HTML("Path"); |
|
408 |
pathLabel.addClickHandler(new ClickHandler() { |
|
409 |
@Override |
|
410 |
public void onClick(ClickEvent event) { |
|
411 |
sortFiles("path"); |
|
412 |
} |
|
413 |
|
|
414 |
}); |
|
415 |
// Create the header row. |
|
416 |
table.setText(0, 0, ""); |
|
417 |
// table.setText(0, 1, "Name"); |
|
418 |
table.setWidget(0, 1, nameLabel); |
|
419 |
table.setWidget(0, 2, ownerLabel); |
|
420 |
// table.setText(0, 3, "Version"); |
|
421 |
table.setWidget(0, 3, pathLabel); |
|
422 |
table.setWidget(0, 4, versionLabel); |
|
423 |
// table.setText(0, 4, "Size"); |
|
424 |
table.setWidget(0, 5, sizeLabel); |
|
425 |
// table.setText(0, 5, "Last modified"); |
|
426 |
table.setWidget(0, 6, dateLabel); |
|
427 |
table.setWidget(0, 7, navBar); |
|
428 |
table.getRowFormatter().setStyleName(0, "gss-ListHeader"); |
|
429 |
|
|
430 |
// Initialize the rest of the rows. |
|
431 |
for (int i = 1; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) { |
|
432 |
table.setText(i, 0, ""); |
|
433 |
table.setText(i, 1, ""); |
|
434 |
table.setText(i, 2, ""); |
|
435 |
table.setText(i, 3, ""); |
|
436 |
table.setText(i, 4, ""); |
|
437 |
table.setText(i, 5, ""); |
|
438 |
table.setText(i, 6, ""); |
|
439 |
table.getCellFormatter().setWordWrap(i, 0, false); |
|
440 |
table.getCellFormatter().setWordWrap(i, 1, false); |
|
441 |
table.getCellFormatter().setWordWrap(i, 2, false); |
|
442 |
table.getCellFormatter().setWordWrap(i, 3, false); |
|
443 |
table.getCellFormatter().setWordWrap(i, 4, false); |
|
444 |
table.getCellFormatter().setWordWrap(i, 5, false); |
|
445 |
table.getCellFormatter().setWordWrap(i, 6, false); |
|
446 |
table.getCellFormatter().setHorizontalAlignment(i, 4, HasHorizontalAlignment.ALIGN_CENTER); |
|
447 |
} |
|
448 |
prevButton.setVisible(false); |
|
449 |
nextButton.setVisible(false); |
|
450 |
} |
|
451 |
|
|
452 |
/** |
|
453 |
* Selects the given row (relative to the current page). |
|
454 |
* |
|
455 |
* @param row the row to be selected |
|
456 |
*/ |
|
457 |
private void selectRow(final int row, boolean toggleSelection) { |
|
458 |
if (row < folderFileCount) { |
|
459 |
if (clickControl) |
|
460 |
if (selectedRows.contains(row) && toggleSelection) { |
|
461 |
int i = selectedRows.indexOf(startIndex + row); |
|
462 |
selectedRows.remove(i); |
|
463 |
styleRow(row, false); |
|
464 |
} else { |
|
465 |
for (int r : selectedRows) { |
|
466 |
int prow = r - startIndex; |
|
467 |
table.setWidget(prow + 1, 0, AbstractImagePrototype.create(images.document()).createImage()); |
|
468 |
} |
|
469 |
selectedRows.add(startIndex + row); |
|
470 |
styleRow(row, true); |
|
471 |
} |
|
472 |
else { |
|
473 |
clearSelectedRows(); |
|
474 |
selectedRows.add(startIndex + row); |
|
475 |
styleRow(row, true); |
|
476 |
} |
|
477 |
if (selectedRows.size() == 1) |
|
478 |
GSS.get().setCurrentSelection(files.get(selectedRows.get(0))); |
|
479 |
else |
|
480 |
GSS.get().setCurrentSelection(getSelectedFiles()); |
|
481 |
//contextMenu.setFiles(getSelectedFiles()); |
|
482 |
//table.setWidget(row + 1, 0, contextMenu); |
|
483 |
} |
|
484 |
} |
|
485 |
|
|
486 |
public List<FileResource> getSelectedFiles() { |
|
487 |
List<FileResource> result = new ArrayList(); |
|
488 |
for (int i : selectedRows) |
|
489 |
result.add(files.get(i)); |
|
490 |
return result; |
|
491 |
} |
|
492 |
|
|
493 |
/** |
|
494 |
* Make the specified row look like selected or not, according to the |
|
495 |
* <code>selected</code> flag. |
|
496 |
* |
|
497 |
* @param row |
|
498 |
* @param selected |
|
499 |
*/ |
|
500 |
void styleRow(final int row, final boolean selected) { |
|
501 |
if (row != -1 && row >= 0) |
|
502 |
if (selected) |
|
503 |
table.getRowFormatter().addStyleName(row + 1, "gss-SelectedRow"); |
|
504 |
else |
|
505 |
table.getRowFormatter().removeStyleName(row + 1, "gss-SelectedRow"); |
|
506 |
} |
|
507 | 531 |
|
508 | 532 |
/** |
509 | 533 |
* Update the display of the file list. |
... | ... | |
514 | 538 |
if (max > count) |
515 | 539 |
max = count; |
516 | 540 |
folderTotalSize = 0; |
517 |
|
|
518 |
if (sort && files != null && files.size() != 0) { |
|
519 |
clearLabels(); |
|
520 |
clearSelectedRows(); |
|
521 |
|
|
522 |
Collections.sort(files, new Comparator<FileResource>() { |
|
523 |
|
|
524 |
@Override |
|
525 |
public int compare(FileResource arg0, FileResource arg1) { |
|
526 |
AbstractImagePrototype descPrototype = AbstractImagePrototype.create(images.desc()); |
|
527 |
AbstractImagePrototype ascPrototype = AbstractImagePrototype.create(images.asc()); |
|
528 |
if (sortingType) |
|
529 |
if (sortingProperty.equals("version")) { |
|
530 |
versionLabel.setHTML("Version " + descPrototype.getHTML()); |
|
531 |
return arg0.getVersion().compareTo(arg1.getVersion()); |
|
532 |
} else if (sortingProperty.equals("owner")) { |
|
533 |
ownerLabel.setHTML("Owner " + descPrototype.getHTML()); |
|
534 |
return arg0.getOwner().compareTo(arg1.getOwner()); |
|
535 |
} else if (sortingProperty.equals("date")) { |
|
536 |
dateLabel.setHTML("Last modified " + descPrototype.getHTML()); |
|
537 |
return arg0.getModificationDate().compareTo(arg1.getModificationDate()); |
|
538 |
} else if (sortingProperty.equals("size")) { |
|
539 |
sizeLabel.setHTML("Size " + descPrototype.getHTML()); |
|
540 |
return arg0.getContentLength().compareTo(arg1.getContentLength()); |
|
541 |
} else if (sortingProperty.equals("name")) { |
|
542 |
nameLabel.setHTML("Name " + descPrototype.getHTML()); |
|
543 |
return arg0.getName().compareTo(arg1.getName()); |
|
544 |
} else if (sortingProperty.equals("path")) { |
|
545 |
pathLabel.setHTML("Path " + descPrototype.getHTML()); |
|
546 |
return arg0.getUri().compareTo(arg1.getUri()); |
|
547 |
} else { |
|
548 |
nameLabel.setHTML("Name " + descPrototype.getHTML()); |
|
549 |
return arg0.getName().compareTo(arg1.getName()); |
|
550 |
} |
|
551 |
else if (sortingProperty.equals("version")) { |
|
552 |
versionLabel.setHTML("Version " + ascPrototype.getHTML()); |
|
553 |
return arg1.getVersion().compareTo(arg0.getVersion()); |
|
554 |
} else if (sortingProperty.equals("owner")) { |
|
555 |
ownerLabel.setHTML("Owner " + ascPrototype.getHTML()); |
|
556 |
return arg1.getOwner().compareTo(arg0.getOwner()); |
|
557 |
} else if (sortingProperty.equals("date")) { |
|
558 |
dateLabel.setHTML("Last modified " + ascPrototype.getHTML()); |
|
559 |
return arg1.getModificationDate().compareTo(arg0.getModificationDate()); |
|
560 |
} else if (sortingProperty.equals("size")) { |
|
561 |
sizeLabel.setHTML("Size " + ascPrototype.getHTML()); |
|
562 |
return arg1.getContentLength().compareTo(arg0.getContentLength()); |
|
563 |
} else if (sortingProperty.equals("name")) { |
|
564 |
nameLabel.setHTML("Name " + ascPrototype.getHTML()); |
|
565 |
return arg1.getName().compareTo(arg0.getName()); |
|
566 |
} else if (sortingProperty.equals("path")) { |
|
567 |
pathLabel.setHTML("Path " + ascPrototype.getHTML()); |
|
568 |
return arg1.getUri().compareTo(arg0.getUri()); |
|
569 |
} else { |
|
570 |
nameLabel.setHTML("Name " + ascPrototype.getHTML()); |
|
571 |
return arg1.getName().compareTo(arg0.getName()); |
|
572 |
} |
|
573 |
} |
|
574 |
|
|
575 |
}); |
|
576 |
|
|
577 |
} |
|
578 |
// Show the selected files. |
|
579 |
int i = 1; |
|
580 |
for (; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) { |
|
581 |
// Don't read past the end. |
|
582 |
// if (i > folderFileCount) |
|
583 |
// break; |
|
584 |
if (startIndex + i > folderFileCount) |
|
585 |
break; |
|
586 |
// Add a new row to the table, then set each of its columns to the |
|
587 |
// proper values. |
|
588 |
table.setWidget(i, 0, AbstractImagePrototype.create(images.document()).createImage()); |
|
589 |
FileResource fileHeader = files.get(startIndex + i - 1); |
|
590 |
table.getRowFormatter().addStyleName(i, "gss-fileRow"); |
|
591 |
table.setHTML(i, 1, fileHeader.getName()); |
|
592 |
table.setText(i, 2, fileHeader.getOwner()); |
|
593 |
table.setText(i, 3, fileHeader.getPath()); |
|
594 |
table.setText(i, 4, String.valueOf(fileHeader.getVersion())); |
|
595 |
table.setText(i, 5, String.valueOf(fileHeader.getFileSizeAsString())); |
|
596 |
final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a"); |
|
597 |
table.setText(i, 6, formatter.format(fileHeader.getModificationDate())); |
|
598 |
folderTotalSize += fileHeader.getContentLength(); |
|
599 |
} |
|
600 |
|
|
601 |
// Clear any remaining slots. |
|
602 |
for (; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) { |
|
603 |
table.setHTML(i, 0, " "); |
|
604 |
table.setHTML(i, 1, " "); |
|
605 |
table.setHTML(i, 2, " "); |
|
606 |
table.setHTML(i, 3, " "); |
|
607 |
table.setHTML(i, 4, " "); |
|
608 |
table.setHTML(i, 5, " "); |
|
609 |
table.setHTML(i, 6, " "); |
|
610 |
table.setHTML(i, 7, " "); |
|
541 |
|
|
542 |
copyListAndContinue(files); |
|
543 |
for(FileResource f : files){ |
|
544 |
folderTotalSize += f.getContentLength(); |
|
611 | 545 |
} |
612 |
|
|
613 | 546 |
if (folderFileCount == 0) { |
614 | 547 |
showingStats = "no files"; |
615 |
prevButton.setVisible(false); |
|
616 |
nextButton.setVisible(false); |
|
617 | 548 |
} else if (folderFileCount < GSS.VISIBLE_FILE_COUNT) { |
618 | 549 |
if (folderFileCount == 1) |
619 | 550 |
showingStats = "1 file"; |
620 | 551 |
else |
621 | 552 |
showingStats = folderFileCount + " files"; |
622 | 553 |
showingStats += " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")"; |
623 |
prevButton.setVisible(false); |
|
624 |
nextButton.setVisible(false); |
|
625 | 554 |
} else { |
626 | 555 |
showingStats = "" + (startIndex + 1) + " - " + max + " of " + count + " files" + " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")"; |
627 |
prevButton.setVisible(startIndex != 0); |
|
628 |
nextButton.setVisible(startIndex + GSS.VISIBLE_FILE_COUNT < count); |
|
629 | 556 |
} |
630 | 557 |
updateCurrentlyShowingStats(); |
631 |
} |
|
632 | 558 |
|
633 |
/** |
|
634 |
* update status panel with currently showing file stats |
|
635 |
*/ |
|
636 |
public void updateCurrentlyShowingStats() { |
|
637 |
GSS.get().getStatusPanel().updateCurrentlyShowing(showingStats); |
|
638 | 559 |
} |
639 | 560 |
|
640 | 561 |
/** |
641 |
* Adjust the height of the table by adding and removing rows as necessary.
|
|
562 |
* Return the proper icon based on the MIME type of the file.
|
|
642 | 563 |
* |
643 |
* @param newHeight the new height to reach |
|
564 |
* @param file |
|
565 |
* @return the icon |
|
644 | 566 |
*/ |
645 |
void resizeTableHeight(final int newHeight) { |
|
646 |
GWT.log("Panel: " + newHeight + ", parent: " + table.getParent().getOffsetHeight(), null); |
|
647 |
// Fill the rest with empty slots. |
|
648 |
if (newHeight > table.getOffsetHeight()) |
|
649 |
while (newHeight > table.getOffsetHeight()) { |
|
650 |
// table.setHTML(table.getRowCount(), 5, " "); |
|
651 |
table.resizeRows(table.getRowCount() + 1); |
|
652 |
GWT.log("Table: " + table.getOffsetHeight() + ", rows: " + table.getRowCount(), null); |
|
653 |
} |
|
654 |
else |
|
655 |
while (newHeight < table.getOffsetHeight()) { |
|
656 |
// table.setHTML(table.getRowCount(), 5, " "); |
|
657 |
table.resizeRows(table.getRowCount() - 1); |
|
658 |
GWT.log("Table: " + table.getOffsetHeight() + ", rows: " + table.getRowCount(), null); |
|
567 |
private ImageResource getFileIcon(FileResource file) { |
|
568 |
String mimetype = file.getContentType(); |
|
569 |
boolean shared = false; |
|
570 |
//TODO: FETCH USER OF OTHER FOLDER ITEM |
|
571 |
//if(GSS.get().getTreeView().getSelection()!=null && (GSS.get().getTreeView().getSelection() instanceof OtherUserResource || GSS.get().getTreeView().getSelection() instanceof OthersFolderResource)) |
|
572 |
/*Folders folders = GSS.get().getFolders(); |
|
573 |
if(folders.getCurrent() != null && folders.isOthersSharedItem(folders.getCurrent())){ |
|
574 |
DnDTreeItem otherUser = (DnDTreeItem) folders.getUserOfSharedItem(folders.getCurrent()); |
|
575 |
if(otherUser==null) |
|
576 |
shared = false; |
|
577 |
else{ |
|
578 |
String uname = otherUser.getOtherUserResource().getUsername(); |
|
579 |
if(uname==null) |
|
580 |
uname = ((DnDTreeItem)folders.getSharesItem()).getOthersResource().getUsernameOfUri(otherUser.getOtherUserResource().getUri()); |
|
581 |
if(uname != null) |
|
582 |
shared = file.isShared(); |
|
659 | 583 |
} |
584 |
} |
|
585 |
else*/ |
|
586 |
shared = file.isShared(); |
|
587 |
if (mimetype == null) |
|
588 |
return shared ? images.documentShared() : images.document(); |
|
589 |
mimetype = mimetype.toLowerCase(); |
|
590 |
if (mimetype.startsWith("application/pdf")) |
|
591 |
return shared ? images.pdfShared() : images.pdf(); |
|
592 |
else if (mimetype.endsWith("excel")) |
|
593 |
return shared ? images.spreadsheetShared() : images.spreadsheet(); |
|
594 |
else if (mimetype.endsWith("msword")) |
|
595 |
return shared ? images.wordprocessorShared() : images.wordprocessor(); |
|
596 |
else if (mimetype.endsWith("powerpoint")) |
|
597 |
return shared ? images.presentationShared() : images.presentation(); |
|
598 |
else if (mimetype.startsWith("application/zip") || |
|
599 |
mimetype.startsWith("application/gzip") || |
|
600 |
mimetype.startsWith("application/x-gzip") || |
|
601 |
mimetype.startsWith("application/x-tar") || |
|
602 |
mimetype.startsWith("application/x-gtar")) |
|
603 |
return shared ? images.zipShared() : images.zip(); |
|
604 |
else if (mimetype.startsWith("text/html")) |
|
605 |
return shared ? images.htmlShared() : images.html(); |
|
606 |
else if (mimetype.startsWith("text/plain")) |
|
607 |
return shared ? images.txtShared() : images.txt(); |
|
608 |
else if (mimetype.startsWith("image/")) |
|
609 |
return shared ? images.imageShared() : images.image(); |
|
610 |
else if (mimetype.startsWith("video/")) |
|
611 |
return shared ? images.videoShared() : images.video(); |
|
612 |
else if (mimetype.startsWith("audio/")) |
|
613 |
return shared ? images.audioShared() : images.audio(); |
|
614 |
return shared ? images.documentShared() : images.document(); |
|
660 | 615 |
} |
661 | 616 |
|
662 | 617 |
/** |
663 |
* Update the file cache with data from the server.
|
|
618 |
* Update status panel with currently showing file stats.
|
|
664 | 619 |
*/ |
620 |
public void updateCurrentlyShowingStats() { |
|
621 |
GSS.get().getStatusPanel().updateCurrentlyShowing(showingStats); |
|
622 |
} |
|
623 |
|
|
665 | 624 |
public void updateFileCache(String query) { |
666 | 625 |
final GSS app = GSS.get(); |
667 | 626 |
clearSelectedRows(); |
668 |
clearLabels(); |
|
627 |
//clearLabels();
|
|
669 | 628 |
startIndex = 0; |
670 | 629 |
app.showLoadingIndicator(); |
671 | 630 |
if (query == null || query.trim().equals("")) { |
... | ... | |
707 | 666 |
|
708 | 667 |
/** |
709 | 668 |
* Fill the file cache with data. |
710 |
* |
|
711 |
* @param _files |
|
712 |
* @param filePaths the files to set |
|
713 | 669 |
*/ |
714 |
private void setFiles(List<FileResource> _files) { |
|
715 |
files = _files; |
|
670 |
public void setFiles(final List<FileResource> _files) { |
|
671 |
if (_files.size() > 0 && ! (GSS.get().getTreeView().getSelection() instanceof TrashResource)) { |
|
672 |
files = new ArrayList<FileResource>(); |
|
673 |
for (FileResource fres : _files) |
|
674 |
files.add(fres); |
|
675 |
} |
|
676 |
else |
|
677 |
files = _files; |
|
716 | 678 |
Collections.sort(files, new Comparator<FileResource>() { |
717 | 679 |
|
718 | 680 |
@Override |
... | ... | |
722 | 684 |
|
723 | 685 |
}); |
724 | 686 |
folderFileCount = files.size(); |
725 |
GWT.log("File count:" + folderFileCount, null); |
|
726 |
} |
|
727 |
|
|
728 |
private void sortFiles(final String sortProperty) { |
|
729 |
if (sortProperty.equals(sortingProperty)) |
|
730 |
sortingType = !sortingType; |
|
731 |
else { |
|
732 |
sortingProperty = sortProperty; |
|
733 |
sortingType = true; |
|
734 |
} |
|
735 |
update(true); |
|
736 |
} |
|
737 |
|
|
738 |
private void clearLabels() { |
|
739 |
nameLabel.setText("Name"); |
|
740 |
versionLabel.setText("Version"); |
|
741 |
sizeLabel.setText("Size"); |
|
742 |
dateLabel.setText("Last modified"); |
|
743 |
ownerLabel.setText("Owner"); |
|
744 |
pathLabel.setText("Path"); |
|
745 | 687 |
} |
746 | 688 |
|
747 |
/** |
|
748 |
* Retrieve the table. |
|
749 |
* |
|
750 |
* @return the table |
|
751 |
*/ |
|
752 |
Grid getTable() { |
|
753 |
return table; |
|
754 |
} |
|
689 |
|
|
755 | 690 |
|
691 |
|
|
756 | 692 |
/** |
757 | 693 |
* Does the list contains the requested filename |
758 | 694 |
* |
... | ... | |
767 | 703 |
} |
768 | 704 |
|
769 | 705 |
public void clearSelectedRows() { |
770 |
for (int r : selectedRows) { |
|
771 |
int row = r - startIndex; |
|
772 |
styleRow(row, false); |
|
773 |
table.setWidget(row + 1, 0, AbstractImagePrototype.create(images.document()).createImage()); |
|
706 |
Iterator<FileResource> it = selectionModel.getSelectedSet().iterator(); |
|
707 |
while(it.hasNext()){ |
|
708 |
selectionModel.setSelected(it.next(),false); |
|
774 | 709 |
} |
775 |
selectedRows.clear(); |
|
776 |
Object sel = GSS.get().getCurrentSelection(); |
|
777 |
if (sel instanceof FileResource || sel instanceof List) |
|
778 |
GSS.get().setCurrentSelection(null); |
|
779 | 710 |
} |
780 | 711 |
|
781 |
public static native void preventIESelection() /*-{ |
|
782 |
$doc.body.onselectstart = function () { return false; }; |
|
783 |
}-*/; |
|
712 |
/** |
|
713 |
* |
|
714 |
*/ |
|
715 |
public void selectAllRows() { |
|
716 |
Iterator<FileResource> it = selectionModel.getSelectedSet().iterator(); |
|
717 |
while(it.hasNext()){ |
|
718 |
selectionModel.setSelected(it.next(),true); |
|
719 |
} |
|
720 |
|
|
784 | 721 |
|
785 |
public static native void enableIESelection() /*-{ |
|
786 |
if ($doc.body.onselectstart != null) |
|
787 |
$doc.body.onselectstart = null; |
|
788 |
}-*/; |
|
722 |
} |
|
789 | 723 |
|
790 |
public void selectAllRows() { |
|
791 |
clearSelectedRows(); |
|
792 |
int count = folderFileCount; |
|
793 |
if (count == 0) |
|
724 |
|
|
725 |
private void sortFiles(final String sortingProperty, final boolean sortingType){ |
|
726 |
Collections.sort(files, new Comparator<FileResource>() { |
|
727 |
|
|
728 |
@Override |
|
729 |
public int compare(FileResource arg0, FileResource arg1) { |
|
730 |
AbstractImagePrototype descPrototype = AbstractImagePrototype.create(images.desc()); |
|
731 |
AbstractImagePrototype ascPrototype = AbstractImagePrototype.create(images.asc()); |
|
732 |
if (sortingType){ |
|
733 |
if (sortingProperty.equals("version")) { |
|
734 |
return arg0.getVersion().compareTo(arg1.getVersion()); |
|
735 |
} else if (sortingProperty.equals("owner")) { |
|
736 |
return arg0.getOwner().compareTo(arg1.getOwner()); |
|
737 |
} else if (sortingProperty.equals("date")) { |
|
738 |
return arg0.getModificationDate().compareTo(arg1.getModificationDate()); |
|
739 |
} else if (sortingProperty.equals("size")) { |
|
740 |
return arg0.getContentLength().compareTo(arg1.getContentLength()); |
|
741 |
} else if (sortingProperty.equals("name")) { |
|
742 |
return arg0.getName().compareTo(arg1.getName()); |
|
743 |
} else if (sortingProperty.equals("path")) { |
|
744 |
return arg0.getUri().compareTo(arg1.getUri()); |
|
745 |
} else { |
|
746 |
return arg0.getName().compareTo(arg1.getName()); |
|
747 |
} |
|
748 |
} |
|
749 |
else if (sortingProperty.equals("version")) { |
|
750 |
|
|
751 |
return arg1.getVersion().compareTo(arg0.getVersion()); |
|
752 |
} else if (sortingProperty.equals("owner")) { |
|
753 |
|
|
754 |
return arg1.getOwner().compareTo(arg0.getOwner()); |
|
755 |
} else if (sortingProperty.equals("date")) { |
|
756 |
|
|
757 |
return arg1.getModificationDate().compareTo(arg0.getModificationDate()); |
|
758 |
} else if (sortingProperty.equals("size")) { |
|
759 |
|
|
760 |
return arg1.getContentLength().compareTo(arg0.getContentLength()); |
|
761 |
} else if (sortingProperty.equals("name")) { |
|
762 |
|
|
763 |
return arg1.getName().compareTo(arg0.getName()); |
|
764 |
} else if (sortingProperty.equals("path")) { |
|
765 |
|
|
766 |
return arg1.getUri().compareTo(arg0.getUri()); |
|
767 |
} else { |
|
768 |
|
|
769 |
return arg1.getName().compareTo(arg0.getName()); |
|
770 |
} |
|
771 |
} |
|
772 |
|
|
773 |
}); |
|
774 |
} |
|
775 |
|
|
776 |
final class FileValueUpdater implements ValueUpdater<String>{ |
|
777 |
private String property; |
|
778 |
private SortableHeader header; |
|
779 |
/** |
|
780 |
* |
|
781 |
*/ |
|
782 |
public FileValueUpdater(SortableHeader header,String property) { |
|
783 |
this.property=property; |
|
784 |
this.header=header; |
|
785 |
} |
|
786 |
@Override |
|
787 |
public void update(String value) { |
|
788 |
header.setSorted(true); |
|
789 |
header.toggleReverseSort(); |
|
790 |
|
|
791 |
for (SortableHeader otherHeader : allHeaders) { |
|
792 |
if (otherHeader != header) { |
|
793 |
otherHeader.setSorted(false); |
|
794 |
otherHeader.setReverseSort(true); |
|
795 |
} |
|
796 |
} |
|
797 |
celltable.redrawHeaders(); |
|
798 |
sortFiles(property, header.getReverseSort()); |
|
799 |
SearchResults.this.update(true); |
|
800 |
} |
|
801 |
|
|
802 |
} |
|
803 |
/** |
|
804 |
* Creates a new ArrayList<FileResources> from the given files ArrayList |
|
805 |
* in order that the input files remain untouched |
|
806 |
* and continues to find user's full names of each FileResource element |
|
807 |
* in the new ArrayList |
|
808 |
* |
|
809 |
* @param filesInput |
|
810 |
*/ |
|
811 |
private void copyListAndContinue(List<FileResource> filesInput){ |
|
812 |
List<FileResource> copiedFiles = new ArrayList<FileResource>(); |
|
813 |
for(FileResource file : filesInput) { |
|
814 |
copiedFiles.add(file); |
|
815 |
} |
|
816 |
handleFullNames(copiedFiles); |
|
817 |
} |
|
818 |
|
|
819 |
/** |
|
820 |
* Examines whether or not the user's full name exists in the |
|
821 |
* userFullNameMap in the GSS.java for every element of the input list. |
|
822 |
* If the user's full name does not exist in the map then a command is being made. |
|
823 |
* |
|
824 |
* @param filesInput |
|
825 |
*/ |
|
826 |
private void handleFullNames(List<FileResource> filesInput){ |
|
827 |
if(filesInput.size() == 0){ |
|
828 |
showCellTable(); |
|
829 |
return; |
|
830 |
} |
|
831 |
|
|
832 |
if(GSS.get().findUserFullName(filesInput.get(0).getOwner()) == null){ |
|
833 |
findFullNameAndUpdate(filesInput); |
|
794 | 834 |
return; |
795 |
int max = startIndex + GSS.VISIBLE_FILE_COUNT; |
|
796 |
if (max > count) |
|
797 |
max = count; |
|
798 |
int i = 1; |
|
799 |
for (; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) { |
|
800 |
// Don't read past the end. |
|
801 |
// if (i > folderFileCount) |
|
802 |
// break; |
|
803 |
if (startIndex + i > folderFileCount) |
|
804 |
break; |
|
805 |
selectedRows.add(startIndex + i - 1); |
|
806 |
styleRow(i - 1, true); |
|
807 | 835 |
} |
808 |
GSS.get().setCurrentSelection(getSelectedFiles()); |
|
809 |
//contextMenu.setFiles(getSelectedFiles()); |
|
810 |
//table.setWidget(i - 1, 0, contextMenu); |
|
836 |
|
|
837 |
if(filesInput.size() >= 1){ |
|
838 |
filesInput.remove(filesInput.get(0)); |
|
839 |
if(filesInput.isEmpty()){ |
|
840 |
showCellTable(); |
|
841 |
}else{ |
|
842 |
handleFullNames(filesInput); |
|
843 |
} |
|
844 |
} |
|
811 | 845 |
} |
846 |
|
|
847 |
/** |
|
848 |
* Makes a command to search for full name from a given username. |
|
849 |
* Only after the completion of the command the celltable is shown |
|
850 |
* or the search for the next full name continues. |
|
851 |
* |
|
852 |
* @param filesInput |
|
853 |
*/ |
|
854 |
private void findFullNameAndUpdate(final List<FileResource> filesInput){ |
|
855 |
String aUserName = filesInput.get(0).getOwner(); |
|
856 |
String path = GSS.get().getApiPath() + "users/" + aUserName; |
|
857 |
|
|
858 |
GetCommand<UserSearchResource> gg = new GetCommand<UserSearchResource>(UserSearchResource.class, path, false,null) { |
|
859 |
@Override |
|
860 |
public void onComplete() { |
|
861 |
final UserSearchResource result = getResult(); |
|
862 |
for (UserResource user : result.getUsers()){ |
|
863 |
String username = user.getUsername(); |
|
864 |
String userFullName = user.getName(); |
|
865 |
GSS.get().putUserToMap(username, userFullName); |
|
866 |
if(filesInput.size() >= 1){ |
|
867 |
filesInput.remove(filesInput.get(0)); |
|
868 |
if(filesInput.isEmpty()){ |
|
869 |
showCellTable(); |
|
870 |
}else{ |
|
871 |
handleFullNames(filesInput); |
|
872 |
} |
|
873 |
} |
|
874 |
} |
|
875 |
} |
|
876 |
@Override |
|
877 |
public void onError(Throwable t) { |
|
878 |
GWT.log("", t); |
|
879 |
GSS.get().displayError("Unable to fetch user's full name from the given username " + filesInput.get(0).getOwner()); |
|
880 |
if(filesInput.size() >= 1){ |
|
881 |
filesInput.remove(filesInput.get(0)); |
|
882 |
handleFullNames(filesInput); |
|
883 |
} |
|
884 |
} |
|
885 |
}; |
|
886 |
DeferredCommand.addCommand(gg); |
|
887 |
|
|
888 |
} |
|
889 |
/** |
|
890 |
* Shows the files in the cellTable |
|
891 |
*/ |
|
892 |
|
|
893 |
private void showCellTable(){ |
|
894 |
|
|
895 |
//celltable.setRowCount(files.size()); |
|
896 |
//celltable.setRowData(0,files); |
|
897 |
if(files.size()>=GSS.VISIBLE_FILE_COUNT){ |
|
898 |
pager.setVisible(true); |
|
899 |
} |
|
900 |
else{ |
|
901 |
pager.setVisible(false); |
|
902 |
} |
|
903 |
provider.setList(files); |
|
904 |
provider.refresh(); |
|
905 |
//celltable.redraw(); |
|
906 |
celltable.redrawHeaders(); |
|
907 |
} |
|
908 |
|
|
909 |
|
|
812 | 910 |
|
813 | 911 |
} |
Also available in: Unified diff