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;
}
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> ");
}
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;
}
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;
}
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);
}
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);
}
Aggregations