Search in sources :

Example 6 with ListBox

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

the class DTCellValueWidgetFactory method makeBooleanSelector.

private ListBox makeBooleanSelector(final DTCellValue52 value) {
    final ListBox lb = new ListBox();
    int indexTrue = 0;
    int indexFalse = 1;
    if (allowEmptyValues) {
        indexTrue = 1;
        indexFalse = 2;
        lb.addItem(GuidedDecisionTableConstants.INSTANCE.Choose(), "");
    }
    lb.addItem("true");
    lb.addItem("false");
    Boolean currentItem = value.getBooleanValue();
    if (currentItem == null) {
        lb.setSelectedIndex(0);
    } else {
        lb.setSelectedIndex(currentItem ? indexTrue : indexFalse);
    }
    // Wire up update handler
    lb.setEnabled(!isReadOnly);
    if (!isReadOnly) {
        lb.addChangeHandler(new ChangeHandler() {

            public void onChange(ChangeEvent event) {
                final String txtValue = lb.getValue(lb.getSelectedIndex());
                Boolean boolValue = (txtValue.equals("") ? null : txtValue.equals("true"));
                value.setBooleanValue(boolValue);
            }
        });
    }
    return lb;
}
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) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 7 with ListBox

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

the class DefaultValueWidgetFactory method getDefaultValueWidget.

