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