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 | 0 | public class KSButtonImpl extends KSButtonAbstract{ |
31 | |
|
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 | |
|
57 | |
public void insert(Widget w, int beforeIndex) { |
58 | 0 | insert(w, getElement(), beforeIndex, true); |
59 | 0 | } |
60 | |
} |
61 | |
|
62 | 0 | private SpanPanel panel = new SpanPanel(); |
63 | |
private Anchor anchor; |
64 | 0 | private InlineLabel disabledLabel = new InlineLabel(); |
65 | 0 | private boolean enabled = true; |
66 | |
private ButtonStyle currentStyle; |
67 | |
|
68 | |
public boolean isEnabled() { |
69 | 0 | return enabled; |
70 | |
} |
71 | |
|
72 | |
public void setEnabled(boolean enabled) { |
73 | 0 | anchor.setEnabled(enabled); |
74 | 0 | if(enabled){ |
75 | 0 | panel.remove(disabledLabel); |
76 | 0 | panel.add(anchor); |
77 | |
} |
78 | |
else{ |
79 | 0 | panel.remove(anchor); |
80 | 0 | panel.add(disabledLabel); |
81 | |
} |
82 | 0 | } |
83 | |
|
84 | |
@Override |
85 | |
public HandlerRegistration addClickHandler(ClickHandler handler) { |
86 | 0 | return anchor.addClickHandler(handler); |
87 | |
} |
88 | |
|
89 | |
@Override |
90 | |
public void setText(String text){ |
91 | 0 | anchor.setText(text); |
92 | 0 | disabledLabel.setText(text); |
93 | 0 | } |
94 | |
|
95 | |
@Override |
96 | |
public HandlerRegistration addMouseOverHandler(MouseOverHandler handler) { |
97 | 0 | return anchor.addMouseOverHandler(handler); |
98 | |
} |
99 | |
|
100 | |
@Override |
101 | |
public HandlerRegistration addMouseOutHandler(MouseOutHandler handler) { |
102 | 0 | return anchor.addMouseOutHandler(handler); |
103 | |
} |
104 | |
|
105 | |
@Override |
106 | |
public void init(String text) { |
107 | 0 | init(text, ButtonStyle.PRIMARY); |
108 | 0 | } |
109 | |
|
110 | |
@Override |
111 | |
public void init(String text, ButtonStyle style) { |
112 | |
|
113 | 0 | this.currentStyle = style; |
114 | 0 | disabledLabel.setText(text); |
115 | 0 | anchor = new Anchor(); |
116 | 0 | if(currentStyle.getStyle() != null){ |
117 | 0 | disabledLabel.setStyleName(currentStyle.getStyle()); |
118 | 0 | anchor.setStyleName(currentStyle.getStyle()); |
119 | |
} |
120 | 0 | String disabledStyle = currentStyle.getDisabledStyle(); |
121 | 0 | if(disabledStyle == null){ |
122 | 0 | disabledLabel.addStyleName("disabled"); |
123 | |
} |
124 | |
else{ |
125 | 0 | disabledLabel.setStyleName(disabledStyle); |
126 | |
} |
127 | 0 | anchor.setText(text); |
128 | 0 | anchor.setHref("javascript:return false;"); |
129 | |
|
130 | 0 | panel.add(anchor); |
131 | 0 | anchor.setTabIndex(0); |
132 | |
|
133 | 0 | this.initWidget(panel); |
134 | 0 | } |
135 | |
|
136 | |
@Override |
137 | |
public void addStyleName(String style) { |
138 | 0 | anchor.addStyleName(style); |
139 | 0 | disabledLabel.addStyleName(style); |
140 | 0 | } |
141 | |
|
142 | |
@Override |
143 | |
public void removeStyleName(String style) { |
144 | 0 | anchor.removeStyleName(style); |
145 | 0 | disabledLabel.removeStyleName(style); |
146 | 0 | } |
147 | |
|
148 | |
@Override |
149 | |
public void setStyleName(String style) { |
150 | 0 | anchor.setStyleName(style); |
151 | 0 | disabledLabel.setStyleName(style); |
152 | 0 | } |
153 | |
|
154 | |
@Override |
155 | |
public void init() { |
156 | 0 | init("", ButtonStyle.PRIMARY); |
157 | 0 | } |
158 | |
|
159 | |
@Override |
160 | |
public void init(String text, ClickHandler handler) { |
161 | 0 | init(text, ButtonStyle.PRIMARY); |
162 | 0 | anchor.addClickHandler(handler); |
163 | 0 | } |
164 | |
|
165 | |
public void init(String text, ButtonStyle style, ClickHandler handler) { |
166 | 0 | init(text, style); |
167 | 0 | anchor.addClickHandler(handler); |
168 | 0 | } |
169 | |
} |