Search in sources :

Example 6 with DatePicker

use of org.uberfire.ext.widgets.common.client.common.DatePicker in project drools-wb by kiegroup.

the class RuleAttributeWidget method getEditorWidget.

private Widget getEditorWidget(final RuleAttribute at, final int idx, final boolean isReadOnly) {
    Widget editor = null;
    final String attributeName = at.getAttributeName();
    if (attributeName.equals(RULEFLOW_GROUP_ATTR) || attributeName.equals(AGENDA_GROUP_ATTR) || attributeName.equals(ACTIVATION_GROUP_ATTR) || attributeName.equals(TIMER_ATTR) || attributeName.equals(CALENDARS_ATTR)) {
        final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_STRING);
        tb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            tb.addValueChangeHandler(new ValueChangeHandler<String>() {

                public void onValueChange(ValueChangeEvent<String> event) {
                    at.setValue(tb.getValue());
                }
            });
        }
        tb.setValue(at.getValue());
        editor = tb;
    } else if (attributeName.equals(SALIENCE_ATTR)) {
        final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_NUMERIC_INTEGER);
        tb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            tb.addValueChangeHandler(new ValueChangeHandler<String>() {

                public void onValueChange(ValueChangeEvent<String> event) {
                    at.setValue(tb.getValue());
                }
            });
        }
        tb.setValue(at.getValue());
        editor = tb;
    } else if (attributeName.equals(DURATION_ATTR)) {
        final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_NUMERIC_LONG);
        tb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            tb.addValueChangeHandler(new ValueChangeHandler<String>() {

                public void onValueChange(ValueChangeEvent<String> event) {
                    at.setValue(tb.getValue());
                }
            });
        }
        tb.setValue(at.getValue());
        editor = tb;
    } else if (attributeName.equals(NO_LOOP_ATTR) || attributeName.equals(LOCK_ON_ACTIVE_ATTR) || attributeName.equals(AUTO_FOCUS_ATTR) || attributeName.equals(ENABLED_ATTR)) {
        editor = checkBoxEditor(at, isReadOnly);
    } else if (attributeName.equals(DATE_EFFECTIVE_ATTR) || attributeName.equals(DATE_EXPIRES_ATTR)) {
        if (isReadOnly) {
            final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_STRING);
            tb.setValue(at.getValue());
            tb.setEnabled(false);
        } else {
            final DatePicker datePicker = new DatePicker(false);
            // Wire up update handler
            datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {

                @Override
                public void onValueChange(final ValueChangeEvent<Date> event) {
                    final Date date = datePicker.getValue();
                    final String sDate = (date == null ? null : DATE_FORMATTER.format(datePicker.getValue()));
                    at.setValue(sDate);
                }
            });
            datePicker.setFormat(DATE_FORMAT);
            datePicker.setValue(assertDateValue(at));
            editor = datePicker;
        }
    } else if (attributeName.equals(DIALECT_ATTR)) {
        final ListBox lb = new ListBox();
        lb.addItem(DIALECTS[0]);
        lb.addItem(DIALECTS[1]);
        lb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            lb.addChangeHandler(new ChangeHandler() {

                @Override
                public void onChange(ChangeEvent event) {
                    final int selectedIndex = lb.getSelectedIndex();
                    if (selectedIndex < 0) {
                        return;
                    }
                    at.setValue(lb.getValue(selectedIndex));
                }
            });
        }
        if (at.getValue() == null || at.getValue().isEmpty()) {
            lb.setSelectedIndex(1);
            at.setValue(DIALECTS[1]);
        } else if (at.getValue().equals(DIALECTS[0])) {
            lb.setSelectedIndex(0);
        } else if (at.getValue().equals(DIALECTS[1])) {
            lb.setSelectedIndex(1);
        } else {
            lb.setSelectedIndex(1);
            at.setValue(DIALECTS[1]);
        }
        editor = lb;
    }
    DirtyableHorizontalPane horiz = new DirtyableHorizontalPane();
    if (editor != null) {
        horiz.add(editor);
        if (!isReadOnly) {
            horiz.add(getRemoveIcon(idx));
        }
    }
    return horiz;
}
Also used : IsWidget(com.google.gwt.user.client.ui.IsWidget) Widget(com.google.gwt.user.client.ui.Widget) 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) 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) DirtyableHorizontalPane(org.uberfire.ext.widgets.common.client.common.DirtyableHorizontalPane) DatePicker(org.uberfire.ext.widgets.common.client.common.DatePicker) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Aggregations

DatePicker (org.uberfire.ext.widgets.common.client.common.DatePicker)6 Date (java.util.Date)5 TextBox (org.gwtbootstrap3.client.ui.TextBox)4 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)3 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)3 ListBox (org.gwtbootstrap3.client.ui.ListBox)3 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 Widget (com.google.gwt.user.client.ui.Widget)2 SmallLabel (org.uberfire.ext.widgets.common.client.common.SmallLabel)2 IsWidget (com.google.gwt.user.client.ui.IsWidget)1 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)1 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)1 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)1 HasValue (org.drools.workbench.models.guided.dtree.shared.model.nodes.HasValue)1 Value (org.drools.workbench.models.guided.dtree.shared.model.values.Value)1 RuleAttributeWidget (org.drools.workbench.screens.guided.rule.client.editor.RuleAttributeWidget)1 EnumDropDown (org.drools.workbench.screens.guided.rule.client.widget.EnumDropDown)1