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