Skip to content

Commit

Permalink
[25736] E-mail dispatch option in the appointment creation dialog (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daksic28 authored and huthomas committed Dec 14, 2023
1 parent 32baf88 commit eb6cf82
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ public void focusGained(FocusEvent e) {
controlDecoration.showHoverText(Messages.AppointmentDetailComposite_search_contact_via_fields_hover);
}
});

ContentProposalAdapter cppa = new ContentProposalAdapter(txtPatSearch, new TextContentAdapter(), aopp, null,
null);
aopp.configureContentProposalAdapter(cppa);

cppa.addContentProposalListener(new IContentProposalListener() {

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -369,11 +369,11 @@ public void widgetSelected(SelectionEvent e) {
gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gd.widthHint = 80;
comboType.setLayoutData(gd);

txtReason = new Text(compTypeReason, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2);
txtReason.setLayoutData(gd);

comboStatus = new Combo(compTypeReason, SWT.DROP_DOWN);
comboStatus.setItems(appointmentService.getStates().toArray(new String[appointmentService.getStates().size()]));
gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
Expand Down Expand Up @@ -429,7 +429,7 @@ private void reloadContactLabel() {
b.append(StringUtils.SPACE);
b.append(Optional.ofNullable(c.get().getDescription3()).orElse(StringUtils.EMPTY));
if (c.get().isPatient()) {

IPatient p = CoreModelServiceHolder.get().load(c.get().getId(), IPatient.class).get();
if (p.getDateOfBirth() != null) {
b.append(StringUtils.LF);
Expand Down Expand Up @@ -636,7 +636,7 @@ public IAppointment setToModel() {
appointment.setState(comboStatus.getText());
appointment.setType(comboType.getText());
appointment.setSchedule(comboArea.getText());

appointment.setReason(txtReason.getText());
if (txtDataIsMatchingContact()) {
appointment.setSubjectOrPatient(((IContact) txtPatSearch.getData()).getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ private void selectSavedEmailTemplate() {
}
findAndSelectTemplate(savedTemplate, templates);
}

private void findAndSelectTemplate(String savedTemplate, List<ITextTemplate> templates) {
private void findAndSelectTemplate(String savedTemplate, List<ITextTemplate> templates) {
if (savedTemplate != null && !savedTemplate.trim().isEmpty()) {
for (ITextTemplate template : templates) {
if (savedTemplate.equals(template.getName())) {
Expand All @@ -183,8 +183,8 @@ private void findAndSelectTemplate(String savedTemplate, List<ITextTemplate> tem
}
emailTemplatesViewer.setSelection(new StructuredSelection(templates.get(0)));
}

public Object getSelectedTemplate() {
public Object getSelectedTemplate() {
return (emailTemplatesViewer != null && emailTemplatesViewer.getStructuredSelection() != null)
? emailTemplatesViewer.getStructuredSelection().getFirstElement()
: null;
Expand All @@ -200,7 +200,7 @@ private String calculateTestValue() {
return textReplacement.performReplacement(ContextServiceHolder.get().getRootContext(), TEMPLATE_TEXT);
}

private MessageDialog createMessageDialog(Shell shell) {
private MessageDialog createMessageDialog(Shell shell) {
return new MessageDialog(shell, Messages.Warnung, null, Messages.Warning_Kein_Pea, MessageDialog.WARNING,
new String[] { Messages.Core_Ok }, 0) {
@Override
Expand Down Expand Up @@ -298,7 +298,7 @@ public IPatient patient() {
}
}

public EmailDetails extractEmailDetails() {
public EmailDetails extractEmailDetails() {
ITextTemplate selectedTemplateViewerDetails = getSelectedEmailTemplateViewerDetails();
if (selectedTemplateViewerDetails != null) {
IPatient selectedPatient = getSelectedPatient();
Expand All @@ -308,4 +308,4 @@ public EmailDetails extractEmailDetails() {
}
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,12 @@ public class Messages {
public static String AppointmentDetailComposite_starting_from = ch.elexis.core.l10n.Messages.Core_Since;
public static String AppointmentDetailComposite_tag = ch.elexis.core.l10n.Messages.AppointmentDetailComposite_tag;
public static String AppointmentDetailComposite_until = ch.elexis.core.l10n.Messages.AppointmentDetailComposite_until;
public static String Appointment_Confirmation = ch.elexis.core.l10n.Messages.Appointment_Confirmation;
public static String Core_Ok = ch.elexis.core.l10n.Messages.Core_Ok;
public static String Core_E_Mail = ch.elexis.core.l10n.Messages.Core_E_Mail;
public static String Core_Temlate = ch.elexis.core.l10n.Messages.Core_Temlate;
public static String Warnung = ch.elexis.core.l10n.Messages.Warning;
public static String Warning_Kein_Pea = ch.elexis.core.l10n.Messages.Warning_No_Pea;


}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ protected void okPressed() {
sendEmailIfConfirmationChecked();
super.okPressed();
}

@Override
protected void cancelPressed() {
ContextServiceHolder.get().getRootContext().setNamed("sendMailDialog.taskDescriptor", null);
Expand All @@ -69,21 +68,21 @@ protected boolean isResizable() {
return true;
}

private void initializeAppointmentIfNecessary() {
private void initializeAppointmentIfNecessary() {
if (appointment == null) {
appointment = CoreModelServiceHolder.get().create(IAppointment.class);
appointment.setStartTime(LocalDateTime.now());
}
}

private void saveAndReloadAppointment() {
private void saveAndReloadAppointment() {
if (appointment != null) {
CoreModelServiceHolder.get().save(detailComposite.setToModel());
}
eventBroker.post(ElexisEventTopics.EVENT_RELOAD, IAppointment.class);
}

private void sendEmailIfConfirmationChecked() {
private void sendEmailIfConfirmationChecked() {
if (detailComposite.getEmailCheckboxStatus()) {
EmailDetails emailDetails = detailComposite.getEmailDeteils();
emailSender.sendEmail(emailDetails, appointment);
Expand Down
4 changes: 3 additions & 1 deletion bundles/ch.elexis.agenda/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Export-Package: ch.elexis.agenda.data,
ch.elexis.agenda.util,
ch.elexis.dialogs
Bundle-RequiredExecutionEnvironment: JavaSE-11
Import-Package: com.google.common.cache;version="15.0.0",
Import-Package: ch.elexis.core.mail,
ch.elexis.core.mail.ui.client,
com.google.common.cache;version="15.0.0",
com.ibm.icu.util,
javax.inject;version="1.0.0",
org.eclipse.e4.ui.di,
Expand Down
3 changes: 3 additions & 0 deletions bundles/ch.elexis.agenda/src/ch/elexis/agenda/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public final class Messages {
public static String AgendaImages_cannotCopy = ch.elexis.core.l10n.Messages.AgendaImages_cannotCopy;
public static String AgendaImages_6 = ch.elexis.core.l10n.Messages.AgendaImages_6;
public static String AgendaImages_7 = ch.elexis.core.l10n.Messages.AgendaImages_7;
public static String AgendaStandard_E_Mail = ch.elexis.core.l10n.Messages.Core_Standard_E_Mail;
public static String AgendaStandard_E_Mail_Template = ch.elexis.core.l10n.Messages.Core_Standard_E_Mail_Template;
public static String AgendaStandard_E_Mail_Title = ch.elexis.core.l10n.Messages.Core_Standard_E_Mail_Title;
public static String Tageseinteilung_dayPlanning = ch.elexis.core.l10n.Messages.Tageseinteilung_dayPlanning;
public static String Tageseinteilung_praxis = ch.elexis.core.l10n.Messages.Core_Practice;
public static String Tageseinteilung_enterPeriods = ch.elexis.core.l10n.Messages.Tageseinteilung_enterPeriods;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.elexis.agenda.preferences;

import java.util.ArrayList;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.jface.action.MenuManager;
Expand All @@ -9,6 +10,7 @@
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.jface.viewers.StructuredSelection;
Expand All @@ -21,6 +23,7 @@
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.List;
Expand All @@ -30,6 +33,10 @@

import ch.elexis.agenda.Messages;
import ch.elexis.core.data.activator.CoreHub;
import ch.elexis.core.mail.MailAccount.TYPE;
import ch.elexis.core.mail.MailTextTemplate;
import ch.elexis.core.mail.ui.client.MailClientComponent;
import ch.elexis.core.model.ITextTemplate;
import ch.elexis.core.model.agenda.AreaType;
import ch.elexis.core.services.holder.AppointmentServiceHolder;
import ch.elexis.core.services.holder.ConfigServiceHolder;
Expand Down Expand Up @@ -57,8 +64,15 @@ public class AgendaDefinitionPreferencePage extends PreferencePage implements IW
private java.util.List<String> areas;
private java.util.List<String> appointmentTypes;
private java.util.List<String> appointmentStatus;
private java.util.List<String> ret;
private java.util.List<String> accounts;
private java.util.List<String> accountsInput;
private java.util.List<Object> combined;
private java.util.List<ITextTemplate> templates;
private Button btnAvoidDoubleBooking;
private ComboViewer comboViewerAreaType;
private ComboViewer appointmentTemplatesViewer, accountsViewer;
private String selectedTemplateName;

/**
* Create the preference page.
Expand Down Expand Up @@ -251,7 +265,9 @@ public void mouseDown(MouseEvent e) {
btnAvoidDoubleBooking.setText(Messages.AgendaDefinitionen_AvoidPatientDoubleBooking);
btnAvoidDoubleBooking.setSelection(CoreHub.localCfg.get(PreferenceConstants.AG_AVOID_PATIENT_DOUBLE_BOOKING,
PreferenceConstants.AG_AVOID_PATIENT_DOUBLE_BOOKING_DEFAULT));

Label spacing = new Label(container, SWT.NONE);
emailConfirmationsGroup(container);
loadCombos();
refresh();

return container;
Expand All @@ -274,9 +290,113 @@ protected void performApply() {
super.performApply();
}

private void emailConfirmationsGroup(Composite parentComposite) {
Group emailConfirmationsGroup = new Group(parentComposite, SWT.NONE);
emailConfirmationsGroup.setText(Messages.AgendaStandard_E_Mail_Title);
emailConfirmationsGroup.setLayout(new GridLayout(2, false));
emailConfirmationsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
new Label(emailConfirmationsGroup, SWT.NONE).setText(Messages.AgendaStandard_E_Mail);
accountsViewer = new ComboViewer(emailConfirmationsGroup);
accountsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
accountsViewer.setContentProvider(ArrayContentProvider.getInstance());
accountsViewer.setLabelProvider(new LabelProvider());
Label emailTemplatesLabel = new Label(emailConfirmationsGroup, SWT.NONE);
emailTemplatesLabel.setText(Messages.AgendaStandard_E_Mail_Template);
emailTemplatesLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
LabelProvider templateLabelProvider = new LabelProvider() {
@Override
public String getText(Object element) {
return getTemplateText(element);
}
};
appointmentTemplatesViewer = new ComboViewer(emailConfirmationsGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
appointmentTemplatesViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
appointmentTemplatesViewer.setContentProvider(ArrayContentProvider.getInstance());
appointmentTemplatesViewer.setLabelProvider(templateLabelProvider);
appointmentTemplatesViewer.addSelectionChangedListener(event -> {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (selection != null && !selection.isEmpty()) {
Object element = selection.getFirstElement();
templateLabelProvider.getText(element);
selectedTemplateName = templateLabelProvider.getText(element);
}
});
loadCombos();
}

private void loadCombos() {
accountsInput = getSendMailAccounts();
accountsInput.add(0, "");
accountsViewer.setInput(accountsInput);
combined = new ArrayList<>();
combined.add("");
combined.addAll(MailTextTemplate.load());
appointmentTemplatesViewer.setInput(combined);
appointmentTemplatesViewer.refresh();
loadSavedPreferences();
}

private java.util.List<String> getSendMailAccounts() {
ret = new ArrayList<String>();
accounts = MailClientComponent.getMailClient().getAccountsLocal();
ret.addAll(accounts.stream().filter(aid -> MailClientComponent.getMailClient().getAccount(aid).isPresent())
.filter(aid -> MailClientComponent.getMailClient().getAccount(aid).get().getType() == TYPE.SMTP)
.collect(Collectors.toList()));
accounts = MailClientComponent.getMailClient().getAccounts();
ret.addAll(accounts.stream().filter(aid -> MailClientComponent.getMailClient().getAccount(aid).isPresent())
.filter(aid -> MailClientComponent.getMailClient().getAccount(aid).get().getType() == TYPE.SMTP)
.collect(Collectors.toList()));
return ret;
}

@Override
public boolean performOk() {
IStructuredSelection selectedAccount = accountsViewer.getStructuredSelection();
String selectedTemplate = selectedTemplateName;
if (selectedAccount != null) {
ConfigServiceHolder.get().set(PreferenceConstants.PREF_DEFAULT_MAIL_ACCOUNT_APPOINTMENT,
(String) selectedAccount.getFirstElement());
}
if (selectedTemplate != null) {
String template = selectedTemplateName;
ConfigServiceHolder.get().set(PreferenceConstants.PREF_DEFAULT_MAIL_ACCOUNT_APPOINTMENT_TEMPLATE, template);
}
return super.performOk();
}

private void loadSavedPreferences() {
String savedAccount = ConfigServiceHolder.get().get(PreferenceConstants.PREF_DEFAULT_MAIL_ACCOUNT_APPOINTMENT,
null);
if (savedAccount != null) {
accountsViewer.setSelection(new StructuredSelection(savedAccount));
}
String savedTemplate = ConfigServiceHolder.get()
.get(PreferenceConstants.PREF_DEFAULT_MAIL_ACCOUNT_APPOINTMENT_TEMPLATE, null);
if (savedTemplate != null) {
templates = MailTextTemplate.load();
for (ITextTemplate template : templates) {
if (savedTemplate.equals(template.getName())) {
appointmentTemplatesViewer.setSelection(new StructuredSelection(template));
break;
}
}
}
}

private String getTemplateText(Object element) {
if (element instanceof ITextTemplate) {
ITextTemplate template = (ITextTemplate) element;
String mandatorLabel = (template.getMandator() != null) ? " (" + template.getMandator().getLabel() + ")"
: StringUtils.EMPTY;
return template.getName() + mandatorLabel;
}
return "";
}

/**
* Initialize the preference page.
*/
@Override
public void init(IWorkbench workbench) {
// Initialize the preference page
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ public class PreferenceConstants {

public static final String AG_AVOID_PATIENT_DOUBLE_BOOKING = "agenda/patient/doppelteTerminvergabeVermeiden";
public static final boolean AG_AVOID_PATIENT_DOUBLE_BOOKING_DEFAULT = false;
public static final String PREF_DEFAULT_MAIL_ACCOUNT_APPOINTMENT = "agenda/appointment";
public static final String PREF_DEFAULT_MAIL_ACCOUNT_APPOINTMENT_TEMPLATE = "agenda/appointmenttemplate";
public static final String PREF_DEFAULT_MAIL_ACCOUNT = "account";
}

0 comments on commit eb6cf82

Please sign in to comment.