001: /*
002: * GWT-Ext Widget Library
003: * Copyright(c) 2007-2008, GWT-Ext.
004: * licensing@gwt-ext.com
005: *
006: * http://www.gwt-ext.com/license
007: */
008: package com.gwtext.sample.showcase2.client.tabs;
009:
010: import com.gwtext.client.core.EventObject;
011: import com.gwtext.client.widgets.Button;
012: import com.gwtext.client.widgets.Component;
013: import com.gwtext.client.widgets.Panel;
014: import com.gwtext.client.widgets.TabPanel;
015: import com.gwtext.client.widgets.event.ButtonListenerAdapter;
016: import com.gwtext.client.widgets.event.TabPanelListenerAdapter;
017: import com.gwtext.client.widgets.layout.VerticalLayout;
018: import com.gwtext.client.widgets.menu.BaseItem;
019: import com.gwtext.client.widgets.menu.Item;
020: import com.gwtext.client.widgets.menu.Menu;
021: import com.gwtext.client.widgets.menu.event.BaseItemListenerAdapter;
022: import com.gwtext.sample.showcase2.client.SampleData;
023: import com.gwtext.sample.showcase2.client.ShowcasePanel;
024:
025: public class TabPanelSample extends ShowcasePanel {
026:
027: private TabPanel tabPanel;
028: private int index;
029: private Menu menu;
030:
031: public String getSourceUrl() {
032: return "source/tabs/TabPanelSample.java.html";
033: }
034:
035: public String getCssUrl() {
036: return "source/tabs/TabPanelSample.css.html";
037: }
038:
039: public Panel getViewPanel() {
040: if (panel == null) {
041: panel = new Panel();
042:
043: Panel verticalPanel = new Panel();
044: verticalPanel.setLayout(new VerticalLayout(15));
045:
046: Button button = new Button("Add Tab",
047: new ButtonListenerAdapter() {
048: public void onClick(Button button, EventObject e) {
049: Panel tab = addTab();
050: tabPanel.activate(tab.getId());
051: tabPanel.scrollToTab(tab, true);
052: }
053: });
054: button.setIconCls("new-tab-icon");
055: verticalPanel.add(button);
056:
057: tabPanel = new TabPanel();
058: tabPanel.setResizeTabs(true);
059: tabPanel.setMinTabWidth(115);
060: tabPanel.setTabWidth(135);
061: tabPanel.setEnableTabScroll(true);
062: tabPanel.setWidth(450);
063: tabPanel.setHeight(250);
064: tabPanel.setActiveTab(0);
065:
066: tabPanel.addListener(new TabPanelListenerAdapter() {
067: public void onContextMenu(TabPanel source, Panel tab,
068: EventObject e) {
069: showMenu(tab, e);
070: }
071: });
072:
073: for (index = 0; index < 7; index++) {
074: addTab();
075: }
076: verticalPanel.add(tabPanel);
077:
078: panel.add(verticalPanel);
079:
080: }
081: return panel;
082: }
083:
084: private void showMenu(final Panel tab, EventObject e) {
085: if (menu == null) {
086: menu = new Menu();
087: Item close = new Item("Close Tab");
088: close.setId("close-tab-item");
089: close.addListener(new BaseItemListenerAdapter() {
090: public void onClick(BaseItem item, EventObject e) {
091: tabPanel.remove(tabPanel.getActiveTab());
092: }
093: });
094: menu.addItem(close);
095:
096: Item closeOthers = new Item("Close Other Tabs");
097: closeOthers.setId("close-others-item");
098: closeOthers.addListener(new BaseItemListenerAdapter() {
099: public void onClick(BaseItem item, EventObject e) {
100: Component[] items = tabPanel.getItems();
101: for (int i = 0; i < items.length; i++) {
102: Component component = items[i];
103: if (!component.getId().equals(
104: tabPanel.getActiveTab().getId())) {
105: tabPanel.remove(component);
106: }
107: }
108: }
109: });
110: menu.addItem(closeOthers);
111: }
112:
113: BaseItem closeOthers = menu.getItem("close-others-item");
114: if (tabPanel.getItems().length == 1) {
115: closeOthers.disable();
116: } else {
117: closeOthers.enable();
118: }
119: menu.showAt(e.getXY());
120: }
121:
122: private Panel addTab() {
123: Panel tab = new Panel();
124: tab.setAutoScroll(true);
125: tab.setTitle("New Tab " + (++index));
126: tab.setIconCls("tab-icon");
127: tab.setHtml("Tab Body " + index + "<br/><br/>"
128: + SampleData.getBogusMarkup());
129: tab.setClosable(true);
130: tabPanel.add(tab);
131: return tab;
132: }
133:
134: public String getIntro() {
135: return "<p>This TabPanel demonstrates:</p>" + " <p>"
136: + " - Auto tab resizing<br>"
137: + " - Tab scrolling<br>"
138: + " - Tabs with icons<br>"
139: + " - Tab Context menu<br>" + " </p>";
140: }
141: }
|