Search in sources :

Example 91 with ChangeHandler

use of com.google.gwt.event.dom.client.ChangeHandler 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)

Example 92 with ChangeHandler

use of com.google.gwt.event.dom.client.ChangeHandler in project drools-wb by kiegroup.

the class ExpressionBuilder method createStartPointWidget.

private Widget createStartPointWidget() {
    ListBox startPoint = new ListBox();
    startPoint.addItem(GuidedRuleEditorResources.CONSTANTS.Choose(), "");
    for (String gv : getDataModelOracle().getGlobalVariables()) {
        startPoint.addItem(gv, GLOBAL_VARIABLE_VALUE_PREFIX + "." + gv);
    }
    for (String v : getRuleModel().getAllLHSVariables()) {
        startPoint.addItem(v, VARIABLE_VALUE_PREFIX + "." + v);
    }
    startPoint.setVisibleItemCount(1);
    startPoint.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            ListBox lb = (ListBox) event.getSource();
            int index = lb.getSelectedIndex();
            if (index > 0) {
                onStartPointChange(lb.getValue(index));
            }
        }
    });
    return startPoint;
}
Also used : ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ExpressionTypeChangeEvent(org.drools.workbench.screens.guided.rule.client.editor.ExpressionTypeChangeEvent) ExpressionChangeEvent(org.drools.workbench.screens.guided.rule.client.editor.ExpressionChangeEvent) ExpressionChangeHandler(org.drools.workbench.screens.guided.rule.client.editor.ExpressionChangeHandler) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) ExpressionTypeChangeHandler(org.drools.workbench.screens.guided.rule.client.editor.ExpressionTypeChangeHandler) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 93 with ChangeHandler

use of com.google.gwt.event.dom.client.ChangeHandler in project drools-wb by kiegroup.

the class FromAccumulateCompositeFactPatternWidget method getCompositeLabel.

