use of org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup in project drools-wb by kiegroup.
the class PopupCreator method showPatternPopupForComposite.
/**
* This shows a popup for adding fields to a composite
*/
public void showPatternPopupForComposite(final HasConstraints hasConstraints) {
final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorImages508.INSTANCE.Wizard(), GuidedRuleEditorResources.CONSTANTS.AddFieldsToThisConstraint());
final ListBox box = new ListBox();
box.addItem("...");
this.oracle.getFieldCompletions(this.pattern.getFactType(), new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] fields) {
for (int i = 0; i < fields.length; i++) {
final String fieldName = fields[i].getName();
box.addItem(fieldName);
}
}
});
box.setSelectedIndex(0);
box.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
String factType = pattern.getFactType();
String fieldName = box.getItemText(box.getSelectedIndex());
String fieldType = getDataModelOracle().getFieldType(factType, fieldName);
hasConstraints.addConstraint(new SingleFieldConstraint(factType, fieldName, fieldType, null));
modeller.refreshWidget();
popup.hide();
}
});
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.AddARestrictionOnAField(), box);
final ListBox composites = new ListBox();
// NON-NLS
composites.addItem("...");
composites.addItem(GuidedRuleEditorResources.CONSTANTS.AllOfAnd(), CompositeFieldConstraint.COMPOSITE_TYPE_AND);
composites.addItem(GuidedRuleEditorResources.CONSTANTS.AnyOfOr(), CompositeFieldConstraint.COMPOSITE_TYPE_OR);
composites.setSelectedIndex(0);
composites.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
CompositeFieldConstraint comp = new CompositeFieldConstraint();
comp.setCompositeJunctionType(composites.getValue(composites.getSelectedIndex()));
hasConstraints.addConstraint(comp);
modeller.refreshWidget();
popup.hide();
}
});
InfoPopup infoComp = new InfoPopup(GuidedRuleEditorResources.CONSTANTS.MultipleFieldConstraints(), GuidedRuleEditorResources.CONSTANTS.MultipleConstraintsTip());
HorizontalPanel horiz = new HorizontalPanel();
horiz.add(composites);
horiz.add(infoComp);
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.MultipleFieldConstraint(), horiz);
// Include Expression Editor
popup.addRow(new SmallLabel("<i>" + GuidedRuleEditorResources.CONSTANTS.AdvancedOptionsColon() + "</i>"));
Button predicate = new Button(GuidedRuleEditorResources.CONSTANTS.NewFormula());
predicate.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
SingleFieldConstraint con = new SingleFieldConstraint();
con.setConstraintValueType(SingleFieldConstraint.TYPE_PREDICATE);
hasConstraints.addConstraint(con);
modeller.refreshWidget();
popup.hide();
}
});
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.AddANewFormulaStyleExpression(), predicate);
final Button expressionEditorButton = makeExpressionEditorButton(hasConstraints, popup);
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.ExpressionEditor(), expressionEditorButton);
popup.show();
}
use of org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup 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();
}
use of org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup 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();
}
use of org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup in project drools-wb by kiegroup.
the class ActionCallMethodWidget method showAddFieldPopup.
protected void showAddFieldPopup(Widget w) {
final AsyncPackageDataModelOracle oracle = this.getModeller().getDataModelOracle();
final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorImages508.INSTANCE.Wizard(), GuidedRuleEditorResources.CONSTANTS.ChooseAMethodToInvoke());
final ListBox box = new ListBox();
box.addItem("...");
for (int i = 0; i < fieldCompletionTexts.length; i++) {
box.addItem(fieldCompletionValues[i], fieldCompletionTexts[i]);
}
box.setSelectedIndex(0);
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.ChooseAMethodToInvoke(), box);
box.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
final String methodNameWithParams = box.getItemText(box.getSelectedIndex());
oracle.getMethodParams(variableClass, methodNameWithParams, new Callback<List<String>>() {
@Override
public void callback(final List<String> methodParameters) {
final String methodName = box.getValue(box.getSelectedIndex());
model.setMethodName(methodName);
model.setState(ActionCallMethod.TYPE_DEFINED);
for (String methodParameter : methodParameters) {
model.addFieldValue(new ActionFieldFunction(methodName, null, methodParameter));
}
getModeller().refreshWidget();
popup.hide();
}
});
}
});
popup.show();
}
use of org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup in project drools-wb by kiegroup.
the class ExpressionBuilder method showBindingPopUp.
private void showBindingPopUp() {
final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorResources.CONSTANTS.ExpressionEditor());
final TextBox varName = new TextBox();
if (expression.isBound()) {
varName.setText(expression.getBinding());
}
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.BindTheExpressionToAVariable(), new InputGroup() {
{
add(varName);
add(new InputGroupButton() {
{
add(new Button(HumanReadableConstants.INSTANCE.Set()) {
{
addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
String var = varName.getText();
if (getModeller().isVariableNameUsed(var)) {
Window.alert(GuidedRuleEditorResources.CONSTANTS.TheVariableName0IsAlreadyTaken(var));
return;
}
expression.setBinding(var);
getModeller().refreshWidget();
popup.hide();
}
});
}
});
}
});
}
});
popup.show();
}
Aggregations