Announcement

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

    Canvas.onDestroy () not called?

    When I call canvas.addChild (child), child.onInit () is called.
    When I call canvas.removeChild (child), child.onDestroy () is NOT called.

    Questions:
    1. Is this a bug?
    2. If this is not a bug, how should I detect that a Canvas is being destroyed?

    1. the SmartGWT or SmartClient version and browser version(s) involved;
    SmartGWT 2.5
    GWT 2.3.0
    FireFox 6.0.2
    Chrome 15.0.874.120 m

    3. for a client-side problem, the contents of the Developer Console (see FAQ for usage);
    Code:
    13:30:28.741:INFO:Log:initialized
    13:30:28.749:WARN:Log:NOTE: Firebug is enabled. Firebug greatly slows the performance of applications that make heavy use of JavaScript. Isomorphic highly recommends Firebug for troubleshooting, but Firebug and other development tools should be disabled when assessing the real-world performance of SmartClient applications.
    13:30:32.687:INFO:Log:isc.Page is loaded
    5. sample code.
    Code:
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.layout.VLayout;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.events.ClickEvent;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.core.client.GWT;
    
    public class TestRemoveChild implements EntryPoint {
    
      public void onModuleLoad () {
    
        // layout upon which to place a Canvas
        final VLayout canvasLayout = new VLayout ();
        canvasLayout.setWidth (600);
        canvasLayout.setHeight (400);
        canvasLayout.setBackgroundColor ("red");
    
        // create Canvas with opacity
        final Canvas canvas = new Canvas () {
          @Override
          protected void onInit () {
            GWT.log ("Canvas.onInit ()");
            super.onInit ();
          }
          
          @Override
          protected void onDestroy () {
            GWT.log ("Canvas.onDestroy ()");
            super.onDestroy ();
          }
        };
        canvas.setBackgroundColor ("blue");
        canvas.setLeft (10);
        canvas.setTop (10);
        canvas.setWidth (50);
        canvas.setHeight (50);
    
        // add a button that shows a dialog with a canvas with opaticy set
        final IButton addChildButton = new IButton ();
        addChildButton.setTitle ("Add Child");
        addChildButton.addClickHandler (new ClickHandler () {
          public void onClick (final ClickEvent clickEvent) {
            GWT.log ("Adding child");
            canvasLayout.addChild (canvas);
          }
        });
    
        // add a button that shows a dialog with a canvas with no opaticy set
        final IButton removeChildButton = new IButton ();
        removeChildButton.setTitle ("Remove Child");
        removeChildButton.addClickHandler (new ClickHandler () {
          public void onClick (final ClickEvent clickEvent) {
            GWT.log ("Removing child");
            canvasLayout.removeChild (canvas);
          }
        });
    
        // add
        final VLayout mainLayout = new VLayout ();
        mainLayout.addMember (addChildButton);
        mainLayout.addMember (removeChildButton);
        mainLayout.addMember (canvasLayout);
        mainLayout.draw ();
      }
    }

    #2
    Not a bug, removing a child does not destroy it, destroy() does.

    Comment


      #3
      So when I want to get rid of a Canvas, is this what I need to do?
      1. Call parent.removeChild (canvas), and
      2. Call canvas.destroy ()

      And if I wanted to reuse it, I could do this?
      1. Call parent.removeChild (canvas), and
      2. Call parent2.addChild (canvas)

      Comment


        #4
        Yes, except as far as getting rid of a Canvas, there is no need to removeChild() before destroy() - destroy() will cause automatic removal.

        Comment


          #5
          Cool, thanks!

          Comment

          Working...
          X