@Override
protected Widget getCompositeLabel() {
    ClickHandler leftPatternclick = new ClickHandler() {

        public void onClick(ClickEvent event) {
            showFactTypeSelector();
        }
    };
    ClickHandler sourcePatternClick = new ClickHandler() {

        public void onClick(ClickEvent event) {
            showSourcePatternSelector();
        }
    };
    String lbl = "<div class='form-field'>" + HumanReadable.getCEDisplayName("from accumulate") + "</div>";
    FlexTable panel = new FlexTable();
    int r = 0;
    if (pattern.getFactPattern() == null) {
        panel.setWidget(r++, 0, new ClickableLabel("<br> <font color='red'>" + GuidedRuleEditorResources.CONSTANTS.clickToAddPattern() + "</font>", leftPatternclick, !this.readOnly));
    }
    panel.setWidget(r++, 0, new HTML(lbl));
    if (this.getFromAccumulatePattern().getSourcePattern() == null) {
        panel.setWidget(r++, 0, new ClickableLabel("<br> <font color='red'>" + GuidedRuleEditorResources.CONSTANTS.clickToAddPattern() + "</font>", sourcePatternClick, !this.readOnly));
    } else {
        IPattern rPattern = this.getFromAccumulatePattern().getSourcePattern();
        RuleModellerWidget sourcePatternWidget;
        if (rPattern instanceof FactPattern) {
            sourcePatternWidget = new FactPatternWidget(this.getModeller(), getEventBus(), rPattern, true, true, this.readOnly);
        } else if (rPattern instanceof FromAccumulateCompositeFactPattern) {
            sourcePatternWidget = new FromAccumulateCompositeFactPatternWidget(this.getModeller(), this.getEventBus(), (FromAccumulateCompositeFactPattern) rPattern, this.readOnly);
        } else if (rPattern instanceof FromCollectCompositeFactPattern) {
            sourcePatternWidget = new FromCollectCompositeFactPatternWidget(this.getModeller(), this.getEventBus(), (FromCollectCompositeFactPattern) rPattern, this.readOnly);
        } else if (rPattern instanceof FromEntryPointFactPattern) {
            sourcePatternWidget = new FromEntryPointFactPatternWidget(this.getModeller(), this.getEventBus(), (FromEntryPointFactPattern) rPattern, this.readOnly);
        } else if (rPattern instanceof FromCompositeFactPattern) {
            sourcePatternWidget = new FromCompositeFactPatternWidget(this.getModeller(), this.getEventBus(), (FromCompositeFactPattern) rPattern, this.readOnly);
        } else {
            throw new IllegalArgumentException("Unsupported pattern " + rPattern + " for right side of FROM ACCUMULATE");
        }
        sourcePatternWidget.addOnModifiedCommand(new Command() {

            public void execute() {
                setModified(true);
            }
        });
        panel.setWidget(r++, 0, addRemoveButton(sourcePatternWidget, new ClickHandler() {

            public void onClick(ClickEvent event) {
                if (Window.confirm(GuidedRuleEditorResources.CONSTANTS.RemoveThisBlockOfData())) {
                    setModified(true);
                    getFromAccumulatePattern().setSourcePattern(null);
                    getModeller().refreshWidget();
                }
            }
        }));
    }
    final TabPanel tPanel = new TabPanel() {

        {
            addStyleName("uf-tabbar-panel");
        }
    };
    final NavTabs navTabs = new NavTabs() {

        {
            addStyleName("uf-tabbar-panel-nav-tabs");
            addStyleName("nav-tabs-pf");
        }
    };
    final TabContent content = new TabContent();
    tPanel.add(navTabs);
    tPanel.add(content);
    FlexTable codeTable = new FlexTable();
    int codeTableRow = 0;
    int codeTableCol = 0;
    codeTable.setWidget(codeTableRow, codeTableCol++, new HTML("<div class='form-field'>" + GuidedRuleEditorResources.CONSTANTS.Init() + ":</div>"));
    final TextBox initField = new TextBox();
    initField.setTitle(GuidedRuleEditorResources.CONSTANTS.InitCode());
    initField.setText(getFromAccumulatePattern().getInitCode());
    initField.setEnabled(!this.readOnly);
    codeTable.setWidget(codeTableRow++, codeTableCol--, initField);
    codeTable.setWidget(codeTableRow, codeTableCol++, new HTML("<div class='form-field'>" + GuidedRuleEditorResources.CONSTANTS.Action() + ":</div>"));
    final TextBox actionField = new TextBox();
    actionField.setTitle(GuidedRuleEditorResources.CONSTANTS.ActionCode());
    actionField.setText(getFromAccumulatePattern().getActionCode());
    actionField.setEnabled(!this.readOnly);
    codeTable.setWidget(codeTableRow++, codeTableCol--, actionField);
    codeTable.setWidget(codeTableRow, codeTableCol++, new HTML("<div class='form-field'>" + GuidedRuleEditorResources.CONSTANTS.Reverse() + ":</div>"));
    final TextBox reverseField = new TextBox();
    reverseField.setTitle(GuidedRuleEditorResources.CONSTANTS.ReverseCode());
    reverseField.setText(getFromAccumulatePattern().getReverseCode());
    reverseField.setEnabled(!this.readOnly);
    codeTable.setWidget(codeTableRow++, codeTableCol--, reverseField);
    codeTable.setWidget(codeTableRow, codeTableCol++, new HTML("<div class='form-field'>" + GuidedRuleEditorResources.CONSTANTS.Result() + ":</div>"));
    final TextBox resultField = new TextBox();
    resultField.setTitle(GuidedRuleEditorResources.CONSTANTS.ResultCode());
    resultField.setText(getFromAccumulatePattern().getResultCode());
    resultField.setEnabled(!this.readOnly);
    codeTable.setWidget(codeTableRow++, codeTableCol--, resultField);
    // panel.setWidget(r++, 0, codeTable);
    final ScrollPanel codePanel = new ScrollPanel();
    codePanel.add(codeTable);
    final TabPane codeTabPane = new TabPane() {

        {
            add(codePanel);
        }
    };
    final TabListItem codeTabListItem = new TabListItem(GuidedRuleEditorResources.CONSTANTS.CustomCode()) {

        {
            addStyleName("uf-dropdown-tab-list-item");
            setDataTargetWidget(codeTabPane);
            getElement().getStyle().setFontSize(12, Style.Unit.PX);
        }
    };
    navTabs.add(codeTabListItem);
    content.add(codeTabPane);
    FlexTable functionTable = new FlexTable();
    functionTable.setWidget(0, 0, new HTML("<div class='form-field'>" + GuidedRuleEditorResources.CONSTANTS.Function() + ":</div>"));
    final TextBox functionField = new TextBox();
    functionField.setTitle(GuidedRuleEditorResources.CONSTANTS.FunctionCode());
    functionField.setText(getFromAccumulatePattern().getFunction());
    functionField.setEnabled(!this.readOnly);
    functionTable.setWidget(0, 1, functionField);
    // panel.setWidget(r++, 0, functionTable);
    final ScrollPanel functionPanel = new ScrollPanel();
    functionPanel.add(functionTable);
    final TabPane functionTabPane = new TabPane() {

        {
            add(functionPanel);
        }
    };
    final TabListItem functionTabListItem = new TabListItem(GuidedRuleEditorResources.CONSTANTS.Function()) {

        {
            addStyleName("uf-dropdown-tab-list-item");
            setDataTargetWidget(functionTabPane);
            getElement().getStyle().setFontSize(12, Style.Unit.PX);
        }
    };
    navTabs.add(functionTabListItem);
    content.add(functionTabPane);
    ChangeHandler changehandler = new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            Widget sender = (Widget) event.getSource();
            TextBox senderTB = (TextBox) event.getSource();
            String code = senderTB.getText();
            setModified(true);
            if (sender == initField) {
                getFromAccumulatePattern().setFunction(null);
                functionField.setText("");
                getFromAccumulatePattern().setInitCode(code);
            } else if (sender == actionField) {
                getFromAccumulatePattern().setFunction(null);
                functionField.setText("");
                getFromAccumulatePattern().setActionCode(code);
            } else if (sender == reverseField) {
                getFromAccumulatePattern().setFunction(null);
                functionField.setText("");
                getFromAccumulatePattern().setReverseCode(code);
            } else if (sender == resultField) {
                getFromAccumulatePattern().setFunction(null);
                functionField.setText("");
                getFromAccumulatePattern().setResultCode(code);
            } else if (sender == functionField) {
                getFromAccumulatePattern().clearCodeFields();
                initField.setText("");
                actionField.setText("");
                reverseField.setText("");
                resultField.setText("");
                getFromAccumulatePattern().setFunction(code);
            }
        }
    };
    initField.addChangeHandler(changehandler);
    actionField.addChangeHandler(changehandler);
    reverseField.addChangeHandler(changehandler);
    resultField.addChangeHandler(changehandler);
    functionField.addChangeHandler(changehandler);
    boolean useFunction = getFromAccumulatePattern().useFunctionOrCode().equals(FromAccumulateCompositeFactPattern.USE_FUNCTION);
    if (useFunction) {
        functionTabListItem.setActive(true);
        functionTabPane.setActive(true);
    } else {
        codeTabListItem.setActive(true);
        codeTabPane.setActive(true);
    }
    panel.setWidget(r++, 0, tPanel);
    return panel;
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) 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) HTML(com.google.gwt.user.client.ui.HTML) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) TextBox(org.gwtbootstrap3.client.ui.TextBox) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) ClickableLabel(org.uberfire.ext.widgets.common.client.common.ClickableLabel) TabPanel(org.gwtbootstrap3.client.ui.TabPanel) TabPane(org.gwtbootstrap3.client.ui.TabPane) FlexTable(com.google.gwt.user.client.ui.FlexTable) TabContent(org.gwtbootstrap3.client.ui.TabContent) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) NavTabs(org.gwtbootstrap3.client.ui.NavTabs) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) Command(com.google.gwt.user.client.Command) ScrollPanel(com.google.gwt.user.client.ui.ScrollPanel) TabListItem(org.gwtbootstrap3.client.ui.TabListItem)

