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.HasType;
020import com.github.gwtbootstrap.client.ui.base.IconAnchor;
021import com.github.gwtbootstrap.client.ui.constants.ButtonType;
022import com.github.gwtbootstrap.client.ui.constants.IconSize;
023import com.github.gwtbootstrap.client.ui.constants.IconType;
024import com.github.gwtbootstrap.client.ui.resources.ButtonSize;
025import com.google.gwt.event.dom.client.ClickHandler;
026import com.google.gwt.event.dom.client.HasClickHandlers;
027import com.google.gwt.event.shared.HandlerRegistration;
028import com.google.gwt.uibinder.client.UiChild;
029import com.google.gwt.user.client.ui.Widget;
030
031//@formatter:off
032/**
033 * Split Dropdown button.
034 * 
035 * @author Dominik Mayer
036 * @since 2.0.4.0
037 * @see <a
038 *      href="http://twitter.github.com/bootstrap/components.html#buttonDropdowns">Bootstrap
039 *      documentation</a>
040 * 
041 */
042//@formatter:on
043public class SplitDropdownButton extends DropdownBase implements
044                HasClickHandlers , HasType<ButtonType> {
045
046        private Button button;
047
048        private Button trigger;
049
050        /**
051         * Create an Empty Split Dropdown Button
052         */
053        public SplitDropdownButton() {
054                super("div");
055                addStyleName("btn-group");
056        }
057
058        /**
059         * Create an Empty Split Dropdown Button with text.
060         * @param text
061         */
062        public SplitDropdownButton(String text) {
063                this();
064                setText(text);
065        }
066
067        /**
068         * {@inheritDoc}
069         */
070        @Override
071        public void setText(String text) {
072                button.setText(text);
073        }
074
075        @Override
076        protected IconAnchor createTrigger() {
077                button = new Button();
078                addWidget(button);
079                trigger = new Button();
080                trigger.setCaret(true);
081                return trigger;
082        }
083
084        /**
085         * Set Button size
086         * @param size button size
087         */
088        public void setSize(ButtonSize size) {
089                trigger.setSize(size);
090        }
091
092        /**
093         * {@inheritDoc}
094         */
095        @Override
096        public void setType(ButtonType type) {
097                trigger.setType(type);
098        }
099
100    /**
101     * {@inheritDoc}
102     */
103    @Override
104        public void setIcon(IconType type) {
105                button.setIcon(type);
106        }
107
108        /**
109         * {@inheritDoc}
110         */
111        public HandlerRegistration addClickHandler(ClickHandler handler) {
112                return button.addClickHandler(handler);
113        }
114
115    /**
116     * {@inheritDoc}
117     */
118    @Override
119    public void setIconSize(IconSize size) {
120        button.setIconSize(size);
121    }
122    
123    @Override
124    @UiChild(tagname="customTrigger" , limit=1)
125    public void addCustomTrigger(Widget w) {
126        button.insert(w, 0);
127    }
128    
129    /**
130     * {@inheritDoc}
131     */
132    @Override
133    public void setCustomIconStyle(String customIconStyle) {
134        button.setCustomIconStyle(customIconStyle);
135    }
136
137}