Search in sources :

Example 1 with StatusChangeEvent

use of com.vaadin.flow.data.binder.StatusChangeEvent in project flow-components by vaadin.

the class EditorImplTest method save_editorIsOpened_editorIsInBufferedMode_beanIsInvalid_editorIsNotClosed.

@Test
public void save_editorIsOpened_editorIsInBufferedMode_beanIsInvalid_editorIsNotClosed() {
    editor.getBinder().forField(new TextField()).withValidator(value -> !value.equals("bar"), "").bind(ValueProvider.identity(), (item, value) -> {
    });
    editor.editItem("bar");
    fakeClientResponse();
    editor.refreshedItems.clear();
    editor.setBuffered(true);
    AtomicReference<StatusChangeEvent> statusEventCapture = new AtomicReference<>();
    AtomicReference<EditorEvent<String>> saveEventCapture = new AtomicReference<>();
    AtomicReference<EditorEvent<String>> closeEventCapture = new AtomicReference<>();
    Assert.assertFalse(doSave(statusEventCapture, saveEventCapture, closeEventCapture));
    Assert.assertEquals(0, editor.refreshedItems.size());
    Assert.assertNotNull(statusEventCapture.get());
    Assert.assertNull(saveEventCapture.get());
    Assert.assertNull(closeEventCapture.get());
    Assert.assertTrue(statusEventCapture.get().hasValidationErrors());
}
Also used : VaadinSession(com.vaadin.flow.server.VaadinSession) Grid(com.vaadin.flow.component.grid.Grid) ValueProvider(com.vaadin.flow.function.ValueProvider) Binder(com.vaadin.flow.data.binder.Binder) EditorImpl(com.vaadin.flow.component.grid.editor.EditorImpl) Test(org.junit.Test) EditorEvent(com.vaadin.flow.component.grid.editor.EditorEvent) StatusChangeEvent(com.vaadin.flow.data.binder.StatusChangeEvent) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) List(java.util.List) Rule(org.junit.Rule) UI(com.vaadin.flow.component.UI) Assert(org.junit.Assert) ExpectedException(org.junit.rules.ExpectedException) TextField(com.vaadin.flow.component.textfield.TextField) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) EditorEvent(com.vaadin.flow.component.grid.editor.EditorEvent) StatusChangeEvent(com.vaadin.flow.data.binder.StatusChangeEvent) TextField(com.vaadin.flow.component.textfield.TextField) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 2 with StatusChangeEvent

use of com.vaadin.flow.data.binder.StatusChangeEvent in project karnak by OsiriX-Foundation.

the class DicomWorkListView method bindFields.

@SuppressWarnings("serial")
private void bindFields() {
    binderForWorkListQuery.forField(callingAetFld).asRequired("Ce champ est obligatoire").bind(WorkListQueryData::getCallingAet, WorkListQueryData::setCallingAet);
    binderForWorkListQuery.forField(workListAetFld).asRequired("Ce champ est obligatoire").bind(WorkListQueryData::getWorkListAet, WorkListQueryData::setWorkListAet);
    binderForWorkListQuery.forField(workListHostnameFld).asRequired("Ce champ est obligatoire").bind(WorkListQueryData::getWorkListHostname, WorkListQueryData::setWorkListHostname);
    binderForWorkListQuery.forField(workListPortFld).asRequired("Ce champ est obligatoire").withValidator(new IntegerRangeValidator("Le port est invalide", 1, 65535)).bind(WorkListQueryData::getWorkListPort, WorkListQueryData::setWorkListPort);
    binderForWorkListQuery.bind(scheduledStationAetFld, WorkListQueryData::getScheduledStationAet, WorkListQueryData::setScheduledStationAet);
    binderForWorkListQuery.bind(scheduledModalitySelector, WorkListQueryData::getScheduledModality, WorkListQueryData::setScheduledModality);
    binderForWorkListQuery.bind(patientIdfld, WorkListQueryData::getPatientId, WorkListQueryData::setPatientId);
    binderForWorkListQuery.bind(admissionIdFld, WorkListQueryData::getAdmissionId, WorkListQueryData::setAdmissionId);
    binderForWorkListQuery.bind(scheduledFromFld, WorkListQueryData::getScheduledFrom, WorkListQueryData::setScheduledFrom);
    binderForWorkListQuery.bind(scheduledToFld, WorkListQueryData::getScheduledTo, WorkListQueryData::setScheduledTo);
    binderForWorkListQuery.bind(patientNameFld, WorkListQueryData::getPatientName, WorkListQueryData::setPatientName);
    binderForWorkListQuery.bind(accessionNumberFld, WorkListQueryData::getAccessionNumber, WorkListQueryData::setAccessionNumber);
    binderForWorkListQuery.readBean(workListQueryData);
    binderForWorkListQuery.addStatusChangeListener(new StatusChangeListener() {

        @Override
        public void statusChange(StatusChangeEvent event) {
            if (callingAetFld.isEmpty() || workListAetFld.isEmpty() || workListHostnameFld.isEmpty() || workListPortFld.isEmpty()) {
                queryBtn.setEnabled(false);
            } else {
                queryBtn.setEnabled(!event.hasValidationErrors());
            }
            attributes.clear();
            dataProviderForAttributes.refreshAll();
            queryResultLayout.setVisible(false);
        }
    });
}
Also used : IntegerRangeValidator(com.vaadin.flow.data.validator.IntegerRangeValidator) WorkListQueryData(org.karnak.backend.model.dicom.WorkListQueryData) StatusChangeListener(com.vaadin.flow.data.binder.StatusChangeListener) StatusChangeEvent(com.vaadin.flow.data.binder.StatusChangeEvent)

Aggregations

StatusChangeEvent (com.vaadin.flow.data.binder.StatusChangeEvent)2 UI (com.vaadin.flow.component.UI)1 Grid (com.vaadin.flow.component.grid.Grid)1 EditorEvent (com.vaadin.flow.component.grid.editor.EditorEvent)1 EditorImpl (com.vaadin.flow.component.grid.editor.EditorImpl)1 TextField (com.vaadin.flow.component.textfield.TextField)1 Binder (com.vaadin.flow.data.binder.Binder)1 StatusChangeListener (com.vaadin.flow.data.binder.StatusChangeListener)1 IntegerRangeValidator (com.vaadin.flow.data.validator.IntegerRangeValidator)1 ValueProvider (com.vaadin.flow.function.ValueProvider)1 VaadinSession (com.vaadin.flow.server.VaadinSession)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 ExpectedException (org.junit.rules.ExpectedException)1 WorkListQueryData (org.karnak.backend.model.dicom.WorkListQueryData)1