Example 94 with ChangeHandler

use of com.google.gwt.event.dom.client.ChangeHandler in project drools-wb by kiegroup.

the class CallMethodWidget method showAddFieldPopup.

protected void showAddFieldPopup(final Widget w) {
    final FormStylePopup popup = new FormStylePopup(TestScenarioAltedImages.INSTANCE.Wizard(), TestScenarioConstants.INSTANCE.ChooseAMethodToInvoke());
    ListBox box = new ListBox();
    box.addItem("...");
    for (int i = 0; i < fieldCompletionTexts.length; i++) {
        box.addItem(fieldCompletionTexts[i], fieldCompletionValues[i]);
    }
    box.setSelectedIndex(0);
    popup.addAttribute(TestScenarioConstants.INSTANCE.ChooseAMethodToInvoke(), box);
    box.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            mCall.setState(ActionCallMethod.TYPE_DEFINED);
            ListBox sourceW = (ListBox) event.getSource();
            final String methodName = sourceW.getItemText(sourceW.getSelectedIndex());
            final String methodNameWithParams = sourceW.getValue(sourceW.getSelectedIndex());
            mCall.setMethodName(methodName);
            oracle.getMethodParams(variableClass, methodNameWithParams, new Callback<List<String>>() {

                @Override
                public void callback(final List<String> fieldList) {
                    // String fieldType = oracle.getFieldType( variableClass, fieldName );
                    int i = 0;
                    for (String fieldParameter : fieldList) {
                        mCall.addFieldValue(new CallFieldValue(methodName, String.valueOf(i), fieldParameter));
                        i++;
                    }
                    parent.renderEditor();
                    popup.hide();
                }
            });
        }
    });
    popup.show();
}
Also used : Callback(org.uberfire.client.callbacks.Callback) 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) List(java.util.List) ListBox(org.gwtbootstrap3.client.ui.ListBox) CallFieldValue(org.drools.workbench.models.testscenarios.shared.CallFieldValue)

