Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Drag and drop DND Canvas to ListGrid

    Hy, how to DND a Canvas to a ListGrid ?

    DND for Canvas to Canvas is working with DropOverHandler and DropHandler.
    DND for ListGrid to ListGrid is working with DropOverHandler and DropHandler.
    DND for Canvas to Canvas is working with DropOverHandler.
    But adding DropHandler on ListGrid doesn't work. When i fire drop my drag Canvas on my ListGrid to drop, the DropHandler does not react.

    Moving and dropping Canvas to Canvas :
    onDropOver START on idCanvasDrag
    drag object : class com.smartgwt.client.widgets.Canvas
    onDropOver STOP on idCanvasDrag
    onDrop START on idCanvasDrag
    drag object : class com.smartgwt.client.widgets.Canvas
    onDrop STOP on idCanvasDrag

    Moving and dropping Canvas to Canvas :
    onDropOver START on idCanvasDrag
    drag object : class com.smartgwt.client.widgets.Canvas
    onDropOver STOP on idCanvasDrag
    ??? where is the drop ???

    Moving and dropping ListGrid to ListGrid :
    onDropOver START on idListGridDrag
    drag object : class com.smartgwt.client.widgets.grid.ListGrid
    onDropOver STOP on idListGridDrag
    onDrop START on idListGridDrag
    drag object : class com.smartgwt.client.widgets.grid.ListGrid
    onDrop STOP on idListGridDrag

    Second question, when i add DropHandler on ListGrid, only the code in my handler is execute. The initial implementation of DND ListGrid to ListGrid disappears.
    How to Override the DropHandler without replace it ?

    Third (and last) question :)
    When i leave java annotation @Override i can't build :
    The method onDropOver(DropOverEvent) of type new DropOverHandler(){} must override a superclass method
    SmartGwt doesn't support annotation ?

    Code:
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.DataSourceField;
    import com.smartgwt.client.types.Alignment;
    import com.smartgwt.client.types.DSDataFormat;
    import com.smartgwt.client.types.DragDataAction;
    import com.smartgwt.client.types.FieldType;
    import com.smartgwt.client.types.ListGridFieldType;
    import com.smartgwt.client.util.EventHandler;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.events.DragStopEvent;
    import com.smartgwt.client.widgets.events.DragStopHandler;
    import com.smartgwt.client.widgets.events.DropEvent;
    import com.smartgwt.client.widgets.events.DropHandler;
    import com.smartgwt.client.widgets.events.DropOutEvent;
    import com.smartgwt.client.widgets.events.DropOutHandler;
    import com.smartgwt.client.widgets.events.DropOverEvent;
    import com.smartgwt.client.widgets.events.DropOverHandler;
    import com.smartgwt.client.widgets.grid.HeaderSpan;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.grid.ListGridRecord;
    import com.smartgwt.client.widgets.layout.HLayout;
    
    /**
     * Entry point classes define <code>onModuleLoad()</code>.
     */
    public class TestModuleSmartGwt implements EntryPoint {
    
    	  /**
    	   * This is the entry point method.
    	   */
    	  public void onModuleLoad() {
    
    		  testDND();
    		  
    	  }
    	  
    	  public void testDND() {
    		  
    	        HLayout hLayoutTop = new HLayout();  
    	        hLayoutTop.setMembersMargin(15);  
    	        hLayoutTop.setLayoutMargin(15);  
    		  
    		  Canvas canvastoDrag = new Canvas("idCanvasDrag");
    		  canvastoDrag.setCanDrag(true);
    		  canvastoDrag.setCanDrop(true);		  
    		  canvastoDrag.setContents("My contents (object to drag)");
    		  canvastoDrag.setBorder("2px solid blue");
    
    		  Canvas canvasToDropIn = new Canvas("idCanvasDrop");
    		  canvasToDropIn.setCanAcceptDrop(true);
    		  canvasToDropIn.setContents("My contents (drop here)");
    		  canvasToDropIn.setBorder("2px solid red");
    		  
    		  canvasToDropIn.addDropOverHandler(new DropOverHandler() {
    //			@Override
    			public void onDropOver(DropOverEvent event) {
    				Object draggable = EventHandler.getDragTarget();
    				Canvas droppable = EventHandler.getDragTarget();				
    				System.out.println("onDropOver START on "+droppable.getID());
    				System.out.println("drag object : "+draggable.getClass());				
    				System.out.println("onDropOver STOP on "+droppable.getID());				
    			}			  
    		  });
    
    		  canvasToDropIn.addDropHandler(new DropHandler() {
    //			@Override
    			public void onDrop(DropEvent event) {								
    				Object draggable = EventHandler.getDragTarget();
    				Canvas droppable = EventHandler.getDragTarget();
    				System.out.println("onDrop START on "+droppable.getID());				
    				System.out.println("drag object : "+draggable.getClass());				
    				System.out.println("onDrop STOP on "+droppable.getID());			
    			}		
    		  });
    		  
    		  int nbr = 3;
    		  ListGridRecord listGridRecord[] = new ListGridRecord[nbr];
    		  for( int i=0; i<nbr; i++) {
    			  listGridRecord[i] = new ListGridRecord();
    			  listGridRecord[i].setAttribute("ID", "col_id_value_"+i);
    			  listGridRecord[i].setAttribute("TXT", "col_txt_value_"+i);
    		  }
    		  
    		  ListGridField col1 = new ListGridField("ID");  
    		  ListGridField col2 = new ListGridField("TXT");
    		  
    		  ListGrid listGridToDrag = new ListGrid();
    		  listGridToDrag.setCanAcceptDrop(true);
    		  listGridToDrag.setWidth(200);  
    		  listGridToDrag.setHeight(224);
    		  listGridToDrag.setID("idListGridDrag");
    		  listGridToDrag.setCanDrag(true);
    		  listGridToDrag.setCanDragRecordsOut(true);		  
    		  listGridToDrag.setCanDrop(true);
    		  listGridToDrag.setDragDataAction(DragDataAction.MOVE);
    		  listGridToDrag.setRecords(listGridRecord);
    		  listGridToDrag.setFields(col1, col2);
    		  
    		  ListGrid listGridToDropIn = new ListGrid();		  
    		  listGridToDropIn.setCanAcceptDrop(true);
    		  listGridToDropIn.setCanAcceptDroppedRecords(true);
    		  listGridToDropIn.setWidth(200);  
    		  listGridToDropIn.setHeight(224);
    		  listGridToDropIn.setID("idListGridDrop");		  
    		  listGridToDropIn.setCanAcceptDrop(true);
    		  
    		  listGridToDropIn.addDropOverHandler(new DropOverHandler() {
    //			@Override
    			public void onDropOver(DropOverEvent event) {								
    				Object draggable = EventHandler.getDragTarget();
    				Canvas droppable = EventHandler.getDragTarget();
    				System.out.println("onDropOver START on "+droppable.getID());
    				System.out.println("drag object : "+draggable.getClass());				
    				System.out.println("onDropOver STOP on "+droppable.getID());			
    			}			  
    		  });
    		  
    		  listGridToDropIn.addDropHandler(new DropHandler() {
    //			@Override
    			public void onDrop(DropEvent event) {
    				Object draggable = EventHandler.getDragTarget();
    				Canvas droppable = EventHandler.getDragTarget();
    				System.out.println("onDrop START on "+droppable.getID());
    				System.out.println("drag object : "+draggable.getClass());				
    				System.out.println("onDrop STOP on "+droppable.getID());				
    			}		
    		  });		  
    
    		  hLayoutTop.addMember(canvastoDrag);
    		  hLayoutTop.addMember(canvasToDropIn);
    		  
    		  hLayoutTop.addMember(listGridToDropIn);
    		  hLayoutTop.addMember(listGridToDrag);
    		  
    		  RootPanel.get().add(hLayoutTop);	  
    	  }
    }

    #2
    On dragging a Canvas to a ListGrid - see ListGrid.willAcceptDrop() - the Canvas has no "data" that the ListGrid can take, so by default it ignores the attempted drop. Override willAcceptDrop() to return true when your Canvas is being dragged onto the grid.

    We're checking on why adding a drop handler would destroy built-in behavior..

    Comment


      #3
      Originally posted by Isomorphic
      Override willAcceptDrop() to return true when your Canvas is being dragged onto the grid.

      We're checking on why adding a drop handler would destroy built-in behavior..
      I need to add support for willAcceptDrop() as an override point. Will post and update when it makes it into a build.

      Comment


        #4
        I need to add support for willAcceptDrop() as an override point. Will post and update when it makes it into a build.
        Hi Sanjiv,
        there's already a method willAcceptDrop() on ListGrid. Is this what you meant with creating an override point, or will it be a general java point where you can add a class (e.g. like a FileFilter accept() implementation) or is it more like "create a class extending ListGrid and override willAcceptDrop()" ?

        regards,

        Comment


          #5
          I really need to override Canvas.willAcceptDrop()
          is it possible to add override point in Canvas.onInit() for this method in the same way you made it on Layout.getDropComponent(...)?

          Thank you.

          Comment


            #6
            Ok we've added this.
            It should show up in nightly builds from this point on.

            Here's a test case which should work if you're interested -- note the 'willAcceptDrop' override on the second grid - if you have it return true rather than false, the drop will continue.

            Code:
            	public void onModuleLoad() {
            		  HStack hStack = new HStack(10);
            	        hStack.setHeight(160);
            	        
            	        class PartsListGrid extends ListGrid {
            	        	PartsListGrid () {
            	        		setFields(new ListGridField("a"));
            	        	}
            	        };
            
            	        final PartsListGrid myList1 = new PartsListGrid();
            	        myList1.setEmptyMessage("No Records");
            	        myList1.setCanDragRecordsOut(true);
            	        myList1.setCanReorderFields(true);
            	        myList1.setDragDataAction(DragDataAction.MOVE);
            	        
            	        RecordList data = new RecordList();
            	        data.add(new ListGridRecord() {{setAttribute("a", "aaa");}});
            	  
            	        myList1.setData(data);
            	        hStack.addMember(myList1);
            
            	        final PartsListGrid myList2 = new PartsListGrid() {
            	        	@Override
            	        	public Boolean willAcceptDrop () {
            	        		return new Boolean(false);
            	        	}
            	        };
            	        myList2.setEmptyMessage("No Records");
            	        myList2.setCanAcceptDroppedRecords(true);
            	        myList2.setCanAcceptDrop(true);
            	        myList2.addDropHandler(new DropHandler() {
            			
            				@Override
            				public void onDrop(DropEvent event) {
            					SC.say("DROP!");
            					
            				}
            	
            	        });
            	     
            	        hStack.addMember(myList2);
            	        hStack.draw();
            	}

            Comment


              #7
              Thank you. I will wait for the nightly builds then.

              Comment

              Working...
              X