1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.common.ui.client.widgets.rules; |
17 | |
|
18 | |
import com.google.gwt.event.dom.client.ClickEvent; |
19 | |
import com.google.gwt.event.dom.client.ClickHandler; |
20 | |
import com.google.gwt.event.shared.HandlerRegistration; |
21 | |
import com.google.gwt.user.client.ui.Button; |
22 | |
import com.google.gwt.user.client.ui.HorizontalPanel; |
23 | |
|
24 | 0 | public class AndOrButton extends HorizontalPanel { |
25 | |
|
26 | 0 | Button andButton = new Button(" AND "); |
27 | 0 | Button orButton = new Button("OR"); |
28 | |
HandlerRegistration andHandlerRegi; |
29 | |
HandlerRegistration orHandlerRegi; |
30 | |
|
31 | |
public final static int And = 1; |
32 | |
public final static int Or = 2; |
33 | 0 | private int value = And; |
34 | |
|
35 | 0 | public AndOrButton(){ |
36 | 0 | super.add(andButton); |
37 | |
|
38 | |
|
39 | 0 | super.add(orButton); |
40 | |
|
41 | 0 | andButton.setStyleName("KS-Rules-Toggle-Button"); |
42 | |
|
43 | 0 | orButton.setStyleName("KS-Rules-Toggle-Button"); |
44 | 0 | update(AndOrButton.And); |
45 | 0 | andButton.addClickHandler(new ClickHandler(){ |
46 | |
@Override |
47 | |
public void onClick(ClickEvent event) { |
48 | 0 | update(AndOrButton.Or); |
49 | 0 | } |
50 | |
}); |
51 | 0 | orButton.addClickHandler(new ClickHandler(){ |
52 | |
@Override |
53 | |
public void onClick(ClickEvent event) { |
54 | 0 | update(AndOrButton.And); |
55 | 0 | } |
56 | |
}); |
57 | 0 | } |
58 | |
|
59 | |
public int getValue(){ |
60 | 0 | return value; |
61 | |
} |
62 | |
|
63 | |
public void addClickHandler(ClickHandler clickHandler) { |
64 | 0 | andHandlerRegi = andButton.addClickHandler(clickHandler); |
65 | 0 | orHandlerRegi = orButton.addClickHandler(clickHandler); |
66 | 0 | } |
67 | |
|
68 | |
public void removeClickHandler() { |
69 | 0 | andHandlerRegi.removeHandler(); |
70 | 0 | orHandlerRegi.removeHandler(); |
71 | 0 | } |
72 | |
|
73 | |
public void setValue(int v){ |
74 | 0 | this.value = v; |
75 | 0 | update(this.value); |
76 | 0 | } |
77 | |
|
78 | |
private void update(int value){ |
79 | 0 | this.value = value; |
80 | |
|
81 | 0 | if(value == And) { |
82 | 0 | andButton.setStyleName("KS-Rules-Toggle-Label"); |
83 | 0 | orButton.setStyleName("KS-Rules-Toggle-Button"); |
84 | 0 | } else if (value == Or){ |
85 | 0 | orButton.setStyleName("KS-Rules-Toggle-Label"); |
86 | 0 | andButton.setStyleName("KS-Rules-Toggle-Button"); |
87 | |
} |
88 | 0 | } |
89 | |
|
90 | |
public void setEnabled(boolean enabled) { |
91 | 0 | andButton.setEnabled(enabled); |
92 | 0 | orButton.setEnabled(enabled); |
93 | 0 | } |
94 | |
} |