Search in sources :

Example 1 with Validator

use of org.gwtbootstrap3.client.ui.form.validator.Validator in project kura by eclipse.

the class AbstractServicesUi method renderPasswordField.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void renderPasswordField(final GwtConfigParameter param, boolean isFirstInstance, FormGroup formGroup) {
    this.valid.put(param.getId(), true);
    if (isFirstInstance) {
        FormLabel formLabel = new FormLabel();
        formLabel.setText(param.getName());
        if (param.isRequired()) {
            formLabel.setShowRequiredIndicator(true);
        }
        formLabel.setTitle(param.getId());
        formGroup.add(formLabel);
        InlineHelpBlock ihb = new InlineHelpBlock();
        ihb.setIconType(IconType.EXCLAMATION_TRIANGLE);
        formGroup.add(ihb);
        if (param.getDescription() != null) {
            HelpBlock toolTip = new HelpBlock();
            toolTip.setText(getDescription(param));
            formGroup.add(toolTip);
        }
    }
    final Input input = new Input();
    input.setType(InputType.PASSWORD);
    if (param.getValue() != null) {
        input.setText(param.getValue());
    } else {
        input.setText("");
    }
    if (param.getMin() != null && param.getMin().equals(param.getMax())) {
        input.setReadOnly(true);
        input.setEnabled(false);
    }
    input.setValidateOnBlur(true);
    input.addValidator(new Validator() {

        @Override
        public List<EditorError> validate(Editor editor, Object value) {
            setDirty(true);
            List<EditorError> result = new ArrayList<EditorError>();
            if ((input.getText() == null || "".equals(input.getText().trim())) && param.isRequired()) {
                // null in required field
                result.add(new BasicEditorError(input, input.getText(), MSGS.formRequiredParameter()));
                AbstractServicesUi.this.valid.put(param.getName(), false);
            } else {
                param.setValue(input.getText());
                AbstractServicesUi.this.valid.put(param.getName(), true);
            }
            return result;
        }

        @Override
        public int getPriority() {
            return 0;
        }
    });
    formGroup.add(input);
}
Also used : BasicEditorError(org.gwtbootstrap3.client.ui.form.error.BasicEditorError) Input(org.gwtbootstrap3.client.ui.Input) InlineHelpBlock(org.gwtbootstrap3.client.ui.InlineHelpBlock) HelpBlock(org.gwtbootstrap3.client.ui.HelpBlock) BasicEditorError(org.gwtbootstrap3.client.ui.form.error.BasicEditorError) EditorError(com.google.gwt.editor.client.EditorError) InlineHelpBlock(org.gwtbootstrap3.client.ui.InlineHelpBlock) ArrayList(java.util.ArrayList) List(java.util.List) FormLabel(org.gwtbootstrap3.client.ui.FormLabel) Editor(com.google.gwt.editor.client.Editor) Validator(org.gwtbootstrap3.client.ui.form.validator.Validator)

Example 2 with Validator

use of org.gwtbootstrap3.client.ui.form.validator.Validator in project kura by eclipse.

the class AbstractServicesUi method renderTextField.

