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 com.github.gwtbootstrap.client.ui.base.DropdownBase; 019import com.github.gwtbootstrap.client.ui.base.IconAnchor; 020import com.github.gwtbootstrap.client.ui.constants.*; 021import com.github.gwtbootstrap.client.ui.resources.ButtonSize; 022import com.google.gwt.event.dom.client.ClickHandler; 023import com.google.gwt.event.shared.HandlerRegistration; 024 025//@formatter:off 026/** 027 * Button with a dropdown menu. 028 * 029 * <p> 030 * <h3>UiBinder Usage:</h3> 031 * 032 * <pre> 033 * {@code 034 * <b:DropdownButton text="I am the Caption"> 035 * <b:NavHeader>Header</b:NavHeader> 036 * <b:NavLink>Link 1</b:NavLink> 037 * <b:NavLink>Link 2</b:NavLink> 038 * </b:DropdownButton> 039 * } 040 * </pre> 041 * </p> 042 * 043 * @since 2.0.4.0 044 * 045 * @author Dominik Mayer 046 * 047 * @see <a href="http://getbootstrap.com/2.3.2/components.html#buttonDropdowns">Bootstrap documentation</a> 048 * @see Dropdown 049 * @see SplitDropdownButton 050 */ 051//@formatter:on 052public class DropdownButton extends DropdownBase { 053 054 private Button trigger; 055 056 /** 057 * Creates a DropdownButton without a caption. 058 */ 059 public DropdownButton() { 060 super("div"); 061 addStyleName("btn-group"); 062 } 063 064 /** 065 * Creates a DropdownButton with the given caption. 066 * 067 * @param caption 068 * the button's caption 069 */ 070 public DropdownButton(String caption) { 071 this(); 072 setText(caption); 073 } 074 075 /** 076 * {@inheritDoc} 077 */ 078 @Override 079 protected IconAnchor createTrigger() { 080 trigger = new Button(); 081 trigger.setCaret(true); 082 return trigger; 083 } 084 085 /** 086 * Sets the button's size. 087 * 088 * @param size 089 * the button's size 090 */ 091 public void setSize(ButtonSize size) { 092 trigger.setSize(size); 093 } 094 095 /** 096 * Sets the button's type. 097 * 098 * @param type 099 * the button's type 100 */ 101 public void setType(ButtonType type) { 102 trigger.setType(type); 103 } 104 105 /** 106 * Sets the button's icon. 107 * 108 * @param type 109 * the icon's type 110 */ 111 @Override 112 public void setIcon(IconType type) { 113 setBaseIcon(type); 114 } 115 116 /** 117 * {@inheritDoc} 118 */ 119 @Override 120 public void setBaseIcon(BaseIconType type) { 121 trigger.setBaseIcon(type); 122 } 123 124 @Override 125 public HandlerRegistration addClickHandler(ClickHandler handler) { 126 return trigger.addClickHandler(handler); 127 } 128 129 /** 130 * {@inheritDoc} 131 */ 132 @Override 133 public void setIconSize(IconSize size) { 134 trigger.setIconSize(size); 135 } 136 137 /** 138 * {@inheritDoc} 139 */ 140 @Override 141 public void setCustomIconStyle(String customIconStyle) { 142 trigger.setCustomIconStyle(customIconStyle); 143 } 144 145 /** 146 * {@inheritDoc} 147 */ 148 @Override 149 public void setIconPosition(IconPosition position) { 150 trigger.setIconPosition(position); 151 } 152}