com.extjs.gxt.ui.client.widget
Class Component

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.Widget
          extended by com.extjs.gxt.ui.client.widget.Component
All Implemented Interfaces:
Observable, com.google.gwt.event.shared.HasHandlers, com.google.gwt.user.client.EventListener
Direct Known Subclasses:
BoxComponent, ColorPalette, DataListItem, DataViewItem, Document, FillToolItem, FramePanel, Header, Item, MenuBarItem, SeparatorToolItem, Shortcut, TabItem.HeaderItem, TableItem, TreeItem

public abstract class Component
extends com.google.gwt.user.client.ui.Widget
implements Observable

Base class for GXT components. All subclasses of Component can automatically participate in the standard GXT component lifecycle of creation, attach and detach. They also have automatic support for basic hide/show and enable/disable behavior. Component allows any subclass to be lazy-rendered into any GXT Container. Components added to a GWT Panel will be rendered when inserted. All visual widgets that require rendering into a layout should subclass Component (or BoxComponent if managed box model handling is required).

The following 4 methods inherited from UIObject (setSize, setWidth, setHeight, setPixelSize) have been overridden and do nothing. Any component whose size can change should subclass BoxComponent.

All components are registered and unregistered with the @link ComponentManager when the are attached and detached.

Events:
Enable : ComponentEvent(component)
Fires after the component is enabled.
Disable : ComponentEvent(component)
Fires after the component is disabled.
BeforeHide : ComponentEvent(component)
Fires before the component is hidden. Listeners can cancel the action by calling BaseEvent.setCancelled(boolean).
BeforeShow : ComponentEvent(component)
Fires before the component is shown. Listeners can cancel the action by calling BaseEvent.setCancelled(boolean).
Hide : ComponentEvent(component)
Fires after the component is hidden.
Show : ComponentEvent(component)
Fires after the component is shown.
Attach : ComponentEvent(component)
Fires after the component is attached.
Detach : ComponentEvent(component)
Fires after the component is detached.
BeforeRender : ComponentEvent(component)
Fires before the component is rendered. Listeners can cancel the action by calling BaseEvent.setCancelled(boolean).
Render : ComponentEvent(component)
Fires after the component is rendered.
BrowserEvent : ComponentEvent(component, event)
Fires on any browser event the component receives. Listeners will be called prior to any event processing and before onComponentEvent(ComponentEvent) is called. Listeners can call BaseEvent.setCancelled(boolean) to cancel the processing of the event.
BeforeStateRestore : ComponentEvent(component, state)
Fires before the state of the component is restored. Listeners can cancel the action by calling BaseEvent.setCancelled(boolean).
StateRestore : ComponentEvent(component, state)
Fires after the state of the component is restored.
BeforeStateSave : ComponentEvent(component, state)
Fires before the state of the component is saved to the configured state provider.
StateSave : ComponentEvent(component, state)
Fires after the state of the component is saved to the configured state provider.

See Also:
ComponentManager

Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.UIObject.DebugIdImpl, com.google.gwt.user.client.ui.UIObject.DebugIdImplEnabled
 
Field Summary
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Constructor Summary
Component()
          Creates a new component..
 
Method Summary
 void addListener(EventType eventType, Listener<? extends BaseEvent> listener)
          Appends an event handler to this component.
 void addPlugin(ComponentPlugin plugin)
          Adds a component plugin.
 void addStyleName(java.lang.String style)
          Adds a CSS style name to the component's underlying element.
 void addWidgetListener(WidgetListener listener)
          Adds a listener to receive widget events.
 void clearState()
          Clears the component's state.
 void disable()
          Disable this component.
 void disableEvents(boolean disable)
          True to disable event processing.
 void disableTextSelection(boolean disable)
          Enables and disables text selection for the component.
 El el()
          Returns the component's el instance.
 void enable()
          Enable this component.
 void enableEvents(boolean enable)
          Enables or disables event processing.
 boolean fireEvent(EventType type)
          Fires an event with the given event type.
 boolean fireEvent(EventType eventType, BaseEvent be)
          Fires an event.
 boolean fireEvent(EventType type, ComponentEvent ce)
          Fires the specified event with the given event type.
 El fly(com.google.gwt.user.client.Element elem)
          Returns the global flyweight instance.
 void focus()
          Try to focus this component.
 java.lang.String getBaseStyle()
          Returns the component's base style.
 boolean getBorders()
          Returns the component's border state.
 Menu getContextMenu()
          Returns the component's context menu.