Example 95 with ChangeHandler

use of com.google.gwt.event.dom.client.ChangeHandler in project drools-wb by kiegroup.

the class MethodParameterCallValueEditor method boundVariable.

private ListBox boundVariable(final FieldNature c) {
    /*
         * If there is a bound variable that is the same type of the current
         * variable type, then propose a list
         */
    final ListBox listVariable = new ListBox();
    List<String> vars = model.getFactNamesInScope(ex, true);
    for (String v : vars) {
        FactData factData = (FactData) model.getFactTypes().get(v);
        if (factData.getType().equals(this.methodParameter.type)) {
            // First selection is empty
            if (listVariable.getItemCount() == 0) {
                listVariable.addItem("...");
            }
            listVariable.addItem("=" + v);
        }
    }
    if (methodParameter.value.equals("=")) {
        listVariable.setSelectedIndex(0);
    } else {
        for (int i = 0; i < listVariable.getItemCount(); i++) {
            if (listVariable.getItemText(i).equals(methodParameter.value)) {
                listVariable.setSelectedIndex(i);
            }
        }
    }
    if (listVariable.getItemCount() > 0) {
        listVariable.addChangeHandler(new ChangeHandler() {

            public void onChange(ChangeEvent event) {
                methodParameter.value = listVariable.getValue(listVariable.getSelectedIndex());
                refresh();
            }
        });
    }
    return listVariable;
}
Also used : ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Aggregations

ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)98 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)98 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)41 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)41 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)31 ListBox (org.gwtbootstrap3.client.ui.ListBox)31 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)28 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)27 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)27 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)27 ArrayList (java.util.ArrayList)21 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)20 PerunError (cz.metacentrum.perun.webgui.model.PerunError)16 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)15 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)13 FormStylePopup (org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup)12 HashMap (java.util.HashMap)11 Map (java.util.Map)9 Button (org.gwtbootstrap3.client.ui.Button)9 HTML (com.google.gwt.user.client.ui.HTML)7