No announcement yet.
  • 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.

    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);
    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.
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.layout.VLayout;
    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 () {
          protected void onInit () {
            GWT.log ("Canvas.onInit ()");
            super.onInit ();
          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 ();

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


      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)


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


          Cool, thanks!