<X> X
getData(java.lang.String key)
          Returns the application defined property for the given name, or null if it has not been set.
 com.google.gwt.user.client.Element getElement()
           
 Style.HideMode getHideMode()
          Returns the component's hide mode.
 java.lang.String getId()
          Returns the id of this component.
 java.lang.String getItemId()
          Returns the item id of this component.
 java.util.List<Listener<? extends BaseEvent>> getListeners(EventType eventType)
          Returns a list of listeners registered for the given event type.
<X> X
getModel()
          Returns the component's model.
 java.util.Map<java.lang.String,java.lang.Object> getState()
          Returns the component's state.
 java.lang.String getStateId()
          Returns the component's state id.
 ToolTip getToolTip()
          Returns the component's tool tip.
 boolean hasListeners()
          Returns true if the observable has any listeners.
 boolean hasListeners(EventType eventType)
          Returns true if the observable has listeners for the given event type.
 void hide()
          Hide this component.
 void hideToolTip()
          Hides the component's tool tip (if one exists).
 boolean isDisabledEvents()
          Returns true if events are disabled.
 boolean isEnabled()
          Returns true if the component is enabled.
 boolean isRendered()
          Returns true if the component is rendered.
 boolean isStateful()
          Returns true if the component is saving and restore it's state.
 boolean isVisible()
          Returns true if the component is visible.
 El mask()
          Puts a mask over this component to disable user interaction.
 El mask(java.lang.String message)
          Puts a mask over this component to disable user interaction.
 El mask(java.lang.String message, java.lang.String messageStyleName)
          Puts a mask over this component to disable user interaction.
 void onBrowserEvent(com.google.gwt.user.client.Event event)
          Components delegate event handling to onComponentEvent(ComponentEvent).
 void onComponentEvent(ComponentEvent ce)
          Any events a component receives will be forwarded to this method.
 void recalculate()
          Called when the component is in a LayoutContainer and the container's layout executes.
 void removeAllListeners()
          Removes all listeners.
 void removeFromParent()
           
 void removeListener(EventType eventType, Listener<? extends BaseEvent> listener)
          Removes a listener.
 void removeStyleName(java.lang.String style)
          Removes a CSS style name from the component's underlying element.
 void removeSwallow(SwallowEvent e)
          Removes a swallow event.
 void removeToolTip()
           
 void removeWidgetListener(WidgetListener listener)
          Removes a listener.
 void render(com.google.gwt.user.client.Element target)
          Renders the element.
 void render(com.google.gwt.user.client.Element target, int index)
          Renders the element.
 void repaint()
          Repaints the component if rendered.
 void saveState()
          Saves the component's current state by passing it to the StateManager and saving it using the state id or component id as the key.
 void setBorders(boolean show)
          Adds or removes a border.
 void setContextMenu(Menu menu)
          Sets the component's context menu.
 void setData(java.lang.String key, java.lang.Object data)
          Sets the application defined property with the given name.
 void setElement(com.google.gwt.user.client.Element elem)
           
 void setEnabled(boolean enabled)
          Convenience function for setting disabled/enabled by boolean.
 void setHeight(java.lang.String height)
          Overrides UIObject and does nothing.
 void setHideMode(Style.HideMode hideMode)
          Sets the components hide mode (default to HideMode.DISPLAY).
 void setId(java.lang.String id)
          Sets the component's id.
 void setIntStyleAttribute(java.lang.String attr, int value)
          Sets a style attribute.
 void setItemId(java.lang.String id)
          Sets the component's item id.
 void setPixelSize(int width, int height)
          Overrides UIObject and does nothing.
 void setSize(java.lang.String width, java.lang.String height)
          Overrides UIObject and does nothing.
 void setStateful(boolean stateful)
          A flag which causes the Component to attempt to restore the state of internal properties from a saved state on startup (defaults to false).
 void setStateId(java.lang.String stateId)
          Sets the component's state id which is a unique id for this component to use for state management purposes (defaults to the component id if one was set, otherwise null if the component is using a generated id).
 void setStyleAttribute(java.lang.String attr, java.lang.String value)
          Sets a style attribute.
 void setStyleName(java.lang.String style)
           
 void setTitle(java.lang.String title)
           
 void setToolTip(java.lang.String text)
          Sets the component's tool tip.
 void setToolTip(ToolTipConfig config)
          Sets the component's tool tip with the given config.
 void setVisible(boolean visible)
          Convenience function to hide or show this component by boolean.
 void setWidth(java.lang.String width)
          Overrides UIObject and does nothing.
 void setZIndex(int zIndex)
           
 void show()
          Show this component.
 void sinkEvents(int eventBitsToAdd)
           
 SwallowEvent swallowEvent(EventType eventType, com.google.gwt.user.client.Element element, boolean preventDefault)
          Adds a swallow event.
 SwallowEvent swallowEvent(SwallowEvent e)
           
 java.lang.String toString()
           
 void unmask()
          Unmasks the component.
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
fireEvent, getParent, isAttached
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getOffsetHeight, getOffsetWidth, getStyleName, getStylePrimaryName, getTitle, isVisible, removeStyleDependentName, setStylePrimaryName, setVisible, unsinkEvents
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Component

