use of org.gwtbootstrap3.client.ui.ListBox in project drools-wb by kiegroup.
the class GuidedScoreCardEditor method listBoxEditor.
private ListBox listBoxEditor(final String[] values, final String currentValue, final boolean allowEmptyValue) {
final ListBox listBox = new ListBox();
if (allowEmptyValue) {
listBox.addItem(GuidedScoreCardConstants.INSTANCE.pleaseChoose());
}
for (final String value : values) {
listBox.addItem(value);
}
final int selectedIndex = Arrays.asList(values).indexOf(currentValue);
listBox.setSelectedIndex(selectedIndex >= 0 ? selectedIndex + (allowEmptyValue ? 1 : 0) : 0);
return listBox;
}
use of org.gwtbootstrap3.client.ui.ListBox 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 org.gwtbootstrap3.client.ui.ListBox 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;
}
use of org.gwtbootstrap3.client.ui.ListBox in project drools-wb by kiegroup.
the class GuidedScoreCardEditor method addAttribute.
private void addAttribute(final FlexTable selectedTable, final Attribute attribute) {
// Disable the fact & field dropdowns
((ListBox) selectedTable.getWidget(2, 0)).setEnabled(false);
// ( (ListBox) selectedTable.getWidget( 2, 1 ) ).setEnabled( false );
final ListBox edd = ((ListBox) selectedTable.getWidget(2, 1));
edd.setEnabled(false);
int selectedIndex = edd.getSelectedIndex() > -1 ? edd.getSelectedIndex() : 0;
String field = edd.getValue(selectedIndex);
// field is in the format 'fieldName : datatype';
// the actual name
String fieldName = field.substring(0, field.indexOf(":")).trim();
// the data type
String dataType = field.substring(field.indexOf(":") + 1).trim();
// enum values
final ListBox factDD = (ListBox) selectedTable.getWidget(2, 0);
String factName = factDD.getValue(factDD.getSelectedIndex());
boolean enumColumn = oracle.hasEnums(factName, fieldName);
final List<String> operators = new ArrayList<String>();
if ("String".equalsIgnoreCase(dataType)) {
if (enumColumn) {
operators.addAll(Arrays.asList(enumStringOperators));
} else {
operators.addAll(Arrays.asList(stringOperators));
}
} else if ("boolean".equalsIgnoreCase(dataType)) {
operators.addAll(Arrays.asList(booleanOperators));
} else {
operators.addAll(Arrays.asList(numericOperators));
}
if (characteristicsAttrMap.get(selectedTable) == null) {
final Characteristic characteristic = getCharacteristicFromTable(selectedTable);
// first attribute, construct and add the table
VerticalPanel vPanel = characteristicsAttrPanelMap.get(selectedTable);
vPanel.add(addAttributeCellTable(selectedTable, characteristic, enumColumn, dataType, operators));
characteristicsAttrPanelMap.remove(selectedTable);
}
Attribute newAttribute = null;
if (attribute != null) {
characteristicsAttrMap.get(selectedTable).getList().add(attribute);
} else {
newAttribute = new Attribute();
characteristicsAttrMap.get(selectedTable).getList().add(newAttribute);
newAttribute.setOperator(operators.get(0));
}
characteristicsAttrMap.get(selectedTable).refresh();
if ("boolean".equalsIgnoreCase(dataType)) {
((Button) selectedTable.getWidget(0, 3)).setEnabled(characteristicsAttrMap.get(selectedTable).getList().size() != 2);
if (newAttribute != null) {
newAttribute.setValue(GuidedScoreCardConstants.INSTANCE.notApplicable());
}
}
}
use of org.gwtbootstrap3.client.ui.ListBox 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;
}
Aggregations