Search in sources :

Example 26 with ChangeHandler

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

the class ExpressionBuilder method createWidgetForExpression.

// Render Widgets for the Expression. ExpressionMethodParameter and ExpressionText parts
// are represented by a TextBox to allow the User to edit the values, Updates are
// reflected in the model.
private Widget createWidgetForExpression() {
    final HorizontalPanel container = new HorizontalPanel();
    container.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    container.setStylePrimaryName(GuidedRuleEditorResources.INSTANCE.css().container());
    for (ExpressionPart expressionPart : expression.getParts()) {
        if (expressionPart instanceof ExpressionUnboundFact) {
            continue;
        } else if (this.readOnly) {
            container.add(new Label(expressionPart.getName()));
        } else if (expressionPart instanceof ExpressionMethod) {
            container.add(new Label(expressionPart.getName()));
            container.add(new Label("("));
            final ExpressionMethod em = (ExpressionMethod) expressionPart;
            final List<ExpressionFormLine> emParams = em.getOrderedParams();
            for (int index = 0; index < emParams.size(); index++) {
                final ExpressionFormLine paramValueHolder = emParams.get(index);
                final String paramDataType = em.getParameterDataType(paramValueHolder);
                final ExpressionMethodParameter paramValue = ((ExpressionMethodParameter) paramValueHolder.getRootExpression());
                final TextBox paramValueEditor = TextBoxFactory.getTextBox(paramDataType);
                paramValueEditor.addValueChangeHandler(new ValueChangeHandler<String>() {

                    @Override
                    public void onValueChange(ValueChangeEvent<String> event) {
                        paramValue.setText(event.getValue());
                    }
                });
                paramValueEditor.setText(paramValue.getName());
                container.add(paramValueEditor);
                if (index < emParams.size() - 1) {
                    container.add(new Label(", "));
                }
            }
            container.add(new Label(")"));
        } else if (!(expressionPart instanceof ExpressionText)) {
            container.add(new Label(expressionPart.getName()));
        } else {
            final TextBox tb = new TextBox();
            final ExpressionText expressionTextPart = (ExpressionText) expressionPart;
            tb.setText(expressionTextPart.getName());
            tb.addChangeHandler(new ChangeHandler() {

                @Override
                public void onChange(final ChangeEvent changeEvent) {
                    expressionTextPart.setText(tb.getText());
                }
            });
            container.add(tb);
        }
        container.add(new Label("."));
    }
    return container;
}
Also used : ExpressionMethodParameter(org.drools.workbench.models.datamodel.rule.ExpressionMethodParameter) ExpressionPart(org.drools.workbench.models.datamodel.rule.ExpressionPart) Label(com.google.gwt.user.client.ui.Label) ClickableLabel(org.uberfire.ext.widgets.common.client.common.ClickableLabel) SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) ExpressionText(org.drools.workbench.models.datamodel.rule.ExpressionText) TextBox(org.gwtbootstrap3.client.ui.TextBox) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) ExpressionMethod(org.drools.workbench.models.datamodel.rule.ExpressionMethod) ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) 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) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel)

Example 27 with ChangeHandler

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

the class ExpressionBuilder method getWidgetForCurrentType.

private Widget getWidgetForCurrentType() {
    if (isExpressionEmpty()) {
        return createStartPointWidget();
    }
    final ChangeHandler changeHandler = new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            ListBox box = (ListBox) event.getSource();
            panel.remove(box);
            if (box.getSelectedIndex() > 0) {
                onChangeSelection(box.getValue(box.getSelectedIndex()));
            }
        }
    };
    final ListBox listBox = new ListBox();
    listBox.addItem(GuidedRuleEditorResources.CONSTANTS.Choose(), "");
    if (includeDeleteOption()) {
        listBox.addItem("<==" + GuidedRuleEditorResources.CONSTANTS.DeleteItem(), DELETE_VALUE);
    }
    listBox.addItem("-- Text --", TEXT_VALUE);
    getCompletionsForCurrentType(expression.getParts().size() > 1, new Callback<Map<String, String>>() {

        @Override
        public void callback(final Map<String, String> completions) {
            for (Map.Entry<String, String> entry : completions.entrySet()) {
                listBox.addItem(entry.getKey(), entry.getValue());
            }
            listBox.addChangeHandler(changeHandler);
        }
    });
    return listBox;
}
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) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 28 with ChangeHandler

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

the class FromCompositeFactPatternWidget method showFactTypeSelector.

/**
 * Pops up the fact selector.
 */
protected void showFactTypeSelector() {
    AsyncPackageDataModelOracle oracle = this.getModeller().getDataModelOracle();
    final ListBox box = new ListBox();
    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.setFactPattern(new FactPattern(box.getItemText(box.getSelectedIndex())));
            setModified(true);
            getModeller().refreshWidget();
            popup.hide();
        }
    });
    popup.show();
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) 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) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 29 with ChangeHandler

use of com.google.gwt.event.dom.client.ChangeHandler 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;
}
Also used : ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) Grid(com.google.gwt.user.client.ui.Grid) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 30 with ChangeHandler

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

the class FactPatternWidget method predicateEditor.

/**
 * This provides an inline formula editor, not unlike a spreadsheet does.
 */
private Widget predicateEditor(final SingleFieldConstraint c) {
    HorizontalPanel pred = new HorizontalPanel();
    pred.setWidth("100%");
    Image img = new Image(GuidedRuleEditorResources.INSTANCE.images().functionAssets());
    img.setTitle(GuidedRuleEditorResources.CONSTANTS.FormulaBooleanTip());
    pred.add(img);
    if (c.getValue() == null) {
        c.setValue("");
    }
    final TextBox box = new TextBox();
    box.setText(c.getValue());
    if (!this.readOnly) {
        box.addChangeHandler(new ChangeHandler() {

            public void onChange(ChangeEvent event) {
                setModified(true);
                c.setValue(box.getText());
            }
        });
        box.setWidth("100%");
        pred.add(box);
    } else {
        pred.add(new SmallLabel(c.getValue()));
    }
    return pred;
}
Also used : SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) 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) 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) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) TextBox(org.gwtbootstrap3.client.ui.TextBox) Image(com.google.gwt.user.client.ui.Image)

Aggregations

ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)123 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)123 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)48 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)48 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)34 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)31 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)31 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)31 ListBox (org.gwtbootstrap3.client.ui.ListBox)31 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)29 ArrayList (java.util.ArrayList)26 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)21 PerunError (cz.metacentrum.perun.webgui.model.PerunError)17 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)16 HTML (com.google.gwt.user.client.ui.HTML)14 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)14 HashMap (java.util.HashMap)13 ListBox (com.google.gwt.user.client.ui.ListBox)12 FormStylePopup (org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup)12 Map (java.util.Map)11