Search in sources :

Example 16 with FormStylePopup

use of org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup 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();
}
Also used : SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) CustomFormConfiguration(org.guvnor.common.services.workingset.client.factconstraints.customform.CustomFormConfiguration) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) HTML(com.google.gwt.user.client.ui.HTML) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) Button(org.gwtbootstrap3.client.ui.Button) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) HashSet(java.util.HashSet)

Example 17 with FormStylePopup

use of org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup in project drools-wb by kiegroup.

the class PopupCreator method showBindFieldPopup.

/**
 * Display a little editor for field bindings.
 */
public void showBindFieldPopup(final FactPattern fp, final SingleFieldConstraint con, final ModelField[] fields, final PopupCreator popupCreator) {
    final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorResources.CONSTANTS.AddAField());
    // popup.setWidth( 500 + "px" );
    // popup.setHeight( 100 + "px" );
    final HorizontalPanel vn = new HorizontalPanel();
    final TextBox varName = new BindingTextBox();
    if (con.getFieldBinding() != null) {
        varName.setText(con.getFieldBinding());
    }
    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 (modeller.isVariableNameUsed(var)) {
                Window.alert(GuidedRuleEditorResources.CONSTANTS.TheVariableName0IsAlreadyTaken(var));
                return;
            }
            con.setFieldBinding(var);
            modeller.refreshWidget();
            popup.hide();
        }
    });
    popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.BindTheFieldCalled0ToAVariable(con.getFieldName()), vn);
    // Show the sub-field selector is there are applicable sub-fields
    if (hasApplicableFields(fields)) {
        Button sub = new Button(GuidedRuleEditorResources.CONSTANTS.ShowSubFields());
        popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.ApplyAConstraintToASubFieldOf0(con.getFieldName()), sub);
        sub.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                popup.hide();
                popupCreator.showPatternPopup(fp, con, true);
            }
        });
    }
    popup.show();
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) BindingTextBox(org.kie.workbench.common.widgets.client.widget.BindingTextBox) Button(org.gwtbootstrap3.client.ui.Button) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) BindingTextBox(org.kie.workbench.common.widgets.client.widget.BindingTextBox) TextBox(org.gwtbootstrap3.client.ui.TextBox)

Example 18 with FormStylePopup

use of org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup in project drools-wb by kiegroup.

the class FromCollectCompositeFactPatternWidget method showRightPatternSelector.

/**
 * Pops up the fact selector.
 */
protected void showRightPatternSelector(final Widget w) {
    final ListBox box = new ListBox();
    AsyncPackageDataModelOracle oracle = this.getModeller().getDataModelOracle();
    String[] facts = oracle.getFactTypes();
    box.addItem(GuidedRuleEditorResources.CONSTANTS.Choose());
    for (int i = 0; i < facts.length; i++) {
        box.addItem(facts[i]);
    }
    box.setSelectedIndex(0);
    final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorResources.CONSTANTS.NewFactPattern());
    popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.chooseFactType(), box);
    box.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            getFromCollectPattern().setRightPattern(new FactPattern(box.getItemText(box.getSelectedIndex())));
            setModified(true);
            getModeller().refreshWidget();
            popup.hide();
        }
    });
    final Button freeFormDRLBtn = new Button(GuidedRuleEditorResources.CONSTANTS.FreeFormDrl());
    final Button fromBtn = new Button(HumanReadableConstants.INSTANCE.From());
    final Button fromAccumulateBtn = new Button(HumanReadableConstants.INSTANCE.FromAccumulate());
    final Button fromCollectBtn = new Button(HumanReadableConstants.INSTANCE.FromCollect());
    final Button fromEntryPointBtn = new Button(HumanReadableConstants.INSTANCE.FromEntryPoint());
    ClickHandler btnsClickHandler = new ClickHandler() {

        public void onClick(ClickEvent event) {
            Widget sender = (Widget) event.getSource();
            if (sender == fromBtn) {
                getFromCollectPattern().setRightPattern(new FromCompositeFactPattern());
            } else if (sender == fromAccumulateBtn) {
                getFromCollectPattern().setRightPattern(new FromAccumulateCompositeFactPattern());
            } else if (sender == fromCollectBtn) {
                getFromCollectPattern().setRightPattern(new FromCollectCompositeFactPattern());
            } else if (sender == freeFormDRLBtn) {
                getFromCollectPattern().setRightPattern(new FreeFormLine());
            } else if (sender == fromEntryPointBtn) {
                getFromCollectPattern().setRightPattern(new FromEntryPointFactPattern());
            } else {
                throw new IllegalArgumentException("Unknown sender: " + sender);
            }
            setModified(true);
            getModeller().refreshWidget();
            popup.hide();
        }
    };
    freeFormDRLBtn.addClickHandler(btnsClickHandler);
    fromBtn.addClickHandler(btnsClickHandler);
    fromAccumulateBtn.addClickHandler(btnsClickHandler);
    fromCollectBtn.addClickHandler(btnsClickHandler);
    fromEntryPointBtn.addClickHandler(btnsClickHandler);
    popup.addAttribute("", freeFormDRLBtn);
    popup.addAttribute("", fromBtn);
    popup.addAttribute("", fromAccumulateBtn);
    popup.addAttribute("", fromCollectBtn);
    popup.addAttribute("", fromEntryPointBtn);
    popup.show();
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) Widget(com.google.gwt.user.client.ui.Widget) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) Button(org.gwtbootstrap3.client.ui.Button) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 19 with FormStylePopup

