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 */ 016package com.github.gwtbootstrap.client.ui; 017 018import java.util.Iterator; 019 020import com.github.gwtbootstrap.client.ui.base.HasIcon; 021import com.github.gwtbootstrap.client.ui.base.HasStyle; 022import com.github.gwtbootstrap.client.ui.base.IsResponsive; 023import com.github.gwtbootstrap.client.ui.base.Style; 024import com.github.gwtbootstrap.client.ui.constants.*; 025import com.google.gwt.event.dom.client.ClickHandler; 026import com.google.gwt.event.dom.client.HasClickHandlers; 027import com.google.gwt.event.shared.GwtEvent; 028import com.google.gwt.event.shared.HandlerRegistration; 029import com.google.gwt.uibinder.client.UiChild; 030import com.google.gwt.user.client.DOM; 031import com.google.gwt.user.client.ui.HasEnabled; 032import com.google.gwt.user.client.ui.HasWidgets; 033import com.google.gwt.user.client.ui.IsWidget; 034import com.google.gwt.user.client.ui.Widget; 035 036/** 037 * The tab widget for {@link TabPanel}. 038 * 039 * <p> 040 * It's for UiBinder. 041 * Tab class provide easy syntax on UiBinder. 042 * </p> 043 * Example: 044 * <pre> 045 * {@code 046 * <b:TabPanel> 047 * <b:Tab heading="Typically"> 048 * <b:Heading size="3">Typically Tab</b:Heading> 049 * <b:Paragraph> 050 * huhuhu hahha 051 * </b:Paragraph> 052 * </b:Tab> 053 * <b:Tab heading="Custom"> 054 * <b:customTab> 055 * <b:Image resources="{res.logo}"/> 056 * </b:customTab> 057 * <b:Heading size="3">CustomTab Tab</b:Heading> 058 * </b:Tab> 059 * </b:TabPanel> 060 * } 061 * </pre> 062 * } 063 * 064 * </pre> 065 * @since 2.0.4.0 066 * @author ohashi keisuke 067 */ 068public class Tab implements IsWidget, HasWidgets, HasClickHandlers, HasStyle, IsResponsive, HasIcon, HasEnabled { 069 070 TabLink link = new TabLink(); 071 072 /** 073 * Create tmpy tab 074 */ 075 public Tab() { 076 TabPane tabPane = new TabPane(); 077 078 tabPane.setHref(DOM.createUniqueId()); 079 080 link.setTabPane(tabPane); 081 } 082 083 /** 084 * Tab as a TabLink 085 */ 086 @Override 087 public Widget asWidget() { 088 return link; 089 } 090 091 /** 092 * Returns true if the widget is enabled, false if not. 093 */ 094 @Override 095 public boolean isEnabled() { 096 return link.isEnabled(); 097 } 098 099 /** 100 * Sets whether this widget is enabled. 101 * 102 * @param enabled <code>true</code> to enable the widget, <code>false</code> 103 * to disable it 104 */ 105 @Override 106 public void setEnabled(boolean enabled) { 107 link.setEnabled(enabled); 108 } 109 110 /** 111 * Get Container TabPane 112 * @return TabPane 113 */ 114 protected TabPane getTabPane() { 115 return link.getTabPane(); 116 } 117 118 /** 119 * Return TabLink 120 * @return tabLink 121 */ 122 public TabLink asTabLink() { 123 return link; 124 } 125 126 /** 127 * Set tab active 128 * @param active 129 */ 130 public void setActive(boolean active) { 131 link.setActive(active); 132 } 133 134 /** 135 * has active style name 136 * @return true:active false:deactive 137 */ 138 public boolean isActive() { 139 return link.isActive(); 140 } 141 142 /** 143 * Set tab text 144 * @param text tab text 145 */ 146 public void setHeading(String text) { 147 link.setText(text); 148 } 149 150 /** 151 * Get Tab text 152 * @return tab text 153 */ 154 public String getHeading() { 155 return link.getText(); 156 } 157 158 /** 159 * Add widget to tab pane. 160 */ 161 @Override 162 public void add(Widget w) { 163 link.getTabPane().add(w); 164 } 165 166 /** 167 * Clear tab pane children 168 */ 169 @Override 170 public void clear() { 171 link.getTabPane().clear(); 172 } 173 174 /** 175 * call {@link TabPane#iterator()} 176 */ 177 @Override 178 public Iterator<Widget> iterator() { 179 return link.getTabPane().iterator(); 180 } 181 182 /** 183 * call {@link TabPane#remove(Widget)} 184 * 185 * @return {@link TabPane#remove(Widget)} result 186 */ 187 @Override 188 public boolean remove(Widget w) { 189 return link.getTabPane().remove(w); 190 } 191 192 /** 193 * add ClickEventHandler to TabLink 194 * {@inheritDoc} 195 */ 196 @Override 197 public HandlerRegistration addClickHandler(ClickHandler handler) { 198 return link.addClickHandler(handler); 199 } 200 201 /** 202 * set TabLink icon type. 203 * {@inheritDoc} 204 */ 205 @Override 206 public void setIcon(IconType type) { 207 setBaseIcon(type); 208 } 209 210 /** 211 * {@inheritDoc} 212 */ 213 @Override 214 public void setBaseIcon(BaseIconType type) { 215 this.link.setBaseIcon(type); 216 } 217 218 /** 219 * Set TabLink icon size 220 * {@inheritDoc} 221 */ 222 @Override 223 public void setIconSize(IconSize size) { 224 link.setIconSize(size); 225 } 226 227 /** 228 * Set TabLink and TabPane show on device. 229 * {@inheritDoc} 230 */ 231 @Override 232 public void setShowOn(Device device) { 233 link.setShowOn(device); 234 link.getTabPane().setShowOn(device); 235 } 236 237 /** 238 * Set TabLink and TabPane show on device. 239 * {@inheritDoc} 240 */ 241 @Override 242 public void setHideOn(Device device) { 243 link.setHideOn(device); 244 link.getTabPane().setHideOn(device); 245 } 246 247 /** 248 * set TabLink style 249 * {@inheritDoc} 250 */ 251 @Override 252 public void setStyle(Style style) { 253 link.setStyle(style); 254 } 255 256 /** 257 * add TabLink style 258 * {@inheritDoc} 259 */ 260 @Override 261 public void addStyle(Style style) { 262 link.addStyle(style); 263 } 264 265 /** 266 * remove TabLink style 267 * {@inheritDoc} 268 */ 269 @Override 270 public void removeStyle(Style style) { 271 link.removeStyle(style); 272 } 273 274 /** 275 * fire TabLink event 276 * {@inheritDoc} 277 */ 278 @Override 279 public void fireEvent(GwtEvent<?> event) { 280 link.fireEvent(event); 281 } 282 283 @UiChild(limit=1,tagname="customTab") 284 public void addDecorate(Widget w) { 285 link.add(w); 286 } 287 288 /** 289 * {@inheritDoc} 290 */ 291 @Override 292 public void setCustomIconStyle(String customIconStyle) { 293 link.setCustomIconStyle(customIconStyle); 294 } 295 296 /** 297 * {@inheritDoc} 298 */ 299 @Override 300 public void setIconPosition(IconPosition position) { 301 link.setIconPosition(position); 302 } 303}