Search in sources :

Example 1 with CheckBox

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

the class RuleAttributeWidget method checkBoxEditor.

private Widget checkBoxEditor(final RuleAttribute at, final boolean isReadOnly) {
    final CheckBox box = new CheckBox();
    box.setEnabled(!isReadOnly);
    if (at.getValue() == null || at.getValue().isEmpty()) {
        box.setValue(false);
        at.setValue(FALSE_VALUE);
    } else {
        box.setValue((at.getValue().equals(TRUE_VALUE)));
    }
    box.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            at.setValue((box.getValue()) ? TRUE_VALUE : FALSE_VALUE);
        }
    });
    return box;
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CheckBox(org.gwtbootstrap3.client.ui.CheckBox) ClickEvent(com.google.gwt.event.dom.client.ClickEvent)

Example 2 with CheckBox

use of org.gwtbootstrap3.client.ui.CheckBox in project ovirt-engine by oVirt.

the class ErrataFilterPanel method addValueChangeHandler.

public void addValueChangeHandler(final ValueChangeHandler<ErrataFilterValue> handler) {
    ValueChangeHandler<Boolean> internalHandler = event -> {
        // Do this deferred to give the javascript time to activate/deactivate the buttons.
        Scheduler.get().scheduleDeferred(() -> {
            // one of the checkboxes changed, but get all three checkbox values for the event
            ErrataFilterValue value = new ErrataFilterValue(securityCheckbox.isActive(), bugCheckbox.isActive(), enhancementCheckbox.isActive());
            handler.onValueChange(new ValueChangeEvent<ErrataFilterValue>(value) {
            });
        });
    };
    securityCheckbox.addValueChangeHandler(internalHandler);
    bugCheckbox.addValueChangeHandler(internalHandler);
    enhancementCheckbox.addValueChangeHandler(internalHandler);
}
Also used : ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) AssetProvider(org.ovirt.engine.ui.webadmin.gin.AssetProvider) GWT(com.google.gwt.core.client.GWT) Composite(com.google.gwt.user.client.ui.Composite) ErrataFilterValue(org.ovirt.engine.ui.uicommonweb.models.ErrataFilterValue) UiBinder(com.google.gwt.uibinder.client.UiBinder) ApplicationConstants(org.ovirt.engine.ui.webadmin.ApplicationConstants) Scheduler(com.google.gwt.core.client.Scheduler) CheckBoxButton(org.gwtbootstrap3.client.ui.CheckBoxButton) CssResource(com.google.gwt.resources.client.CssResource) UiField(com.google.gwt.uibinder.client.UiField) ButtonGroup(org.gwtbootstrap3.client.ui.ButtonGroup) ErrataFilterValue(org.ovirt.engine.ui.uicommonweb.models.ErrataFilterValue) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent)

Example 3 with CheckBox

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

the class ColumnsPagePresenter method hideColumnCheckBox.

CheckBox hideColumnCheckBox(final GuidedDecisionTableModellerView.Presenter modeller, final MetadataCol52 metaDataColumn) {
    final String label = GuidedDecisionTableConstants.INSTANCE.HideThisColumn() + GuidedDecisionTableConstants.COLON;
    final CheckBox hideColumnCheckBox = makeCheckBox(label);
    hideColumnCheckBox.setValue(metaDataColumn.isHideColumn());
    hideColumnCheckBox.addClickHandler(hideMetadataClickHandler(modeller, hideColumnCheckBox, metaDataColumn));
    return hideColumnCheckBox;
}
Also used : CheckBox(org.gwtbootstrap3.client.ui.CheckBox)

Example 4 with CheckBox

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

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

the class ColumnsPagePresenterTest method testHideColumnCheckBox.

@Test
public void testHideColumnCheckBox() {
    final CheckBox expectedCheckBox = mock(CheckBox.class);
    final ClickHandler clickHandler = mock(ClickHandler.class);
    final boolean isHideColumn = true;
    doReturn(isHideColumn).when(metadataColumn).isHideColumn();
    doReturn(expectedCheckBox).when(presenter).makeCheckBox(eq("HideThisColumn:"));
    doReturn(clickHandler).when(presenter).hideMetadataClickHandler(modeller, expectedCheckBox, metadataColumn);
    final CheckBox actualCheckBox = presenter.hideColumnCheckBox(modeller, metadataColumn);
    verify(expectedCheckBox).setValue(isHideColumn);
    verify(expectedCheckBox).addClickHandler(clickHandler);
    assertEquals(expectedCheckBox, actualCheckBox);
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CheckBox(org.gwtbootstrap3.client.ui.CheckBox) Test(org.junit.Test)

Aggregations

CheckBox (org.gwtbootstrap3.client.ui.CheckBox)15 Test (org.junit.Test)5 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)4 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)4 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)2 HTML (com.google.gwt.user.client.ui.HTML)2 MetadataCol52 (org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52)2 GuidedDecisionTableView (org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView)2 ColumnLabelWidget (org.drools.workbench.screens.guided.dtable.client.widget.table.columns.control.ColumnLabelWidget)2 DeleteColumnManagementAnchorWidget (org.drools.workbench.screens.guided.dtable.client.widget.table.columns.control.DeleteColumnManagementAnchorWidget)2 InfoPopup (org.uberfire.ext.widgets.common.client.common.InfoPopup)2 GWT (com.google.gwt.core.client.GWT)1 Scheduler (com.google.gwt.core.client.Scheduler)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 DateTimeFormat (com.google.gwt.i18n.client.DateTimeFormat)1 CssResource (com.google.gwt.resources.client.CssResource)1 UiBinder (com.google.gwt.uibinder.client.UiBinder)1 UiField (com.google.gwt.uibinder.client.UiField)1 Composite (com.google.gwt.user.client.ui.Composite)1