use of org.kie.soup.project.datamodel.oracle.ModelField in project drools-wb by kiegroup.
the class ActionInsertFactWidget method showAddFieldPopup.
protected void showAddFieldPopup(Widget w) {
final AsyncPackageDataModelOracle oracle = this.getModeller().getDataModelOracle();
final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorImages508.INSTANCE.Wizard(), GuidedRuleEditorResources.CONSTANTS.AddAField());
final ListBox box = new ListBox();
box.addItem("...");
final ModelField[] availableFieldCompletions = ModelFieldUtil.getAvailableFieldCompletions(fieldCompletions, model);
final boolean isEnabled = !isReadOnly() && availableFieldCompletions.length > 0;
if (availableFieldCompletions.length > 0) {
for (int i = 0; i < availableFieldCompletions.length; i++) {
box.addItem(availableFieldCompletions[i].getName());
}
}
box.setSelectedIndex(0);
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.AddField(), box);
box.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
String fieldName = box.getItemText(box.getSelectedIndex());
String fieldType = oracle.getFieldType(model.getFactType(), fieldName);
model.addFieldValue(new ActionFieldValue(fieldName, "", fieldType));
setModified(true);
getModeller().refreshWidget();
popup.hide();
}
});
/*
* Propose a textBox to the user to make him set a variable name
*/
final HorizontalPanel vn = new HorizontalPanel();
final TextBox varName = new TextBox();
if (this.model.getBoundName() != null) {
varName.setText(this.model.getBoundName());
}
final Button ok = new Button(HumanReadableConstants.INSTANCE.Set());
vn.add(varName);
vn.add(ok);
ok.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
String var = varName.getText();
if (getModeller().isVariableNameUsed(var) && ((model.getBoundName() != null && model.getBoundName().equals(var) == false) || model.getBoundName() == null)) {
Window.alert(GuidedRuleEditorResources.CONSTANTS.TheVariableName0IsAlreadyTaken(var));
return;
}
model.setBoundName(var);
setModified(true);
getModeller().refreshWidget();
popup.hide();
}
});
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.BoundVariable(), vn);
box.setEnabled(isEnabled);
varName.setEnabled(isEnabled);
ok.setEnabled(isEnabled);
popup.show();
}
use of org.kie.soup.project.datamodel.oracle.ModelField in project drools-wb by kiegroup.
the class ActionSetFieldWidget method showAddFieldPopup.
protected void showAddFieldPopup(ClickEvent w) {
final AsyncPackageDataModelOracle oracle = this.getModeller().getDataModelOracle();
final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorImages508.INSTANCE.Wizard(), GuidedRuleEditorResources.CONSTANTS.AddAField());
final ListBox box = new ListBox();
box.addItem("...");
final ModelField[] availableFieldCompletions = ModelFieldUtil.getAvailableFieldCompletions(fieldCompletions, model);
final boolean isEnabled = !isReadOnly() && availableFieldCompletions.length > 0;
if (availableFieldCompletions.length > 0) {
for (int i = 0; i < availableFieldCompletions.length; i++) {
box.addItem(availableFieldCompletions[i].getName());
}
}
box.setSelectedIndex(0);
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.AddField(), box);
box.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
String fieldName = box.getItemText(box.getSelectedIndex());
String fieldType = oracle.getFieldType(variableClass, fieldName);
model.addFieldValue(new ActionFieldValue(fieldName, "", fieldType));
setModified(true);
getModeller().refreshWidget();
popup.hide();
}
});
box.setEnabled(isEnabled);
popup.show();
}
use of org.kie.soup.project.datamodel.oracle.ModelField in project drools-wb by kiegroup.
the class ConstraintValueEditorHelperTest method testEvents_BoundTypeIsNotEvent.
@Test
public void testEvents_BoundTypeIsNotEvent() throws Exception {
AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(serviceCaller, validatorInstance);
oracle.setPackageName("org.test");
oracle.addModelFields(new HashMap<String, ModelField[]>() {
{
put("org.test.Event1", new ModelField[] { modelField("this", "org.test.Event1") });
put("org.test.Event2", new ModelField[] { modelField("this", "org.test.Event2") });
}
});
oracle.addEventTypes(new HashMap<String, Boolean>() {
{
put("org.test.Event1", false);
put("org.test.Event2", true);
}
});
oracle.addSuperTypes(new HashMap<String, List<String>>() {
{
put("org.test.Event1", Collections.EMPTY_LIST);
put("org.test.Event2", Collections.EMPTY_LIST);
}
});
oracle.filter();
FactPattern pattern1 = new FactPattern();
pattern1.setFactType("Event1");
pattern1.setBoundName("$e");
SingleFieldConstraint constraint = new SingleFieldConstraint();
constraint.setFactType("Event1");
constraint.setFieldName("this");
constraint.setFieldType("Event1");
constraint.setOperator(OperatorsOracle.SIMPLE_CEP_OPERATORS[0]);
pattern1.addConstraint(constraint);
model.addLhsItem(pattern1);
ConstraintValueEditorHelper helper = new ConstraintValueEditorHelper(model, oracle, "Event2", "this", constraint, "Event2", new DropDownData());
helper.isApplicableBindingsInScope("$e", new Callback<Boolean>() {
@Override
public void callback(Boolean result) {
assertFalse(result);
}
});
}
use of org.kie.soup.project.datamodel.oracle.ModelField in project drools-wb by kiegroup.
the class TestGuidedScoreCardFileIndexer method getModuleDataModelOracle.
@Override
protected ModuleDataModelOracle getModuleDataModelOracle(final Path path) {
final ModuleDataModelOracle dmo = new ModuleDataModelOracleImpl();
dmo.addModuleModelFields(new HashMap<String, ModelField[]>() {
{
put("org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Applicant", new ModelField[] { new ModelField("age", "java.lang.Integer", ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.ACCESSOR, DataType.TYPE_NUMERIC_INTEGER) });
put("org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Mortgage", new ModelField[] { new ModelField("amount", "java.lang.Integer", ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.ACCESSOR, DataType.TYPE_NUMERIC_INTEGER) });
}
});
return dmo;
}
use of org.kie.soup.project.datamodel.oracle.ModelField in project drools-wb by kiegroup.
the class GuidedScoreCardEditor method getCharacteristicFromTable.
private Characteristic getCharacteristicFromTable(FlexTable flexTable) {
ListBox enumDropDown;
final Characteristic characteristic = new Characteristic();
characteristic.setName(((TextBox) flexTable.getWidget(0, 1)).getValue());
// Characteristic Fact Type
enumDropDown = (ListBox) flexTable.getWidget(2, 0);
if (enumDropDown.getSelectedIndex() > -1) {
final String simpleFactName = enumDropDown.getValue(enumDropDown.getSelectedIndex());
characteristic.setFact(simpleFactName);
oracle.getFieldCompletions(simpleFactName, new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] fields) {
if (fields != null) {
for (ModelField mf : fields) {
if (mf.getType().equals(simpleFactName)) {
characteristic.setFact(mf.getClassName());
break;
}
}
}
}
});
// Characteristic Field (cannot be set if no Fact Type has been set)
enumDropDown = (ListBox) flexTable.getWidget(2, 1);
if (enumDropDown.getSelectedIndex() > -1) {
String fieldName = enumDropDown.getValue(enumDropDown.getSelectedIndex());
fieldName = fieldName.substring(0, fieldName.indexOf(":")).trim();
characteristic.setField(fieldName);
} else {
characteristic.setField("");
}
getDataTypeForField(simpleFactName, characteristic.getField(), new Callback<String>() {
@Override
public void callback(final String result) {
characteristic.setDataType(result);
}
});
}
// Characteristic Reason Code
characteristic.setReasonCode(((TextBox) flexTable.getWidget(2, 3)).getValue());
// Characteristic Base Line Score
final String baselineScore = ((TextBox) flexTable.getWidget(2, 2)).getValue();
try {
characteristic.setBaselineScore(Double.parseDouble(baselineScore));
} catch (Exception e) {
characteristic.setBaselineScore(0.0d);
}
return characteristic;
}
Aggregations