|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.Widget
com.google.gwt.user.client.ui.Composite
public abstract class Composite
A type of widget that can wrap another widget, hiding the wrapped widget's methods. When added to a panel, a composite behaves exactly as if the widget it wraps had been added.
The composite is useful for creating a single widget out of an aggregate of multiple other widgets contained in a single panel.
public class CompositeExample implements EntryPoint { /** * A composite of a TextBox and a CheckBox that optionally enables it. */ private static class OptionalTextBox extends Composite implements ClickListener { private TextBox textBox = new TextBox(); private CheckBox checkBox = new CheckBox(); /** * Constructs an OptionalTextBox with the given caption on the check. * * @param caption the caption to be displayed with the check box */ public OptionalTextBox(String caption) { // Place the check above the text box using a vertical panel. VerticalPanel panel = new VerticalPanel(); panel.add(checkBox); panel.add(textBox); // Set the check box's caption, and check it by default. checkBox.setText(caption); checkBox.setChecked(true); checkBox.addClickListener(this); // All composites must call setWidget() in their constructors. initWidget(panel); // Give the overall composite a style name. setStyleName("example-OptionalCheckBox"); } public void onClick(Widget sender) { if (sender == checkBox) { // When the check box is clicked, update the text box's enabled state. textBox.setEnabled(checkBox.isChecked()); } } /** * Sets the caption associated with the check box. * * @param caption the check box's caption */ public void setCaption(String caption) { // Note how we use the use composition of the contained widgets to provide // only the methods that we want to. checkBox.setText(caption); } /** * Gets the caption associated with the check box. * * @return the check box's caption */ public String getCaption() { return checkBox.getText(); } } public void onModuleLoad() { // Create an optional text box and add it to the root panel. OptionalTextBox otb = new OptionalTextBox("Check this to enable me"); RootPanel.get().add(otb); } }
Constructor Summary | |
---|---|
Composite()
|
Method Summary | |
---|---|
Element |
getElement()
This override checks to ensure initWidget(Widget) has been called. |
protected void |
initWidget(Widget widget)
Sets the widget to be wrapped by the composite. |
protected void |
onAttach()
This method is called when a widget is attached to the browser's document. |
protected void |
onDetach()
This method is called when a widget is detached from the browser's document. |
protected void |
setWidget(Widget widget)
Deprecated. this method is deprecated, and will be removed when GWT leaves beta (use initWidget(Widget) instead) |
Methods inherited from class com.google.gwt.user.client.ui.Widget |
---|
getParent, isAttached, onBrowserEvent, onLoad, removeFromParent |
Methods inherited from class com.google.gwt.user.client.ui.UIObject |
---|
addStyleName, getAbsoluteLeft, getAbsoluteTop, getOffsetHeight, getOffsetWidth, getStyleName, getTitle, isVisible, isVisible, removeStyleName, setElement, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setTitle, setVisible, setVisible, setWidth, sinkEvents, toString, unsinkEvents |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Composite()
Method Detail |
---|
public Element getElement()
initWidget(Widget)
has been called.
getElement
in class UIObject
protected void initWidget(Widget widget)
Widget
methods on this object, or adding it
to a panel. This method may only be called once for a given composite.
widget
- the widget to be wrappedprotected void onAttach()
Widget
Panel
. To receive
notification when a widget is attached to the document, override the
Widget.onLoad()
method.
onAttach
in class Widget
protected void onDetach()
Widget
Panel
.
onDetach
in class Widget
protected void setWidget(Widget widget)
initWidget(Widget)
instead)
widget
- the widget to be wrapped
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |