1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.common.ui.client.widgets.impl;
17
18 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract;
19
20 import com.google.gwt.event.dom.client.ClickHandler;
21 import com.google.gwt.event.dom.client.MouseOutHandler;
22 import com.google.gwt.event.dom.client.MouseOverHandler;
23 import com.google.gwt.event.shared.HandlerRegistration;
24 import com.google.gwt.user.client.DOM;
25 import com.google.gwt.user.client.ui.Anchor;
26 import com.google.gwt.user.client.ui.ComplexPanel;
27 import com.google.gwt.user.client.ui.InlineLabel;
28 import com.google.gwt.user.client.ui.Widget;
29
30 public class KSButtonImpl extends KSButtonAbstract{
31
32
33 private static class SpanPanel extends ComplexPanel{
34
35 public SpanPanel(){
36 setElement(DOM.createSpan());
37 }
38
39
40
41
42
43
44 @Override
45 public void add(Widget w) {
46 add(w, getElement());
47 }
48
49
50
51
52
53
54
55
56
57 public void insert(Widget w, int beforeIndex) {
58 insert(w, getElement(), beforeIndex, true);
59 }
60 }
61
62 private SpanPanel panel = new SpanPanel();
63 private Anchor anchor;
64 private InlineLabel disabledLabel = new InlineLabel();
65 private boolean enabled = true;
66 private ButtonStyle currentStyle;
67
68 public boolean isEnabled() {
69 return enabled;
70 }
71
72 public void setEnabled(boolean enabled) {
73 anchor.setEnabled(enabled);
74 if(enabled){
75 panel.remove(disabledLabel);
76 panel.add(anchor);
77 }
78 else{
79 panel.remove(anchor);
80 panel.add(disabledLabel);
81 }
82 }
83
84 @Override
85 public HandlerRegistration addClickHandler(ClickHandler handler) {
86 return anchor.addClickHandler(handler);
87 }
88
89 @Override
90 public void setText(String text){
91 anchor.setText(text);
92 disabledLabel.setText(text);
93 }
94
95 @Override
96 public HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
97 return anchor.addMouseOverHandler(handler);
98 }
99
100 @Override
101 public HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
102 return anchor.addMouseOutHandler(handler);
103 }
104
105 @Override
106 public void init(String text) {
107 init(text, ButtonStyle.PRIMARY);
108 }
109
110 @Override
111 public void init(String text, ButtonStyle style) {
112
113 this.currentStyle = style;
114 disabledLabel.setText(text);
115 anchor = new Anchor();
116 if(currentStyle.getStyle() != null){
117 disabledLabel.setStyleName(currentStyle.getStyle());
118 anchor.setStyleName(currentStyle.getStyle());
119 }
120 String disabledStyle = currentStyle.getDisabledStyle();
121 if(disabledStyle == null){
122 disabledLabel.addStyleName("disabled");
123 }
124 else{
125 disabledLabel.setStyleName(disabledStyle);
126 }
127 anchor.setText(text);
128 anchor.setHref("javascript:return false;");
129
130 panel.add(anchor);
131 anchor.setTabIndex(0);
132
133 this.initWidget(panel);
134 }
135
136 @Override
137 public void addStyleName(String style) {
138 anchor.addStyleName(style);
139 disabledLabel.addStyleName(style);
140 }
141
142 @Override
143 public void removeStyleName(String style) {
144 anchor.removeStyleName(style);
145 disabledLabel.removeStyleName(style);
146 }
147
148 @Override
149 public void setStyleName(String style) {
150 anchor.setStyleName(style);
151 disabledLabel.setStyleName(style);
152 }
153
154 @Override
155 public void init() {
156 init("", ButtonStyle.PRIMARY);
157 }
158
159 @Override
160 public void init(String text, ClickHandler handler) {
161 init(text, ButtonStyle.PRIMARY);
162 anchor.addClickHandler(handler);
163 }
164
165 public void init(String text, ButtonStyle style, ClickHandler handler) {
166 init(text, style);
167 anchor.addClickHandler(handler);
168 }
169 }