use of org.guvnor.common.services.workingset.client.factconstraints.customform.CustomFormConfiguration in project drools-wb by kiegroup.
the class ConstraintValueEditor method literalEditor.
private Widget literalEditor() {
// Custom screen
if (this.constraint instanceof SingleFieldConstraint) {
final SingleFieldConstraint con = (SingleFieldConstraint) this.constraint;
CustomFormConfiguration customFormConfiguration = getWorkingSetManager().getCustomFormConfiguration(modeller.getPath(), factType, fieldName);
if (customFormConfiguration != null) {
Button btnCustom = new Button(con.getValue(), new ClickHandler() {
public void onClick(ClickEvent event) {
showTypeChoice(constraint);
}
});
btnCustom.setEnabled(!this.readOnly);
return btnCustom;
}
}
// Label if read-only
if (this.readOnly) {
return new SmallLabel(getSanitizedValue());
}
// Enumeration (these support multi-select for "in" and "not in", so check before comma separated lists)
if (this.dropDownData != null) {
final String operator = constraint.getOperator();
final boolean multipleSelect = OperatorsOracle.operatorRequiresList(operator);
EnumDropDown enumDropDown = new EnumDropDown(constraint.getValue(), new DropDownValueChanged() {
public void valueChanged(String newText, String newValue) {
// Prevent recursion once value change has been applied
if (!newValue.equals(constraint.getValue())) {
constraint.setValue(newValue);
executeOnValueChangeCommand();
}
}
}, dropDownData, multipleSelect, modeller.getPath());
return enumDropDown;
}
// Comma separated value list (this will become a dedicated Widget but for now a TextBox suffices)
String operator = null;
if (this.constraint instanceof SingleFieldConstraint) {
SingleFieldConstraint sfc = (SingleFieldConstraint) this.constraint;
operator = sfc.getOperator();
}
if (OperatorsOracle.operatorRequiresList(operator)) {
return getNewTextBox(DataType.TYPE_STRING);
}
// Date picker
boolean isCEPOperator = CEPOracle.isCEPOperator((this.constraint).getOperator());
if (DataType.TYPE_DATE.equals(this.fieldType) || (DataType.TYPE_THIS.equals(this.fieldName) && isCEPOperator)) {
if (this.readOnly) {
return new SmallLabel(constraint.getValue());
}
final DatePicker datePicker = new DatePicker(false);
// Wire up update handler
datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {
@Override
public void onValueChange(final ValueChangeEvent<Date> event) {
final Date date = datePicker.getValue();
final String sDate = (date == null ? null : DATE_FORMATTER.format(datePicker.getValue()));
boolean update = constraint.getValue() == null || !constraint.getValue().equals(sDate);
constraint.setValue(sDate);
if (update) {
executeOnValueChangeCommand();
}
}
});
datePicker.setFormat(DATE_FORMAT);
datePicker.setValue(getSanitizedDateValue());
return datePicker;
}
// Default editor for all other literals
return getNewTextBox(fieldType);
}
use of org.guvnor.common.services.workingset.client.factconstraints.customform.CustomFormConfiguration in project drools-wb by kiegroup.
the class ConstraintValueEditor method showTypeChoice.
/**
* Show a list of possibilities for the value type.
*/
private void showTypeChoice(final BaseSingleFieldConstraint con) {
CustomFormConfiguration customFormConfiguration = getWorkingSetManager().getCustomFormConfiguration(modeller.getPath(), factType, fieldName);
if (customFormConfiguration != null) {
if (!(con instanceof SingleFieldConstraint)) {
Window.alert("Unexpected constraint type!");
return;
}
final CustomFormPopUp customFormPopUp = new CustomFormPopUp(GuidedRuleEditorImages508.INSTANCE.Wizard(), GuidedRuleEditorResources.CONSTANTS.FieldValue(), customFormConfiguration);
final SingleFieldConstraint sfc = (SingleFieldConstraint) con;
customFormPopUp.addOkButtonHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
sfc.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
sfc.setId(customFormPopUp.getFormId());
sfc.setValue(customFormPopUp.getFormValue());
doTypeChosen(customFormPopUp);
}
});
customFormPopUp.show(sfc.getId(), sfc.getValue());
return;
}
final FormStylePopup form = new FormStylePopup(GuidedRuleEditorImages508.INSTANCE.Wizard(), GuidedRuleEditorResources.CONSTANTS.FieldValue());
Button lit = new Button(GuidedRuleEditorResources.CONSTANTS.LiteralValue());
int litValueType = isDropDownDataEnum && dropDownData != null ? SingleFieldConstraint.TYPE_ENUM : SingleFieldConstraint.TYPE_LITERAL;
lit.addClickHandler(getValueTypeFormOnClickHandler(con, form, litValueType));
boolean showLiteralSelector = true;
boolean showFormulaSelector = !OperatorsOracle.operatorRequiresList(con.getOperator());
boolean showVariableSelector = !OperatorsOracle.operatorRequiresList(con.getOperator());
boolean showExpressionSelector = !OperatorsOracle.operatorRequiresList(con.getOperator());
if (con instanceof SingleFieldConstraint) {
SingleFieldConstraint sfc = (SingleFieldConstraint) con;
String fieldName = sfc.getFieldName();
if (fieldName.equals(DataType.TYPE_THIS)) {
showLiteralSelector = CEPOracle.isCEPOperator(sfc.getOperator());
showFormulaSelector = showFormulaSelector && showLiteralSelector;
}
} else if (con instanceof ConnectiveConstraint) {
ConnectiveConstraint cc = (ConnectiveConstraint) con;
String fieldName = cc.getFieldName();
if (fieldName.equals(DataType.TYPE_THIS)) {
showLiteralSelector = CEPOracle.isCEPOperator(cc.getOperator());
showFormulaSelector = showFormulaSelector && showLiteralSelector;
}
}
// Literal value selector
if (showLiteralSelector) {
form.addAttributeWithHelp(GuidedRuleEditorResources.CONSTANTS.LiteralValue(), GuidedRuleEditorResources.CONSTANTS.LiteralValue(), GuidedRuleEditorResources.CONSTANTS.LiteralValTip(), lit);
}
// Template key selector
if (modeller.isTemplate()) {
String templateKeyLabel = GuidedRuleEditorResources.CONSTANTS.TemplateKey();
Button templateKeyButton = new Button(templateKeyLabel);
templateKeyButton.addClickHandler(getValueTypeFormOnClickHandler(con, form, SingleFieldConstraint.TYPE_TEMPLATE));
form.addAttributeWithHelp(templateKeyLabel, templateKeyLabel, GuidedRuleEditorResources.CONSTANTS.TemplateKeyTip(), templateKeyButton);
}
// Divider, if we have any advanced options
if (showVariableSelector || showFormulaSelector || showExpressionSelector) {
form.addRow(new HTML("<hr/>"));
form.addRow(new SmallLabel(GuidedRuleEditorResources.CONSTANTS.AdvancedOptions()));
}
// Show variables selector, if there are any variables in scope
if (showVariableSelector) {
List<String> bindingsInScope = this.model.getBoundVariablesInScope(this.constraint);
if (bindingsInScope.size() > 0 || DataType.TYPE_COLLECTION.equals(this.fieldType)) {
final Button bindingButton = new Button(GuidedRuleEditorResources.CONSTANTS.BoundVariable());
// This Set is used as a 1flag to know whether the button has been added; due to use of callbacks
final Set<Button> bindingButtonContainer = new HashSet<Button>();
for (String var : bindingsInScope) {
helper.isApplicableBindingsInScope(var, new Callback<Boolean>() {
@Override
public void callback(final Boolean result) {
if (Boolean.TRUE.equals(result)) {
if (!bindingButtonContainer.contains(bindingButton)) {
bindingButtonContainer.add(bindingButton);
bindingButton.addClickHandler(getValueTypeFormOnClickHandler(con, form, SingleFieldConstraint.TYPE_VARIABLE));
form.addAttributeWithHelp(GuidedRuleEditorResources.CONSTANTS.AVariable(), GuidedRuleEditorResources.CONSTANTS.ABoundVariable(), GuidedRuleEditorResources.CONSTANTS.BoundVariableTip(), bindingButton);
}
}
}
});
}
}
}
// Formula selector
if (showFormulaSelector) {
Button formula = new Button(GuidedRuleEditorResources.CONSTANTS.NewFormula());
formula.addClickHandler(getValueTypeFormOnClickHandler(con, form, SingleFieldConstraint.TYPE_RET_VALUE));
form.addAttributeWithHelp(GuidedRuleEditorResources.CONSTANTS.AFormula(), GuidedRuleEditorResources.CONSTANTS.AFormula(), GuidedRuleEditorResources.CONSTANTS.FormulaExpressionTip(), formula);
}
// Expression selector
if (showExpressionSelector) {
Button expression = new Button(GuidedRuleEditorResources.CONSTANTS.ExpressionEditor());
expression.addClickHandler(getValueTypeFormOnClickHandler(con, form, SingleFieldConstraint.TYPE_EXPR_BUILDER_VALUE));
form.addAttributeWithHelp(GuidedRuleEditorResources.CONSTANTS.ExpressionEditor(), GuidedRuleEditorResources.CONSTANTS.ExpressionEditor(), GuidedRuleEditorResources.CONSTANTS.ExpressionEditorTip(), expression);
}
form.show();
}
use of org.guvnor.common.services.workingset.client.factconstraints.customform.CustomFormConfiguration in project drools-wb by kiegroup.
the class DSLSentenceWidget method getCustomFormEditor.
/**
* If there is an active working-set defining a custom form configuration
* for the factType and field defined by variableDef, then a button a custom
* form editor (aka Widget wrapping a button) is returned. Otherwise, the
* result of
* {@link #getBox(DSLVariableValue, String) }
* is returned.
* @param variableDef
* @param value
* @return
*/
private Widget getCustomFormEditor(String variableDef, DSLVariableValue value) {
// Parse Fact Type and Field for retrieving Custom Form configuration
// from WorkingSetManager
// Format for the custom form definition within a DSLSentence is <varName>:<type>:<Fact.field>
int lastIndex = variableDef.lastIndexOf(":");
String factAndField = variableDef.substring(lastIndex + 1, variableDef.length());
int dotIndex = factAndField.indexOf(".");
String factType = factAndField.substring(0, dotIndex);
String field = factAndField.substring(dotIndex + 1, factAndField.length());
// is there any custom form configurated for this factType.field?
final CustomFormConfiguration customFormConfiguration = getWorkingSetManager().getCustomFormConfiguration(this.getModeller().getPath(), factType, field);
boolean editorReadOnly = this.readOnly;
if (!editorReadOnly) {
// if no one is forcing us to be in readonly mode, let's see
// if there is a constraint for the fact type of the custom form
editorReadOnly = !this.getModeller().getDataModelOracle().isFactTypeRecognized(factType);
}
if (customFormConfiguration != null) {
return new DSLCustomFormButton(variableDef, value, customFormConfiguration, editorReadOnly);
}
return getBox(value, "", editorReadOnly);
}
Aggregations