Search in sources :

Example 36 with ModelField

use of org.kie.soup.project.datamodel.oracle.ModelField in project drools-wb by kiegroup.

the class GuidedScoreCardEditor method getModel.

public ScoreCardModel getModel() {
    // ScoreCardModel could be null if the ScoreCard failed to load (e.g. the file was not found in VFS)
    if (model == null) {
        return null;
    }
    // Otherwise populate model from UI...
    model.setBaselineScore(Double.parseDouble(tbBaselineScore.getValue()));
    model.setInitialScore(Double.parseDouble(tbInitialScore.getValue()));
    model.setUseReasonCodes(ddUseReasonCode.getSelectedIndex() == 1);
    if (ddReasonCodeAlgorithm.getSelectedIndex() > 0) {
        model.setReasonCodesAlgorithm(ddReasonCodeAlgorithm.getValue(ddReasonCodeAlgorithm.getSelectedIndex()));
    } else {
        model.setReasonCodesAlgorithm("");
    }
    ListBox enumDropDown = (ListBox) scorecardPropertiesGrid.getWidget(1, 0);
    if (enumDropDown.getSelectedIndex() > 0) {
        final String simpleFactName = enumDropDown.getValue(enumDropDown.getSelectedIndex());
        model.setFactName(simpleFactName);
        oracle.getFieldCompletions(simpleFactName, new Callback<ModelField[]>() {

            @Override
            public void callback(final ModelField[] fields) {
                if (fields != null) {
                    for (final ModelField mf : fields) {
                        if (mf.getType().equals(simpleFactName)) {
                            model.setFactName(mf.getClassName());
                            break;
                        }
                    }
                }
            }
        });
    } else {
        model.setFactName("");
    }
    enumDropDown = (ListBox) scorecardPropertiesGrid.getWidget(1, 1);
    if (enumDropDown.getSelectedIndex() > 0) {
        String fieldName = enumDropDown.getValue(enumDropDown.getSelectedIndex());
        fieldName = fieldName.substring(0, fieldName.indexOf(":")).trim();
        model.setFieldName(fieldName);
    } else {
        model.setFieldName("");
    }
    if (ddReasonCodeField.getSelectedIndex() > 0) {
        String rcField = ddReasonCodeField.getValue(ddReasonCodeField.getSelectedIndex());
        rcField = rcField.substring(0, rcField.indexOf(":")).trim();
        model.setReasonCodeField(rcField);
    } else {
        model.setReasonCodeField("");
    }
    model.getCharacteristics().clear();
    for (final FlexTable flexTable : characteristicsTables) {
        final Characteristic characteristic = getCharacteristicFromTable(flexTable);
        // Characteristic Attributes
        characteristic.getAttributes().clear();
        characteristic.getAttributes().addAll(characteristicsAttrMap.get(flexTable).getList());
        model.getCharacteristics().add(characteristic);
    }
    model.setAgendaGroup(tbAgendaGroup.getValue());
    model.setRuleFlowGroup(tbRuleFlowGroup.getValue());
    return model;
}
Also used : ModelField(org.kie.soup.project.datamodel.oracle.ModelField) Characteristic(org.drools.workbench.models.guided.scorecard.shared.Characteristic) FlexTable(com.google.gwt.user.client.ui.FlexTable) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 37 with ModelField

use of org.kie.soup.project.datamodel.oracle.ModelField in project drools-wb by kiegroup.

the class FactPatternWidget method fieldLabel.

/**
 * get the field widget. This may be a simple label, or it may be bound (and
 * show the var name) or a icon to create a binding. It will only show the
 * binding option of showBinding is true.
 */
