Skip to content

Commit

Permalink
fix closing in AddExperimentDialog.java
Browse files Browse the repository at this point in the history
  • Loading branch information
KochTobi committed Sep 3, 2024
1 parent bd86e25 commit 541a070
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
import life.qbic.datamanager.security.UserPermissions;
import life.qbic.datamanager.views.AppRoutes.Projects;
import life.qbic.datamanager.views.Context;
import life.qbic.datamanager.views.notifications.CancelConfirmationDialogFactory;
import life.qbic.datamanager.views.notifications.MessageSourceNotificationFactory;
import life.qbic.datamanager.views.notifications.NotificationDialog;
import life.qbic.datamanager.views.notifications.Toast;
import life.qbic.datamanager.views.projects.overview.ProjectOverviewMain;
import life.qbic.datamanager.views.projects.project.ProjectMainLayout;
Expand Down Expand Up @@ -76,6 +78,7 @@ public class ProjectSideNavigationComponent extends Div implements
private final transient ExperimentInformationService experimentInformationService;
private final AddExperimentToProjectService addExperimentToProjectService;
private final transient UserPermissions userPermissions;
private final CancelConfirmationDialogFactory cancelConfirmationDialogFactory;
private final MessageSourceNotificationFactory messageSourceNotificationFactory;
private final TerminologyService terminologyService;
private final SpeciesLookupService speciesLookupService;
Expand All @@ -88,13 +91,16 @@ public ProjectSideNavigationComponent(
UserPermissions userPermissions,
SpeciesLookupService speciesLookupService,
TerminologyService terminologyService,
CancelConfirmationDialogFactory cancelConfirmationDialogFactory,
MessageSourceNotificationFactory messageSourceNotificationFactory) {
content = new Div();
requireNonNull(projectInformationService);
requireNonNull(experimentInformationService);
requireNonNull(addExperimentToProjectService);
this.messageSourceNotificationFactory = requireNonNull(messageSourceNotificationFactory,
"messageSourceNotificationFactory must not be null");
this.cancelConfirmationDialogFactory = requireNonNull(cancelConfirmationDialogFactory,
"cancelConfirmationDialogFactory must not be null");
this.speciesLookupService = speciesLookupService;
this.addExperimentToProjectService = addExperimentToProjectService;
this.userPermissions = requireNonNull(userPermissions, "userPermissions must not be null");
Expand Down Expand Up @@ -321,7 +327,14 @@ private void showAddExperimentDialog() {
var creationDialog = new AddExperimentDialog(speciesLookupService,
terminologyService);
creationDialog.addExperimentAddEventListener(this::onExperimentAddEvent);
creationDialog.addCancelListener(event -> event.getSource().close());
creationDialog.addCancelListener(cancelEvent -> {
NotificationDialog confirmationDialog = cancelConfirmationDialogFactory.cancelConfirmationDialog(
it -> creationDialog.close(),
"experiment.create",
getLocale()
);
confirmationDialog.open();
});
creationDialog.open();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ protected void onConfirmClicked(ClickEvent<Button> clickEvent) {

@Override
protected void onCancelClicked(ClickEvent<Button> clickEvent) {
close();
//as this is the first listener called on cancel event, no closing should happen here.
//If this method closes the dialog, the calling code has no opportunity to prevent that.
}

public void setExperiment(ExperimentDraft experiment) {
Expand All @@ -150,12 +151,6 @@ public void addCancelListener(ComponentEventListener<CancelEvent> listener) {
addListener(CancelEvent.class, listener);
}

@Override
public void close() {
super.close();
reset();
}

public static class CancelEvent extends UserCancelEvent<AddExperimentDialog> {

public CancelEvent(AddExperimentDialog source, boolean fromClient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import life.qbic.datamanager.views.general.Main;
import life.qbic.datamanager.views.general.download.OfferDownload;
import life.qbic.datamanager.views.general.download.QualityControlDownload;
import life.qbic.datamanager.views.notifications.CancelConfirmationDialogFactory;
import life.qbic.datamanager.views.notifications.MessageSourceNotificationFactory;
import life.qbic.datamanager.views.notifications.NotificationDialog;
import life.qbic.datamanager.views.notifications.Toast;
import life.qbic.datamanager.views.projects.project.ProjectMainLayout;
import life.qbic.datamanager.views.projects.project.experiments.ExperimentInformationMain;
Expand Down Expand Up @@ -89,6 +91,7 @@ public class ProjectInformationMain extends Main implements BeforeEnterObserver
private final QualityControlDownload qualityControlDownload;
private final OfferListComponent offerListComponent;
private final QualityControlListComponent qualityControlListComponent;
private final CancelConfirmationDialogFactory cancelConfirmationDialogFactory;
private final MessageSourceNotificationFactory messageSourceNotificationFactory;
private final TerminologyService terminologyService;
private Context context;
Expand All @@ -102,6 +105,7 @@ public ProjectInformationMain(@Autowired ProjectDetailsComponent projectDetailsC
@Autowired ProjectPurchaseService projectPurchaseService,
@Autowired QualityControlService qualityControlService,
@Autowired TerminologyService terminologyService,
CancelConfirmationDialogFactory cancelConfirmationDialogFactory,
MessageSourceNotificationFactory messageSourceNotificationFactory) {
this.projectDetailsComponent = requireNonNull(projectDetailsComponent,
"projectDetailsComponent must not be null");
Expand All @@ -120,7 +124,8 @@ public ProjectInformationMain(@Autowired ProjectDetailsComponent projectDetailsC
"qualityControlService must not be null");
this.messageSourceNotificationFactory = requireNonNull(messageSourceNotificationFactory,
"messageSourceNotificationFactory must not be null");

this.cancelConfirmationDialogFactory = requireNonNull(cancelConfirmationDialogFactory,
"cancelConfirmationDialogFactory must not be null");

offerListComponent = getConfiguredOfferList();
qualityControlListComponent = getConfiguredQualityControlList();
Expand Down Expand Up @@ -323,7 +328,14 @@ private void routeToExperiment(ExperimentId experimentId) {
private void showAddExperimentDialog() {
var creationDialog = new AddExperimentDialog(ontologyTermInformationService, terminologyService);
creationDialog.addExperimentAddEventListener(this::onExperimentAddEvent);
creationDialog.addCancelListener(event -> event.getSource().close());
creationDialog.addCancelListener(cancelEvent -> {
NotificationDialog confirmationDialog = cancelConfirmationDialogFactory.cancelConfirmationDialog(
it -> creationDialog.close(),
"experiment.create",
getLocale()
);
confirmationDialog.open();
});
creationDialog.open();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ project.create.cancel-confirmation.confirm-text=Discard project creation
#sample-batch.edit.cancel-confirmation.message.type=TBD
#sample-batch.edit.cancel-confirmation.message.text=TBD
#sample-batch.edit.cancel-confirmation.confirm-text=TBD
experiment.create.cancel-confirmation.title=Discard new experiment creation?
experiment.create.cancel-confirmation.message.type=text
experiment.create.cancel-confirmation.message.text=You will lose all the information entered for this experiment.
experiment.create.cancel-confirmation.confirm-text=Discard experiment creation

0 comments on commit 541a070

Please sign in to comment.