All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.extjs.gxt.ui.client.widget.TabItem Maven / Gradle / Ivy

There is a newer version: 2.3.1-gwt22
Show newest version
/*
 * 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;

import com.extjs.gxt.ui.client.core.Template;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Frame;

/**
 * A tab in a TabPanel.
 * 
 * 
*
Events:
* *
BeforeClose : TabPanelEvent(tabPanel, item)
*
Fires before an item is closed by the user clicking the close icon. * Listeners can set the doit field to false to * cancel the action.
*
    *
  • tabPanel : this
  • *
  • item : the item that was closed.
  • *
*
* *
Close : TabPanelEvent(tabPanel, item)
*
Fires after an item is closed by the user clicking the close icon.
*
    *
  • tabPanel : this
  • *
  • item : the item that was closed.
  • *
*
*
*/ public class TabItem extends LayoutContainer { public class HeaderItem extends Component { String text, iconStyle; /** * Returns the header's icon style * * @return the icon style */ public String getIconStyle() { return iconStyle; } /** * Returns the header's text. * * @return the text */ public String getText() { return text; } @Override public void onComponentEvent(ComponentEvent ce) { super.onComponentEvent(ce); if (ce.getEventType() == Event.ONCLICK) { onClick(ce); } } /** * Sets the header's icon style (pre-render). * * @param iconStyle the icon style */ public void setIconStyle(String iconStyle) { if (rendered) { el().selectNode(".x-tab-strip-text").removeStyleName(this.iconStyle).addStyleName(iconStyle); } this.iconStyle = iconStyle; } /** * Sets the header's text. * * @param text the text */ public void setText(String text) { this.text = text; if (rendered) { el().child(".x-tab-strip-text").dom.setInnerHTML(text); } } protected void onClick(ComponentEvent ce) { tabPanel.onItemClick(TabItem.this, ce); } protected void onMouseOut(ComponentEvent ce) { tabPanel.onItemOver(TabItem.this, false); } protected void onMouseOver(BaseEvent be) { tabPanel.onItemOver(TabItem.this, true); } protected void onRender(Element target, int pos) { tabPanel.onItemRender(TabItem.this, target, pos); } } Template template; TabPanel tabPanel; HeaderItem header; private String textStyle; private boolean closable; /** * Creates a new tab item. */ public TabItem() { header = new HeaderItem(); } /** * Creates a new tab item with the given text. * * @param text the item's text */ public TabItem(String text) { this(); setText(text); } /** * Closes the tab item. */ public void close() { tabPanel.remove(this); } @Override public void disable() { super.disable(); header.disable(); } @Override public void enable() { super.enable(); header.enable(); } /** * Returns the item's header component. * * @return the header component */ public HeaderItem getHeader() { return header; } /** * Returns the item's icon style. * * @return the icon style */ public String getIconStyle() { return header.getIconStyle(); } /** * Returns the item's tab panel. * * @return the tab panel */ public TabPanel getTabPanel() { return tabPanel; } /** * Returns the item's text. * * @return the text */ public String getText() { return header.getText(); } /** * Returns the item's text style name. * * @return the style name */ public String getTextStyle() { return textStyle; } /** * Returns true if the item can be closed. * * @return the closable the close state */ public boolean isClosable() { return closable; } /** * Sets whether the tab may be closed (defaults to false). * * @param closable the closabable state */ public void setClosable(boolean closable) { this.closable = closable; } /** * Sets the item's icon style. * * @param iconStyle the icon style */ public void setIconStyle(String iconStyle) { header.setIconStyle(iconStyle); } /** * Sets the item's text. * * @param text the new text */ public void setText(String text) { header.setText(text); } /** * Sets the style name to be applied to the item's text element. * * @param textStyle the style name */ public void setTextStyle(String textStyle) { this.textStyle = textStyle; } /** * Sets a url for the content area of the item. * * @param url the url * @return the frame widget */ public Frame setUrl(String url) { Frame f = new Frame(url); fly(f.getElement()).setStyleAttribute("frameBorder", "0"); f.setSize("100%", "100%"); removeAll(); add(new WidgetComponent(f)); return f; } @Override public String toString() { return el() != null ? el().toString() : super.toString(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy