Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close open dialogs #994

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.contextmenu.MenuItem;
import com.vaadin.flow.component.contextmenu.SubMenu;
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Hr;
import com.vaadin.flow.component.html.Span;
@@ -16,6 +17,9 @@
import com.vaadin.flow.component.sidenav.SideNavItem;
import com.vaadin.flow.router.BeforeEnterEvent;
import com.vaadin.flow.router.BeforeEnterObserver;
import com.vaadin.flow.router.BeforeLeaveEvent;
import com.vaadin.flow.router.BeforeLeaveListener;
import com.vaadin.flow.router.BeforeLeaveObserver;
import com.vaadin.flow.router.RouteParam;
import com.vaadin.flow.router.RouteParameters;
import com.vaadin.flow.spring.annotation.SpringComponent;
@@ -68,7 +72,7 @@
@SpringComponent
@UIScope
public class ProjectSideNavigationComponent extends Div implements
BeforeEnterObserver {
BeforeEnterObserver, BeforeLeaveObserver {

public static final String PROJECT_ID_ROUTE_PARAMETER = "projectId";
public static final String EXPERIMENT_ID_ROUTE_PARAMETER = "experimentId";
@@ -84,6 +88,7 @@ public class ProjectSideNavigationComponent extends Div implements
private final transient TerminologyService terminologyService;
private final transient SpeciesLookupService speciesLookupService;
private Context context = new Context();
private AddExperimentDialog addExperimentDialog;

public ProjectSideNavigationComponent(
ProjectInformationService projectInformationService,
@@ -325,12 +330,12 @@ private Div createExperimentSection(String projectId, List<Experiment> experimen
}

private void showAddExperimentDialog() {
var creationDialog = new AddExperimentDialog(speciesLookupService,
this.addExperimentDialog = new AddExperimentDialog(speciesLookupService,
terminologyService);
creationDialog.addExperimentAddEventListener(this::onExperimentAddEvent);
creationDialog.addCancelListener(cancelEvent -> showCancelConfirmationDialog(creationDialog));
creationDialog.setEscAction(it -> showCancelConfirmationDialog(creationDialog));
creationDialog.open();
this.addExperimentDialog.addExperimentAddEventListener(this::onExperimentAddEvent);
this.addExperimentDialog.addCancelListener(cancelEvent -> showCancelConfirmationDialog(this.addExperimentDialog));
this.addExperimentDialog.setEscAction(it -> showCancelConfirmationDialog(this.addExperimentDialog));
this.addExperimentDialog.open();
}

private void showCancelConfirmationDialog(AddExperimentDialog creationDialog) {
@@ -383,6 +388,11 @@ private void displayExperimentCreationSuccess(String experimentName) {
toast.open();
}

@Override
public void beforeLeave(BeforeLeaveEvent event) {
Optional.ofNullable(this.addExperimentDialog).ifPresent(Dialog::close);
}

private static class ProjectNavigationEvent extends ComponentEvent<Component> {

@Serial
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@
* <p>
* Additionally, it provides the possibility to create new experiments with its
* {@link AddExperimentDialog} and enables the user to select an experiment of interest via
* {@link AddExperimentDialog} and enables the user to select an experiment of interest via
* clicking on the item within {@link ListBox} associated with the experiment.
* <p>
* Finally, it allows components to be informed about a new experiment creation or selection via the
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import static life.qbic.datamanager.views.projects.project.experiments.experiment.SampleOriginType.SPECIMEN;

import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.html.Anchor;
import com.vaadin.flow.component.html.AnchorTarget;
import com.vaadin.flow.component.html.Div;
@@ -16,6 +17,8 @@
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.tabs.TabSheet;
import com.vaadin.flow.data.renderer.ComponentRenderer;
import com.vaadin.flow.router.BeforeLeaveEvent;
import com.vaadin.flow.router.BeforeLeaveObserver;
import com.vaadin.flow.router.RouteParam;
import com.vaadin.flow.router.RouteParameters;
import com.vaadin.flow.server.StreamResource;
@@ -78,7 +81,7 @@
*/
@UIScope
@SpringComponent
public class ExperimentDetailsComponent extends PageArea {
public class ExperimentDetailsComponent extends PageArea implements BeforeLeaveObserver {

public static final String PROJECT_ID_ROUTE_PARAMETER = "projectId";
public static final String EXPERIMENT_ID_ROUTE_PARAMETER = "experimentId";
@@ -106,6 +109,7 @@ public class ExperimentDetailsComponent extends PageArea {
private final transient CancelConfirmationDialogFactory cancelConfirmationDialogFactory;
private Context context;
private int experimentalGroupCount;
private Dialog dialog;


public ExperimentDetailsComponent(
@@ -236,7 +240,9 @@ private void onEditButtonClicked() {
cancelEvent -> showCancelConfirmationDialog(editExperimentDialog));
editExperimentDialog.setEscAction(
() -> showCancelConfirmationDialog(editExperimentDialog));
this.dialog = editExperimentDialog;
editExperimentDialog.open();

});
}

@@ -316,6 +322,7 @@ private void openExperimentalVariablesAddDialog() {
addDialog.addCancelEventListener(cancelEvent -> showCancelConfirmationDialog(addDialog, true));
addDialog.setEscAction(() -> showCancelConfirmationDialog(addDialog, true));
addDialog.addConfirmEventListener(this::onExperimentalVariablesAddConfirmed);
this.dialog = addDialog;
addDialog.open();
}

@@ -341,6 +348,7 @@ private void openExperimentalVariablesEditDialog() {
cancelEvent -> showCancelConfirmationDialog(editDialog, false));
editDialog.setEscAction(() -> showCancelConfirmationDialog(editDialog, false));
editDialog.addConfirmEventListener(this::onExperimentalVariablesEditConfirmed);
this.dialog = editDialog;
editDialog.open();
}

@@ -493,6 +501,7 @@ private void openExperimentalGroupAddDialog() {
dialog.addCancelEventListener(cancelEvent -> cancelEvent.getSource().close());
dialog.addConfirmEventListener(this::onExperimentalGroupAddConfirmed);
dialog.open();
this.dialog = dialog;
}

private void onExperimentalGroupAddConfirmed(
@@ -523,6 +532,7 @@ private void openExperimentalGroupEditDialog() {
var dialog = ExperimentalGroupsDialog.editable(levels, groups);
dialog.addCancelEventListener(cancelEvent -> cancelEvent.getSource().close());
dialog.addConfirmEventListener(this::onExperimentalGroupEditConfirmed);
this.dialog = dialog;
dialog.open();
}

@@ -663,6 +673,11 @@ private void onGroupsDefined() {
experimentalGroups.add(experimentalGroupsCollection);
}

@Override
public void beforeLeave(BeforeLeaveEvent event) {
Optional.ofNullable(this.dialog).ifPresent(Dialog::close);
}

/**
* Describes a species, specimen or analyte icon with label, type and source. Note that the icon
* source is stored instead of the icon itself, because mixing enums and Components causes trouble
Original file line number Diff line number Diff line change
@@ -12,6 +12,10 @@
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.router.BeforeEnterEvent;
import com.vaadin.flow.router.BeforeEnterObserver;
import com.vaadin.flow.router.BeforeLeaveEvent;
import com.vaadin.flow.router.BeforeLeaveListener;
import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
@@ -28,6 +32,7 @@
import life.qbic.projectmanagement.application.ontology.SpeciesLookupService;
import life.qbic.projectmanagement.application.ontology.TerminologyService;
import life.qbic.projectmanagement.domain.model.OntologyTerm;
import org.aspectj.lang.annotation.Before;

/**
* <b>AddExperimentDialog</b>
Original file line number Diff line number Diff line change
@@ -3,8 +3,11 @@
import static java.util.Objects.requireNonNull;
import static life.qbic.logging.service.LoggerFactory.logger;

import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.router.BeforeEnterEvent;
import com.vaadin.flow.router.BeforeEnterObserver;
import com.vaadin.flow.router.BeforeLeaveEvent;
import com.vaadin.flow.router.BeforeLeaveObserver;
import com.vaadin.flow.router.NotFoundException;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.RouteParam;
@@ -13,7 +16,9 @@
import com.vaadin.flow.spring.annotation.UIScope;
import jakarta.annotation.security.PermitAll;
import java.io.Serial;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import life.qbic.application.commons.ApplicationException;
import life.qbic.application.commons.Result;
import life.qbic.datamanager.security.UserPermissions;
@@ -71,7 +76,8 @@
@UIScope
@Route(value = "projects/:projectId?/info", layout = ProjectMainLayout.class)
@PermitAll
public class ProjectInformationMain extends Main implements BeforeEnterObserver {
public class ProjectInformationMain extends Main implements BeforeEnterObserver,
BeforeLeaveObserver {

public static final String PROJECT_ID_ROUTE_PARAMETER = "projectId";
public static final String EXPERIMENT_ID_ROUTE_PARAMETER = "experimentId";
@@ -94,6 +100,9 @@ public class ProjectInformationMain extends Main implements BeforeEnterObserver
private final transient MessageSourceNotificationFactory messageSourceNotificationFactory;
private final transient TerminologyService terminologyService;
private Context context;
private UploadPurchaseDialog uploadPurchaseDialog;
private UploadQualityControlDialog uploadQualityControlDialog;
private AddExperimentDialog addExperimentDialog;

public ProjectInformationMain(@Autowired ProjectSummaryComponent projectSummaryComponent,
@Autowired ExperimentListComponent experimentListComponent,
@@ -208,17 +217,17 @@ private void onDeleteOfferClicked(DeleteOfferClickEvent deleteOfferClickEvent) {
private void onUploadOfferClicked(UploadOfferClickEvent uploadOfferClickEvent,
ProjectPurchaseService projectPurchaseService,
String projectId) {
UploadPurchaseDialog dialog = new UploadPurchaseDialog();
dialog.addConfirmListener(confirmEvent -> {
this.uploadPurchaseDialog = new UploadPurchaseDialog();
uploadPurchaseDialog.addConfirmListener(confirmEvent -> {
List<OfferDTO> offerDTOs = confirmEvent.getSource().purchaseItems().stream()
.map(it -> new OfferDTO(it.signed(), it.fileName(), it.content()))
.toList();
projectPurchaseService.addPurchases(projectId, offerDTOs);
refreshOffers(projectPurchaseService, projectId, uploadOfferClickEvent.getSource());
confirmEvent.getSource().close();
});
dialog.addCancelListener(cancelEvent -> cancelEvent.getSource().close());
dialog.open();
uploadPurchaseDialog.addCancelListener(cancelEvent -> cancelEvent.getSource().close());
uploadPurchaseDialog.open();
}

private QualityControlListComponent getConfiguredQualityControlList() {
@@ -251,9 +260,9 @@ private void onDeleteQualityControlClicked(DeleteQualityControlEvent deleteQuali
}

private void onUploadQualityControlClicked() {
UploadQualityControlDialog dialog = new UploadQualityControlDialog(
this.uploadQualityControlDialog = new UploadQualityControlDialog(
context.projectId().orElseThrow(), experimentInformationService);
dialog.addConfirmListener(confirmEvent -> {
uploadQualityControlDialog.addConfirmListener(confirmEvent -> {
List<QualityControlReport> qualityControlReports = confirmEvent.getSource()
.qualityControlItems()
.stream()
@@ -264,8 +273,8 @@ private void onUploadQualityControlClicked() {
refreshQualityControls();
confirmEvent.getSource().close();
});
dialog.addCancelListener(cancelEvent -> cancelEvent.getSource().close());
dialog.open();
uploadQualityControlDialog.addCancelListener(cancelEvent -> cancelEvent.getSource().close());
uploadQualityControlDialog.open();
}

private void refreshQualityControls() {
@@ -324,11 +333,12 @@ private void routeToExperiment(ExperimentId experimentId) {
}

private void showAddExperimentDialog() {
var creationDialog = new AddExperimentDialog(ontologyTermInformationService, terminologyService);
creationDialog.addExperimentAddEventListener(this::onExperimentAddEvent);
creationDialog.addCancelListener(cancelEvent -> showCancelConfirmationDialog(creationDialog));
creationDialog.setEscAction(() -> showCancelConfirmationDialog(creationDialog));
creationDialog.open();
this.addExperimentDialog = new AddExperimentDialog(ontologyTermInformationService,
terminologyService);
addExperimentDialog.addExperimentAddEventListener(this::onExperimentAddEvent);
addExperimentDialog.addCancelListener(cancelEvent -> showCancelConfirmationDialog(addExperimentDialog));
addExperimentDialog.setEscAction(() -> showCancelConfirmationDialog(addExperimentDialog));
addExperimentDialog.open();
}

private void showCancelConfirmationDialog(AddExperimentDialog creationDialog) {
@@ -360,4 +370,11 @@ private ExperimentId createExperiment(ProjectId projectId,
throw new ApplicationException("Experiment Creation failed");
}
}

@Override
public void beforeLeave(BeforeLeaveEvent event) {
Optional.ofNullable(this.addExperimentDialog).ifPresent(Dialog::close);
Optional.ofNullable(this.uploadQualityControlDialog).ifPresent(Dialog::close);
Optional.ofNullable(this.uploadPurchaseDialog).ifPresent(Dialog::close);
}
}
Original file line number Diff line number Diff line change
@@ -5,13 +5,16 @@
import com.vaadin.flow.component.ComponentEvent;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.value.ValueChangeMode;
import com.vaadin.flow.router.BeforeEnterEvent;
import com.vaadin.flow.router.BeforeEnterObserver;
import com.vaadin.flow.router.BeforeLeaveEvent;
import com.vaadin.flow.router.BeforeLeaveObserver;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent;
import com.vaadin.flow.spring.annotation.UIScope;
@@ -21,6 +24,7 @@
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import life.qbic.application.commons.ApplicationException;
@@ -72,7 +76,8 @@
@SpringComponent
@UIScope
@PermitAll
public class SampleInformationMain extends Main implements BeforeEnterObserver {
public class SampleInformationMain extends Main implements BeforeEnterObserver,
BeforeLeaveObserver {

public static final String PROJECT_ID_ROUTE_PARAMETER = "projectId";
public static final String EXPERIMENT_ID_ROUTE_PARAMETER = "experimentId";
@@ -99,6 +104,7 @@ public class SampleInformationMain extends Main implements BeforeEnterObserver {
private final TemplateService templateService;
private final SampleRegistrationServiceV2 sampleRegistrationServiceV2;
private transient Context context;
private Dialog dialog;

public SampleInformationMain(@Autowired ExperimentInformationService experimentInformationService,
@Autowired BatchRegistrationService batchRegistrationService,
@@ -264,6 +270,7 @@ private void onRegisterBatchClicked() {
event -> showCancelConfirmationDialog(event.getSource()));
registerSampleBatchDialog.setEscAction(
() -> showCancelConfirmationDialog(registerSampleBatchDialog));
this.dialog = registerSampleBatchDialog;
registerSampleBatchDialog.open();
}

@@ -399,6 +406,7 @@ private void onEditBatchClicked(EditBatchEvent editBatchEvent) {
event -> showCancelConfirmationDialog(event.getSource()));
editSampleBatchDialog.setEscAction(
() -> showCancelConfirmationDialog(editSampleBatchDialog));
this.dialog = editSampleBatchDialog;
editSampleBatchDialog.open();
}

@@ -512,6 +520,11 @@ private void reloadSampleInformation() {
sampleDetailsComponent.setContext(context);
}

@Override
public void beforeLeave(BeforeLeaveEvent event) {
Optional.ofNullable(this.dialog).ifPresent(Dialog::close);
}

private static class HandledException extends RuntimeException {

public HandledException(Throwable cause) {