configuring dnd
authorkoutsoub <devnull@localhost>
Thu, 3 Feb 2011 09:57:16 +0000 (11:57 +0200)
committerkoutsoub <devnull@localhost>
Thu, 3 Feb 2011 09:57:16 +0000 (11:57 +0200)
src/gr/ebs/gss/client/CellTreeView.java
src/gr/ebs/gss/client/CellTreeViewModel.java
src/gr/ebs/gss/client/FileList.java

index 22b6836..d38b783 100644 (file)
@@ -471,7 +471,29 @@ public class CellTreeView extends Composite{
                        }
                }
        }
-       
+       public void openNodeContainingResource(RestResource resource){
+               TreeNode node = tree.getRootTreeNode();
+               openNodeContainingResource(node,resource);
+       }
+       private void openNodeContainingResource(TreeNode node, RestResource resource){
+               int count = node.getChildCount();
+               for(int i=0;i<count;i++){
+                               if(node.getChildValue(i).equals(resource)){
+                                       GWT.log("FOUND RESOURCE");
+                                       //node.setChildOpen(i, false, true);
+                                       node.setChildOpen(i, true, true);
+                                       return;
+                               }
+                               else{
+                                       if(node.isChildOpen(i)){
+                                               TreeNode n = node.setChildOpen(i, true);
+                                               if(n!=null)
+                                                       openNodeContainingResource(n,resource);
+                                       }
+                               }
+                       
+               }
+       }
        
        public interface RefreshHandler{
                void onRefresh();               
index 363af4a..6c747fe 100644 (file)
@@ -18,6 +18,7 @@
  */
 package gr.ebs.gss.client;
 
+import static com.google.gwt.query.client.GQuery.$;
 import gr.ebs.gss.client.CellTreeView.Images;
 import gr.ebs.gss.client.CellTreeView.RefreshHandler;
 import gr.ebs.gss.client.rest.GetCommand;
@@ -50,7 +51,6 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import static com.google.gwt.query.client.GQuery.$;
 
 import com.google.gwt.cell.client.AbstractCell;
 import com.google.gwt.cell.client.Cell;
@@ -58,7 +58,6 @@ import com.google.gwt.cell.client.ValueUpdater;
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.dom.client.Style.Cursor;
 import com.google.gwt.safehtml.client.SafeHtmlTemplates;
-import com.google.gwt.safehtml.client.SafeHtmlTemplates.Template;
 import com.google.gwt.safehtml.shared.SafeHtml;
 import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
 import com.google.gwt.user.client.DeferredCommand;
@@ -201,6 +200,17 @@ public class CellTreeViewModel implements TreeViewModel{
                options.setDroppableHoverClass("droppableHover");
                // use a DroppableFunction here. We can also add a DropHandler in the tree
                // itself
+               options.setOnOver(new DroppableFunction() {
+                               
+                               @Override
+                               public void f(DragAndDropContext context) {
+                                       GWT.log("-->OnActivate:"+context.getDroppableData());
+                                       if(context.getDroppableData()!=null && context.getDroppableData() instanceof RestResource){
+                                               GSS.get().getTreeView().openNodeContainingResource((RestResource) context.getDroppableData());
+                                       }
+                                       
+                               }
+                       });
                options.setOnDrop(new DroppableFunction() {
 
                  public void f(DragAndDropContext context) {
index cd2d468..a55c33e 100644 (file)
@@ -29,6 +29,7 @@ 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;
@@ -349,17 +350,8 @@ public class FileList extends Composite {
 
                      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>");
@@ -492,15 +484,14 @@ public class FileList extends Composite {
                    // prevents dragging when user click on the category drop-down list
                    draggableOptions.setCancel("select");
                    
-                   draggableOptions.setOnDragStart(new DragFunction() {
+                   draggableOptions.setOnBeforeDragStart(new DragFunction() {
                                
                                @Override
                                public void f(DragContext context) {
                                         FileResource value = context.getDraggableData();
-                                       if(!selectionModel.isSelected(value)){
-                                               dragStop.onDragStop(new DragStopEvent(context));
-                                               return;
-                                       }
+                                    if(!selectionModel.isSelected(value)){
+                                       throw new StopDragException();
+                                     }
                                        
                                }
                        });