// BZ-996932: Added value change notifications.
public static Widget getDefaultValueWidget(final AttributeCol52 ac, final boolean isReadOnly, final DefaultValueChangedEventHandler defaultValueChangedEventHandler) {
    Widget editor = null;
    final String attribute = ac.getAttribute();
    if (Objects.equals(attribute, Attribute.DIALECT.getAttributeName())) {
        final ListBox lb = new ListBox();
        lb.addItem(RuleAttributeWidget.DIALECTS.get(0));
        lb.addItem(RuleAttributeWidget.DIALECTS.get(1));
        if (ac.getDefaultValue() == null) {
            ac.setDefaultValue(new DTCellValue52(RuleAttributeWidget.DIALECTS.get(1)));
        }
        final DTCellValue52 defaultValue = ac.getDefaultValue();
        final String stringValue = defaultValue.getStringValue();
        lb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            lb.addChangeHandler(event -> {
                final int selectedIndex = lb.getSelectedIndex();
                if (selectedIndex < 0) {
                    return;
                }
                DTCellValue52 editedDefaultValue = defaultValue.cloneDefaultValueCell();
                editedDefaultValue.setStringValue(lb.getValue(selectedIndex));
                defaultValueChangedEventHandler.onDefaultValueChanged(new DefaultValueChangedEvent(defaultValue, editedDefaultValue));
            });
        }
        if (stringValue == null || stringValue.isEmpty()) {
            lb.setSelectedIndex(1);
            defaultValue.setStringValue(RuleAttributeWidget.DIALECTS.get(1));
        } else if (stringValue.equals(RuleAttributeWidget.DIALECTS.get(0))) {
            lb.setSelectedIndex(0);
        } else if (stringValue.equals(RuleAttributeWidget.DIALECTS.get(1))) {
            lb.setSelectedIndex(1);
        } else {
            lb.setSelectedIndex(1);
            defaultValue.setStringValue(RuleAttributeWidget.DIALECTS.get(1));
        }
        editor = lb;
    } else if (Objects.equals(attribute, Attribute.SALIENCE.getAttributeName())) {
        final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_NUMERIC_INTEGER);
        if (ac.getDefaultValue() == null) {
            ac.setDefaultValue(new DTCellValue52(0));
        } else {
            assertIntegerDefaultValue(ac.getDefaultValue());
        }
        final DTCellValue52 defaultValue = ac.getDefaultValue();
        final Integer numericValue = (Integer) defaultValue.getNumericValue();
        tb.setValue(numericValue == null ? "" : numericValue.toString());
        tb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            tb.addValueChangeHandler(event -> {
                DTCellValue52 editedDefaultValue = defaultValue.cloneDefaultValueCell();
                try {
                    editedDefaultValue.setNumericValue(Integer.valueOf(event.getValue()));
                } catch (NumberFormatException nfe) {
                    editedDefaultValue.setNumericValue(0);
                    tb.setValue("0");
                } finally {
                    defaultValueChangedEventHandler.onDefaultValueChanged(new DefaultValueChangedEvent(defaultValue, editedDefaultValue));
                }
            });
        }
        editor = tb;
    } else if (Objects.equals(attribute, Attribute.DURATION.getAttributeName())) {
        final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_NUMERIC_LONG);
        if (ac.getDefaultValue() == null) {
            ac.setDefaultValue(new DTCellValue52(0L));
        } else {
            assertLongDefaultValue(ac.getDefaultValue());
        }
        final DTCellValue52 defaultValue = ac.getDefaultValue();
        final Long numericValue = (Long) defaultValue.getNumericValue();
        tb.setValue(numericValue == null ? "" : numericValue.toString());
        tb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            tb.addValueChangeHandler(event -> {
                DTCellValue52 editedDefaultValue = defaultValue.cloneDefaultValueCell();
                try {
                    editedDefaultValue.setNumericValue(Long.valueOf(event.getValue()));
                } catch (NumberFormatException nfe) {
                    editedDefaultValue.setNumericValue(0L);
                    tb.setValue("0");
                } finally {
                    defaultValueChangedEventHandler.onDefaultValueChanged(new DefaultValueChangedEvent(defaultValue, editedDefaultValue));
                }
            });
        }
        editor = tb;
    } else if (Objects.equals(Attribute.getAttributeDataType(attribute), DataType.TYPE_STRING)) {
        final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_STRING);
        if (ac.getDefaultValue() == null) {
            ac.setDefaultValue(new DTCellValue52(""));
        }
        final DTCellValue52 defaultValue = ac.getDefaultValue();
        tb.setValue(defaultValue.getStringValue());
        tb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            tb.addValueChangeHandler(event -> {
                DTCellValue52 editedDefaultValue = defaultValue.cloneDefaultValueCell();
                editedDefaultValue.setStringValue(tb.getValue());
                defaultValueChangedEventHandler.onDefaultValueChanged(new DefaultValueChangedEvent(defaultValue, editedDefaultValue));
            });
        }
        editor = tb;
    } else if (Objects.equals(Attribute.getAttributeDataType(attribute), DataType.TYPE_BOOLEAN)) {
        final CheckBox cb = new CheckBox();
        if (ac.getDefaultValue() == null) {
            ac.setDefaultValue(new DTCellValue52(Boolean.FALSE));
        } else {
            assertBooleanDefaultValue(ac.getDefaultValue());
        }
        final DTCellValue52 defaultValue = ac.getDefaultValue();
        final Boolean booleanValue = defaultValue.getBooleanValue();
        cb.setEnabled(!isReadOnly);
        if (booleanValue == null) {
            cb.setValue(false);
            defaultValue.setBooleanValue(Boolean.FALSE);
        } else {
            cb.setValue(booleanValue);
        }
        cb.addClickHandler(event -> {
            DTCellValue52 editedDefaultValue = defaultValue.cloneDefaultValueCell();
            editedDefaultValue.setBooleanValue(cb.getValue());
            defaultValueChangedEventHandler.onDefaultValueChanged(new DefaultValueChangedEvent(defaultValue, editedDefaultValue));
        });
        editor = cb;
    } else if (Objects.equals(Attribute.getAttributeDataType(attribute), DataType.TYPE_DATE)) {
        if (ac.getDefaultValue() == null) {
            ac.setDefaultValue(new DTCellValue52(new Date()));
        } else {
            assertDateDefaultValue(ac.getDefaultValue());
        }
        final DTCellValue52 defaultValue = ac.getDefaultValue();
        if (isReadOnly) {
            final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_STRING);
            tb.setValue(format.format(defaultValue.getDateValue()));
            tb.setEnabled(false);
        } else {
            final DatePicker datePicker = new DatePicker();
            // Wire up update handler
            datePicker.addChangeDateHandler(event -> {
                DTCellValue52 editedDefaultValue = defaultValue.cloneDefaultValueCell();
                editedDefaultValue.setDateValue(datePicker.getValue());
                defaultValueChangedEventHandler.onDefaultValueChanged(new DefaultValueChangedEvent(defaultValue, editedDefaultValue));
            });
            final Date dateValue = defaultValue.getDateValue();
            datePicker.setFormat(DATE_FORMAT);
            datePicker.setValue(dateValue);
            editor = datePicker;
        }
    }
    return editor;
}
Also used : DataType(org.kie.soup.project.datamodel.oracle.DataType) Date(java.util.Date) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) ApplicationPreferences(org.kie.workbench.common.services.shared.preferences.ApplicationPreferences) TextBox(org.gwtbootstrap3.client.ui.TextBox) ListBox(org.gwtbootstrap3.client.ui.ListBox) TextBoxFactory(org.kie.workbench.common.widgets.client.widget.TextBoxFactory) Objects(java.util.Objects) Attribute(org.drools.workbench.models.datamodel.rule.Attribute) Widget(com.google.gwt.user.client.ui.Widget) DateTimeFormat(com.google.gwt.i18n.client.DateTimeFormat) DatePicker(org.uberfire.ext.widgets.common.client.common.DatePicker) RuleAttributeWidget(org.drools.workbench.screens.guided.rule.client.widget.attribute.RuleAttributeWidget) CheckBox(org.gwtbootstrap3.client.ui.CheckBox) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) Widget(com.google.gwt.user.client.ui.Widget) RuleAttributeWidget(org.drools.workbench.screens.guided.rule.client.widget.attribute.RuleAttributeWidget) TextBox(org.gwtbootstrap3.client.ui.TextBox) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) Date(java.util.Date) CheckBox(org.gwtbootstrap3.client.ui.CheckBox) DatePicker(org.uberfire.ext.widgets.common.client.common.DatePicker) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 8 with ListBox

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

