Skip to content

Commit

Permalink
adjust EditProjectInformationDialog.java closing
Browse files Browse the repository at this point in the history
  • Loading branch information
KochTobi committed Sep 3, 2024
1 parent a9b4d51 commit a432cc8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public EditProjectInformationDialog(ContactRepository contactRepository) {
List<Contact> knownContacts = contactRepository.findAll().stream().map(contact ->
new Contact(contact.fullName(), contact.emailAddress())).toList();

if(knownContacts.isEmpty()) {
if (knownContacts.isEmpty()) {
formLayout.hideContactBox();
} else {
formLayout.setKnownContacts(knownContacts);
Expand Down Expand Up @@ -91,13 +91,26 @@ 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 addProjectUpdateEventListener(ComponentEventListener<ProjectUpdateEvent> listener) {
addListener(ProjectUpdateEvent.class, listener);
}

public void addCancelListener(ComponentEventListener<CancelEvent> listener) {
addListener(CancelEvent.class, listener);
}

public static class CancelEvent extends
life.qbic.datamanager.views.events.UserCancelEvent<EditProjectInformationDialog> {

public CancelEvent(EditProjectInformationDialog source, boolean fromClient) {
super(source, fromClient);
}
}

/**
* <b>Project Update Event</b>
Expand Down Expand Up @@ -192,6 +205,7 @@ public Optional<Contact> getResponsiblePerson() {
public void setResponsiblePerson(Contact responsiblePerson) {
this.responsiblePerson = responsiblePerson;
}

public Contact getProjectManager() {
return projectManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import life.qbic.datamanager.views.Context;
import life.qbic.datamanager.views.general.PageArea;
import life.qbic.datamanager.views.general.funding.FundingEntry;
import life.qbic.datamanager.views.notifications.CancelConfirmationDialogFactory;
import life.qbic.datamanager.views.projects.edit.EditProjectInformationDialog;
import life.qbic.datamanager.views.projects.edit.EditProjectInformationDialog.ProjectInformation;
import life.qbic.datamanager.views.projects.edit.EditProjectInformationDialog.ProjectUpdateEvent;
Expand Down Expand Up @@ -63,19 +64,23 @@ public class ProjectDetailsComponent extends PageArea {
private final transient ExperimentInformationService experimentInformationService;
private final transient ContactRepository contactRepository;
private final UserPermissions userPermissions;
private final CancelConfirmationDialogFactory cancelConfirmationDialogFactory;
private Context context;

public ProjectDetailsComponent(@Autowired ProjectInformationService projectInformationService,
@Autowired ExperimentInformationService experimentInformationService,
@Autowired ContactRepository contactRepository,
@Autowired UserPermissions userPermissions) {
@Autowired UserPermissions userPermissions,
CancelConfirmationDialogFactory cancelConfirmationDialogFactory) {
this.projectInformationService = requireNonNull(projectInformationService,
"projectInformationService must not be null");
this.experimentInformationService = requireNonNull(experimentInformationService,
"experimentInformationService must not be null");
this.contactRepository = requireNonNull(contactRepository,
"contactRepository must not be null");
this.userPermissions = requireNonNull(userPermissions, "userPermissions must not be null");
this.cancelConfirmationDialogFactory = requireNonNull(cancelConfirmationDialogFactory,
"cancelConfirmationDialogFactory must not be null");
layoutComponent();
addListenerForNewEditEvent();
addClassName("project-details-component");
Expand Down Expand Up @@ -227,6 +232,10 @@ private void openProjectInformationDialog() {
EditProjectInformationDialog editProjectInformationDialog = generateEditProjectInformationDialog(
proj);
editProjectInformationDialog.addProjectUpdateEventListener(this::onProjectUpdateEvent);
editProjectInformationDialog.addCancelListener(
cancelEvent -> cancelConfirmationDialogFactory.cancelConfirmationDialog(
it -> editProjectInformationDialog.close(), "project.edit", getLocale())
.open());
editProjectInformationDialog.open();
}
, () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ project.create.cancel-confirmation.title=Discard new project creation?
project.create.cancel-confirmation.message.type=text
project.create.cancel-confirmation.message.text=You will lose all the information entered for this project.
project.create.cancel-confirmation.confirm-text=Discard project creation
project.edit.cancel-confirmation.title=Discard project changes?
project.edit.cancel-confirmation.message.type=text
project.edit.cancel-confirmation.message.text=You will lose all changes made to this project.
project.edit.cancel-confirmation.confirm-text=Discard changes
#sample-batch.edit.cancel-confirmation.title=TBD
#sample-batch.edit.cancel-confirmation.message.type=TBD
#sample-batch.edit.cancel-confirmation.message.text=TBD
Expand All @@ -20,7 +24,7 @@ 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
experiment.edit.cancel-confirmation.title=Discard experiment editing?
experiment.edit.cancel-confirmation.title=Discard experiment changes?
experiment.edit.cancel-confirmation.message.type=text
experiment.edit.cancel-confirmation.message.text=You abort the editing process for this experiment. All information entered will be lost..
experiment.edit.cancel-confirmation.confirm-text=Discard experiment editing
experiment.edit.cancel-confirmation.message.text=You will lose all changes made to this experiment.
experiment.edit.cancel-confirmation.confirm-text=Discard changes

0 comments on commit a432cc8

Please sign in to comment.