update trash node on empty
[pithos] / src / gr / ebs / gss / client / FileList.java
index 659af02..f2a9953 100644 (file)
@@ -22,9 +22,6 @@ import static com.google.gwt.query.client.GQuery.$;
 import gr.ebs.gss.client.rest.GetCommand;
 import gr.ebs.gss.client.rest.RestCommand;
 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;
@@ -32,9 +29,14 @@ 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;
 
@@ -46,6 +48,7 @@ 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;
@@ -59,6 +62,7 @@ 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;
@@ -69,12 +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.VerticalPanel;
-import com.google.gwt.user.client.ui.Widget;
 import com.google.gwt.view.client.MultiSelectionModel;
 import com.google.gwt.view.client.ProvidesKey;
 import com.google.gwt.view.client.SelectionChangeEvent;
@@ -196,6 +198,16 @@ public class FileList extends Composite {
                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> {
 
            /**
@@ -314,12 +326,27 @@ public class FileList extends Composite {
                        }
                        
                };
-               final DragAndDropColumn<FileResource,String> nameColumn = new DragAndDropColumn<FileResource,String>(new TextCell()) {
+               final DragAndDropColumn<FileResource,SafeHtml> nameColumn = new DragAndDropColumn<FileResource,SafeHtml>(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.appendEscaped(object.getName());
+                                       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.appendEscaped(object.getName());
+                               return sb.toSafeHtml();
                        }
                        
                        
@@ -334,20 +361,14 @@ public class FileList extends Composite {
                                super.onBrowserEvent2(event);
                        }
                };
+               
+               celltable.addDragStopHandler(dragStop);
                celltable.addDragStartHandler(new DragStartEventHandler() {
 
                      public void onDragStart(DragStartEvent event) {
                        FileResource value = event.getDraggableData();
-                       if(!selectionModel.isSelected(value)){
-                               event.getHelper().removeFromParent();
-                               return;
-                       }
-                       
                        com.google.gwt.dom.client.Element helper = event.getHelper();
-                       
                        SafeHtmlBuilder sb = new SafeHtmlBuilder();
-                       // reuse the contact cell to render the inner html of the drag helper.
-                       ///new CotactCell(images.blank()).render(new Context(0,0, value), value, sb);
                        sb.appendHtmlConstant("<b>");
                        sb.appendEscaped(value.getName());
                        sb.appendHtmlConstant("</b>");
@@ -479,6 +500,18 @@ public class FileList extends Composite {
                    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();
+                                     }
+                                       
+                               }
+                       });
                  }