Search in sources :

Example 11 with ListBox

use of org.gwtbootstrap3.client.ui.ListBox in project drools-wb by kiegroup.

the class ValueEditorFactory method getValueEditor.

public Widget getValueEditor(final String className, final String fieldName, final HasValue hasValue, final AsyncPackageDataModelOracle oracle, final boolean isMultipleSelect) {
    String dataType = oracle.getFieldType(className, fieldName);
    // Operators "contained in" and "not contained in" fallback to Strings
    if (isMultipleSelect) {
        dataType = DataType.TYPE_STRING;
    }
    // Fields with enumerations fallback to Strings
    DropDownData dd = null;
    if (oracle.hasEnums(className, fieldName)) {
        final Map<String, String> currentValueMap = getCurrentValueMap();
        dd = oracle.getEnums(className, fieldName, currentValueMap);
    }
    // Ensure Node has a value if needed
    if (hasValue.getValue() == null) {
        final Value value = ValueUtilities.makeEmptyValue(dataType);
        if (value == null) {
            ErrorPopup.showMessage(GuidedDecisionTreeConstants.INSTANCE.dataTypeNotSupported0(dataType));
            return null;
        } else {
            hasValue.setValue(value);
        }
    }
    // Setup the correct widget corresponding to the data type
    if (dataType.equals(DataType.TYPE_DATE)) {
        final DatePicker valueEditor = new DatePicker(false);
        // Wire-up update handler
        valueEditor.addValueChangeHandler(new ValueChangeHandler<Date>() {

            @Override
            public void onValueChange(final ValueChangeEvent<Date> event) {
                hasValue.getValue().setValue(valueEditor.getValue());
            }
        });
        // Set Widget's value
        valueEditor.setFormat(DATE_FORMAT);
        valueEditor.setValue((Date) hasValue.getValue().getValue());
        return valueEditor;
    } else if (dataType.equals(DataType.TYPE_BOOLEAN)) {
        final ListBox valueEditor = new ListBox();
        valueEditor.addItem("true");
        valueEditor.addItem("false");
        // Wire-up update handler
        valueEditor.addClickHandler(new ClickHandler() {

            public void onClick(final ClickEvent event) {
                final String txtValue = valueEditor.getValue(valueEditor.getSelectedIndex());
                final Boolean value = Boolean.valueOf(txtValue);
                hasValue.getValue().setValue(value);
            }
        });
        // Set Widget's value
        valueEditor.setSelectedIndex(hasValue.getValue().getValue().equals(Boolean.TRUE) ? 0 : 1);
        return valueEditor;
    } else {
        // If we have enumeration data show a ListBox
        if (dd != null) {
            final ListBox valueEditor = makeListBox(dd, hasValue, oracle, isMultipleSelect);
            return valueEditor;
        }
        // Otherwise show a TextBox
        final TextBox valueEditor = TextBoxFactory.getTextBox(dataType);
        // Wire-up Handlers before setting value, as invalid values cause the ValueChangeHandler to be invoked
        valueEditor.addValueChangeHandler(new ValueChangeHandler<String>() {

            @Override
            public void onValueChange(final ValueChangeEvent<String> event) {
                hasValue.getValue().setValue(event.getValue());
            }
        });
        // Set Widget's value
        valueEditor.setText(ValueUtilities.convertNodeValue(hasValue.getValue()));
        return valueEditor;
    }
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) TextBox(org.gwtbootstrap3.client.ui.TextBox) Date(java.util.Date) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) HasValue(org.drools.workbench.models.guided.dtree.shared.model.nodes.HasValue) Value(org.drools.workbench.models.guided.dtree.shared.model.values.Value) DatePicker(org.uberfire.ext.widgets.common.client.common.DatePicker) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 12 with ListBox

use of org.gwtbootstrap3.client.ui.ListBox in project drools-wb by kiegroup.

the class RuleModellerConditionSelectorPopup method makeChoicesListBox.

private ListBox makeChoicesListBox(final String filter) {
    choices = GWT.create(ListBox.class);
    choices.setMultipleSelect(true);
    choices.setPixelSize(getChoicesWidth(), getChoicesHeight());
    choices.addKeyUpHandler(new KeyUpHandler() {

        public void onKeyUp(com.google.gwt.event.dom.client.KeyUpEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                selectSomething();
            }
        }
    });
    final Predicate<String> predicate = (item) -> item.toLowerCase().contains(Objects.isNull(filter) ? "" : filter.toLowerCase());
    boolean itemsAdded = addDSLSentences(predicate);
    if (!onlyShowDSLStatements) {
        itemsAdded = addFacts(predicate, itemsAdded) || itemsAdded;
        addExistentialConditionalElements(itemsAdded);
        addFromConditionalElements();
        addFreeFormDrl();
    }
    return choices;
}
Also used : ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) GuidedRuleEditorResources(org.drools.workbench.screens.guided.rule.client.resources.GuidedRuleEditorResources) HumanReadable(org.kie.workbench.common.widgets.client.resources.HumanReadable) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) ListBox(org.gwtbootstrap3.client.ui.ListBox) GWT(com.google.gwt.core.client.GWT) HTML(com.google.gwt.user.client.ui.HTML) Command(com.google.gwt.user.client.Command) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) ModalFooterOKCancelButtons(org.uberfire.ext.widgets.common.client.common.popups.footers.ModalFooterOKCancelButtons) ModalBody(org.gwtbootstrap3.client.ui.ModalBody) CheckBox(org.gwtbootstrap3.client.ui.CheckBox) InfoPopup(org.uberfire.ext.widgets.common.client.common.InfoPopup) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) Predicate(java.util.function.Predicate) KeyUpHandler(com.google.gwt.event.dom.client.KeyUpHandler) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) Objects(java.util.Objects) Widget(com.google.gwt.user.client.ui.Widget) KeyCodes(com.google.gwt.event.dom.client.KeyCodes) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) KeyUpHandler(com.google.gwt.event.dom.client.KeyUpHandler) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 13 with ListBox

use of org.gwtbootstrap3.client.ui.ListBox 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 14 with ListBox

use of org.gwtbootstrap3.client.ui.ListBox 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();
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) 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) ActionFieldFunction(org.drools.workbench.models.datamodel.rule.ActionFieldFunction) List(java.util.List) ListBox(org.gwtbootstrap3.client.ui.ListBox) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)

Example 15 with ListBox

use of org.gwtbootstrap3.client.ui.ListBox 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();
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) TextBox(org.gwtbootstrap3.client.ui.TextBox) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) Button(org.gwtbootstrap3.client.ui.Button) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Aggregations

ListBox (org.gwtbootstrap3.client.ui.ListBox)61 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)31 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)30 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)15 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)15 FormStylePopup (org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup)12 Widget (com.google.gwt.user.client.ui.Widget)11 Test (org.junit.Test)11 Button (org.gwtbootstrap3.client.ui.Button)10 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)10 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)9 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)9 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)7 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)7 TextBox (org.gwtbootstrap3.client.ui.TextBox)7 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)6 IsWidget (com.google.gwt.user.client.ui.IsWidget)6 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)6 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)6 DropDownData (org.kie.soup.project.datamodel.oracle.DropDownData)6