// Field Render based on Type
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void renderTextField(final GwtConfigParameter param, boolean isFirstInstance, final FormGroup formGroup) {
    this.valid.put(param.getId(), true);
    if (isFirstInstance) {
        FormLabel formLabel = new FormLabel();
        formLabel.setText(param.getName());
        if (param.isRequired()) {
            formLabel.setShowRequiredIndicator(true);
        }
        formLabel.setTitle(param.getId());
        formGroup.add(formLabel);
        InlineHelpBlock ihb = new InlineHelpBlock();
        ihb.setIconType(IconType.EXCLAMATION_TRIANGLE);
        formGroup.add(ihb);
        HelpBlock tooltip = new HelpBlock();
        tooltip.setText(getDescription(param));
        formGroup.add(tooltip);
    }
    final TextBoxBase textBox = createTextBox(param);
    String formattedValue = new String();
    // double value as expected
    switch(param.getType()) {
        case LONG:
            if (param.getValue() != null && !"".equals(param.getValue().trim())) {
                formattedValue = String.valueOf(Long.parseLong(param.getValue()));
            }
            break;
        case DOUBLE:
            if (param.getValue() != null && !"".equals(param.getValue().trim())) {
                formattedValue = String.valueOf(Double.parseDouble(param.getValue()));
            }
            break;
        case FLOAT:
            if (param.getValue() != null && !"".equals(param.getValue().trim())) {
                formattedValue = String.valueOf(Float.parseFloat(param.getValue()));
            }
            break;
        case SHORT:
            if (param.getValue() != null && !"".equals(param.getValue().trim())) {
                formattedValue = String.valueOf(Short.parseShort(param.getValue()));
            }
            break;
        case BYTE:
            if (param.getValue() != null && !"".equals(param.getValue().trim())) {
                formattedValue = String.valueOf(Byte.parseByte(param.getValue()));
            }
            break;
        case INTEGER:
            if (param.getValue() != null && !"".equals(param.getValue().trim())) {
                formattedValue = String.valueOf(Integer.parseInt(param.getValue()));
            }
            break;
        default:
            formattedValue = param.getValue();
            break;
    }
    if (param.getValue() != null) {
        textBox.setText(formattedValue);
    } else {
        textBox.setText("");
    }
    if (param.getMin() != null && param.getMin().equals(param.getMax())) {
        textBox.setReadOnly(true);
        textBox.setEnabled(false);
    }
    formGroup.add(textBox);
    textBox.setValidateOnBlur(true);
    textBox.addValidator(new Validator() {

        @Override
        public List<EditorError> validate(Editor editor, Object value) {
            setDirty(true);
            return validateTextBox(param, textBox, formGroup);
        }

        @Override
        public int getPriority() {
            return 0;
        }
    });
// textBox.validate();
}
Also used : InlineHelpBlock(org.gwtbootstrap3.client.ui.InlineHelpBlock) HelpBlock(org.gwtbootstrap3.client.ui.HelpBlock) InlineHelpBlock(org.gwtbootstrap3.client.ui.InlineHelpBlock) ArrayList(java.util.ArrayList) List(java.util.List) FormLabel(org.gwtbootstrap3.client.ui.FormLabel) Editor(com.google.gwt.editor.client.Editor) Validator(org.gwtbootstrap3.client.ui.form.validator.Validator) TextBoxBase(org.gwtbootstrap3.client.ui.base.TextBoxBase)

Example 3 with Validator

use of org.gwtbootstrap3.client.ui.form.validator.Validator in project kie-wb-common by kiegroup.

the class ReassignmentEditorWidgetTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    GwtMockito.initMocks(this);
    modal = mock(BaseModal.class);
    notStarted = mock(Option.class);
    notCompleted = mock(Option.class);
    customerBinder = mock(DataBinder.class);
    multipleLiveSearchSelectionHandlerUsers = mock(MultipleLiveSearchSelectionHandler.class);
    multipleLiveSearchSelectionHandlerGroups = mock(MultipleLiveSearchSelectionHandler.class);
    doNothing().when(modal).hide();
    doNothing().when(modal).show();
    doNothing().when(reassignmentEvent).fire(any(ReassignmentEvent.class));
    doCallRealMethod().when(reassignmentEditorWidget).setReadOnly(any(boolean.class));
    doCallRealMethod().when(reassignmentEditorWidget).getNameHeader();
    setFieldValue(reassignmentEditorWidget, "view", view);
    setFieldValue(reassignmentEditorWidget, "translationService", translationService);
    doCallRealMethod().when(typeSelect).setValue(any(String.class));
    doCallRealMethod().when(typeSelect).getValue();
    doCallRealMethod().when(view).setReadOnly(any(boolean.class));
    doCallRealMethod().when(view).initTypeSelector();
    doCallRealMethod().when(view).createOrEdit(any(ReassignmentWidgetView.class), any(ReassignmentRow.class));
    doCallRealMethod().when(view).ok();
    setFieldValue(view, "modal", modal);
    setFieldValue(view, "customerBinder", customerBinder);
    setFieldValue(view, "multipleLiveSearchSelectionHandlerUsers", multipleLiveSearchSelectionHandlerUsers);
    setFieldValue(view, "multipleLiveSearchSelectionHandlerGroups", multipleLiveSearchSelectionHandlerGroups);
    setFieldValue(view, "reassignmentEvent", reassignmentEvent);
    setFieldValue(view, "validator", validator);
    setFieldValue(view, "closeButton", new HTMLButtonElement());
    setFieldValue(view, "okButton", new HTMLButtonElement());
    setFieldValue(view, "customerBinder", customerBinder);
    setFieldValue(view, "typeSelect", typeSelect);
    setFieldValue(view, "notStarted", notStarted);
    setFieldValue(view, "notCompleted", notCompleted);
    doCallRealMethod().when(typeSelect).setValue(any(String.class));
    doCallRealMethod().when(typeSelect).getValue();
    when(validator.validate(any(ReassignmentRow.class))).thenReturn(Collections.EMPTY_SET);
    doCallRealMethod().when(view).init(any(ReassignmentEditorWidgetView.Presenter.class));
    when(translationService.getValue(any(String.class))).thenReturn("Reassignment");
    view.initTypeSelector();
}
Also used : BaseModal(org.uberfire.ext.widgets.common.client.common.popups.BaseModal) MultipleLiveSearchSelectionHandler(org.uberfire.ext.widgets.common.client.dropdown.MultipleLiveSearchSelectionHandler) ReassignmentEvent(org.kie.workbench.common.stunner.bpmn.client.forms.fields.reassignmentsEditor.event.ReassignmentEvent) Option(org.gwtbootstrap3.extras.select.client.ui.Option) DataBinder(org.jboss.errai.databinding.client.api.DataBinder) HTMLButtonElement(elemental2.dom.HTMLButtonElement) ReassignmentRow(org.kie.workbench.common.stunner.bpmn.client.forms.fields.model.ReassignmentRow) Before(org.junit.Before)

Example 4 with Validator

use of org.gwtbootstrap3.client.ui.form.validator.Validator in project kie-wb-common by kiegroup.

