use of com.google.gwt.event.dom.client.ChangeHandler in project drools-wb by kiegroup.
the class ExpressionBuilder method createWidgetForExpression.
// Render Widgets for the Expression. ExpressionMethodParameter and ExpressionText parts
// are represented by a TextBox to allow the User to edit the values, Updates are
// reflected in the model.
private Widget createWidgetForExpression() {
final HorizontalPanel container = new HorizontalPanel();
container.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
container.setStylePrimaryName(GuidedRuleEditorResources.INSTANCE.css().container());
for (ExpressionPart expressionPart : expression.getParts()) {
if (expressionPart instanceof ExpressionUnboundFact) {
continue;
} else if (this.readOnly) {
container.add(new Label(expressionPart.getName()));
} else if (expressionPart instanceof ExpressionMethod) {
container.add(new Label(expressionPart.getName()));
container.add(new Label("("));
final ExpressionMethod em = (ExpressionMethod) expressionPart;
final List<ExpressionFormLine> emParams = em.getOrderedParams();
for (int index = 0; index < emParams.size(); index++) {
final ExpressionFormLine paramValueHolder = emParams.get(index);
final String paramDataType = em.getParameterDataType(paramValueHolder);
final ExpressionMethodParameter paramValue = ((ExpressionMethodParameter) paramValueHolder.getRootExpression());
final TextBox paramValueEditor = TextBoxFactory.getTextBox(paramDataType);
paramValueEditor.addValueChangeHandler(new ValueChangeHandler<String>() {
@Override
public void onValueChange(ValueChangeEvent<String> event) {
paramValue.setText(event.getValue());
}
});
paramValueEditor.setText(paramValue.getName());
container.add(paramValueEditor);
if (index < emParams.size() - 1) {
container.add(new Label(", "));
}
}
container.add(new Label(")"));
} else if (!(expressionPart instanceof ExpressionText)) {
container.add(new Label(expressionPart.getName()));
} else {
final TextBox tb = new TextBox();
final ExpressionText expressionTextPart = (ExpressionText) expressionPart;
tb.setText(expressionTextPart.getName());
tb.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(final ChangeEvent changeEvent) {
expressionTextPart.setText(tb.getText());
}
});
container.add(tb);
}
container.add(new Label("."));
}
return container;
}
use of com.google.gwt.event.dom.client.ChangeHandler in project drools-wb by kiegroup.
the class ExpressionBuilder method getWidgetForCurrentType.
private Widget getWidgetForCurrentType() {
if (isExpressionEmpty()) {
return createStartPointWidget();
}
final ChangeHandler changeHandler = new ChangeHandler() {
public void onChange(ChangeEvent event) {
ListBox box = (ListBox) event.getSource();
panel.remove(box);
if (box.getSelectedIndex() > 0) {
onChangeSelection(box.getValue(box.getSelectedIndex()));
}
}
};
final ListBox listBox = new ListBox();
listBox.addItem(GuidedRuleEditorResources.CONSTANTS.Choose(), "");
if (includeDeleteOption()) {
listBox.addItem("<==" + GuidedRuleEditorResources.CONSTANTS.DeleteItem(), DELETE_VALUE);
}
listBox.addItem("-- Text --", TEXT_VALUE);
getCompletionsForCurrentType(expression.getParts().size() > 1, new Callback<Map<String, String>>() {
@Override
public void callback(final Map<String, String> completions) {
for (Map.Entry<String, String> entry : completions.entrySet()) {
listBox.addItem(entry.getKey(), entry.getValue());
}
listBox.addChangeHandler(changeHandler);
}
});
return listBox;
}
use of com.google.gwt.event.dom.client.ChangeHandler in project drools-wb by kiegroup.
the class FromCompositeFactPatternWidget method showFactTypeSelector.
/**
* Pops up the fact selector.
*/
protected void showFactTypeSelector() {
AsyncPackageDataModelOracle oracle = this.getModeller().getDataModelOracle();
final ListBox box = new ListBox();
String[] facts = oracle.getFactTypes();
box.addItem(GuidedRuleEditorResources.CONSTANTS.Choose());
for (int i = 0; i < facts.length; i++) {
box.addItem(facts[i]);
}
box.setSelectedIndex(0);
final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorResources.CONSTANTS.NewFactPattern());
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.chooseFactType(), box);
box.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
pattern.setFactPattern(new FactPattern(box.getItemText(box.getSelectedIndex())));
setModified(true);
getModeller().refreshWidget();
popup.hide();
}
});
popup.show();
}
use of com.google.gwt.event.dom.client.ChangeHandler in project drools-wb by kiegroup.
the class GuidedScoreCardEditor method getScorecardProperties.
private Widget getScorecardProperties() {
scorecardPropertiesGrid = new Grid(4, 4);
scorecardPropertiesGrid.setCellSpacing(5);
scorecardPropertiesGrid.setCellPadding(5);
tbInitialScore = TextBoxFactory.getTextBox(DataType.TYPE_NUMERIC_DOUBLE);
tbInitialScore.setText(Double.toString(model.getInitialScore()));
String factName = model.getFactName();
// if fact is a fully qualified className, strip off the packageName
if (factName.lastIndexOf(".") > -1) {
factName = factName.substring(factName.lastIndexOf(".") + 1);
}
dropDownFacts.clear();
dropDownFacts.addItem(GuidedScoreCardConstants.INSTANCE.pleaseChoose());
final String[] eligibleFacts = oracle.getFactTypes();
for (final String factType : eligibleFacts) {
dropDownFacts.addItem(factType);
}
dropDownFacts.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(final ChangeEvent event) {
scoreCardPropertyFactChanged(dropDownFacts, dropDownFields);
}
});
final int selectedFactIndex = Arrays.asList(eligibleFacts).indexOf(factName);
dropDownFacts.setSelectedIndex(selectedFactIndex >= 0 ? selectedFactIndex + 1 : 0);
scoreCardPropertyFactChanged(dropDownFacts, dropDownFields);
// Reason Codes List Box
ddReasonCodeField = new ListBox();
getEligibleFields(factName, typesForRC, new Callback<String[]>() {
@Override
public void callback(final String[] eligibleReasonCodeFields) {
ddReasonCodeField.addItem(GuidedScoreCardConstants.INSTANCE.pleaseChoose());
ddReasonCodeField.setEnabled(eligibleReasonCodeFields.length > 0);
for (final String field : eligibleReasonCodeFields) {
ddReasonCodeField.addItem(field);
}
final String rcField = model.getReasonCodeField() + " : List";
final int selectedReasonCodeIndex = Arrays.asList(eligibleReasonCodeFields).indexOf(rcField);
ddReasonCodeField.setSelectedIndex(selectedReasonCodeIndex >= 0 ? selectedReasonCodeIndex : 0);
}
});
final boolean useReasonCodes = model.isUseReasonCodes();
final String reasonCodesAlgo = model.getReasonCodesAlgorithm();
ddUseReasonCode = booleanEditor(Boolean.toString(useReasonCodes));
ddReasonCodeAlgorithm = listBoxEditor(reasonCodeAlgorithms, reasonCodesAlgo, true);
tbBaselineScore = TextBoxFactory.getTextBox(DataType.TYPE_NUMERIC_DOUBLE);
scorecardPropertiesGrid.setText(0, 0, GuidedScoreCardConstants.INSTANCE.facts());
scorecardPropertiesGrid.setText(0, 1, GuidedScoreCardConstants.INSTANCE.resultantScoreField());
scorecardPropertiesGrid.setText(0, 2, GuidedScoreCardConstants.INSTANCE.initialScore());
scorecardPropertiesGrid.setWidget(1, 0, dropDownFacts);
scorecardPropertiesGrid.setWidget(1, 1, dropDownFields);
scorecardPropertiesGrid.setWidget(1, 2, tbInitialScore);
scorecardPropertiesGrid.setText(2, 0, GuidedScoreCardConstants.INSTANCE.useReasonCodes());
scorecardPropertiesGrid.setText(2, 1, GuidedScoreCardConstants.INSTANCE.resultantReasonCodesField());
scorecardPropertiesGrid.setText(2, 2, GuidedScoreCardConstants.INSTANCE.reasonCodesAlgorithm());
scorecardPropertiesGrid.setText(2, 3, GuidedScoreCardConstants.INSTANCE.baselineScore());
scorecardPropertiesGrid.setWidget(3, 0, ddUseReasonCode);
scorecardPropertiesGrid.setWidget(3, 1, ddReasonCodeField);
scorecardPropertiesGrid.setWidget(3, 2, ddReasonCodeAlgorithm);
scorecardPropertiesGrid.setWidget(3, 3, tbBaselineScore);
/* TODO : Remove this explicitly Disabled Reasoncode support field*/
ddUseReasonCode.setEnabled(false);
ddReasonCodeField.setEnabled(false);
tbBaselineScore.setText(Double.toString(model.getBaselineScore()));
scorecardPropertiesGrid.getCellFormatter().setWidth(0, 0, "200px");
scorecardPropertiesGrid.getCellFormatter().setWidth(0, 1, "250px");
scorecardPropertiesGrid.getCellFormatter().setWidth(0, 2, "200px");
scorecardPropertiesGrid.getCellFormatter().setWidth(0, 3, "200px");
return scorecardPropertiesGrid;
}
use of com.google.gwt.event.dom.client.ChangeHandler in project drools-wb by kiegroup.
the class FactPatternWidget method predicateEditor.
/**
* This provides an inline formula editor, not unlike a spreadsheet does.
*/
private Widget predicateEditor(final SingleFieldConstraint c) {
HorizontalPanel pred = new HorizontalPanel();
pred.setWidth("100%");
Image img = new Image(GuidedRuleEditorResources.INSTANCE.images().functionAssets());
img.setTitle(GuidedRuleEditorResources.CONSTANTS.FormulaBooleanTip());
pred.add(img);
if (c.getValue() == null) {
c.setValue("");
}
final TextBox box = new TextBox();
box.setText(c.getValue());
if (!this.readOnly) {
box.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
setModified(true);
c.setValue(box.getText());
}
});
box.setWidth("100%");
pred.add(box);
} else {
pred.add(new SmallLabel(c.getValue()));
}
return pred;
}
Aggregations