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