The very first advice I can give you is to not implement it they way you 
have done it.

public BaseBox(String name){
  this.name=name; 
  addMembers(name);
}

protected void addMembers(final String name) {
  this.name = name;
  box = createBox(name);
}

protected abstract Widget createBox(String name);

The constructor of BaseBox calls an abstract method that is implemented by 
a sub class of BaseBox. That means when createBox() is called, the 
constructor of your sub class (e.g. TextBox) has not yet been executed and 
fields you may set in your constructor are not initialized yet. If these 
fields are used in createBox() you will get NullPointerException. A 
constructor should never call a method that can be overridden by sub 
classes. To fix that you can override Widget.onLoad() which will 
automatically be called by GWT when the widget is added to the page. You 
could call your create methods in onLoad then.

Also you have used inheritance which is kind of wrong. Inheritance means 
"is-a" but a TextBox is not a FlowPanel (TextBox is-a BaseBox is-not-a 
FlowPanel). So you should use composition which means you should make your 
BaseBox extends Composite and then call initWidget() to initialize it with 
a FlowPanel. That way you hide methods that you would inherit from 
FlowPanel otherwise, e.g. TextBox.add(new Button()) doesn't make a lot of 
sense right? With composition TextBox.add() does not exist.

Next to your redraw problem: Normally you would directly apply changes, 
e.g. in your showTitle() method you would directly execute the 
corresponding code to change the widget, e.g label.setVisible(! 
title.isEmpty());. GWT also allows you to schedule "finally" commands that 
are executed at the end of the current event loop. This allows you to batch 
changes and only do the redrawing work once for all changes. For example 
take a look at LayoutPanel.add() which schedules a layout command.


-- J.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Reply via email to