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.constants.ButtonType;
019import com.github.gwtbootstrap.client.ui.constants.IconType;
020import com.github.gwtbootstrap.client.ui.resources.ButtonSize;
021import com.google.gwt.safehtml.shared.SafeHtml;
022import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
023
024/**
025 * A ButtonCell with Bootstrap Style, supporting Icons and icon types.
026 * 
027 * @author Carlos A Becker
028 * @since 2.0.4.0
029 * 
030 * @see Button
031 * 
032 */
033public class ButtonCell extends com.google.gwt.cell.client.ButtonCell {
034
035        private IconType icon = null;
036        private ButtonType type = null;
037        private ButtonSize size = null;
038
039        public ButtonCell() {
040        }
041
042        public ButtonCell(ButtonType type) {
043                super();
044                this.type = type;
045        }
046
047        public ButtonCell(IconType icon) {
048                super();
049                this.icon = icon;
050        }
051        
052        public ButtonCell(ButtonSize size) {
053                super();
054                this.size = size;
055        }
056
057    public ButtonCell(IconType icon, ButtonType type) {
058                super();
059                this.icon = icon;
060                this.type = type;
061        }
062    
063    public ButtonCell(IconType icon, ButtonSize size) {
064                super();
065                this.icon = icon;
066                this.size = size;
067        }
068    
069    public ButtonCell(ButtonType type, ButtonSize size) {
070                super();
071                this.type = type;
072                this.size = size;
073        }
074    
075    public ButtonCell(IconType icon, ButtonType type, ButtonSize size) {
076                super();
077                this.icon = icon;
078                this.type = type;
079                this.size = size;
080        }
081
082        @Override
083        public void render(Context context, SafeHtml data, SafeHtmlBuilder sb) {
084                sb.appendHtmlConstant("<button type=\"button\" class=\"btn "
085                                + (type != null ? type.get() : "") + (size != null ? " " + size.get() : "") + "\" tabindex=\"-1\">");
086                if (data != null) {
087                        if (icon != null) {
088                sb.appendHtmlConstant("<i class=\"" + icon.get() + "\"></i> ");
089            }
090                        sb.append(data);
091                }
092                sb.appendHtmlConstant("</button>");
093        }
094        
095    public IconType getIcon() {
096        return icon;
097    }
098
099    public void setIcon(IconType icon) {
100        this.icon = icon;
101    }
102
103    public ButtonType getType() {
104        return type;
105    }
106
107    public void setType(ButtonType type) {
108        this.type = type;
109    }
110
111        public ButtonSize getSize() {
112                return size;
113        }
114
115        public void setSize(ButtonSize size) {
116                this.size = size;
117        }
118        
119    // TODO add icon size support
120}