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