public Component()
Creates a new component..

Method Detail

addListener

public void addListener(EventType eventType,
                        Listener<? extends BaseEvent> listener)
Appends an event handler to this component.

Specified by:
addListener in interface Observable
Parameters:
eventType - the eventType
listener - the listener to be added

addPlugin

public void addPlugin(ComponentPlugin plugin)
Adds a component plugin.

Parameters:
plugin - the component plugin

addStyleName

public void addStyleName(java.lang.String style)
Adds a CSS style name to the component's underlying element.

Overrides:
addStyleName in class com.google.gwt.user.client.ui.UIObject
Parameters:
style - the CSS style name to add

addWidgetListener

public void addWidgetListener(WidgetListener listener)
Adds a listener to receive widget events.

Parameters:
listener - the listener to be added

clearState

public void clearState()
Clears the component's state.


disable

public void disable()
Disable this component. Fires the Disable event.


disableEvents

public void disableEvents(boolean disable)
True to disable event processing.

Parameters:
disable - true to disable

disableTextSelection

public void disableTextSelection(boolean disable)
Enables and disables text selection for the component.

Parameters:
disable - true to disable text selection

el

public El el()
Returns the component's el instance.

Returns:
the el instance

enable

public void enable()
Enable this component. Fires the Enable event.


enableEvents

public void enableEvents(boolean enable)
Enables or disables event processing.

Parameters:
enable - the enable state

fireEvent

public boolean fireEvent(EventType type)
Fires an event with the given event type.

Parameters:
type - the event type
Returns:
false if any listeners return false

fireEvent

public boolean fireEvent(EventType eventType,
                         BaseEvent be)
Description copied from interface: Observable
Fires an event.

Specified by:
fireEvent in interface Observable
Parameters:
eventType - eventType the event type
be - the base event
Returns:
true if any listeners cancel the event.

fireEvent

public boolean fireEvent(EventType type,
                         ComponentEvent ce)
Fires the specified event with the given event type.

Parameters:
type - the event type
ce - the base event
Returns:
false if any listeners return false

fly

public El fly(com.google.gwt.user.client.Element elem)
Returns the global flyweight instance.

Parameters:
elem - the new wrapped dom element
Returns:
the global flyweight instance

focus

public void focus()
Try to focus this component. Fires the Focus event.


getBaseStyle

public java.lang.String getBaseStyle()
Returns the component's base style.

Returns:
the base style

getBorders

public boolean getBorders()
Returns the component's border state.

Returns:
true if borders are visible

getContextMenu

public Menu getContextMenu()
Returns the component's context menu.

Returns:
the context menu

getData

public <X> X getData(java.lang.String key)
Returns the application defined property for the given name, or null if it has not been set.

Parameters:
key - the name of the property
Returns:
the value or null if it has not been set

getElement

public com.google.gwt.user.client.Element getElement()
Overrides:
getElement in class com.google.gwt.user.client.ui.UIObject

getHideMode

public Style.HideMode getHideMode()
Returns the component's hide mode.

Returns:
the hide mode

getId

public java.lang.String getId()
Returns the id of this component. A new id is generated if an id has not been set.

Returns:
the component's id

getItemId

public java.lang.String getItemId()
Returns the item id of this component. Unlike the component's id, the item id does not have to be unique.

Returns:
the component's item id

getListeners

public java.util.List<Listener<? extends BaseEvent>> getListeners(EventType eventType)
Description copied from interface: Observable
Returns a list of listeners registered for the given event type. The returned list may be modified.

Specified by:
getListeners in interface Observable
Parameters:
eventType - the event type
Returns:
the list of listeners

getModel

public <X> X getModel()
Returns the component's model.

Returns:
the model

getState

public java.util.Map<java.lang.String,java.lang.Object> getState()
Returns the component's state. To save changes made to the state map returned by this method, call saveState().

Returns:
the component's state

getStateId

