use of com.google.gwt.event.dom.client.ChangeHandler in project drools-wb by kiegroup.
the class EditActionUpdatePopup method initialiseBoundTypes.
private void initialiseBoundTypes() {
// Extract all bindings available on the path to the root
final Map<String, TypeNode> bindings = new TreeMap<String, TypeNode>();
Node parent = clone.getParent();
while (parent != null) {
if (parent instanceof TypeNode) {
final TypeNode tn = (TypeNode) parent;
if (tn.isBound()) {
bindings.put(tn.getBinding(), tn);
}
}
parent = parent.getParent();
}
bindingListBox.setEnabled(!bindings.isEmpty());
if (bindings.isEmpty()) {
bindingListBox.addItem(GuidedDecisionTreeConstants.INSTANCE.noBindings());
return;
}
// Add them to the ListBox
int selectedIndex = 0;
final BoundNode boundNode = clone.getBoundNode();
for (String binding : bindings.keySet()) {
bindingListBox.addItem(binding);
if (boundNode != null) {
if (binding.equals(boundNode.getBinding())) {
selectedIndex = bindingListBox.getItemCount() - 1;
}
}
}
// Attach event handler before we set the selected index in case we're selecting the first item
bindingListBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(final ChangeEvent event) {
final String binding = bindingListBox.getItemText(bindingListBox.getSelectedIndex());
clone.setBoundNode(bindings.get(binding));
clone.getFieldValues().clear();
initialiseFieldValues();
}
});
bindingListBox.setSelectedIndex(selectedIndex);
}
use of com.google.gwt.event.dom.client.ChangeHandler in project drools-wb by kiegroup.
the class CEPWindowOperatorsDropdown method getDropDown.
// Actual drop-down
private Widget getDropDown() {
String selected = "";
String selectedText = "";
box = new ListBox();
box.setEnabled(!isReadOnly);
box.addItem(HumanReadableConstants.INSTANCE.noCEPWindow(), "");
for (int i = 0; i < operators.size(); i++) {
String op = operators.get(i);
box.addItem(HumanReadable.getOperatorDisplayName(op), op);
if (op.equals(hcw.getWindow().getOperator())) {
selected = op;
selectedText = HumanReadable.getOperatorDisplayName(op);
box.setSelectedIndex(i + 1);
}
}
selectItem(hcw.getWindow().getOperator());
// Fire event to ensure parent Widgets correct their state depending on selection
final HasValueChangeHandlers<OperatorSelection> source = this;
final OperatorSelection selection = new OperatorSelection(selected, selectedText);
Scheduler.get().scheduleFinally(new Command() {
public void execute() {
operatorChanged(selection);
ValueChangeEvent.fire(source, selection);
}
});
// Signal parent Widget whenever a change happens
box.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
String selected = box.getValue(box.getSelectedIndex());
String selectedText = box.getItemText(box.getSelectedIndex());
OperatorSelection selection = new OperatorSelection(selected, selectedText);
operatorChanged(selection);
ValueChangeEvent.fire(source, selection);
}
});
return box;
}
use of com.google.gwt.event.dom.client.ChangeHandler in project drools-wb by kiegroup.
the class ConstraintValueEditor method variableEditor.
private Widget variableEditor() {
if (this.readOnly) {
return new SmallLabel(this.constraint.getValue());
}
final ListBox box = new ListBox();
box.addItem(GuidedRuleEditorResources.CONSTANTS.Choose());
List<String> bindingsInScope = this.model.getBoundVariablesInScope(this.constraint);
for (String var : bindingsInScope) {
final String binding = var;
helper.isApplicableBindingsInScope(var, new Callback<Boolean>() {
@Override
public void callback(final Boolean result) {
if (Boolean.TRUE.equals(result)) {
box.addItem(binding);
if (ConstraintValueEditor.this.constraint.getValue() != null && ConstraintValueEditor.this.constraint.getValue().equals(binding)) {
box.setSelectedIndex(box.getItemCount() - 1);
}
}
}
});
}
box.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
executeOnValueChangeCommand();
int selectedIndex = box.getSelectedIndex();
if (selectedIndex > 0) {
constraint.setValue(box.getItemText(selectedIndex));
} else {
constraint.setValue(null);
}
}
});
return box;
}
use of com.google.gwt.event.dom.client.ChangeHandler in project drools-wb by kiegroup.
the class RuleAttributeWidget method getEditorWidget.
private Widget getEditorWidget(final RuleAttribute at, final int idx, final boolean isReadOnly) {
Widget editor = null;
final String attributeName = at.getAttributeName();
if (attributeName.equals(RULEFLOW_GROUP_ATTR) || attributeName.equals(AGENDA_GROUP_ATTR) || attributeName.equals(ACTIVATION_GROUP_ATTR) || attributeName.equals(TIMER_ATTR) || attributeName.equals(CALENDARS_ATTR)) {
final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_STRING);
tb.setEnabled(!isReadOnly);
if (!isReadOnly) {
tb.addValueChangeHandler(new ValueChangeHandler<String>() {
public void onValueChange(ValueChangeEvent<String> event) {
at.setValue(tb.getValue());
}
});
}
tb.setValue(at.getValue());
editor = tb;
} else if (attributeName.equals(SALIENCE_ATTR)) {
final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_NUMERIC_INTEGER);
tb.setEnabled(!isReadOnly);
if (!isReadOnly) {
tb.addValueChangeHandler(new ValueChangeHandler<String>() {
public void onValueChange(ValueChangeEvent<String> event) {
at.setValue(tb.getValue());
}
});
}
tb.setValue(at.getValue());
editor = tb;
} else if (attributeName.equals(DURATION_ATTR)) {
final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_NUMERIC_LONG);
tb.setEnabled(!isReadOnly);
if (!isReadOnly) {
tb.addValueChangeHandler(new ValueChangeHandler<String>() {
public void onValueChange(ValueChangeEvent<String> event) {
at.setValue(tb.getValue());
}
});
}
tb.setValue(at.getValue());
editor = tb;
} else if (attributeName.equals(NO_LOOP_ATTR) || attributeName.equals(LOCK_ON_ACTIVE_ATTR) || attributeName.equals(AUTO_FOCUS_ATTR) || attributeName.equals(ENABLED_ATTR)) {
editor = checkBoxEditor(at, isReadOnly);
} else if (attributeName.equals(DATE_EFFECTIVE_ATTR) || attributeName.equals(DATE_EXPIRES_ATTR)) {
if (isReadOnly) {
final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_STRING);
tb.setValue(at.getValue());
tb.setEnabled(false);
} else {
final DatePicker datePicker = new DatePicker(false);
// Wire up update handler
datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {
@Override
public void onValueChange(final ValueChangeEvent<Date> event) {
final Date date = datePicker.getValue();
final String sDate = (date == null ? null : DATE_FORMATTER.format(datePicker.getValue()));
at.setValue(sDate);
}
});
datePicker.setFormat(DATE_FORMAT);
datePicker.setValue(assertDateValue(at));
editor = datePicker;
}
} else if (attributeName.equals(DIALECT_ATTR)) {
final ListBox lb = new ListBox();
lb.addItem(DIALECTS[0]);
lb.addItem(DIALECTS[1]);
lb.setEnabled(!isReadOnly);
if (!isReadOnly) {
lb.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
final int selectedIndex = lb.getSelectedIndex();
if (selectedIndex < 0) {
return;
}
at.setValue(lb.getValue(selectedIndex));
}
});
}
if (at.getValue() == null || at.getValue().isEmpty()) {
lb.setSelectedIndex(1);
at.setValue(DIALECTS[1]);
} else if (at.getValue().equals(DIALECTS[0])) {
lb.setSelectedIndex(0);
} else if (at.getValue().equals(DIALECTS[1])) {
lb.setSelectedIndex(1);
} else {
lb.setSelectedIndex(1);
at.setValue(DIALECTS[1]);
}
editor = lb;
}
DirtyableHorizontalPane horiz = new DirtyableHorizontalPane();
if (editor != null) {
horiz.add(editor);
if (!isReadOnly) {
horiz.add(getRemoveIcon(idx));
}
}
return horiz;
}
use of com.google.gwt.event.dom.client.ChangeHandler in project drools-wb by kiegroup.
the class PopupCreator method showPatternPopup.
/**
* This shows a popup allowing you to add field constraints to a pattern
* (its a popup).
*/
public void showPatternPopup(final FactPattern fp, final SingleFieldConstraint con, final boolean isNested) {
final String factType = getFactType(fp, con);
String title = (con == null) ? GuidedRuleEditorResources.CONSTANTS.ModifyConstraintsFor0(fp.getFactType()) : GuidedRuleEditorResources.CONSTANTS.AddSubFieldConstraint();
final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorImages508.INSTANCE.Wizard(), title);
final ListBox box = new ListBox();
box.addItem("...");
this.oracle.getFieldCompletions(factType, FieldAccessorsAndMutators.ACCESSOR, new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] fields) {
for (int i = 0; i < fields.length; i++) {
// You can't use "this" in a nested accessor
final String fieldName = fields[i].getName();
if (!isNested || !fieldName.equals(DataType.TYPE_THIS)) {
box.addItem(fieldName);
}
}
}
});
box.setSelectedIndex(0);
box.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
String fieldName = box.getItemText(box.getSelectedIndex());
if ("...".equals(fieldName)) {
return;
}
String fieldType = oracle.getFieldType(factType, fieldName);
fp.addConstraint(new SingleFieldConstraint(factType, fieldName, fieldType, con));
modeller.refreshWidget();
popup.hide();
}
});
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.AddARestrictionOnAField(), box);
final ListBox composites = new ListBox();
composites.addItem("...");
composites.addItem(GuidedRuleEditorResources.CONSTANTS.AllOfAnd(), CompositeFieldConstraint.COMPOSITE_TYPE_AND);
composites.addItem(GuidedRuleEditorResources.CONSTANTS.AnyOfOr(), CompositeFieldConstraint.COMPOSITE_TYPE_OR);
composites.setSelectedIndex(0);
composites.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
CompositeFieldConstraint comp = new CompositeFieldConstraint();
comp.setCompositeJunctionType(composites.getValue(composites.getSelectedIndex()));
fp.addConstraint(comp);
modeller.refreshWidget();
popup.hide();
}
});
InfoPopup infoComp = new InfoPopup(GuidedRuleEditorResources.CONSTANTS.MultipleFieldConstraints(), GuidedRuleEditorResources.CONSTANTS.MultipleConstraintsTip1());
HorizontalPanel horiz = new HorizontalPanel();
horiz.add(composites);
horiz.add(infoComp);
if (con == null) {
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.MultipleFieldConstraint(), horiz);
}
if (con == null) {
// NON-NLS
popup.addRow(new SmallLabel("<i>" + GuidedRuleEditorResources.CONSTANTS.AdvancedOptionsColon() + "</i>"));
Button predicate = new Button(GuidedRuleEditorResources.CONSTANTS.NewFormula());
predicate.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
SingleFieldConstraint con = new SingleFieldConstraint();
con.setConstraintValueType(SingleFieldConstraint.TYPE_PREDICATE);
fp.addConstraint(con);
modeller.refreshWidget();
popup.hide();
}
});
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.AddANewFormulaStyleExpression(), predicate);
final Button expressionEditorButton = makeExpressionEditorButton(fp, popup);
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.ExpressionEditor(), expressionEditorButton);
doBindingEditor(popup);
}
popup.show();
}
Aggregations