visv / smartgwt

Automatically exported from code.google.com/p/smartgwt
0 stars 0 forks source link

getDropPortlet() returning null throws exception (see http://forums.smartclient.com/showthread.php?t=17959) #737

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I'm using SmartGWT 4.0

In PortalLayout there is an override point
Code:
public Canvas getDropPortlet(Canvas dragTarget, Integer colNum, Integer rowNum, 
Integer dropPosition)
documented to cancel the drag operation when it returns null.

The following is a simple test case that demonstrates that returning null from 
this method throws a JavaScriptException:

Code:
public void onModuleLoad(){
PortalLayout portalLayout = new PortalLayout(2){
            public Canvas getDropPortlet(Canvas dragTarget, Integer colNum, Integer rowNum, Integer dropPosition){
                if(dragTarget instanceof Portlet)
                    return dragTarget;
                return null;
            }
        };

        for(int i=0;i<2;i++){
            Portlet portlet = new Portlet();
            HeaderControl dragControl = new HeaderControl(HeaderControl.CASCADE);
            dragControl.setCanDrag(true);
            dragControl.setCanDrop(true);
            dragControl.setTooltip("DRAG ME");

            portlet.setHeaderControls(HeaderControls.HEADER_LABEL, dragControl);
            portalLayout.addPortlet(portlet);
        }

        portalLayout.setWidth100();
        portalLayout.setHeight100();
        portalLayout.draw();
}
This code should work as normal when dragging portals around but if the user 
drags the HeaderControl into a portal this should cancel the drag operation 
(the user shouldn't be allowed to drag HeaderControls into a PortalLayout, but 
should be allowed to drag this HeaderControl elsewhere). Returning null in this 
case does indeed cancel the operation but also throws up this exception in my 
logger:

Code:
20110720-18:23:38 FATAL (ServerLogImplLog4J.java:72) [btpool0-5] : Uncaught 
Exception:
com.google.gwt.core.client.JavaScriptException: (TypeError): Cannot call method 
'getOrCreateJsObj' of null
    at Unknown.$fillInStackTrace(StackTraceCreator.java:168)
    at Unknown.fillInStackTrace(StackTraceCreator.java:421)
    at Unknown.JavaScriptException_0(Throwable.java:46)
    at Unknown.caught_0(Exceptions.java:29)
    at Unknown.anonymous(PortalLayout.java:299)
    at Unknown.apply(Impl.java:168)
    at Unknown.entry0(Impl.java:215)
    at Unknown.anonymous(Impl.java:57)

Original issue reported on code.google.com by bbendu...@gmail.com on 13 Feb 2014 at 11:41