Class Composite
- All Implemented Interfaces:
HasAttachHandlers,HasHandlers,EventListener,HasVisibility,IsRenderable,IsWidget
- Direct Known Subclasses:
AbstractCellTree,AbstractHasData,AbstractPager,CaptionPanel,DateBox,DatePicker,DatePickerComponent,DisclosurePanel,NotificationMole,ResizeComposite,SuggestBox,TabBar,TabPanel,ValueBoxEditorDecorator,ValueListBox,ValuePicker
The composite is useful for creating a single widget out of an aggregate of multiple other widgets contained in a single panel.
Example
public class CompositeExample implements EntryPoint {
/**
* A composite of a TextBox and a CheckBox that optionally enables it.
*/
private static class OptionalTextBox extends Composite implements
ClickHandler {
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.addClickHandler(this);
// All composites must call initWidget() in their constructors.
initWidget(panel);
// Give the overall composite a style name.
setStyleName("example-OptionalCheckBox");
}
public void onClick(ClickEvent event) {
if (event.getSource() == 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);
}
}
-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled -
Field Summary
Fields inherited from class com.google.gwt.user.client.ui.Widget
eventsToSinkFields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclaimElement(Element element) Replace the previous contents of the receiver with the given element, presumed to have been created and stamped via a previous call toIsRenderable.render(com.google.gwt.user.client.ui.RenderableStamper).protected WidgetProvides subclasses access to the topmost widget that defines this composite.voidPerform any initialization needed when the widget is not attached to the document.protected voidinitWidget(Widget widget) Sets the widget to be wrapped by the composite.booleanDetermines whether this widget is currently attached to the browser's document (i.e., there is an unbroken chain of widgets between this widget and the underlying browser document).protected voidonAttach()This method is called when a widget is attached to the browser's document.voidonBrowserEvent(Event event) Fired whenever a browser event is received.protected voidonDetach()This method is called when a widget is detached from the browser's document.render(RenderableStamper stamper) voidrender(RenderableStamper stamper, SafeHtmlBuilder builder) Tells this object to render itself as HTML and append it to the given builder.protected ElementEXPERIMENTAL and subject to change.protected voidDeprecated.Methods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, ensureHandlers, fireEvent, getHandlerCount, getHandlerManager, getLayoutData, getParent, isOrWasAttached, onLoad, onUnload, removeFromParent, replaceElement, setLayoutData, setParent, sinkEvents, unsinkEventsMethods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
-
Constructor Details
-
Composite
public Composite()
-
-
Method Details
-
claimElement
Description copied from interface:IsRenderableReplace the previous contents of the receiver with the given element, presumed to have been created and stamped via a previous call toIsRenderable.render(com.google.gwt.user.client.ui.RenderableStamper).- Specified by:
claimElementin interfaceIsRenderable
-
initializeClaimedElement
public void initializeClaimedElement()Description copied from interface:IsRenderablePerform any initialization needed when the widget is not attached to the document. Assumed to be called afterIsRenderable.claimElement(com.google.gwt.dom.client.Element).- Specified by:
initializeClaimedElementin interfaceIsRenderable
-
isAttached
public boolean isAttached()Description copied from class:WidgetDetermines whether this widget is currently attached to the browser's document (i.e., there is an unbroken chain of widgets between this widget and the underlying browser document).- Specified by:
isAttachedin interfaceHasAttachHandlers- Overrides:
isAttachedin classWidget- Returns:
trueif the widget is attached
-
onBrowserEvent
Description copied from interface:EventListenerFired whenever a browser event is received.- Specified by:
onBrowserEventin interfaceEventListener- Overrides:
onBrowserEventin classWidget- Parameters:
event- the event received
-
render
- Specified by:
renderin interfaceIsRenderable- See Also:
-
getWidget
Provides subclasses access to the topmost widget that defines this composite.- Returns:
- the widget
-
initWidget
Sets the widget to be wrapped by the composite. The wrapped widget must be set before calling anyWidgetmethods on this object, or adding it to a panel. This method may only be called once for a given composite.- Parameters:
widget- the widget to be wrapped
-
onAttach
protected void onAttach()Description copied from class:WidgetThis method is called when a widget is attached to the browser's document. To receive notification after a Widget has been added to the document, override the
Widget.onLoad()method or useWidget.addAttachHandler(com.google.gwt.event.logical.shared.AttachEvent.Handler).It is strongly recommended that you override
Widget.onLoad()orWidget.doAttachChildren()instead of this method to avoid inconsistencies between logical and physical attachment states.Subclasses that override this method must call
super.onAttach()to ensure that the Widget has been attached to its underlying Element. -
onDetach
protected void onDetach()Description copied from class:WidgetThis method is called when a widget is detached from the browser's document. To receive notification before a Widget is removed from the document, override the
Widget.onUnload()method or useWidget.addAttachHandler(com.google.gwt.event.logical.shared.AttachEvent.Handler).It is strongly recommended that you override
Widget.onUnload()orWidget.doDetachChildren()instead of this method to avoid inconsistencies between logical and physical attachment states.Subclasses that override this method must call
super.onDetach()to ensure that the Widget has been detached from the underlying Element. Failure to do so will result in application memory leaks due to circular references between DOM Elements and JavaScript objects. -
resolvePotentialElement
Description copied from class:UIObjectEXPERIMENTAL and subject to change. Do not use this in production code.To be overridden by
IsRenderablesubclasses that initialize themselves by by callingsetElement(PotentialElement.build(this)).The receiver must:
- create a real
Elementto replace itsPotentialElement - call
#setElement()with the new Element - and return the new Element
This method is called when the receiver's element is about to be added to a parent node, as a side effect of
DOM.appendChild(com.google.gwt.dom.client.Element, com.google.gwt.dom.client.Element).Note that this method is normally called only on the top element of an IsRenderable tree. Children instead will receive
IsRenderable.render(com.google.gwt.user.client.ui.RenderableStamper)andIsRenderable.claimElement(Element).- Overrides:
resolvePotentialElementin classUIObject- See Also:
- create a real
-
setWidget
Deprecated.UseinitWidget(Widget)insteadThis method was for initializing the Widget to be wrapped by this Composite, but has been deprecated in favor ofinitWidget(Widget).
-
initWidget(Widget)instead