Skip to content

Commit 10b50b0

Browse files
author
Christoph Krautz
committed
Add HasEnabled to ButtonCell
- allow the button cell to be en-/disabled
1 parent a00dbcf commit 10b50b0

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/main/java/com/github/gwtbootstrap/client/ui/ButtonCell.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,24 @@
2020
import com.github.gwtbootstrap.client.ui.resources.ButtonSize;
2121
import com.google.gwt.safehtml.shared.SafeHtml;
2222
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
23+
import com.google.gwt.user.client.ui.HasEnabled;
2324

2425
/**
2526
* A ButtonCell with Bootstrap Style, supporting Icons and icon types.
2627
*
2728
* @author Carlos A Becker
29+
* @author Christoph Krautz
2830
* @since 2.0.4.0
2931
*
3032
* @see Button
3133
*
3234
*/
33-
public class ButtonCell extends com.google.gwt.cell.client.ButtonCell {
35+
public class ButtonCell extends com.google.gwt.cell.client.ButtonCell implements HasEnabled {
3436

3537
private IconType icon = null;
3638
private ButtonType type = null;
3739
private ButtonSize size = null;
40+
private boolean isEnabled = true;
3841

3942
public ButtonCell() {
4043
}
@@ -82,7 +85,11 @@ public ButtonCell(IconType icon, ButtonType type, ButtonSize size) {
8285
@Override
8386
public void render(Context context, SafeHtml data, SafeHtmlBuilder sb) {
8487
sb.appendHtmlConstant("<button type=\"button\" class=\"btn "
85-
+ (type != null ? type.get() : "") + (size != null ? " " + size.get() : "") + "\" tabindex=\"-1\">");
88+
+ (type != null ? type.get() : "")
89+
+ (size != null ? " " + size.get() : "")
90+
+ "\" "
91+
+ (isEnabled ? "" : "disabled=\"disabled\"")
92+
+ "tabindex=\"-1\">");
8693
if (data != null) {
8794
if (icon != null) {
8895
sb.appendHtmlConstant("<i class=\"" + icon.get() + "\"></i> ");
@@ -92,6 +99,16 @@ public void render(Context context, SafeHtml data, SafeHtmlBuilder sb) {
9299
sb.appendHtmlConstant("</button>");
93100
}
94101

102+
@Override
103+
public boolean isEnabled() {
104+
return isEnabled;
105+
}
106+
107+
@Override
108+
public void setEnabled(boolean enabled) {
109+
isEnabled = enabled;
110+
}
111+
95112
public IconType getIcon() {
96113
return icon;
97114
}
@@ -116,5 +133,5 @@ public void setSize(ButtonSize size) {
116133
this.size = size;
117134
}
118135

119-
// TODO add icon size support
136+
// TODO add icon size support
120137
}

0 commit comments

Comments
 (0)