private Widget fieldLabel(final SingleFieldConstraint con, final HasConstraints hasConstraints, final boolean showBinding, final int padding) {
    HorizontalPanel ab = new HorizontalPanel();
    ab.setStyleName("modeller-field-Label");
    StringBuilder bindingLabel = new StringBuilder();
    if (con.isBound()) {
        bindingLabel.append("<b>[");
        bindingLabel.append(con.getFieldBinding());
        bindingLabel.append("]</b>&nbsp;");
    }
    String fieldName = con.getFieldName();
    bindingLabel.append(fieldName);
    if (bindable && showBinding && !this.readOnly) {
        ClickHandler click = new ClickHandler() {

            public void onClick(final ClickEvent event) {
                // If field name is "this" use parent FactPattern type otherwise we can use the Constraint's field type
                String fieldName = con.getFieldName();
                if (DataType.TYPE_THIS.equals(fieldName)) {
                    getConnectives().getDataModelOracle().getFieldCompletions(pattern.getFactType(), new Callback<ModelField[]>() {

                        @Override
                        public void callback(final ModelField[] fields) {
                            popupCreator.showBindFieldPopup(pattern, con, fields, popupCreator);
                        }
                    });
                } else {
                    getConnectives().getDataModelOracle().getFieldCompletions(con.getFieldType(), new Callback<ModelField[]>() {

                        @Override
                        public void callback(final ModelField[] fields) {
                            popupCreator.showBindFieldPopup(pattern, con, fields, popupCreator);
                        }
                    });
                }
            }
        };
        ClickableLabel cl = new ClickableLabel(bindingLabel.toString(), click, !this.readOnly);
        DOM.setStyleAttribute(cl.getElement(), "marginLeft", "" + padding + "pt");
        ab.add(cl);
    } else {
        ab.add(new SmallLabel(bindingLabel.toString()));
    }
    return ab;
}
Also used : SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) ClickableLabel(org.uberfire.ext.widgets.common.client.common.ClickableLabel)

Example 38 with ModelField

use of org.kie.soup.project.datamodel.oracle.ModelField in project drools by kiegroup.

the class RuleModelPersistenceHelper method inferDataTypeFromModelFields.

static String inferDataTypeFromModelFields(final String factType, final String field, final PackageDataModelOracle dmo, final Imports imports) {
    if (factType == null) {
        return null;
    }
    if (field == null) {
        return null;
    }
    // Lookup without package prefix or imports
    ModelField[] modelFields = dmo.getModuleModelFields().get(factType);
    // Lookup with package prefix
    if (modelFields == null) {
        String fqcn = dmo.getPackageName() + "." + factType;
        modelFields = dmo.getModuleModelFields().get(fqcn);
    }
    // Lookup from imports
    if (modelFields == null) {
        for (Import item : imports.getImports()) {
            if (item.getType().endsWith(factType)) {
                modelFields = dmo.getModuleModelFields().get(item.getType());
                if (modelFields != null) {
                    break;
                }
            }
        }
    }
    if (modelFields == null) {
        return null;
    }
    for (ModelField modelField : modelFields) {
        if (modelField.getName().equals(field)) {
            return getSimpleFactType(modelField.getType(), dmo);
        }
    }
    return null;
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) ModelField(org.kie.soup.project.datamodel.oracle.ModelField)

Example 39 with ModelField

use of org.kie.soup.project.datamodel.oracle.ModelField in project drools by kiegroup.

the class AbstractGuidedDecisionTreeDRLPersistenceUnmarshallingTest method addModelField.

protected void addModelField(final String factName, final String fieldName, final String clazz, final String type) {
    ModelField[] modelFields = new ModelField[1];
    modelFields[0] = new ModelField(fieldName, clazz, ModelField.FIELD_CLASS_TYPE.TYPE_DECLARATION_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, type);
    if (packageModelFields.containsKey(factName)) {
        final List<ModelField> existingModelFields = new ArrayList<ModelField>(Arrays.asList(packageModelFields.get(factName)));
        existingModelFields.add(modelFields[0]);
        modelFields = existingModelFields.toArray(modelFields);
    }
    packageModelFields.put(factName, modelFields);
}
Also used : ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ArrayList(java.util.ArrayList)

Example 40 with ModelField

use of org.kie.soup.project.datamodel.oracle.ModelField in project drools by kiegroup.

the class BaseRuleModelTest method addModelField.

protected void addModelField(final String factName, final String fieldName, final String clazz, final String type) {
    ModelField[] modelFields = new ModelField[1];
    modelFields[0] = new ModelField(fieldName, clazz, ModelField.FIELD_CLASS_TYPE.TYPE_DECLARATION_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, type);
    if (packageModelFields.containsKey(factName)) {
        final List<ModelField> existingModelFields = new ArrayList<>(Arrays.asList(packageModelFields.get(factName)));
        existingModelFields.add(modelFields[0]);
        modelFields = existingModelFields.toArray(modelFields);
    }
    packageModelFields.put(factName, modelFields);
}
Also used : ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ArrayList(java.util.ArrayList)

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