the class DTCellValueWidgetFactoryTest method testGetWidgetEnums.

@Test
public void testGetWidgetEnums() throws Exception {
    insertFactCol52.setFactType("Person");
    insertFactCol52.setFactField("name");
    when(oracle.hasEnums("Person", "name")).thenReturn(true);
    Widget widget = factory.getWidget(insertFactCol52, cellValue);
    assertTrue(widget instanceof ListBox);
}
Also used : Widget(com.google.gwt.user.client.ui.Widget) IsWidget(com.google.gwt.user.client.ui.IsWidget) ListBox(org.gwtbootstrap3.client.ui.ListBox) Test(org.junit.Test)

Example 9 with ListBox

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

the class DTCellValueWidgetFactoryTest method testEnumDropdownForBRLColumn.

@Test
public void testEnumDropdownForBRLColumn() throws Exception {
    BRLConditionVariableColumn column = mock(BRLConditionVariableColumn.class);
    doReturn("Person").when(column).getFactType();
    doReturn("name").when(column).getFactField();
    when(oracle.hasEnums("Person", "name")).thenReturn(true);
    IsWidget widget = factory.getWidget(column, cellValue);
    assertTrue(widget instanceof ListBox);
}
Also used : IsWidget(com.google.gwt.user.client.ui.IsWidget) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) ListBox(org.gwtbootstrap3.client.ui.ListBox) Test(org.junit.Test)

Example 10 with ListBox

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

the class CEPWindowOperatorsDropdown method getDropDown.

// Actual drop-down
private Widget getDropDown() {
    String selected = "";
    String selectedText = "";
    box = new ListBox();
    box.setEnabled(!isReadOnly);
    box.addItem(HumanReadableConstants.INSTANCE.noCEPWindow(), "");
    for (int i = 0; i < operators.size(); i++) {
        String op = operators.get(i);
        box.addItem(HumanReadable.getOperatorDisplayName(op), op);
        if (op.equals(hcw.getWindow().getOperator())) {
            selected = op;
            selectedText = HumanReadable.getOperatorDisplayName(op);
            box.setSelectedIndex(i + 1);
        }
    }
    selectItem(hcw.getWindow().getOperator());
    // Fire event to ensure parent Widgets correct their state depending on selection
    final HasValueChangeHandlers<OperatorSelection> source = this;
    final OperatorSelection selection = new OperatorSelection(selected, selectedText);
    Scheduler.get().scheduleFinally(new Command() {

        public void execute() {
            operatorChanged(selection);
            ValueChangeEvent.fire(source, selection);
        }
    });
    // Signal parent Widget whenever a change happens
    box.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            String selected = box.getValue(box.getSelectedIndex());
            String selectedText = box.getItemText(box.getSelectedIndex());
            OperatorSelection selection = new OperatorSelection(selected, selectedText);
            operatorChanged(selection);
            ValueChangeEvent.fire(source, selection);
        }
    });
    return box;
}
Also used : ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) Command(com.google.gwt.user.client.Command) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) 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