*/
package gr.ebs.gss.client;
-import gr.ebs.gss.client.dnd.DnDSimpleFocusPanel;
-import gr.ebs.gss.client.dnd.DnDTreeItem;
+import static com.google.gwt.query.client.GQuery.$;
import gr.ebs.gss.client.rest.GetCommand;
-import gr.ebs.gss.client.rest.MultipleHeadCommand;
import gr.ebs.gss.client.rest.RestCommand;
-import gr.ebs.gss.client.rest.RestException;
import gr.ebs.gss.client.rest.resource.FileResource;
-import gr.ebs.gss.client.rest.resource.FolderResource;
import gr.ebs.gss.client.rest.resource.OtherUserResource;
+import gr.ebs.gss.client.rest.resource.OthersFolderResource;
+import gr.ebs.gss.client.rest.resource.RestResource;
+import gr.ebs.gss.client.rest.resource.RestResourceWrapper;
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 gwtquery.plugins.draggable.client.DraggableOptions;
+import gwtquery.plugins.draggable.client.StopDragException;
+import gwtquery.plugins.draggable.client.DraggableOptions.DragFunction;
+import gwtquery.plugins.draggable.client.DraggableOptions.RevertOption;
+import gwtquery.plugins.draggable.client.events.DragContext;
+import gwtquery.plugins.draggable.client.events.DragStartEvent;
+import gwtquery.plugins.draggable.client.events.DragStopEvent;
+import gwtquery.plugins.draggable.client.events.DragStartEvent.DragStartEventHandler;
+import gwtquery.plugins.draggable.client.events.DragStopEvent.DragStopEventHandler;
+import gwtquery.plugins.droppable.client.gwt.DragAndDropCellTable;
+import gwtquery.plugins.droppable.client.gwt.DragAndDropColumn;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.ImageResourceCell;
+import com.google.gwt.cell.client.SafeHtmlCell;
+import com.google.gwt.cell.client.TextCell;
import com.google.gwt.cell.client.ValueUpdater;
+import com.google.gwt.cell.client.Cell.Context;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.RepeatingCommand;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
+import com.google.gwt.dom.client.Style.Cursor;
+import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.http.client.URL;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;
+import com.google.gwt.safehtml.client.SafeHtmlTemplates;
+import com.google.gwt.safehtml.shared.SafeHtml;
+import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.Column;
+import com.google.gwt.user.cellview.client.SimplePager;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.Composite;
-import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
-import com.google.gwt.user.client.ui.TreeItem;
-import com.google.gwt.user.client.ui.Widget;
-import com.google.gwt.view.client.DefaultSelectionEventManager;
+import com.google.gwt.user.client.ui.VerticalPanel;
+import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.MultiSelectionModel;
import com.google.gwt.view.client.ProvidesKey;
import com.google.gwt.view.client.SelectionChangeEvent;
* A composite that displays the list of files in a particular folder.
*/
public class FileList extends Composite {
+ ListDataProvider<FileResource> provider = new ListDataProvider<FileResource>();
+ interface TableResources extends DragAndDropCellTable.Resources {
+ @Source({CellTable.Style.DEFAULT_CSS, "GssCellTable.css"})
+ TableStyle cellTableStyle();
+ }
+
+ static interface Templates extends SafeHtmlTemplates {
+ Templates INSTANCE = GWT.create(Templates.class);
+ @Template("<div id='dragHelper' style='border:1px solid black; background-color:#ffffff; color:black; width:150px;z-index:100'></div>")
+ SafeHtml outerHelper();
+ }
+
+ /**
+ * The styles applied to the table.
+ */
+ interface TableStyle extends CellTable.Style {
+ }
+
private String showingStats = "";
private int startIndex = 0;
*/
public static final boolean DONE = false;
- /**
- * The context menu for the selected file.
- */
- final DnDSimpleFocusPanel contextMenu;
+
private final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
* Specifies that the images available for this composite will be the ones
* available in FileContextMenu.
*/
- public interface Images extends ClientBundle,FileContextMenu.Images, Folders.Images {
+ public interface Images extends ClientBundle,FileContextMenu.Images, CellTreeView.Images {
@Source("gr/ebs/gss/resources/blank.gif")
ImageResource blank();
ImageResource zipShared();
}
+
+ DragStopEventHandler dragStop = new DragStopEventHandler() {
+
+ @Override
+ public void onDragStop(DragStopEvent event) {
+ GWT.log("DRAG STOPPED");
+
+ }
+ };
+
+ private static class ContactCell extends AbstractCell<gr.ebs.gss.client.rest.resource.FileResource> {
- /**
- * A label with the number of files in this folder.
- */
- private HTML countLabel = new HTML();
+ /**
+ * The html of the image used for contacts.
+ *
+ */
+ private final String imageHtml;
- /**
- * The table widget with the file list.
- */
- //private FileTable table = new FileTable(GSS.VISIBLE_FILE_COUNT + 1, 8);
+ public ContactCell(ImageResource image) {
+ this.imageHtml = AbstractImagePrototype.create(image).getHTML();
+ }
+
+
+
+
+
+ @Override
+ public void render(Context context, FileResource value, SafeHtmlBuilder sb) {
+ // Value can be null, so do a null check..
+ if (value == null) {
+ return;
+ }
+
+ sb.appendHtmlConstant("<table>");
+
+ // Add the contact image.
+ sb.appendHtmlConstant("<tr><td rowspan='3'>");
+ sb.appendHtmlConstant(imageHtml);
+ sb.appendHtmlConstant("</td>");
+
+ // Add the name and address.
+ DisplayHelper.log("value.getName()");
+ sb.appendHtmlConstant("<td style='font-size:95%;' id='"+value.getName()+"'>");
+ sb.appendEscaped(value.getName());
+ sb.appendHtmlConstant("</td></tr><tr><td>");
+ sb.appendEscaped(value.getFileSizeAsString());
+ sb.appendHtmlConstant("</td></tr></table>");
+ }
+
+ }
/**
- * The navigation bar for paginating the results.
+ * Retrieve the celltable.
+ *
+ * @return the celltable
*/
- private HorizontalPanel navBar = new HorizontalPanel();
-
+ public DragAndDropCellTable<FileResource> getCelltable() {
+ return celltable;
+ }
+
+
/**
* The number of files in this folder.
*/
* The widget's image bundle.
*/
private final Images images;
-
private FileContextMenu menuShowing;
- private CellTable<FileResource> celltable;
+ private DragAndDropCellTable<FileResource> celltable;
private final MultiSelectionModel<FileResource> selectionModel;
private final List<SortableHeader> allHeaders = new ArrayList<SortableHeader>();
SortableHeader nameHeader;
+ SimplePager pager;
+ SimplePager pagerTop;
/**
* Construct the file list widget. This entails setting up the widget
* layout, fetching the number of files in the current folder from the
*/
public FileList(Images _images) {
images = _images;
-
-
- contextMenu = new DnDSimpleFocusPanel(new HTML(AbstractImagePrototype.create(images.fileContextMenu()).getHTML()));
- GSS.get().getDragController().makeDraggable(contextMenu);
-
- // Setup the table.
-
-
- // Create the 'navigation' bar at the upper-right.
- HorizontalPanel innerNavBar = new HorizontalPanel();
- innerNavBar.setStyleName("gss-ListNavBar");
- innerNavBar.setSpacing(8);
- innerNavBar.add(countLabel);
- navBar.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
- navBar.add(innerNavBar);
- navBar.setWidth("100%");
+ DragAndDropCellTable.Resources resources = GWT.create(TableResources.class);
ProvidesKey<FileResource> keyProvider = new ProvidesKey<FileResource>(){
@Override
}
};
- final TextColumn<FileResource> nameColumn = new TextColumn<FileResource>() {
-
- @Override
- public String getValue(FileResource object) {
- // TODO Auto-generated method stub
- return object.getName();
- }
-
-
- };
- celltable = new CellTable<FileResource>(keyProvider){
- @Override
- protected void onBrowserEvent2(Event event) {
- if (DOM.eventGetType((Event) event) == Event.ONMOUSEDOWN && DOM.eventGetButton((Event) event) == NativeEvent.BUTTON_RIGHT){
- fireClickEvent((Element) event.getEventTarget().cast());
- }
- super.onBrowserEvent2(event);
- }
- };
-
+ celltable = new DragAndDropCellTable<FileResource>(GSS.VISIBLE_FILE_COUNT,resources,keyProvider);
- Column<FileResource, ImageResource> status = new Column<FileResource, ImageResource>(new ImageResourceCell()) {
+ DragAndDropColumn<FileResource, ImageResource> status = new DragAndDropColumn<FileResource, ImageResource>(new ImageResourceCell(){
+ @Override
+ public boolean handlesSelection() {
+ return false;
+ }
+ }) {
@Override
public ImageResource getValue(FileResource entity) {
return getFileIcon(entity);
}
+
};
- celltable.addColumn(status,"");
-
-
+ celltable.addColumn(status,"");
+
+ initDragOperation(status);
+ final DragAndDropColumn<FileResource,SafeHtml> nameColumn = new DragAndDropColumn<FileResource,SafeHtml>(new SafeHtmlCell()) {
+
+
+ @Override
+ public SafeHtml getValue(FileResource object) {
+ SafeHtmlBuilder sb = new SafeHtmlBuilder();
+ if (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg") ){
+ sb.appendHtmlConstant("<span id='fileList."+ object.getName() +"'>");
+ sb.appendEscaped(object.getName());
+ sb.appendHtmlConstant("</span>");
+ sb.appendHtmlConstant(" <a href='" +
+ GSS.get().getTopPanel().getFileMenu().getDownloadURL(object) +
+ "' title='" + object.getOwner() + " : " + object.getPath() + object.getName() +
+ "' rel='lytebox[mnf]' " +
+ "onclick='myLytebox.start(this, false, false); return false;'>" +
+ "(view)" + "</a>");
+
+
+ }
+ else{
+ sb.appendHtmlConstant("<span id='fileList."+ object.getName() +"'>");
+ sb.appendEscaped(object.getName());
+ sb.appendHtmlConstant("</span>");
+ }
+
+ return sb.toSafeHtml();
+ }
+
+ };
+ initDragOperation(nameColumn);
celltable.addColumn(nameColumn,nameHeader = new SortableHeader("Name"));
allHeaders.add(nameHeader);
- nameHeader.setSorted(true);
- nameHeader.toggleReverseSort();
+ //nameHeader.setSorted(true);
+ //nameHeader.toggleReverseSort();
nameHeader.setUpdater(new FileValueUpdater(nameHeader, "name"));
celltable.redrawHeaders();
- SortableHeader aheader;
- celltable.addColumn(new TextColumn<FileResource>() {
+
+
+
+
+ SortableHeader aheader;
+ DragAndDropColumn<FileResource,String> aColumn;
+ celltable.addColumn(aColumn=new DragAndDropColumn<FileResource,String>(new TextCell()) {
@Override
public String getValue(FileResource object) {
- // TODO Auto-generated method stub
- return object.getOwner();
+ return GSS.get().findUserFullName(object.getOwner());
}
},aheader = new SortableHeader("Owner"));
+ initDragOperation(aColumn);
allHeaders.add(aheader);
aheader.setUpdater(new FileValueUpdater(aheader, "owner"));
- celltable.addColumn(new TextColumn<FileResource>() {
+ celltable.addColumn(aColumn=new DragAndDropColumn<FileResource,String>(new TextCell()) {
@Override
public String getValue(FileResource object) {
// TODO Auto-generated method stub
return object.getPath();
}
},aheader = new SortableHeader("Path"));
+ initDragOperation(aColumn);
allHeaders.add(aheader);
+
aheader.setUpdater(new FileValueUpdater(aheader, "path"));
- celltable.addColumn(new TextColumn<FileResource>() {
+ celltable.addColumn(aColumn=new DragAndDropColumn<FileResource,String>(new TextCell()) {
@Override
public String getValue(FileResource object) {
- // TODO Auto-generated method stub
return object.getVersion().toString();
}
},aheader = new SortableHeader("Version"));
+ initDragOperation(aColumn);
allHeaders.add(aheader);
aheader.setUpdater(new FileValueUpdater(aheader, "version"));
- celltable.addColumn(new TextColumn<FileResource>() {
+ celltable.addColumn(aColumn=new DragAndDropColumn<FileResource,String>(new TextCell()) {
@Override
public String getValue(FileResource object) {
// TODO Auto-generated method stub
return object.getFileSizeAsString();
}
},aheader = new SortableHeader("Size"));
+ initDragOperation(aColumn);
allHeaders.add(aheader);
aheader.setUpdater(new FileValueUpdater(aheader, "size"));
- celltable.addColumn(new TextColumn<FileResource>() {
+ celltable.addColumn(aColumn=new DragAndDropColumn<FileResource,String>(new TextCell()) {
@Override
public String getValue(FileResource object) {
return formatter.format(object.getModificationDate());
},aheader = new SortableHeader("Last Modified"));
allHeaders.add(aheader);
aheader.setUpdater(new FileValueUpdater(aheader, "date"));
- initWidget(celltable);
- setStyleName("gss-List");
+
+
+ provider.addDataDisplay(celltable);
+ celltable.addDragStopHandler(dragStop);
+ celltable.addDragStartHandler(new DragStartEventHandler() {
+
+ public void onDragStart(DragStartEvent event) {
+ FileResource value = event.getDraggableData();
+
+ com.google.gwt.dom.client.Element helper = event.getHelper();
+ SafeHtmlBuilder sb = new SafeHtmlBuilder();
+ sb.appendHtmlConstant("<b>");
+ DisplayHelper.log(value.getName());
+ if(getSelectedFiles().size()==1)
+ sb.appendEscaped(value.getName());
+ else
+ sb.appendEscaped(getSelectedFiles().size()+" files");
+ sb.appendHtmlConstant("</b>");
+ helper.setInnerHTML(sb.toSafeHtml().asString());
+
+ }
+ });
+
+
+
+
+
+
+ VerticalPanel vp = new VerticalPanel();
+ vp.setWidth("100%");
+ pagerTop = new SimplePager(SimplePager.TextLocation.CENTER);
+ pagerTop.setDisplay(celltable);
+ vp.add(pagerTop);
+ celltable.setWidth("100%");
+ vp.add(celltable);
+ pager = new SimplePager(SimplePager.TextLocation.CENTER);
+ pager.setDisplay(celltable);
+
+ vp.add(pager);
+ vp.setCellWidth(celltable, "100%");
+
+ initWidget(vp);
+ pager.setVisible(false);
+ pagerTop.setVisible(false);
+
+ celltable.setStyleName("gss-List");
selectionModel = new MultiSelectionModel<FileResource>();
GSS.get().setCurrentSelection(getSelectedFiles().get(0));
else
GSS.get().setCurrentSelection(getSelectedFiles());
- contextMenu.setFiles(getSelectedFiles());
}
};
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());
}
+ private void initDragOperation(DragAndDropColumn<?, ?> column) {
+
+ // retrieve draggableOptions on the column
+ DraggableOptions draggableOptions = column.getDraggableOptions();
+ // use template to construct the helper. The content of the div will be set
+ // after
+ draggableOptions.setHelper($(Templates.INSTANCE.outerHelper().asString()));
+ //draggableOptions.setZIndex(100);
+ // opacity of the helper
+ draggableOptions.setAppendTo("body");
+ //draggableOptions.setOpacity((float) 0.8);
+ draggableOptions.setContainment("document");
+ // cursor to use during the drag operation
+ draggableOptions.setCursor(Cursor.MOVE);
+ // set the revert option
+ draggableOptions.setRevert(RevertOption.ON_INVALID_DROP);
+ // prevents dragging when user click on the category drop-down list
+ draggableOptions.setCancel("select");
+
+
+ draggableOptions.setOnBeforeDragStart(new DragFunction() {
+
+ @Override
+ public void f(DragContext context) {
+ FileResource value = context.getDraggableData();
+ if(!selectionModel.isSelected(value)){
+ throw new StopDragException();
+ }
+
+ }
+ });
+ }
-
+ public void showContextMenu(Event event){
+ menuShowing = new FileContextMenu(images, false, true);
+ menuShowing=menuShowing.onEmptyEvent(event);
+ }
@Override
public void onBrowserEvent(Event event) {
if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) {
menuShowing = new FileContextMenu(images, false, true);
menuShowing=menuShowing.onEmptyEvent(event);
+ event.preventDefault();
+ event.cancelBubble(true);
}
return;
}
GWT.log("*****GOING TO SHOW CONTEXT MENU ****", null);
menuShowing = new FileContextMenu(images, false, false);
menuShowing=menuShowing.onEvent(event);
+ event.cancelBubble(true);
+ event.preventDefault();
} else if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) {
menuShowing = new FileContextMenu(images, false, true);
menuShowing=menuShowing.onEmptyEvent(event);
+ event.cancelBubble(true);
+ event.preventDefault();
} else if (DOM.eventGetType(event) == Event.ONDBLCLICK)
if (getSelectedFiles().size() == 1) {
GSS app = GSS.get();
return DONE;
}
-
-
-
- /**
- * Make the specified row look like selected or not, according to the
- * <code>selected</code> flag.
- *
- * @param row
- * @param selected
- */
- void styleRow(final int row, final boolean selected) {
-
- }
/**
* Update the display of the file list.
max = count;
folderTotalSize = 0;
- celltable.setRowCount(files.size());
- celltable.setRowData(0,files);
- celltable.redrawHeaders();
+ copyListAndContinue(files);
+ for(FileResource f : files){
+ folderTotalSize += f.getContentLength();
+ }
if (folderFileCount == 0) {
showingStats = "no files";
} else if (folderFileCount < GSS.VISIBLE_FILE_COUNT) {
} else {
showingStats = "" + (startIndex + 1) + " - " + max + " of " + count + " files" + " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")";
}
+ showCellTable();
updateCurrentlyShowingStats();
}
private ImageResource getFileIcon(FileResource file) {
String mimetype = file.getContentType();
boolean shared = false;
- Folders folders = GSS.get().getFolders();
- if(folders.getCurrent() != null && folders.isOthersSharedItem(folders.getCurrent())){
- DnDTreeItem otherUser = (DnDTreeItem) folders.getUserOfSharedItem(folders.getCurrent());
- if(otherUser==null)
- shared = false;
+ if(GSS.get().getTreeView().getSelection()!=null && (GSS.get().getTreeView().getSelection() instanceof OtherUserResource || GSS.get().getTreeView().getSelection() instanceof OthersFolderResource)){
+ OtherUserResource otherUser = null;
+ if(GSS.get().getTreeView().getSelection() instanceof OtherUserResource)
+ otherUser = (OtherUserResource) GSS.get().getTreeView().getSelection();
+ else if (GSS.get().getTreeView().getSelection() instanceof OthersFolderResource){
+ otherUser = GSS.get().getTreeView().getOtherUserResourceOfOtherFolder((OthersFolderResource) GSS.get().getTreeView().getSelection());
+ }
+ if(otherUser ==null)
+ shared=false;
else{
- String uname = otherUser.getOtherUserResource().getUsername();
+ String uname = otherUser.getUsername();
if(uname==null)
- uname = ((DnDTreeItem)folders.getSharesItem()).getOthersResource().getUsernameOfUri(otherUser.getOtherUserResource().getUri());
+ uname = GSS.get().getTreeView().getOthers().getUsernameOfUri(otherUser.getUri());
if(uname != null)
shared = file.isShared();
}
public void updateCurrentlyShowingStats() {
GSS.get().getStatusPanel().updateCurrentlyShowing(showingStats);
}
-
- /**
- * Adjust the height of the table by adding and removing rows as necessary.
- *
- * @param newHeight the new height to reach
- */
- //void resizeTableHeight(final int newHeight) {
- /*GWT.log("Panel: " + newHeight + ", parent: " + table.getParent().getOffsetHeight(), null);
- // Fill the rest with empty slots.
- if (newHeight > table.getOffsetHeight())
- while (newHeight > table.getOffsetHeight()) {
- table.resizeRows(table.getRowCount() + 1);
- GWT.log("Table: " + table.getOffsetHeight() + ", rows: " + table.getRowCount(), null);
- }
- else
- while (newHeight < table.getOffsetHeight()) {
- table.resizeRows(table.getRowCount() - 1);
- GWT.log("Table: " + table.getOffsetHeight() + ", rows: " + table.getRowCount(), null);
- }*/
- //}
-
- public void updateFileCache(boolean updateSelectedFolder, final boolean clearSelection) {
- updateFileCache(updateSelectedFolder, clearSelection, null);
- }
-
- public void updateFileCache(boolean updateSelectedFolder, final boolean clearSelection, final String newFilename) {
- if (!updateSelectedFolder && !GSS.get().getFolders().getCurrent().equals(GSS.get().getFolders().getTrashItem()))
- updateFileCache(clearSelection);
- else if (GSS.get().getFolders().getCurrent() != null) {
- final DnDTreeItem folderItem = (DnDTreeItem) GSS.get().getFolders().getCurrent();
- if (folderItem.getFolderResource() != null) {
- if(GSS.get().getFolders().isFileItem(folderItem) || GSS.get().getFolders().isMySharedItem(folderItem) || GSS.get().getFolders().isOthersSharedItem(folderItem) ){
- update(true);
- GetCommand<FolderResource> gf = new GetCommand<FolderResource>(FolderResource.class, folderItem.getFolderResource().getUri(),folderItem.getFolderResource()) {
-
- @Override
- public void onComplete() {
- folderItem.setUserObject(getResult());
- if(GSS.get().getFolders().isFileItem(folderItem)){
- String[] filePaths = new String[folderItem.getFolderResource().getFilePaths().size()];
- int c=0;
- for(String fpath : folderItem.getFolderResource().getFilePaths()){
- filePaths[c] = fpath + "?" + Math.random();
- c++;
- }
- MultipleHeadCommand<FileResource> getFiles = new MultipleHeadCommand<FileResource>(FileResource.class, filePaths, folderItem.getFolderResource().getFileCache()){
-
- @Override
- public void onComplete(){
- List<FileResource> result = getResult();
- //remove random from path
- for(FileResource r : result){
- String p = r.getUri();
- int indexOfQuestionMark = p.lastIndexOf('?');
- if(indexOfQuestionMark>0)
- r.setUri(p.substring(0, indexOfQuestionMark));
- GWT.log("FETCHED:"+r.getLastModifiedSince(), null);
- }
- folderItem.getFolderResource().setFiles(result);
- folderItem.getFolderResource().setFilesExpanded(true);
- updateFileCache(clearSelection, newFilename);
- }
-
- @Override
- public void onError(String p, Throwable throwable) {
- if(throwable instanceof RestException)
- GSS.get().displayError("Unable to retrieve file details:"+((RestException)throwable).getHttpStatusText());
- }
-
- @Override
- public void onError(Throwable t) {
- GWT.log("", t);
- GSS.get().displayError("Unable to fetch files for folder " + folderItem.getFolderResource().getName());
- }
-
- };
- DeferredCommand.addCommand(getFiles);
- }
- else
- updateFileCache(clearSelection, newFilename);
- }
-
- @Override
- public void onError(Throwable t) {
- GWT.log("", t);
- GSS.get().displayError("Unable to fetch folder " + folderItem.getFolderResource().getName());
- }
- };
- DeferredCommand.addCommand(gf);
- }
- }
- else if (folderItem.getTrashResource() != null) {
- GetCommand<TrashResource> gt = new GetCommand<TrashResource>(TrashResource.class, folderItem.getTrashResource().getUri(), null) {
-
- @Override
- public void onComplete() {
- folderItem.setUserObject(getResult());
- updateFileCache(clearSelection);
- }
-
- @Override
- public void onError(Throwable t) {
- if (t instanceof RestException && (((RestException) t).getHttpStatusCode() == 204 || ((RestException) t).getHttpStatusCode() == 1223)) {
- folderItem.setUserObject(new TrashResource(folderItem.getTrashResource().getUri()));
- updateFileCache(clearSelection);
- } else {
- GWT.log("", t);
- GSS.get().displayError("Unable to fetch trash resource");
- }
- }
- };
- DeferredCommand.addCommand(gt);
- } else if (folderItem.getSharedResource() != null) {
- GetCommand<SharedResource> gt = new GetCommand<SharedResource>(SharedResource.class, folderItem.getSharedResource().getUri(), null) {
-
- @Override
- public void onComplete() {
- folderItem.setUserObject(getResult());
- for(FileResource r : folderItem.getSharedResource().getFiles()){
- String p = r.getUri();
- int indexOfQuestionMark = p.lastIndexOf('?');
- if(indexOfQuestionMark>0)
- r.setUri(p.substring(0, indexOfQuestionMark));
- GWT.log("FETCHED:"+r.getLastModifiedSince(), null);
- }
- folderItem.getSharedResource().setFilesExpanded(true);
- updateFileCache(clearSelection, newFilename);
-
- }
-
- @Override
- public void onError(Throwable t) {
- GWT.log("", t);
- GSS.get().displayError("Unable to fetch My Shares resource");
- }
- };
- DeferredCommand.addCommand(gt);
- } else if (folderItem.getOtherUserResource() != null) {
- GetCommand<OtherUserResource> gt = new GetCommand<OtherUserResource>(OtherUserResource.class, folderItem.getOtherUserResource().getUri(), null) {
-
- @Override
- public void onComplete() {
- folderItem.setUserObject(getResult());
- //updateFileCache(clearSelection, newFilename);
- for(FileResource r : folderItem.getOtherUserResource().getFiles()){
- String p = r.getUri();
- int indexOfQuestionMark = p.lastIndexOf('?');
- if(indexOfQuestionMark>0)
- r.setUri(p.substring(0, indexOfQuestionMark));
- GWT.log("FETCHED:"+r.getLastModifiedSince(), null);
- }
- folderItem.getOtherUserResource().setFilesExpanded(true);
- updateFileCache(clearSelection, newFilename);
-
- }
-
- @Override
- public void onError(Throwable t) {
- GWT.log("", t);
- GSS.get().displayError("Unable to fetch My Shares resource");
- }
- };
- DeferredCommand.addCommand(gt);
- }
- } else
- updateFileCache(clearSelection);
- }
-
-
- private void updateFileCache(boolean clearSelection) {
- updateFileCache(clearSelection, null);
- }
-
- /**
- * Update the file cache with data from the server.
- *
- * @param newFilename the new name of the previously selected file,
- * if a rename operation has taken place
- */
- private void updateFileCache(boolean clearSelection, String newFilename) {
- if (clearSelection)
+
+ public void updateFileCache(boolean clearSelection){
+ if(clearSelection)
clearSelectedRows();
- startIndex = 0;
- final TreeItem folderItem = GSS.get().getFolders().getCurrent();
+ final RestResource folderItem = GSS.get().getTreeView().getSelection();
// Validation.
- if (folderItem == null || GSS.get().getFolders().isOthersShared(folderItem)) {
+ if (folderItem == null || folderItem.equals(GSS.get().getTreeView().getOthers())) {
setFiles(new ArrayList<FileResource>());
update(true);
return;
}
- if (folderItem instanceof DnDTreeItem) {
- DnDTreeItem dnd = (DnDTreeItem) folderItem;
- if (dnd.getFolderResource() != null) {
- if (GSS.get().getFolders().isTrashItem(dnd))
- setFiles(new ArrayList<FileResource>());
- else
- setFiles(dnd.getFolderResource().getFiles());
-
- } else if (dnd.getTrashResource() != null)
- setFiles(dnd.getTrashResource().getFiles());
- else if (dnd.getSharedResource() != null)
- setFiles(dnd.getSharedResource().getFiles());
- else if (dnd.getOtherUserResource() != null)
- setFiles(dnd.getOtherUserResource().getFiles());
- else
- setFiles(dnd.getFolderResource().getFiles());
+ else if (folderItem instanceof RestResourceWrapper) {
+ setFiles(((RestResourceWrapper) folderItem).getResource().getFiles());
+ update(true);
+ }
+ else if (folderItem instanceof SharedResource) {
+ setFiles(((SharedResource) folderItem).getFiles());
+ update(true);
+ }
+ else if (folderItem instanceof OtherUserResource) {
+ setFiles(((OtherUserResource) folderItem).getFiles());
+ update(true);
+ }
+ else if (folderItem instanceof TrashResource) {
+ setFiles(((TrashResource) folderItem).getFiles());
update(true);
-
}
}
+
/**
* Fill the file cache with data.
*/
public void setFiles(final List<FileResource> _files) {
- if (_files.size() > 0 && !GSS.get().getFolders().isTrash(GSS.get().getFolders().getCurrent())) {
+ if (_files.size() > 0 && ! (GSS.get().getTreeView().getSelection() instanceof TrashResource)) {
files = new ArrayList<FileResource>();
for (FileResource fres : _files)
if (!fres.isDeleted())
files.add(fres);
- } else
+ }
+ else
files = _files;
Collections.sort(files, new Comparator<FileResource>() {
});
folderFileCount = files.size();
+
+ nameHeader.setSorted(true);
+ nameHeader.toggleReverseSort();
+ for (SortableHeader otherHeader : allHeaders) {
+ if (otherHeader != nameHeader) {
+ otherHeader.setSorted(false);
+ otherHeader.setReverseSort(true);
+ }
+ }
+ //
}
while(it.hasNext()){
selectionModel.setSelected(it.next(),false);
}
-
- /*for (int r : selectedRows) {
- int row = r - startIndex;
- styleRow(row, false);
- makeRowNotDraggable(row+1);
- }
- selectedRows.clear();
- Object sel = GSS.get().getCurrentSelection();
- if (sel instanceof FileResource || sel instanceof List)
- GSS.get().setCurrentSelection(null);
- if(menuShowing != null && menuShowing.isShowing()){
- menuShowing.hide();
- menuShowing=null;
- }*/
}
/**
*
*/
public void selectAllRows() {
- /*clearSelectedRows();
- int count = folderFileCount;
- if (count == 0)
- return;
- int max = startIndex + GSS.VISIBLE_FILE_COUNT;
- if (max > count)
- max = count;
- int i = 1;
- for (; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) {
- // Don't read past the end.
- // if (i > folderFileCount)
- // break;
- if (startIndex + i > folderFileCount)
- break;
- selectedRows.add(startIndex + i - 1);
- styleRow(i - 1, true);
- makeRowDraggable(i);
+ Iterator<FileResource> it = provider.getList().iterator();
+ while(it.hasNext()){
+ selectionModel.setSelected(it.next(),true);
}
- GSS.get().setCurrentSelection(getSelectedFiles());
- contextMenu.setFiles(getSelectedFiles());*/
-
- }
-
- private void makeRowDraggable(int row){
- /* int contextRow = getWidgetRow(contextMenu, table);
- if (contextRow != -1)
- table.setWidget(contextRow, 0, getFileIcon(files.get(contextRow - 1)).createImage());
- contextMenu.setWidget(new HTML(getFileIcon(files.get(row - 1)).getHTML()));
- table.setWidget(row, 0, contextMenu);
- //for(int i=1;i<table.getCellCount(row);i++)
- //GSS.get().getDragController().makeDraggable(table.getWidget(row, i));
- table.setWidget(row, 1, new DnDSimpleFocusPanel(table.getWidget(row, 1)));
- ((DnDSimpleFocusPanel)table.getWidget(row, 1)).setFiles(getSelectedFiles());
- GSS.get().getDragController().makeDraggable(table.getWidget(row, 1));*/
- }
- private void makeRowNotDraggable(int row){
- /*if(table.getWidget(row, 1) instanceof DnDSimpleFocusPanel){
- ((DnDSimpleFocusPanel)table.getWidget(row, 1)).setFiles(null);
- GSS.get().getDragController().makeNotDraggable(table.getWidget(row, 1));
- table.setWidget(row, 1, new DnDSimpleFocusPanel(((DnDSimpleFocusPanel)table.getWidget(row, 1)).getWidget()));
- }
- */
}
- private int getWidgetRow(Widget widget, Grid grid) {
- /*for (int row = 0; row < grid.getRowCount(); row++)
- for (int col = 0; col < grid.getCellCount(row); col++) {
- Widget w = table.getWidget(row, col);
- if (w == widget)
- return row;
- }*/
- return -1;
- }
-
private void sortFiles(final String sortingProperty, final boolean sortingType){
Collections.sort(files, new Comparator<FileResource>() {
}
}
+ /**
+ * 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(){
+ if(files.size()>=GSS.VISIBLE_FILE_COUNT){
+ pager.setVisible(true);
+ pagerTop.setVisible(true);
+ }
+ else{
+ pagerTop.setVisible(false);
+ pager.setVisible(false);
+ }
+ provider.setList(files);
+ provider.refresh();
+ //celltable.redraw();
+ celltable.redrawHeaders();
+ }
+
+
}