use of org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup in project drools-wb by kiegroup.

the class FromCollectCompositeFactPatternWidget method showFactTypeSelector.

@Override
protected void showFactTypeSelector() {
    final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorResources.CONSTANTS.NewFactPattern());
    popup.setTitle(GuidedRuleEditorResources.CONSTANTS.NewFactPattern());
    final ListBox box = GWT.create(ListBox.class);
    box.addItem(GuidedRuleEditorResources.CONSTANTS.Choose());
    for (Map.Entry<String, String> entry : this.getExtraLeftSidePatternFactTypes().entrySet()) {
        box.addItem(entry.getKey(), entry.getValue());
    }
    box.setSelectedIndex(0);
    box.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            pattern.setFactPattern(new FactPattern(box.getValue(box.getSelectedIndex())));
            setModified(true);
            getModeller().refreshWidget();
            popup.hide();
        }
    });
    popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.chooseFactType(), box);
    popup.show();
}
Also used : ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) ListBox(org.gwtbootstrap3.client.ui.ListBox) HashMap(java.util.HashMap) Map(java.util.Map)

Example 20 with FormStylePopup

use of org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup in project drools-wb by kiegroup.

the class CompositeFactPatternWidget method showFactTypeSelector.

/**
 * Pops up the fact selector.
 */
protected void showFactTypeSelector(final Widget w) {
    final ListBox box = new ListBox();
    AsyncPackageDataModelOracle oracle = this.getModeller().getDataModelOracle();
    String[] facts = oracle.getFactTypes();
    box.addItem(GuidedRuleEditorResources.CONSTANTS.Choose());
    for (int i = 0; i < facts.length; i++) {
        box.addItem(facts[i]);
    }
    box.setSelectedIndex(0);
    final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorResources.CONSTANTS.NewFactPattern());
    popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.chooseFactType(), box);
    box.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            pattern.addFactPattern(new FactPattern(box.getItemText(box.getSelectedIndex())));
            setModified(true);
            getModeller().refreshWidget();
            popup.hide();
        }
    });
    final Button fromBtn = new Button(HumanReadableConstants.INSTANCE.From());
    final Button fromAccumulateBtn = new Button(HumanReadableConstants.INSTANCE.FromAccumulate());
    final Button fromCollectBtn = new Button(HumanReadableConstants.INSTANCE.FromCollect());
    ClickHandler btnsClickHandler = new ClickHandler() {

        public void onClick(ClickEvent event) {
            Widget sender = (Widget) event.getSource();
            if (sender == fromBtn) {
                pattern.addFactPattern(new FromCompositeFactPattern());
            } else if (sender == fromAccumulateBtn) {
                pattern.addFactPattern(new FromAccumulateCompositeFactPattern());
            } else if (sender == fromCollectBtn) {
                pattern.addFactPattern(new FromCollectCompositeFactPattern());
            } else {
                throw new IllegalArgumentException("Unknown sender: " + sender);
            }
            setModified(true);
            getModeller().refreshWidget();
            popup.hide();
        }
    };
    fromBtn.addClickHandler(btnsClickHandler);
    fromAccumulateBtn.addClickHandler(btnsClickHandler);
    fromCollectBtn.addClickHandler(btnsClickHandler);
    popup.addAttribute("", fromBtn);
    popup.addAttribute("", fromAccumulateBtn);
    popup.addAttribute("", fromCollectBtn);
    popup.show();
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Widget(com.google.gwt.user.client.ui.Widget) IFactPattern(org.drools.workbench.models.datamodel.rule.IFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) Button(org.gwtbootstrap3.client.ui.Button) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Aggregations

FormStylePopup (org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup)23 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)15 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)14 Button (org.gwtbootstrap3.client.ui.Button)14 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)12 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)12 ListBox (org.gwtbootstrap3.client.ui.ListBox)12 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)8 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)7 SmallLabel (org.uberfire.ext.widgets.common.client.common.SmallLabel)7 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)6 HTML (com.google.gwt.user.client.ui.HTML)5 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)5 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)5 InfoPopup (org.uberfire.ext.widgets.common.client.common.InfoPopup)5 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)4 Widget (com.google.gwt.user.client.ui.Widget)4 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)4 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)4 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)4