diff --git a/bundles/at.medevit.elexis.agenda.ui/src/at/medevit/elexis/agenda/ui/composite/AppointmentDetailComposite.java b/bundles/at.medevit.elexis.agenda.ui/src/at/medevit/elexis/agenda/ui/composite/AppointmentDetailComposite.java index 1e42982927..3efa713f2e 100644 --- a/bundles/at.medevit.elexis.agenda.ui/src/at/medevit/elexis/agenda/ui/composite/AppointmentDetailComposite.java +++ b/bundles/at.medevit.elexis.agenda.ui/src/at/medevit/elexis/agenda/ui/composite/AppointmentDetailComposite.java @@ -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") @@ -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); @@ -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); @@ -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()); diff --git a/bundles/at.medevit.elexis.agenda.ui/src/at/medevit/elexis/agenda/ui/composite/EmailComposite.java b/bundles/at.medevit.elexis.agenda.ui/src/at/medevit/elexis/agenda/ui/composite/EmailComposite.java index dd6f6f067e..60fbb4ddfe 100644 --- a/bundles/at.medevit.elexis.agenda.ui/src/at/medevit/elexis/agenda/ui/composite/EmailComposite.java +++ b/bundles/at.medevit.elexis.agenda.ui/src/at/medevit/elexis/agenda/ui/composite/EmailComposite.java @@ -171,8 +171,8 @@ private void selectSavedEmailTemplate() { } findAndSelectTemplate(savedTemplate, templates); } - - private void findAndSelectTemplate(String savedTemplate, List templates) { + + private void findAndSelectTemplate(String savedTemplate, List templates) { if (savedTemplate != null && !savedTemplate.trim().isEmpty()) { for (ITextTemplate template : templates) { if (savedTemplate.equals(template.getName())) { @@ -183,8 +183,8 @@ private void findAndSelectTemplate(String savedTemplate, List tem } emailTemplatesViewer.setSelection(new StructuredSelection(templates.get(0))); } - - public Object getSelectedTemplate() { + + public Object getSelectedTemplate() { return (emailTemplatesViewer != null && emailTemplatesViewer.getStructuredSelection() != null) ? emailTemplatesViewer.getStructuredSelection().getFirstElement() : null; @@ -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 @@ -298,7 +298,7 @@ public IPatient patient() { } } - public EmailDetails extractEmailDetails() { + public EmailDetails extractEmailDetails() { ITextTemplate selectedTemplateViewerDetails = getSelectedEmailTemplateViewerDetails(); if (selectedTemplateViewerDetails != null) { IPatient selectedPatient = getSelectedPatient(); @@ -308,4 +308,4 @@ public EmailDetails extractEmailDetails() { } return null; } -} +} \ No newline at end of file diff --git a/bundles/at.medevit.elexis.agenda.ui/src/at/medevit/elexis/agenda/ui/composite/Messages.java b/bundles/at.medevit.elexis.agenda.ui/src/at/medevit/elexis/agenda/ui/composite/Messages.java index 2bbe590ba6..58cfebbeda 100644 --- a/bundles/at.medevit.elexis.agenda.ui/src/at/medevit/elexis/agenda/ui/composite/Messages.java +++ b/bundles/at.medevit.elexis.agenda.ui/src/at/medevit/elexis/agenda/ui/composite/Messages.java @@ -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; + } diff --git a/bundles/at.medevit.elexis.agenda.ui/src/at/medevit/elexis/agenda/ui/dialog/AppointmentDialog.java b/bundles/at.medevit.elexis.agenda.ui/src/at/medevit/elexis/agenda/ui/dialog/AppointmentDialog.java index 40ec238c79..be618849fe 100644 --- a/bundles/at.medevit.elexis.agenda.ui/src/at/medevit/elexis/agenda/ui/dialog/AppointmentDialog.java +++ b/bundles/at.medevit.elexis.agenda.ui/src/at/medevit/elexis/agenda/ui/dialog/AppointmentDialog.java @@ -57,7 +57,6 @@ protected void okPressed() { sendEmailIfConfirmationChecked(); super.okPressed(); } - @Override protected void cancelPressed() { ContextServiceHolder.get().getRootContext().setNamed("sendMailDialog.taskDescriptor", null); @@ -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); diff --git a/bundles/ch.elexis.agenda/META-INF/MANIFEST.MF b/bundles/ch.elexis.agenda/META-INF/MANIFEST.MF index 3cead25458..2ed56ddab3 100644 --- a/bundles/ch.elexis.agenda/META-INF/MANIFEST.MF +++ b/bundles/ch.elexis.agenda/META-INF/MANIFEST.MF @@ -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, diff --git a/bundles/ch.elexis.agenda/src/ch/elexis/agenda/Messages.java b/bundles/ch.elexis.agenda/src/ch/elexis/agenda/Messages.java index 9d68b6b7b0..c9ed9c3407 100644 --- a/bundles/ch.elexis.agenda/src/ch/elexis/agenda/Messages.java +++ b/bundles/ch.elexis.agenda/src/ch/elexis/agenda/Messages.java @@ -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; diff --git a/bundles/ch.elexis.agenda/src/ch/elexis/agenda/preferences/AgendaDefinitionPreferencePage.java b/bundles/ch.elexis.agenda/src/ch/elexis/agenda/preferences/AgendaDefinitionPreferencePage.java index a810a2d550..75e2eef79e 100644 --- a/bundles/ch.elexis.agenda/src/ch/elexis/agenda/preferences/AgendaDefinitionPreferencePage.java +++ b/bundles/ch.elexis.agenda/src/ch/elexis/agenda/preferences/AgendaDefinitionPreferencePage.java @@ -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; @@ -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; @@ -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; @@ -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; @@ -57,8 +64,15 @@ public class AgendaDefinitionPreferencePage extends PreferencePage implements IW private java.util.List areas; private java.util.List appointmentTypes; private java.util.List appointmentStatus; + private java.util.List ret; + private java.util.List accounts; + private java.util.List accountsInput; + private java.util.List combined; + private java.util.List templates; private Button btnAvoidDoubleBooking; private ComboViewer comboViewerAreaType; + private ComboViewer appointmentTemplatesViewer, accountsViewer; + private String selectedTemplateName; /** * Create the preference page. @@ -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; @@ -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 getSendMailAccounts() { + ret = new ArrayList(); + 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 } diff --git a/bundles/ch.elexis.agenda/src/ch/elexis/agenda/preferences/PreferenceConstants.java b/bundles/ch.elexis.agenda/src/ch/elexis/agenda/preferences/PreferenceConstants.java index 5a53bc17d9..b02fbaf15c 100644 --- a/bundles/ch.elexis.agenda/src/ch/elexis/agenda/preferences/PreferenceConstants.java +++ b/bundles/ch.elexis.agenda/src/ch/elexis/agenda/preferences/PreferenceConstants.java @@ -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"; }