public java.lang.String getStateId()
Returns the component's state id. If a state id is specified, it is used as the key when saving and retrieving the component's state.

Returns:
the state id

getToolTip

public ToolTip getToolTip()
Returns the component's tool tip.

Returns:
the tool tip

hasListeners

public boolean hasListeners()
Description copied from interface: Observable
Returns true if the observable has any listeners.

Specified by:
hasListeners in interface Observable
Returns:
true for any listeners

hasListeners

public boolean hasListeners(EventType eventType)
Description copied from interface: Observable
Returns true if the observable has listeners for the given event type.

Specified by:
hasListeners in interface Observable
Parameters:
eventType - the event type
Returns:
true for 1 or more listeners with the given event type

hide

public void hide()
Hide this component. Fires the BeforeHide event before the component is hidden, the fires the Hide event after the component is hidden.


hideToolTip

public void hideToolTip()
Hides the component's tool tip (if one exists).


isDisabledEvents

public boolean isDisabledEvents()
Returns true if events are disabled.

Returns:
true if events disabled

isEnabled

public boolean isEnabled()
Returns true if the component is enabled.

Returns:
the enabled state

isRendered

public boolean isRendered()
Returns true if the component is rendered.

Returns:
the rendered state

isVisible

public boolean isVisible()
Returns true if the component is visible.

Overrides:
isVisible in class com.google.gwt.user.client.ui.UIObject

mask

public El mask()
Puts a mask over this component to disable user interaction.

Returns:
the mask element

mask

public El mask(java.lang.String message)
Puts a mask over this component to disable user interaction.

Parameters:
message - a message to display in the mask
Returns:
the mask element

mask

public El mask(java.lang.String message,
               java.lang.String messageStyleName)
Puts a mask over this component to disable user interaction.

Parameters:
message - a message to display in the mask
messageStyleName - a CSS style name to be applied to the message text
Returns:
the mask element

onBrowserEvent

public void onBrowserEvent(com.google.gwt.user.client.Event event)
Components delegate event handling to onComponentEvent(ComponentEvent). Subclasses should not override.

Specified by:
onBrowserEvent in interface com.google.gwt.user.client.EventListener
Overrides:
onBrowserEvent in class com.google.gwt.user.client.ui.Widget
Parameters:
event - the dom event

onComponentEvent

public void onComponentEvent(ComponentEvent ce)
Any events a component receives will be forwarded to this method. Subclasses should override as needed. The onBrowserEvent(com.google.gwt.user.client.Event) method should not be overridden or modified.

Parameters:
ce - the base event

recalculate

public void recalculate()
Called when the component is in a LayoutContainer and the container's layout executes. This method will not be called on container instances. Default implementation does nothing.


removeAllListeners

public void removeAllListeners()
Removes all listeners.

Specified by:
removeAllListeners in interface Observable

removeFromParent

public void removeFromParent()
Overrides:
removeFromParent in class com.google.gwt.user.client.ui.Widget

removeListener

public void removeListener(EventType eventType,
                           Listener<? extends BaseEvent> listener)
Removes a listener.

Specified by:
removeListener in interface Observable
Parameters:
eventType - the event type
listener - the listener to be removed

removeToolTip

public void removeToolTip()

removeStyleName

public void removeStyleName(java.lang.String style)
Removes a CSS style name from the component's underlying element.

Overrides:
removeStyleName in class com.google.gwt.user.client.ui.UIObject
Parameters:
style - the CSS style name to remove

removeSwallow

public void removeSwallow(SwallowEvent e)
Removes a swallow event.

Parameters:
e - the swallow event to be removed

removeWidgetListener

public void removeWidgetListener(WidgetListener listener)
Removes a listener.

Parameters:
listener - the listener to be removed

render

public void render(com.google.gwt.user.client.Element target)
Renders the element. Typically, this method does not need to be called directly. A component will rendered by its parent if it is a container, or rendered when attached if added to a gwt panel.

Parameters:
target - the element this component should be rendered into

render

public void render(com.google.gwt.user.client.Element target,
                   int index)
Renders the element. Typically, this method does not need to be called directly. A component will rendered by its parent if it is a container, or rendered when attached if added to a gwt panel.

Parameters:
target - the element this component should be rendered into
index - the index within the container before which this component will be inserted (defaults to appending to the end of the container if value is -1)

repaint

public void repaint()
Repaints the component if rendered.


saveState

public void saveState()
Saves the component's current state by passing it to the StateManager and saving it using the state id or component id as the key.


setBorders

public void setBorders(boolean show)
Adds or removes a border. The style name 'x-border' is added to the widget to display a border.

