The first release of GWT Designer allowed the creation of custom composites that could be embedded within other Composites or Modules.
The latest build now adds initial support for visual inheritance of Composites.
The following is an example of three Composites in an inheritance hierarchy. The following Composite uses an AbsolutePanel and two buttons. The AbsolutePanel and one of the Buttons have been exposed as public components using the Expose Widget command. Expose Widget converts a component to a field and adds a public accessor for it. Finally, the text property of the second Button has been exposed as a public property of the Composite using the Expose Property command. Expose Property adds a pair of accessors for getting and setting the desired property of the target widget.
- Code: Select all
package com.mycompany.project.client;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
public class MyC extends Composite {
private Button helloButton;
private AbsolutePanel absolutePanel;
private Button button;
public MyC() {
absolutePanel = new AbsolutePanel();
initWidget(absolutePanel);
button = new Button();
absolutePanel.add(button, 147, 27);
button.setSize("166px", "68px");
button.setText("New Button");
helloButton = new Button();
absolutePanel.add(helloButton, 32, 166);
helloButton.setSize("166px", "68px");
helloButton.setText("Hello");
}
public Button getButton() {
return button;
}
public AbsolutePanel getAbsolutePanel() {
return absolutePanel;
}
public String getHelloButtonText() {
return helloButton.getText();
}
public void setHelloButtonText(String text) {
helloButton.setText(text);
}
}
The second Composite inherits from the first and adds a CheckBox via the accessor on the exposed AbsolutePanel from the superclass. The exposed Button from the superclass has also been moved. Finally, the styleName property of the CheckBox has been exposed.
Note that the exposed AbsolutePanel and Button from the superclass show up in the component tree with a small "i" overlay icon. The second Button defined in the first Composite does not show up in the tree because it is private to that Composite.
- Code: Select all
package com.mycompany.project.client;
import com.google.gwt.user.client.ui.CheckBox;
public class MyC2 extends MyC {
private CheckBox checkBox;
public MyC2() {
super();
getAbsolutePanel().setWidgetPosition(getButton(), 45, 35);
checkBox = new CheckBox();
getAbsolutePanel().add(checkBox, 246, 60);
checkBox.setText("New CheckBox");
}
public String getCheckBoxStyleName() {
return checkBox.getStyleName();
}
public void setCheckBoxStyleName(String styleName) {
checkBox.setStyleName(styleName);
}
}
The final Composite inherits from the second. It does not add any widgets (it could), but it does override the text setting of the second Button using the accessor defined in the first Composite and sets the style of the CheckBox using the accessor defined in the second Composite.
- Code: Select all
package com.mycompany.project.client;
public class MyC3 extends MyC2 {
public MyC3() {
super();
setHelloButtonText("World");
setCheckBoxStyleName("gwt-MenuBar");
}
}