1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.core.statement.ui.client.widgets.rules; |
17 | |
|
18 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
19 | |
import org.kuali.student.core.statement.ui.client.widgets.table.Node; |
20 | |
|
21 | |
import com.google.gwt.event.dom.client.ClickHandler; |
22 | |
import com.google.gwt.event.shared.HandlerRegistration; |
23 | |
import com.google.gwt.user.client.ui.CheckBox; |
24 | |
import com.google.gwt.user.client.ui.FocusPanel; |
25 | |
import com.google.gwt.user.client.ui.HTML; |
26 | |
import com.google.gwt.user.client.ui.HorizontalPanel; |
27 | |
import com.google.gwt.user.client.ui.VerticalPanel; |
28 | |
|
29 | |
public class RuleNodeWidget extends FocusPanel { |
30 | |
|
31 | |
|
32 | |
private Node node; |
33 | 0 | private HTML html = new HTML(); |
34 | |
private HorizontalPanel checkBoxAndEdit; |
35 | 0 | private CheckBox checkBox = new CheckBox(); |
36 | 0 | private KSLabel edit = new KSLabel("Edit"); |
37 | 0 | private KSLabel toggle = new KSLabel(""); |
38 | |
|
39 | |
|
40 | |
private HandlerRegistration editClauseHandlerRegistration; |
41 | |
private ClickHandler editClickHandler; |
42 | 0 | private boolean editMode = false; |
43 | |
private boolean showCheckbox; |
44 | |
|
45 | 0 | public RuleNodeWidget(Node n) { |
46 | 0 | init(n, true); |
47 | 0 | } |
48 | |
|
49 | 0 | public RuleNodeWidget(Node n, boolean showControls) { |
50 | 0 | init(n, showControls); |
51 | 0 | } |
52 | |
|
53 | |
private void init(Node n, boolean showControls) { |
54 | 0 | node = n; |
55 | 0 | this.showCheckbox = showControls; |
56 | 0 | drawNode(n, null, -1, -1); |
57 | 0 | } |
58 | |
|
59 | |
public void drawNode(Node n, RuleTable ruleTable, int rowIndex, int columnIndex) { |
60 | 0 | node = n; |
61 | |
|
62 | 0 | if (!(node.getUserObject() instanceof Token)) { |
63 | 0 | super.setWidget(html); |
64 | 0 | html.setHTML(node.getUserObject().toString()); |
65 | 0 | checkBox.setHTML(node.getUserObject().toString()); |
66 | 0 | return; |
67 | |
} |
68 | |
|
69 | 0 | Token userObject = (Token) node.getUserObject(); |
70 | 0 | String selectionStyle = (userObject.isCheckBoxOn() ? "KS-ReqComp-Selected" : "KS-ReqComp-DeSelected"); |
71 | |
|
72 | |
|
73 | 0 | if (userObject.isTokenOperator()) { |
74 | 0 | VerticalPanel checkBoxAndToggle = new VerticalPanel(); |
75 | 0 | super.setWidget(checkBoxAndToggle); |
76 | 0 | this.addStyleName(userObject.isCheckBoxOn() ? "KS-Rules-Table-Cell-Selected" : "KS-Rules-Table-Cell-DeSelected"); |
77 | 0 | if (showCheckbox) { |
78 | 0 | checkBoxAndToggle.add(checkBox); |
79 | |
} |
80 | 0 | toggle.setText(userObject.getType() == Token.Or ? Token.createOrToken().value.toUpperCase() : Token.createAndToken().value.toUpperCase()); |
81 | 0 | toggle.addStyleName("KS-Rules-Table-Cell-ANDOR"); |
82 | 0 | checkBoxAndToggle.add(toggle); |
83 | 0 | if (ruleTable != null) { |
84 | 0 | ruleTable.getCellFormatter().setStyleName(rowIndex, columnIndex, selectionStyle); |
85 | 0 | ruleTable.getCellFormatter().addStyleName(rowIndex, columnIndex, "KS-Toggle"); |
86 | |
} |
87 | 0 | } else { |
88 | 0 | checkBoxAndEdit = new HorizontalPanel(); |
89 | 0 | HorizontalPanel tableCell = new HorizontalPanel(); |
90 | 0 | super.setWidget(tableCell); |
91 | 0 | this.setStyleName(userObject.isCheckBoxOn() ? "KS-Rules-Table-Cell-Selected" : "KS-Rules-Table-Cell-DeSelected"); |
92 | 0 | if (userObject.getTokenID() != null) { |
93 | 0 | KSLabel rcLabel = new KSLabel(userObject.getTokenID()); |
94 | 0 | rcLabel.setStyleName("KS-Rules-Table-Cell-ID"); |
95 | 0 | tableCell.add(rcLabel); |
96 | |
} |
97 | 0 | tableCell.add(checkBoxAndEdit); |
98 | |
|
99 | 0 | if (showCheckbox) { |
100 | 0 | checkBoxAndEdit.add(checkBox); |
101 | 0 | checkBox.setHTML(node.getUserObject().toString()); |
102 | |
} else { |
103 | 0 | checkBoxAndEdit.add(new KSLabel(node.getUserObject().toString())); |
104 | |
} |
105 | 0 | edit.addStyleName("KS-Rules-URL-Link"); |
106 | 0 | checkBoxAndEdit.add(edit); |
107 | 0 | if (ruleTable != null) { |
108 | 0 | checkBoxAndEdit.setStyleName(selectionStyle); |
109 | |
} |
110 | |
|
111 | 0 | html.addStyleName("KS-ReqComp-Panel"); |
112 | |
} |
113 | |
|
114 | 0 | checkBox.setValue(userObject.isCheckBoxOn()); |
115 | 0 | html.setHTML(node.getUserObject().toString()); |
116 | 0 | } |
117 | |
|
118 | |
public boolean isSelected(){ |
119 | 0 | return checkBox.getValue(); |
120 | |
} |
121 | |
|
122 | |
public boolean isShowCheckbox() { |
123 | 0 | return showCheckbox; |
124 | |
} |
125 | |
|
126 | |
public void setShowCheckbox(boolean showCheckbox) { |
127 | 0 | this.showCheckbox = showCheckbox; |
128 | 0 | } |
129 | |
|
130 | |
public Node getNode() { |
131 | 0 | return node; |
132 | |
} |
133 | |
|
134 | |
public void addEditClauseHandler(ClickHandler ch) { |
135 | 0 | editClickHandler = ch; |
136 | 0 | editClauseHandlerRegistration = edit.addClickHandler(ch); |
137 | 0 | } |
138 | |
|
139 | |
public void clearEditClauseHandler() { |
140 | 0 | if (editClauseHandlerRegistration != null) { |
141 | 0 | editClauseHandlerRegistration.removeHandler(); |
142 | 0 | editClauseHandlerRegistration = null; |
143 | |
} |
144 | 0 | } |
145 | |
|
146 | |
public void setEnabled(boolean enabled) { |
147 | 0 | checkBox.setEnabled(enabled); |
148 | 0 | if (enabled) { |
149 | 0 | edit.removeStyleName("KS-Rules-URL-Link-Readonly"); |
150 | 0 | edit.addStyleName("KS-Rules-URL-Link"); |
151 | 0 | addEditClauseHandler(editClickHandler); |
152 | |
} else { |
153 | 0 | edit.removeStyleName("KS-Rules-URL-Link"); |
154 | 0 | edit.addStyleName("KS-Rules-URL-Link-Readonly"); |
155 | 0 | clearEditClauseHandler(); |
156 | |
} |
157 | 0 | } |
158 | |
|
159 | |
public boolean isEditMode() { |
160 | 0 | return editMode; |
161 | |
} |
162 | |
|
163 | |
public void setEditMode(boolean editMode) { |
164 | 0 | this.editMode = editMode; |
165 | 0 | } |
166 | |
} |