X-Git-Url: https://code.grnet.gr/git/pithos/blobdiff_plain/5b09ea6c7d2b6fcb2cd27c6b8d664f0a962d9b51..bd2b3100be34577bf7bcc8d0d25fc1b14229dff6:/src/gr/ebs/gss/client/FileList.java?ds=sidebyside diff --git a/src/gr/ebs/gss/client/FileList.java b/src/gr/ebs/gss/client/FileList.java index 975ec10..6cf7ab2 100644 --- a/src/gr/ebs/gss/client/FileList.java +++ b/src/gr/ebs/gss/client/FileList.java @@ -18,19 +18,27 @@ */ package gr.ebs.gss.client; - +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.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; @@ -38,17 +46,23 @@ import java.util.Comparator; 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.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.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.safehtml.shared.SafeHtmlUtils; import com.google.gwt.user.cellview.client.CellTable; import com.google.gwt.user.cellview.client.Column; import com.google.gwt.user.cellview.client.TextColumn; @@ -59,14 +73,10 @@ import com.google.gwt.user.client.Event; 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.VerticalPanel; -import com.google.gwt.user.client.ui.Widget; -import com.google.gwt.view.client.DefaultSelectionEventManager; import com.google.gwt.view.client.MultiSelectionModel; import com.google.gwt.view.client.ProvidesKey; import com.google.gwt.view.client.SelectionChangeEvent; @@ -77,11 +87,19 @@ import com.google.gwt.view.client.SelectionChangeEvent.Handler; */ public class FileList extends Composite { - interface TableResources extends CellTable.Resources { + 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("
") + SafeHtml outerHelper(); + } + + /** * The styles applied to the table. */ @@ -181,12 +199,62 @@ public class FileList extends Composite { } + DragStopEventHandler dragStop = new DragStopEventHandler() { + + @Override + public void onDragStop(DragStopEvent event) { + GWT.log("DRAG STOPPED"); + + } + }; + + private static class ContactCell extends AbstractCell { + + /** + * The html of the image used for contacts. + * + */ + private final String imageHtml; + + 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(""); + + // Add the contact image. + sb.appendHtmlConstant(""); + + // Add the name and address. + DisplayHelper.log("value.getName()"); + sb.appendHtmlConstant("
"); + sb.appendHtmlConstant(imageHtml); + sb.appendHtmlConstant(""); + sb.appendEscaped(value.getName()); + sb.appendHtmlConstant("
"); + sb.appendEscaped(value.getFileSizeAsString()); + sb.appendHtmlConstant("
"); + } + + + } /** * Retrieve the celltable. * * @return the celltable */ - public CellTable getCelltable() { + public DragAndDropCellTable getCelltable() { return celltable; } /** @@ -226,7 +294,7 @@ public class FileList extends Composite { VerticalPanel panel; private FileContextMenu menuShowing; - private CellTable celltable; + private DragAndDropCellTable celltable; private final MultiSelectionModel selectionModel; private final List allHeaders = new ArrayList(); SortableHeader nameHeader; @@ -240,7 +308,7 @@ public class FileList extends Composite { */ public FileList(Images _images) { images = _images; - CellTable.Resources resources = GWT.create(TableResources.class); + DragAndDropCellTable.Resources resources = GWT.create(TableResources.class); // Create the 'navigation' bar at the upper-right. @@ -259,27 +327,61 @@ public class FileList extends Composite { } }; - final TextColumn nameColumn = new TextColumn() { + final DragAndDropColumn nameColumn = new DragAndDropColumn(new SafeHtmlCell()) { + @Override - public String getValue(FileResource object) { - // TODO Auto-generated method stub - return object.getName(); + public SafeHtml getValue(FileResource object) { + SafeHtmlBuilder sb = new SafeHtmlBuilder(); + if (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg") ){ + sb.appendHtmlConstant(""); + sb.appendEscaped(object.getName()); + sb.appendHtmlConstant(""); + sb.appendHtmlConstant(" " + + "(view)" + ""); + + + } + else{ + sb.appendHtmlConstant(""); + sb.appendEscaped(object.getName()); + sb.appendHtmlConstant(""); + } + return sb.toSafeHtml(); } }; - celltable = new CellTable(100,resources,keyProvider){ + initDragOperation(nameColumn); + celltable = new DragAndDropCellTable(100,resources,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()); }*/ - GWT.log("event in celltable:"+event.getType()); super.onBrowserEvent2(event); } }; + 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(""); + DisplayHelper.log(value.getName()); + sb.appendEscaped(value.getName()); + sb.appendHtmlConstant(""); + helper.setInnerHTML(sb.toSafeHtml().asString()); + + } + }); Column status = new Column(new ImageResourceCell()) { @Override public ImageResource getValue(FileResource entity) { @@ -386,8 +488,42 @@ public class FileList extends Composite { return new ArrayList(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) { @@ -395,6 +531,8 @@ public class FileList extends Composite { 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; } @@ -402,9 +540,13 @@ public class FileList extends Composite { 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(); @@ -435,19 +577,6 @@ public class FileList extends Composite { return DONE; } - - - - /** - * Make the specified row look like selected or not, according to the - * selected flag. - * - * @param row - * @param selected - */ - void styleRow(final int row, final boolean selected) { - - } /** * Update the display of the file list. @@ -460,7 +589,9 @@ public class FileList extends Composite { folderTotalSize = 0; copyListAndContinue(files); - + for(FileResource f : files){ + folderTotalSize += f.getContentLength(); + } if (folderFileCount == 0) { showingStats = "no files"; } else if (folderFileCount < GSS.VISIBLE_FILE_COUNT) { @@ -485,6 +616,8 @@ public class FileList extends Composite { private ImageResource getFileIcon(FileResource file) { String mimetype = file.getContentType(); boolean shared = false; + //TODO: FETCH USER OF OTHER FOLDER ITEM + //if(GSS.get().getTreeView().getSelection()!=null && (GSS.get().getTreeView().getSelection() instanceof OtherUserResource || GSS.get().getTreeView().getSelection() instanceof OthersFolderResource)) /*Folders folders = GSS.get().getFolders(); if(folders.getCurrent() != null && folders.isOthersSharedItem(folders.getCurrent())){ DnDTreeItem otherUser = (DnDTreeItem) folders.getUserOfSharedItem(folders.getCurrent()); @@ -537,26 +670,6 @@ public class FileList extends Composite { 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); } @@ -565,11 +678,7 @@ public class FileList extends Composite { if (!updateSelectedFolder && !GSS.get().getTreeView().getSelection().equals(GSS.get().getTreeView().getTrash())) updateFileCache(clearSelection); else if (GSS.get().getTreeView().getSelection() != null) { - final RestResource selectedResource = GSS.get().getTreeView().getSelection(); - if (selectedResource instanceof FolderResource) { - - update(true); - } + update(true); } updateFileCache(clearSelection); } @@ -596,8 +705,8 @@ public class FileList extends Composite { update(true); return; } - if (folderItem instanceof FolderResource) { - setFiles(((FolderResource) folderItem).getFiles()); + if (folderItem instanceof RestResourceWrapper) { + setFiles(((RestResourceWrapper) folderItem).getResource().getFiles()); update(true); } if (folderItem instanceof SharedResource) { @@ -614,12 +723,13 @@ public class FileList extends Composite { * Fill the file cache with data. */ public void setFiles(final List _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(); for (FileResource fres : _files) if (!fres.isDeleted()) files.add(fres); - } else*/ + } + else files = _files; Collections.sort(files, new Comparator() { @@ -653,82 +763,20 @@ public class FileList extends Composite { 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 it = selectionModel.getSelectedSet().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() {