Parameters:
show - true to display a border

setContextMenu

public void setContextMenu(Menu menu)
Sets the component's context menu.

Parameters:
menu - the context menu

setData

public void setData(java.lang.String key,
                    java.lang.Object data)
Sets the application defined property with the given name.

Parameters:
key - the name of the property
data - the new value for the property

setElement

public void setElement(com.google.gwt.user.client.Element elem)
Overrides:
setElement in class com.google.gwt.user.client.ui.UIObject

setEnabled

public void setEnabled(boolean enabled)
Convenience function for setting disabled/enabled by boolean.

Parameters:
enabled - the enabled state

setStateful

public void setStateful(boolean stateful)
A flag which causes the Component to attempt to restore the state of internal properties from a saved state on startup (defaults to false). The component must have either a stateId or id assigned for state to be managed. Auto-generated ids are not guaranteed to be stable across page loads and cannot be relied upon to save and restore the same state for a component.

Parameters:
stateful - true to enable state

isStateful

public boolean isStateful()
Returns true if the component is saving and restore it's state.

Returns:
true if stateful

setHeight

public void setHeight(java.lang.String height)
Overrides UIObject and does nothing.

Overrides:
setHeight in class com.google.gwt.user.client.ui.UIObject

setHideMode

public void setHideMode(Style.HideMode hideMode)
Sets the components hide mode (default to HideMode.DISPLAY).

Parameters:
hideMode - the hide mode.

setId

public void setId(java.lang.String id)
Sets the component's id.

Parameters:
id - the new id

setIntStyleAttribute

public void setIntStyleAttribute(java.lang.String attr,
                                 int value)
Sets a style attribute.

Parameters:
attr - the attribute
value - the attribute value

setItemId

public void setItemId(java.lang.String id)
Sets the component's item id.

Parameters:
id - the item id

setPixelSize

public void setPixelSize(int width,
                         int height)
Overrides UIObject and does nothing.

Overrides:
setPixelSize in class com.google.gwt.user.client.ui.UIObject

setSize

public void setSize(java.lang.String width,
                    java.lang.String height)
Overrides UIObject and does nothing.

Overrides:
setSize in class com.google.gwt.user.client.ui.UIObject

setStateId

public void setStateId(java.lang.String stateId)
Sets the component's state id which is a unique id for this component to use for state management purposes (defaults to the component id if one was set, otherwise null if the component is using a generated id).

Parameters:
stateId - the state id

setStyleAttribute

public void setStyleAttribute(java.lang.String attr,
                              java.lang.String value)
Sets a style attribute.

Parameters:
attr - the attribute
value - the attribute value

setStyleName

public void setStyleName(java.lang.String style)
Overrides:
setStyleName in class com.google.gwt.user.client.ui.UIObject

setTitle

public void setTitle(java.lang.String title)
Overrides:
setTitle in class com.google.gwt.user.client.ui.UIObject

setToolTip

public void setToolTip(java.lang.String text)
Sets the component's tool tip.

Parameters:
text - the text

setToolTip

public void setToolTip(ToolTipConfig config)
Sets the component's tool tip with the given config.

Parameters:
config - the tool tip config

setVisible

public void setVisible(boolean visible)
Convenience function to hide or show this component by boolean.

Overrides:
setVisible in class com.google.gwt.user.client.ui.UIObject
Parameters:
visible - the visible state

setWidth

public void setWidth(java.lang.String width)
Overrides UIObject and does nothing.

Overrides:
setWidth in class com.google.gwt.user.client.ui.UIObject

setZIndex

public void setZIndex(int zIndex)

show

public void show()
Show this component. Fires the BeforeShow event before the component is made visible, then fires the Show event after the component is visible.


sinkEvents

public void sinkEvents(int eventBitsToAdd)
Overrides:
sinkEvents in class com.google.gwt.user.client.ui.Widget

swallowEvent

public SwallowEvent swallowEvent(EventType eventType,
                                 com.google.gwt.user.client.Element element,
                                 boolean preventDefault)
Adds a swallow event. When enabled, any events of the given type whose target is or is a child of the given element are swallowed.

Parameters:
eventType - the event type
element - the target element
preventDefault - true to prevent the default action
Returns:
the swallow event config that can be used when removing a swallowing event

swallowEvent

public SwallowEvent swallowEvent(SwallowEvent e)

toString

public java.lang.String toString()
Overrides:
toString in class com.google.gwt.user.client.ui.UIObject

unmask

public void unmask()
Unmasks the component.