001 /* 002 * Copyright 2012 GWT-Bootstrap 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package com.github.gwtbootstrap.client.ui; 017 018 import java.util.Iterator; 019 020 import com.github.gwtbootstrap.client.ui.base.HasIcon; 021 import com.github.gwtbootstrap.client.ui.base.HasStyle; 022 import com.github.gwtbootstrap.client.ui.base.IsResponsive; 023 import com.github.gwtbootstrap.client.ui.base.Style; 024 import com.github.gwtbootstrap.client.ui.constants.Device; 025 import com.github.gwtbootstrap.client.ui.constants.IconSize; 026 import com.github.gwtbootstrap.client.ui.constants.IconType; 027 import com.google.gwt.event.dom.client.ClickHandler; 028 import com.google.gwt.event.dom.client.HasClickHandlers; 029 import com.google.gwt.event.shared.GwtEvent; 030 import com.google.gwt.event.shared.HandlerRegistration; 031 import com.google.gwt.uibinder.client.UiChild; 032 import com.google.gwt.user.client.DOM; 033 import com.google.gwt.user.client.ui.HasWidgets; 034 import com.google.gwt.user.client.ui.IsWidget; 035 import com.google.gwt.user.client.ui.Widget; 036 037 /** 038 * The tab widget for {@link TabPanel}. 039 * 040 * <p> 041 * It's for UiBinder. 042 * Tab class provide easy syntax on UiBinder. 043 * </p> 044 * Example: 045 * <pre> 046 * {@code 047 * <b:TabPanel> 048 * <b:Tab heading="Typically"> 049 * <b:Heading size="3">Typically Tab</b:Heading> 050 * <b:Paragraph> 051 * huhuhu hahha 052 * </b:Paragraph> 053 * </b:Tab> 054 * <b:Tab heading="Custom"> 055 * <b:customTab> 056 * <b:Image resources="{res.logo}"/> 057 * </b:customTab> 058 * <b:Heading size="3">CustomTab Tab</b:Heading> 059 * </b:Tab> 060 * </b:TabPanel> 061 * } 062 * </pre> 063 * } 064 * 065 * </pre> 066 * @since 2.0.4.0 067 * @author ohashi keisuke 068 */ 069 public class Tab implements IsWidget, HasWidgets, HasClickHandlers, HasStyle, IsResponsive,HasIcon { 070 071 TabLink link = new TabLink(); 072 073 /** 074 * Create tmpy tab 075 */ 076 public Tab() { 077 TabPane tabPane = new TabPane(); 078 079 tabPane.setHref(DOM.createUniqueId()); 080 081 link.setTablePane(tabPane); 082 } 083 084 /** 085 * Tab as a TabLink 086 */ 087 @Override 088 public Widget asWidget() { 089 return link; 090 } 091 092 /** 093 * Get Container TabPane 094 * @return TabPane 095 */ 096 protected TabPane getTabPane() { 097 return link.getTabPane(); 098 } 099 100 /** 101 * Return TabLink 102 * @return tabLink 103 */ 104 public TabLink asTabLink() { 105 return link; 106 } 107 108 /** 109 * Set tab active 110 * @param active 111 */ 112 public void setActive(boolean active) { 113 link.setActive(active); 114 } 115 116 /** 117 * has active style name 118 * @return true:active false:deactive 119 */ 120 public boolean isActive() { 121 return link.isActive(); 122 } 123 124 /** 125 * Set tab text 126 * @param text tab text 127 */ 128 public void setHeading(String text) { 129 link.setText(text); 130 } 131 132 /** 133 * Get Tab text 134 * @return tab text 135 */ 136 public String getHeading() { 137 return link.getText(); 138 } 139 140 /** 141 * Add widget to tab pane. 142 */ 143 @Override 144 public void add(Widget w) { 145 link.getTabPane().add(w); 146 } 147 148 /** 149 * Clear tab pane children 150 */ 151 @Override 152 public void clear() { 153 link.getTabPane().clear(); 154 } 155 156 /** 157 * call {@link TabPane#iterator()} 158 */ 159 @Override 160 public Iterator<Widget> iterator() { 161 return link.getTabPane().iterator(); 162 } 163 164 /** 165 * call {@link TabPane#remove(Widget)} 166 * 167 * @return {@link TabPane#remove(Widget)} result 168 */ 169 @Override 170 public boolean remove(Widget w) { 171 return link.getTabPane().remove(w); 172 } 173 174 /** 175 * add ClickEventHandler to TabLink 176 * {@inheritDoc} 177 */ 178 @Override 179 public HandlerRegistration addClickHandler(ClickHandler handler) { 180 return link.addClickHandler(handler); 181 } 182 183 /** 184 * set TabLink icon type. 185 * {@inheritDoc} 186 */ 187 @Override 188 public void setIcon(IconType type) { 189 link.setIcon(type); 190 } 191 192 /** 193 * Set TabLink icon size 194 * {@inheritDoc} 195 */ 196 @Override 197 public void setIconSize(IconSize size) { 198 link.setIconSize(size); 199 } 200 201 /** 202 * Set TabLink and TabPane show on device. 203 * {@inheritDoc} 204 */ 205 @Override 206 public void setShowOn(Device device) { 207 link.setShowOn(device); 208 link.getTabPane().setShowOn(device); 209 } 210 211 /** 212 * Set TabLink and TabPane show on device. 213 * {@inheritDoc} 214 */ 215 @Override 216 public void setHideOn(Device device) { 217 link.setHideOn(device); 218 link.getTabPane().setHideOn(device); 219 } 220 221 /** 222 * set TabLink style 223 * {@inheritDoc} 224 */ 225 @Override 226 public void setStyle(Style style) { 227 link.setStyle(style); 228 } 229 230 /** 231 * add TabLink style 232 * {@inheritDoc} 233 */ 234 @Override 235 public void addStyle(Style style) { 236 link.addStyle(style); 237 } 238 239 /** 240 * remove TabLink style 241 * {@inheritDoc} 242 */ 243 @Override 244 public void removeStyle(Style style) { 245 link.removeStyle(style); 246 } 247 248 /** 249 * fire TabLink event 250 * {@inheritDoc} 251 */ 252 @Override 253 public void fireEvent(GwtEvent<?> event) { 254 link.fireEvent(event); 255 } 256 257 @UiChild(limit=1,tagname="customTab") 258 public void addDecorate(Widget w) { 259 link.add(w); 260 } 261 }