the class NotificationEditorWidgetTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    GwtMockito.initMocks(this);
    BaseModal modal = mock(BaseModal.class);
    taskExpiration = mock(Select.class);
    setFieldValue(view, "taskExpiration", taskExpiration);
    Option notStarted = mock(Option.class);
    notCompleted = mock(Option.class);
    customerBinder = mock(DataBinder.class);
    searchSelectionReplyToHandler = mock(SingleLiveSearchSelectionHandler.class);
    searchSelectionFromHandler = mock(SingleLiveSearchSelectionHandler.class);
    multipleLiveSearchSelectionHandlerUsers = mock(MultipleLiveSearchSelectionHandler.class);
    multipleLiveSearchSelectionHandlerGroups = mock(MultipleLiveSearchSelectionHandler.class);
    notCompletedInput = mock(HTMLInputElement.class);
    notStartedInput = mock(HTMLInputElement.class);
    incorrectEmail = mock(ParagraphElement.class);
    doNothing().when(view).markEmailsAsCorrect();
    doNothing().when(modal).hide();
    doNothing().when(modal).show();
    doNothing().when(notificationEvent).fire(any(NotificationEvent.class));
    presenter = new NotificationEditorWidget(view, translationService);
    doCallRealMethod().when(typeSelect).setValue(any(String.class));
    doCallRealMethod().when(typeSelect).getValue();
    doCallRealMethod().when(view).setReadOnly(any(boolean.class));
    doNothing().when(view).createOrEdit(any(NotificationWidgetView.class), any(NotificationRow.class));
    doNothing().when(view).ok();
    setFieldValue(view, "modal", modal);
    setFieldValue(view, "body", body);
    setFieldValue(view, "customerBinder", customerBinder);
    setFieldValue(view, "notCompletedInput", notCompletedInput);
    setFieldValue(view, "notStartedInput", notStartedInput);
    setFieldValue(view, "subject", subject);
    setFieldValue(view, "emails", subject);
    setFieldValue(view, "searchSelectionFromHandler", searchSelectionFromHandler);
    setFieldValue(view, "searchSelectionReplyToHandler", searchSelectionReplyToHandler);
    setFieldValue(view, "multipleLiveSearchSelectionHandlerUsers", multipleLiveSearchSelectionHandlerUsers);
    setFieldValue(view, "multipleLiveSearchSelectionHandlerGroups", multipleLiveSearchSelectionHandlerGroups);
    setFieldValue(view, "notificationEvent", notificationEvent);
    setFieldValue(view, "validator", validator);
    setFieldValue(view, "closeButton", new HTMLButtonElement());
    setFieldValue(view, "okButton", new HTMLButtonElement());
    setFieldValue(view, "customerBinder", customerBinder);
    setFieldValue(view, "typeSelect", typeSelect);
    setFieldValue(view, "notStarted", notStarted);
    setFieldValue(view, "notCompleted", notCompleted);
    setFieldValue(view, "incorrectEmail", incorrectEmail);
    doCallRealMethod().when(body).setValue(any(String.class));
    doCallRealMethod().when(body).getValue();
    doCallRealMethod().when(subject).setValue(any(String.class));
    doCallRealMethod().when(subject).getValue();
    doCallRealMethod().when(typeSelect).setValue(any(String.class));
    doCallRealMethod().when(typeSelect).getValue();
    setFieldValue(liveSearchReplyToDropDown, "view", liveSearchDropDownView);
    when(validator.validate(any(NotificationRow.class))).thenReturn(Collections.EMPTY_SET);
    doNothing().when(liveSearchReplyToDropDown).setSelectedItem(any(String.class));
    doCallRealMethod().when(view).init(any(NotificationEditorWidgetView.Presenter.class));
    when(translationService.getValue(any(String.class))).thenReturn("Notification");
}
Also used : MultipleLiveSearchSelectionHandler(org.uberfire.ext.widgets.common.client.dropdown.MultipleLiveSearchSelectionHandler) ParagraphElement(com.google.gwt.dom.client.ParagraphElement) HTMLInputElement(elemental2.dom.HTMLInputElement) SingleLiveSearchSelectionHandler(org.uberfire.ext.widgets.common.client.dropdown.SingleLiveSearchSelectionHandler) NotificationEvent(org.kie.workbench.common.stunner.bpmn.client.forms.fields.notificationsEditor.event.NotificationEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) BaseModal(org.uberfire.ext.widgets.common.client.common.popups.BaseModal) Select(org.gwtbootstrap3.extras.select.client.ui.Select) NotificationRow(org.kie.workbench.common.stunner.bpmn.client.forms.fields.model.NotificationRow) Option(org.gwtbootstrap3.extras.select.client.ui.Option) DataBinder(org.jboss.errai.databinding.client.api.DataBinder) HTMLButtonElement(elemental2.dom.HTMLButtonElement) Before(org.junit.Before)

Aggregations

Editor (com.google.gwt.editor.client.Editor)2 HTMLButtonElement (elemental2.dom.HTMLButtonElement)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 FormLabel (org.gwtbootstrap3.client.ui.FormLabel)2 HelpBlock (org.gwtbootstrap3.client.ui.HelpBlock)2 InlineHelpBlock (org.gwtbootstrap3.client.ui.InlineHelpBlock)2 Validator (org.gwtbootstrap3.client.ui.form.validator.Validator)2 Option (org.gwtbootstrap3.extras.select.client.ui.Option)2 DataBinder (org.jboss.errai.databinding.client.api.DataBinder)2 Before (org.junit.Before)2 BaseModal (org.uberfire.ext.widgets.common.client.common.popups.BaseModal)2 MultipleLiveSearchSelectionHandler (org.uberfire.ext.widgets.common.client.dropdown.MultipleLiveSearchSelectionHandler)2 ParagraphElement (com.google.gwt.dom.client.ParagraphElement)1 EditorError (com.google.gwt.editor.client.EditorError)1 HTMLInputElement (elemental2.dom.HTMLInputElement)1 Input (org.gwtbootstrap3.client.ui.Input)1 TextBoxBase (org.gwtbootstrap3.client.ui.base.TextBoxBase)1 BasicEditorError (org.gwtbootstrap3.client.ui.form.error.BasicEditorError)1 Select (org.gwtbootstrap3.extras.select.client.ui.Select)1