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