Announcement

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

    onRecordDrop behaviour in ListGrid

    SmartClient Version: SNAPSHOT_v8.3d_2012-07-03/PowerEdition Deployment (built 2012-07-03)

    I have two ListGrids with drag&drop enabled. I implemented the onRecordDrop where I want to use my own drop behaviour.
    Now when dropping a record onto an already existing one, everything works as expected:
    event.getTargetRecord() gives me the target record with all its attributes.

    When I drop the record onto an empty space in the ListGrid, I would expect that event.getTargetRecord() == null. But in this case I also get a record returned with no attributes at all. Doing then something like event.getTargetRecord().getAttributes() causes JavascriptExceptions.

    Furthermore, even if I call event.cancel() as first statement in onRecordDrop(), after having the mentioned error an add operation is automatically performed.

    Standalone Testcase:

    Code:
    public class Showcase implements EntryPoint {
    
        public void onModuleLoad() {
        	
        	ListGrid lgDragOut = new ListGrid();
        	lgDragOut.setDataSource(DataSource.get("countryDS"));
        	lgDragOut.setCanDragRecordsOut(true);
        	lgDragOut.setDragDataAction(DragDataAction.COPY);
        	lgDragOut.setAutoFetchData(true);
    
        	ListGrid lgAnimals = new ListGrid();
        	lgAnimals.setDataSource(DataSource.get("animals"));
        	lgAnimals.setCanAcceptDroppedRecords(true);
        	lgAnimals.setAutoFetchData(true);
        	lgAnimals.setWidth("50%");
        	lgAnimals.addRecordDropHandler(new RecordDropHandler() {
    			@Override
    			public void onRecordDrop(RecordDropEvent event) {
    
    				event.cancel();
    				
    				if (event.getTargetRecord() == null) {
    					SC.say("target record is null");
    				}
    				else {
    					SC.say("target record is " + event.getTargetRecord().getAttribute("Animal"));
    				}
    			}
    		});
        	
        	HLayout main = new HLayout();
        	main.setWidth100();
        	main.setHeight100();
        	main.addMember(lgAnimals);
        	main.addMember(lgDragOut);
        	main.draw();
        }
    
    }

    #2
    We've fixed an issue that was causing null drop targets to be returned from RecordDropEvent.getTargetRecord() wrapped with a ListGridRecord Java wrapper. This fix should be in the nightly SGWT 3.1d build shortly. Until that point, you may use the workaround of checking whether the inner JavaScriptObject in the record is null, as shown below. (Once the fix is in place, you'd check for null normally and the workaround will no longer be appropriate.)

    Note also that, one other issue in your code sample is that the actual property name of the animal in the record is "commonName", not "Animal", which is the title of the record--I've fixed this below.

    Code:
    public void onRecordDrop(RecordDropEvent event) {
        event.cancel();
        ListGridRecord r = event.getTargetRecord();
        if (r.getJsObj() == null) {
            SC.say("target record is null");
        } else {
            String value = r.getAttribute("commonName");
            SC.say("target record is " + value);
        }
    }
    Now, I did verify your observation that an exception in this case will cause the default handler to execute, even if the event has been canceled. We will consider whether this behavior should change.
    Last edited by Isomorphic; 12 Aug 2012, 12:46.

    Comment


      #3
      Thanks for your efforts. I will implement the workaround.

      Comment

      Working...
      X