Search in sources :

Example 31 with ModelField

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();
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) TextBox(org.gwtbootstrap3.client.ui.TextBox) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) Button(org.gwtbootstrap3.client.ui.Button) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 32 with ModelField

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();
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 33 with ModelField

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);
        }
    });
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) ConstraintValueEditorHelper(org.drools.workbench.screens.guided.rule.client.editor.util.ConstraintValueEditorHelper) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) AsyncPackageDataModelOracleImpl(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracleImpl) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) List(java.util.List) Test(org.junit.Test)

Example 34 with ModelField

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;
}
Also used : ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) ModuleDataModelOracleImpl(org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl)

Example 35 with ModelField

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;
}
Also used : ModelField(org.kie.soup.project.datamodel.oracle.ModelField) Characteristic(org.drools.workbench.models.guided.scorecard.shared.Characteristic) TextBox(org.gwtbootstrap3.client.ui.TextBox) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Aggregations

ModelField (org.kie.soup.project.datamodel.oracle.ModelField)70 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)36 Test (org.junit.Test)34 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)34 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)25 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)24 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)24 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)24 Path (org.uberfire.backend.vfs.Path)24 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)23 ArrayList (java.util.ArrayList)20 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)19 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)14 List (java.util.List)13 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)11 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)11 ModuleDataModelOracleImpl (org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl)10 LimitedEntryActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52)9 LimitedEntryActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52)9 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)9