import gr.ebs.gss.client.rest.resource.SharedResource;
import gr.ebs.gss.client.rest.resource.TrashResource;
import gr.ebs.gss.client.rest.resource.UserResource;
+import gr.ebs.gss.client.rest.resource.UserSearchResource;
import java.util.ArrayList;
import java.util.Collections;
*/
public class FileList extends Composite {
+ interface TableResources extends CellTable.Resources {
+ @Source({CellTable.Style.DEFAULT_CSS, "GssCellTable.css"})
+ TableStyle cellTableStyle();
+ }
+ /**
+ * The styles applied to the table.
+ */
+ interface TableStyle extends CellTable.Style {
+ }
+
private String showingStats = "";
private int startIndex = 0;
*/
public FileList(Images _images) {
images = _images;
-
+ CellTable.Resources resources = GWT.create(TableResources.class);
contextMenu = new DnDSimpleFocusPanel(new HTML(AbstractImagePrototype.create(images.fileContextMenu()).getHTML()));
GSS.get().getDragController().makeDraggable(contextMenu);
};
- celltable = new CellTable<FileResource>(keyProvider){
+ celltable = new CellTable<FileResource>(100,resources,keyProvider){
@Override
protected void onBrowserEvent2(Event event) {
- if (DOM.eventGetType((Event) event) == Event.ONMOUSEDOWN && DOM.eventGetButton((Event) event) == NativeEvent.BUTTON_RIGHT){
+ /*if (DOM.eventGetType((Event) event) == Event.ONMOUSEDOWN && DOM.eventGetButton((Event) event) == NativeEvent.BUTTON_RIGHT){
fireClickEvent((Element) event.getEventTarget().cast());
- }
+ }*/
super.onBrowserEvent2(event);
}
};
celltable.addColumn(new TextColumn<FileResource>() {
@Override
public String getValue(FileResource object) {
- // TODO Auto-generated method stub
- return object.getOwner();
+ return GSS.get().findUserFullName(object.getOwner());
}
},aheader = new SortableHeader("Owner"));
allHeaders.add(aheader);
};
selectionModel.addSelectionChangeHandler(selectionHandler);
- celltable.setSelectionModel(selectionModel,DefaultSelectionEventManager.<FileResource>createDefaultManager());
+ celltable.setSelectionModel(selectionModel,GSSSelectionEventManager.<FileResource>createDefaultManager());
celltable.setPageSize(GSS.VISIBLE_FILE_COUNT);
celltable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
Scheduler.get().scheduleIncremental(new RepeatingCommand() {
sinkEvents(Event.ONDBLCLICK);
GSS.preventIESelection();
}
- public native void fireClickEvent(Element element) /*-{
- var evObj = $doc.createEvent('MouseEvents');
- evObj.initEvent('click', true, true);
- element.dispatchEvent(evObj);
- }-*/;
+
+ //public native void fireClickEvent(Element element) /*-{
+ // var evObj = $doc.createEvent('MouseEvents');
+ //evObj.initEvent('click', true, true);
+ //element.dispatchEvent(evObj);
+ //}-*/;
public List<FileResource> getSelectedFiles() {
return new ArrayList<FileResource>(selectionModel.getSelectedSet());
max = count;
folderTotalSize = 0;
- celltable.setRowCount(files.size());
- celltable.setRowData(0,files);
- celltable.redrawHeaders();
+ copyListAndContinue(files);
+
if (folderFileCount == 0) {
showingStats = "no files";
} else if (folderFileCount < GSS.VISIBLE_FILE_COUNT) {
}
}
+ /**
+ * Creates a new ArrayList<FileResources> from the given files ArrayList
+ * in order that the input files remain untouched
+ * and continues to find user's full names of each FileResource element
+ * in the new ArrayList
+ *
+ * @param filesInput
+ */
+ private void copyListAndContinue(List<FileResource> filesInput){
+ List<FileResource> copiedFiles = new ArrayList<FileResource>();
+ for(FileResource file : filesInput) {
+ copiedFiles.add(file);
+ }
+ handleFullNames(copiedFiles);
+ }
+
+ /**
+ * Examines whether or not the user's full name exists in the
+ * userFullNameMap in the GSS.java for every element of the input list.
+ * If the user's full name does not exist in the map then a command is being made.
+ *
+ * @param filesInput
+ */
+ private void handleFullNames(List<FileResource> filesInput){
+ if(filesInput.size() == 0){
+ showCellTable();
+ return;
+ }
+
+ if(GSS.get().findUserFullName(filesInput.get(0).getOwner()) == null){
+ findFullNameAndUpdate(filesInput);
+ return;
+ }
+
+ if(filesInput.size() >= 1){
+ filesInput.remove(filesInput.get(0));
+ if(filesInput.isEmpty()){
+ showCellTable();
+ }else{
+ handleFullNames(filesInput);
+ }
+ }
+ }
+
+ /**
+ * Makes a command to search for full name from a given username.
+ * Only after the completion of the command the celltable is shown
+ * or the search for the next full name continues.
+ *
+ * @param filesInput
+ */
+ private void findFullNameAndUpdate(final List<FileResource> filesInput){
+ String aUserName = filesInput.get(0).getOwner();
+ String path = GSS.get().getApiPath() + "users/" + aUserName;
+
+ GetCommand<UserSearchResource> gg = new GetCommand<UserSearchResource>(UserSearchResource.class, path, false,null) {
+ @Override
+ public void onComplete() {
+ final UserSearchResource result = getResult();
+ for (UserResource user : result.getUsers()){
+ String username = user.getUsername();
+ String userFullName = user.getName();
+ GSS.get().putUserToMap(username, userFullName);
+ if(filesInput.size() >= 1){
+ filesInput.remove(filesInput.get(0));
+ if(filesInput.isEmpty()){
+ showCellTable();
+ }else{
+ handleFullNames(filesInput);
+ }
+ }
+ }
+ }
+ @Override
+ public void onError(Throwable t) {
+ GWT.log("", t);
+ GSS.get().displayError("Unable to fetch user's full name from the given username " + filesInput.get(0).getOwner());
+ if(filesInput.size() >= 1){
+ filesInput.remove(filesInput.get(0));
+ handleFullNames(filesInput);
+ }
+ }
+ };
+ DeferredCommand.addCommand(gg);
+
+ }
+ /**
+ * Shows the files in the cellTable
+ */
+
+ private void showCellTable(){
+ celltable.setRowCount(files.size());
+ celltable.setRowData(0,files);
+ celltable.redrawHeaders();
+ }
+
+
}