Announcement

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

    GWT to SmartGWT - draw() and Canvas

    Hi all, I'm quite new with both SmartGWT and the MVP pattern.
    I actually began building my app. with GWT, but then changed to SmartGWT.

    Now.

    1) with GWT to build a custom widget I had to extend Composite, now with SmartGWT everything is a Canvas ?

    2) What about the .draw() method ? when does it have to be called ? what does it do ? (ie. difference between RootPanel.get().add(vLayout); and vLayout.draw(); ?)


    let's say I have something like
    Code:
    public class Foo extends Canvas {
    Foo() {
    HLayout foo = new HLayout();
    foo.addMember(new Label("test"));
    }
    }
    in the main class:
    Code:
    public void onModuleLoad() {
    HLayout main = new HLayout();
    main.setWidth100();
    main.setHeight100();
    
    main.addMember(new Foo());
    main.draw();
    
    }
    Now, if based on some event I want to add Bar
    Code:
    public class Bar extends Canvas {
    Bar() {
    HLayout bar = new HLayout();
    bar.addMember(new Label("another"));
    }
    }
    to the page.. I would add it with addMember.. and then call the draw() method.. on what ? the main Canvas or the just added Bar ?


    Hope you can understand something about this mess of a post.

    Thanks,
    Stefano

    #2
    1) Depends but in general you want to extend the class closest to the widget you want to implement, so if you want a custom Grid extend ListGrid, if you want a custom form extend DyanmicForm etc... for general cases use Canvas

    2) .draw is usually called after initializing your interface. Usually you have one container that contains all the interface (possibly many containers inside it) and once you initialize things you call draw. You DO NOT need to call it for every widget instead use .addMember()

    In your example with Bar,
    Code:
    public class Bar extends Canvas {
    Bar() {
    HLayout bar = new HLayout();
    bar.addMember(new Label("another"));
    this.draw();
    }
    }
    unless you are adding Bar to another Canvas in which case call draw() on the first parent in the heirarchy.

    Comment


      #3
      Hey thanks for the quick answer :)

      So i should call draw() on the container and this will draw all the children ?
      And it seems it doesn't have to be called after all the "addMember".. which is quite surprising :I

      I tried this:
      Code:
      public void onModuleLoad() {
      		HLayout main = new HLayout();
      		
      		Foo foo = new Foo();
      		main.addMember(foo);	
      		
      		main.draw();
      		
      		Bar bar = new Bar();
      		main.addMember(bar);
      }
      public class Foo extends Label {
      	public Foo() {
      		super("Foo");
      	}
      }
      public class Bar extends Label {
      	public Bar() {
      		super("BAR");
      	}
      }
      And I actually see both "Foo" and "BAR" one near the other (HLayout)..

      If instead I do:
      Code:
      public void onModuleLoad() {
      		HLayout main = new HLayout();
      		
      		Foo foo = new Foo();
      		main.addMember(foo);	
      		
      		Bar bar = new Bar();
      		main.addMember(bar);
      }
      public class Foo extends Label {
      	public Foo() {
      		super("Foo");
      		this.draw();
      	}
      }
      public class Bar extends Label {
      	public Bar() {
      		super("BAR");
      		this.draw();
      	}
      }
      I see "Foo" and "BAR" in the very same place, one on top of the other.. which of course, is correct, I'm not drawing the HLayout :O

      Comment


        #4
        You only need to call main.draw() at the very end of onModuleLoad() and it will work as excepted. Your best bet is to check out the showcase, they are all done in a very similiar fashion, it is good code to start learning from.

        Comment

        Working...
        X