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.dom.client.HasClickHandlers; 025 import com.google.gwt.event.shared.HandlerRegistration; 026 027 //@formatter:off 028 /** 029 * Dropdown button. 030 * 031 * @author Dominik Mayer 032 * @since 2.0.4.0 033 * @see <a 034 * href="http://twitter.github.com/bootstrap/components.html#buttonDropdowns">Bootstrap 035 * documentation</a> 036 * 037 */ 038 //@formatter:on 039 public class SplitDropdownButton extends DropdownBase implements 040 HasClickHandlers { 041 042 private Button button; 043 044 private Button trigger; 045 046 public SplitDropdownButton() { 047 super("div"); 048 addStyleName("btn-group"); 049 } 050 051 public SplitDropdownButton(String text) { 052 this(); 053 setText(text); 054 } 055 056 @Override 057 public void setText(String text) { 058 button.setText(text); 059 } 060 061 @Override 062 protected IconAnchor createTrigger() { 063 button = new Button(); 064 addWidget(button); 065 trigger = new Button(); 066 trigger.setCaret(true); 067 return trigger; 068 } 069 070 public void setSize(ButtonSize size) { 071 trigger.setSize(size); 072 } 073 074 public void setType(ButtonType type) { 075 trigger.setType(type); 076 } 077 078 public void setIcon(IconType type) { 079 button.setIcon(type); 080 } 081 082 public HandlerRegistration addClickHandler(ClickHandler handler) { 083 return button.addClickHandler(handler); 084 } 085 }