Search in sources :

Example 6 with OperationResult

use of io.jmix.ui.util.OperationResult in project jmix by jmix-framework.

the class StandardEditor method commitChanges.

/**
 * Validates screen and commits data context.
 *
 * @return operation result
 */
protected OperationResult commitChanges() {
    ValidationErrors validationErrors = validateScreen();
    if (!validationErrors.isEmpty()) {
        ScreenValidation screenValidation = getApplicationContext().getBean(ScreenValidation.class);
        screenValidation.showValidationErrors(this, validationErrors);
        return OperationResult.fail();
    }
    Runnable standardCommitAction = () -> {
        EntitySet committedEntities = getScreenData().getDataContext().commit();
        InstanceContainer<T> container = getEditedEntityContainer();
        if (container instanceof HasLoader) {
            DataLoader loader = ((HasLoader) container).getLoader();
            if (loader instanceof InstanceLoader) {
                @SuppressWarnings("rawtypes") InstanceLoader instanceLoader = (InstanceLoader) loader;
                if (instanceLoader.getEntityId() == null) {
                    committedEntities.optional(getEditedEntity()).ifPresent(entity -> instanceLoader.setEntityId(EntityValues.getId(entity)));
                }
            }
        }
        fireEvent(AfterCommitChangesEvent.class, new AfterCommitChangesEvent(this));
    };
    BeforeCommitChangesEvent beforeEvent = new BeforeCommitChangesEvent(this, standardCommitAction);
    fireEvent(BeforeCommitChangesEvent.class, beforeEvent);
    if (beforeEvent.isCommitPrevented()) {
        if (beforeEvent.getCommitResult() != null) {
            return beforeEvent.getCommitResult();
        }
        return OperationResult.fail();
    }
    standardCommitAction.run();
    return OperationResult.success();
}
Also used : InMemoryCrudEntityContext(io.jmix.core.accesscontext.InMemoryCrudEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) java.util(java.util) Preconditions(io.jmix.core.common.util.Preconditions) io.jmix.ui.model(io.jmix.ui.model) ValidationErrors(io.jmix.ui.component.ValidationErrors) io.jmix.core(io.jmix.core) Frame(io.jmix.ui.component.Frame) EntityValues(io.jmix.core.entity.EntityValues) Strings(com.google.common.base.Strings) Component(io.jmix.ui.component.Component) Icons(io.jmix.ui.icon.Icons) Action(io.jmix.ui.action.Action) BaseAction(io.jmix.ui.action.BaseAction) Nullable(javax.annotation.Nullable) NotificationType(io.jmix.ui.Notifications.NotificationType) Subscription(io.jmix.core.common.event.Subscription) UnknownOperationResult(io.jmix.ui.util.UnknownOperationResult) UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) JmixIcon(io.jmix.ui.icon.JmixIcon) Consumer(java.util.function.Consumer) TriggerOnce(io.jmix.core.common.event.TriggerOnce) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) OperationResult(io.jmix.ui.util.OperationResult) UiScreenProperties(io.jmix.ui.UiScreenProperties) ValidationErrors(io.jmix.ui.component.ValidationErrors)

Example 7 with OperationResult

use of io.jmix.ui.util.OperationResult in project jmix-sneferu by mariodavid.

the class CancelEditorInteractionTest method when_interactionIsPerformed_then_screenIsCanceledAndNothingIsCommitted.

