com.extjs.gxt.ui.client.widget.toolbar.TextToolItem Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gxt Show documentation
Show all versions of gxt Show documentation
Rich Internet Application Framework for GWT
/*
* Ext GWT - Ext for GWT
* Copyright(c) 2007, 2008, Ext JS, LLC.
* [email protected]
*
* http://extjs.com/license
*/
package com.extjs.gxt.ui.client.widget.toolbar;
import com.extjs.gxt.ui.client.Events;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.event.ToolBarEvent;
import com.extjs.gxt.ui.client.util.WidgetHelper;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.menu.Menu;
import com.extjs.gxt.ui.client.widget.tips.ToolTipConfig;
import com.google.gwt.user.client.Element;
/**
* A tool item with an optional text and icon style.
*
*
* - Events:
*
* - Select : ToolBarEvent(toolBar, item, event)
* Fires after the item is selected.
*
* - toolBar : the parent tolbar
* - item : this
* - event : the dom event
*
*
*
*/
public class TextToolItem extends ToolItem {
/**
* The wrapped button instance.
*/
protected Button button;
/**
* Creates a new tool item text.
*/
public TextToolItem() {
button = new Button();
}
/**
* Creates a new text tool item.
*
* @param text the tool item text
*/
public TextToolItem(String text) {
this();
setText(text);
}
/**
* Creates a new text tool item.
*
* @param text the text
* @param iconStyle the icon style
*/
public TextToolItem(String text, String iconStyle) {
this();
setText(text);
setIconStyle(iconStyle);
}
/**
* Adds a selection listener.
*
* @param listener the selection listener
*/
public void addSelectionListener(SelectionListener listener) {
addListener(Events.Select, listener);
}
/**
* Returns the item's icon style.
*
* @return the icon style
*/
public String getIconStyle() {
return button.getIconStyle();
}
/**
* Returns the item's menu (if it has one).
*
* @return the menu
*/
public Menu getMenu() {
return button.getMenu();
}
/**
* Returns the item's parent tool bar.
*
* @return the toolbar
*/
public ToolBar getToolBar() {
return toolBar;
}
/**
* Removes a selection listener.
*
* @param listener the listener to be removed
*/
public void removeSelectionListener(SelectionListener listener) {
removeListener(Events.Select, listener);
}
/**
* Sets the item's icon style.
*
* @param iconStyle the icon style
*/
public void setIconStyle(String iconStyle) {
button.setIconStyle(iconStyle);
}
/**
* Sets the item's menu.
*
* @param menu the menu
*/
public void setMenu(Menu menu) {
button.setMenu(menu);
}
/**
* Sets the item's text.
*
* @param text the text
*/
public void setText(String text) {
button.setText(text);
}
@Override
public void setToolTip(String text) {
button.setToolTip(text);
}
@Override
public void setToolTip(ToolTipConfig config) {
button.setToolTip(config);
}
@Override
protected void doAttachChildren() {
super.doAttachChildren();
WidgetHelper.doAttach(button);
}
@Override
protected void doDetachChildren() {
super.doDetachChildren();
WidgetHelper.doDetach(button);
}
protected void onButtonSelect(ButtonEvent be) {
ToolBarEvent evt = new ToolBarEvent(toolBar, this);
evt.event = be.event;
fireEvent(Events.Select, evt);
}
@Override
protected void onDisable() {
button.disable();
}
@Override
protected void onEnable() {
button.enable();
}
@Override
protected void onRender(Element target, int index) {
button.render(target, index);
button.addListener(Events.Select, new Listener() {
public void handleEvent(ButtonEvent be) {
onButtonSelect(be);
}
});
setElement(button.getElement());
}
}