Commit de1c0908 authored by Thomas Huster's avatar Thomas Huster
Browse files

[16427] save template dialog find existing templates and update view

parent b1e1cd7a
Loading
Loading
Loading
Loading
+6 −17
Original line number Diff line number Diff line
@@ -60,9 +60,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.elexis.core.constants.Preferences;
import ch.elexis.core.constants.StringConstants;
import ch.elexis.core.data.activator.CoreHub;
import ch.elexis.core.data.constants.ExtensionPointConstantsData;
import ch.elexis.core.data.events.ElexisEvent;
import ch.elexis.core.data.events.ElexisEventDispatcher;
import ch.elexis.core.data.interfaces.text.ITextResolver;
import ch.elexis.core.data.interfaces.text.ReplaceCallback;
@@ -948,6 +948,8 @@ public class TextContainer {
			// set sticker for this template if not to ask for addressee
			DocumentSelectDialog.setDontAskForAddresseeForThisTemplate(brief,
				std.dontShowAddresseeSelection);
			ElexisEventDispatcher.getInstance()
				.fire(new ElexisEvent(null, Brief.class, ElexisEvent.EVENT_RELOAD));
		}
	}
	
@@ -1093,25 +1095,12 @@ public class TextContainer {
					selectedMand = lMands.get(i - 1);
				}
			}
			Query<Brief> qbe = new Query<Brief>(Brief.class);
			qbe.add(Brief.FLD_TYPE, Query.EQUALS, Brief.TEMPLATE);
			if (selectedMand != null) {
				qbe.startGroup();
				qbe.add(Brief.FLD_DESTINATION_ID, Query.EQUALS, selectedMand.getId());
				qbe.or();
				qbe.add(Brief.FLD_DESTINATION_ID, Query.EQUALS, StringTool.leer);
				qbe.endGroup();
				qbe.and();
			}
			qbe.add(Brief.FLD_GELOESCHT, Query.NOT_EQUAL, StringConstants.ONE);
			qbe.add(Brief.FLD_SUBJECT, Query.EQUALS, title);
			List<Brief> l = qbe.execute();
			if (l.size() > 0) {
			List<Brief> existing = TextTemplate.findExistingTemplates(bSysTemplate, title, null, (selectedMand != null ? selectedMand.getId() : null));
			if (existing.size() > 0) {
				if (MessageDialog.openQuestion(getShell(),
					Messages.TextContainer_TemplateExistsCaption,
					Messages.TextContainer_TemplateExistsBody)) {
					Brief old = l.get(0);
					old.delete();
					existing.forEach(b -> b.delete());
				} else {
					return;
				}
+16 −8
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormText;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.part.ViewPart;
import org.slf4j.LoggerFactory;

import ch.elexis.core.constants.Preferences;
import ch.elexis.core.data.activator.CoreHub;
@@ -77,17 +78,19 @@ public class TextTemplateView extends ViewPart {
	private List<TextTemplate> templates;
	private List<TextTemplate> requiredTemplates;
	
	public TextTemplateView(){
		initActiveTextPlugin();
		loadRequiredAndExistingTemplates();
		
		ElexisEventDispatcher.getInstance()
			.addListeners(new ElexisUiEventListenerImpl(Brief.class, ElexisEvent.EVENT_RELOAD) {
	private ElexisUiEventListenerImpl reloadListener =
		new ElexisUiEventListenerImpl(Brief.class, ElexisEvent.EVENT_RELOAD) {
			@Override
			public void runInUi(ElexisEvent ev){
				refresh();
			}
		});
		};
	
	public TextTemplateView(){
		initActiveTextPlugin();
		loadRequiredAndExistingTemplates();
		
		ElexisEventDispatcher.getInstance().addListeners(reloadListener);
	}
	
	private void loadRequiredAndExistingTemplates(){
@@ -530,6 +533,11 @@ public class TextTemplateView extends ViewPart {
		// TODO Auto-generated method stub
	}
	
	@Override
	public void dispose(){
		ElexisEventDispatcher.getInstance().removeListeners(reloadListener);
	}
	
	private void initActiveTextPlugin(){
		if (plugin == null) {
			String ExtensionToUse = CoreHub.localCfg.get(Preferences.P_TEXTMODUL, null);
@@ -591,7 +599,7 @@ public class TextTemplateView extends ViewPart {
			}
		}
		templates = txtTemplates;
		if (tableViewer != null) {
		if (tableViewer != null && !tableViewer.getControl().isDisposed()) {
			tableViewer.setInput(templates);
			tableViewer.refresh(true);
		}