@Test
void when_interactionIsPerformed_then_screenIsCanceledAndNothingIsCommitted(UiTestAPI uiTestAPI) {
    // given:
    StandardEditorTestAPI<Veterinarian, VeterinarianEdit> visitEdit = uiTestAPI.openStandardEditor(Veterinarian.class, VeterinarianEdit.class);
    // and:
    visitEdit.interact(enter(textInputField("firstNameField"), "Oak"));
    // when:
    final OperationResult operationResult = visitEdit.andThenGet(cancelEditor());
    // then:
    assertThat(operationResult).isEqualTo(OperationResult.success());
    // and:
    assertThat(dataManager.load(Veterinarian.class).all().list()).isEmpty();
}
Also used : VeterinarianEdit(io.jmix.petclinic.screen.veterinarian.veterinarian.VeterinarianEdit) Veterinarian(io.jmix.petclinic.entity.veterinarian.Veterinarian) OperationResult(io.jmix.ui.util.OperationResult) SneferuUiTest(de.diedavids.sneferu.SneferuUiTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with OperationResult

use of io.jmix.ui.util.OperationResult in project jmix-sneferu by mariodavid.

the class CloseEditorInteractionTest method given_validForm_when_interactionIsPerformed_then_screenIsClosedAndSuccessIsReturned.

@Test
void given_validForm_when_interactionIsPerformed_then_screenIsClosedAndSuccessIsReturned(UiTestAPI uiTestAPI) {
    // given:
    StandardEditorTestAPI<Veterinarian, VeterinarianEdit> visitEdit = uiTestAPI.openStandardEditor(Veterinarian.class, VeterinarianEdit.class);
    // and:
    visitEdit.interact(enter(textInputField("firstNameField"), "Oak"));
    // when:
    final OperationResult operationResult = visitEdit.andThenGet(closeEditor());
    // then:
    assertThat(operationResult).isEqualTo(OperationResult.success());
}
Also used : VeterinarianEdit(io.jmix.petclinic.screen.veterinarian.veterinarian.VeterinarianEdit) Veterinarian(io.jmix.petclinic.entity.veterinarian.Veterinarian) OperationResult(io.jmix.ui.util.OperationResult) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SneferuUiTest(de.diedavids.sneferu.SneferuUiTest)

Example 9 with OperationResult

use of io.jmix.ui.util.OperationResult in project jmix-sneferu by mariodavid.

the class CloseInputDialogInteractionTest method when_interactionIsPerformed_then_inputDialogIsClosedAndSuccessIsReturned.

@Test
void when_interactionIsPerformed_then_inputDialogIsClosedAndSuccessIsReturned(UiTestAPI uiTestAPI) {
    // given:
    final String pikachuIdentifier = "025";
    final Pet pikachu = storePikachu(pikachuIdentifier);
    // and:
    openPetByIdInputDialog(uiTestAPI);
    // when:
    final InputDialogTestAPI openedInputDialog = uiTestAPI.getOpenedInputDialog();
    // and:
    final OperationResult operationResult = openedInputDialog.interact(enter(textInputField("id"), pikachuIdentifier)).andThenGet(closeInputDialogWith(InputDialog.INPUT_DIALOG_OK_ACTION));
    // then:
    assertThat(operationResult).isEqualTo(OperationResult.success());
    // and: after the input dialog, the Pet editor is opened
    final StandardEditorTestAPI<Pet, PetEdit> openedPetEditor = uiTestAPI.getOpenedEditorScreen(PetEdit.class);
    final Pet pet = openedPetEditor.get(editedEntity());
    assertThat(pet).isEqualTo(pikachu);
}
Also used : PetEdit(io.jmix.petclinic.screen.pet.pet.PetEdit) InputDialogTestAPI(de.diedavids.sneferu.screen.InputDialogTestAPI) OperationResult(io.jmix.ui.util.OperationResult) Pet(io.jmix.petclinic.entity.pet.Pet) SneferuUiTest(de.diedavids.sneferu.SneferuUiTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with OperationResult

use of io.jmix.ui.util.OperationResult in project jmix-sneferu by mariodavid.

the class CreateVisitTest method aVisitCanBeCreated_whenAllFieldsAreFilled.

@Test
void aVisitCanBeCreated_whenAllFieldsAreFilled(UiTestAPI uiTestAPI) {
    // given:
    final Pet pikachu = dataManager.create(Pet.class);
    pikachu.setName("Pikachu");
    pikachu.setIdentificationNumber("025");
    final Pet savedPikachu = dataManager.save(pikachu);
    // and:
    final StandardLookupTestAPI<Visit, VisitBrowse> visitBrowse = uiTestAPI.openStandardLookup(Visit.class, VisitBrowse.class);
    visitBrowse.interact(click(button("createBtn")));
    // when:
    final StandardEditorTestAPI<Visit, VisitEdit> visitEdit = uiTestAPI.getOpenedEditorScreen(VisitEdit.class);
    OperationResult outcome = (OperationResult) visitEdit.interact(enter(dateField("visitStartField"), LocalDateTime.now())).interact(enter(textField("descriptionField"), "Regular Visit")).interact(select(comboBox("typeField"), VisitType.REGULAR_CHECKUP)).interact(select(entityComboBox("petField"), savedPikachu)).andThenGet(closeEditor());
    // then:
    assertThat(outcome).isEqualTo(OperationResult.success());
    // and:
    assertThat(uiTestAPI.isActive(visitEdit)).isFalse();
}
Also used : VisitEdit(io.jmix.petclinic.screen.visit.VisitEdit) Visit(io.jmix.petclinic.entity.visit.Visit) OperationResult(io.jmix.ui.util.OperationResult) Pet(io.jmix.petclinic.entity.pet.Pet) VisitBrowse(io.jmix.petclinic.screen.visit.VisitBrowse) SneferuUiTest(de.diedavids.sneferu.SneferuUiTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

OperationResult (io.jmix.ui.util.OperationResult)12 SneferuUiTest (de.diedavids.sneferu.SneferuUiTest)8 Test (org.junit.jupiter.api.Test)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 Pet (io.jmix.petclinic.entity.pet.Pet)3 Veterinarian (io.jmix.petclinic.entity.veterinarian.Veterinarian)3 Visit (io.jmix.petclinic.entity.visit.Visit)3 VeterinarianEdit (io.jmix.petclinic.screen.veterinarian.veterinarian.VeterinarianEdit)3 VisitEdit (io.jmix.petclinic.screen.visit.VisitEdit)3 Screen (io.jmix.ui.screen.Screen)3 InputDialogTestAPI (de.diedavids.sneferu.screen.InputDialogTestAPI)2 PetEdit (io.jmix.petclinic.screen.pet.pet.PetEdit)2 NotificationType (io.jmix.ui.Notifications.NotificationType)2 Action (io.jmix.ui.action.Action)2 BaseAction (io.jmix.ui.action.BaseAction)2 Icons (io.jmix.ui.icon.Icons)2 Strings (com.google.common.base.Strings)1 UIScope (com.vaadin.spring.annotation.UIScope)1 CssLayout (com.vaadin.ui.CssLayout)1 Layout (com.vaadin.ui.Layout)1