Commit d43a1ed4 authored by Thomas Huster's avatar Thomas Huster

[20758] use local task service component instead of services holder

parent 8d88c960
Pipeline #15416 passed with stages
in 8 minutes and 9 seconds
......@@ -5,10 +5,14 @@ Bundle-SymbolicName: at.medevit.elexis.outbox.ui;singleton:=true
Bundle-Version: 3.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: ch.elexis.core.documents,
ch.elexis.core.mail,
ch.elexis.core.model,
ch.elexis.core.services.holder,
ch.elexis.core.tasks.model,
ch.rgw.io,
org.apache.commons.io;version="2.4.0",
org.apache.commons.lang;version="2.6.0",
org.json,
org.slf4j
Require-Bundle: at.medevit.elexis.outbox;bundle-version="1.0.0",
org.eclipse.ui;bundle-version="3.7.0",
......@@ -17,5 +21,7 @@ Require-Bundle: at.medevit.elexis.outbox;bundle-version="1.0.0",
ch.elexis.core.ui;bundle-version="3.2.0",
ch.elexis.core.ui.icons;bundle-version="3.3.0",
org.eclipse.core.expressions;bundle-version="3.2.0"
Service-Component: OSGI-INF/outboxConsumer.xml
Service-Component: OSGI-INF/outboxConsumer.xml,
OSGI-INF/at.medevit.elexis.outbox.ui.OutboxServiceComponent.xml,
OSGI-INF/at.medevit.elexis.outbox.ui.TaskServiceComponent.xml
Bundle-ActivationPolicy: lazy
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="at.medevit.elexis.outbox.ui">
<implementation class="at.medevit.elexis.outbox.ui.OutboxServiceComponent" />
<reference bind="setService" cardinality="1..1" interface="at.medevit.elexis.outbox.model.IOutboxElementService" name="IOutboxElementService" policy="static" unbind="unsetService" />
</scr:component>
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="at.medevit.elexis.outbox.ui.OutboxServiceComponent">
<reference bind="setService" interface="at.medevit.elexis.outbox.model.IOutboxElementService" name="Service" unbind="unsetService"/>
<implementation class="at.medevit.elexis.outbox.ui.OutboxServiceComponent"/>
</scr:component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="at.medevit.elexis.outbox.ui.TaskServiceComponent">
<reference bind="setService" interface="ch.elexis.core.tasks.model.ITaskService" name="Service" unbind="unsetService"/>
<implementation class="at.medevit.elexis.outbox.ui.TaskServiceComponent"/>
</scr:component>
\ No newline at end of file
......@@ -130,6 +130,10 @@
class="at.medevit.elexis.outbox.ui.DefaultOutboxElementLabelProvider"
id="at.medevit.elexis.outbox.ui.defaultOutboxElementLabelProvider">
</uiprovider>
<uiprovider
class="at.medevit.elexis.outbox.ui.CoreOutboxElementLabelProvider"
id="at.medevit.elexis.outbox.ui.CoreOutboxElementLabelProvider">
</uiprovider>
</extension>
<extension
point="org.eclipse.core.expressions.propertyTesters">
......
package at.medevit.elexis.outbox.ui;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.slf4j.LoggerFactory;
import at.medevit.elexis.outbox.model.IOutboxElement;
import at.medevit.elexis.outbox.model.OutboxElementType;
import at.medevit.elexis.outbox.ui.part.provider.IOutboxElementUiProvider;
import ch.elexis.core.mail.MailMessage;
import ch.elexis.core.model.IDocument;
import ch.elexis.core.model.tasks.IIdentifiedRunnable;
import ch.elexis.core.tasks.model.ITaskDescriptor;
import ch.elexis.core.ui.icons.Images;
public class CoreOutboxElementLabelProvider implements IOutboxElementUiProvider {
private CoreLabelProvider labelProvider;
private Map<String, IIdentifiedRunnable> identifiedRunnablesMap;
public CoreOutboxElementLabelProvider(){
labelProvider = new CoreLabelProvider();
identifiedRunnablesMap = buildIdentifiedRunnablesMap();
}
private Map<String, IIdentifiedRunnable> buildIdentifiedRunnablesMap(){
List<IIdentifiedRunnable> available = TaskServiceComponent.get().getIdentifiedRunnables();
if (available != null && !available.isEmpty()) {
Map<String, IIdentifiedRunnable> ret = new HashMap<>();
available.stream().forEach(ir -> ret.put(ir.getId(), ir));
return ret;
}
return Collections.emptyMap();
}
@Override
public ImageDescriptor getFilterImage(){
// TODO Auto-generated method stub
return null;
}
@Override
public ViewerFilter getFilter(){
// TODO Auto-generated method stub
return null;
}
@Override
public LabelProvider getLabelProvider(){
return labelProvider;
}
@Override
public IColorProvider getColorProvider(){
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isProviderFor(IOutboxElement element){
OutboxElementType elementType = OutboxElementType.parseType(element.getUri());
if (OutboxElementType.DOC.equals(elementType)) {
return true;
} else if (OutboxElementType.DB.equals(elementType)) {
return element.getObject() instanceof ITaskDescriptor;
}
return false;
}
@Override
public void doubleClicked(IOutboxElement element){
OutboxElementType elementType =
OutboxElementType.parseType(((IOutboxElement) element).getUri());
if (OutboxElementType.DB.equals(elementType)) {
if (((IOutboxElement) element).getObject() instanceof ITaskDescriptor) {
ITaskDescriptor taskDescriptor =
(ITaskDescriptor) ((IOutboxElement) element).getObject();
if ("sendMailFromContext".equals(taskDescriptor.getIdentifiedRunnableId())) {
MailMessage msg =
MailMessage.fromJson(taskDescriptor.getRunContext().get("message"));
// call open mail message dialog command
}
}
} else if (OutboxElementType.DOC.equals(elementType)) {
IDocument document = (IDocument) element.getObject();
if (document != null) {
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().showView("ch.elexis.core.ui.documents.views.DocumentsView");
} catch (PartInitException e) {
LoggerFactory.getLogger(getClass()).error("Could not open documents view", e);
}
}
}
}
class CoreLabelProvider extends LabelProvider {
private Image taskImage;
@Override
public String getText(Object element){
OutboxElementType elementType =
OutboxElementType.parseType(((IOutboxElement) element).getUri());
if (OutboxElementType.DB.equals(elementType)) {
if (((IOutboxElement) element).getObject() instanceof ITaskDescriptor) {
return getTaskDescriptorText(
(ITaskDescriptor) ((IOutboxElement) element).getObject());
}
}
return ((IOutboxElement) element).getLabel();
}
private String getTaskDescriptorText(ITaskDescriptor taskDescriptor){
StringBuilder sb = new StringBuilder();
IIdentifiedRunnable ir =
identifiedRunnablesMap.get(taskDescriptor.getIdentifiedRunnableId());
sb.append(ir.getLocalizedDescription());
if ("sendMailFromContext".equals(taskDescriptor.getIdentifiedRunnableId())) {
MailMessage msg =
MailMessage.fromJson(taskDescriptor.getRunContext().get("message"));
if (msg != null) {
sb.append(" an ").append(msg.getTo());
if (StringUtils.isNotBlank(msg.getCc())) {
sb.append(", cc ").append(msg.getCc());
}
return sb.toString();
}
}
return sb.toString();
}
@Override
public Image getImage(Object element){
OutboxElementType elementType =
OutboxElementType.parseType(((IOutboxElement) element).getUri());
if (OutboxElementType.DOC.equals(elementType)) {
return Images.IMG_DOCUMENT_TEXT.getImage();
} else if (OutboxElementType.DB.equals(elementType)) {
if (((IOutboxElement) element).getObject() instanceof ITaskDescriptor) {
return getTaskImage();
}
}
return null;
}
private Image getTaskImage(){
if (taskImage == null) {
try {
taskImage = ImageDescriptor
.createFromURL(new URL(
"platform:/plugin/ch.elexis.core.ui.tasks/rsc/icons/screwdriver.png"))
.createImage();
} catch (MalformedURLException e) {
LoggerFactory.getLogger(getClass()).warn("Error loading task image ", e);
}
}
return taskImage;
}
}
}
......@@ -5,6 +5,7 @@ import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.program.Program;
import at.medevit.elexis.outbox.model.IOutboxElement;
import at.medevit.elexis.outbox.model.OutboxElementType;
......@@ -43,13 +44,17 @@ public class DefaultOutboxElementLabelProvider implements IOutboxElementUiProvid
@Override
public boolean isProviderFor(IOutboxElement element){
OutboxElementType elementType = OutboxElementType.parseType(element.getUri());
return OutboxElementType.FILE.equals(elementType)
|| OutboxElementType.DB.equals(elementType)
|| OutboxElementType.DOC.equals(elementType);
return OutboxElementType.FILE.equals(elementType);
}
@Override
public void doubleClicked(IOutboxElement element){}
public void doubleClicked(IOutboxElement element){
OutboxElementType elementType =
OutboxElementType.parseType(((IOutboxElement) element).getUri());
if (OutboxElementType.FILE.equals(elementType)) {
Program.launch(((IOutboxElement) element).getUri());
}
}
class DefaultLabelProvider extends LabelProvider {
@Override
......@@ -62,11 +67,7 @@ public class DefaultOutboxElementLabelProvider implements IOutboxElementUiProvid
OutboxElementType elementType =
OutboxElementType.parseType(((IOutboxElement) element).getUri());
if (OutboxElementType.FILE.equals(elementType)) {
return Images.IMG_BULLET_YELLOW.getImage();
} else if (OutboxElementType.DOC.equals(elementType)) {
return Images.IMG_BULLET_GREY.getImage();
} else if (OutboxElementType.DB.equals(elementType)) {
return Images.IMG_BULLET_GREEN.getImage();
return Images.IMG_DOCUMENT.getImage();
}
return null;
}
......
......@@ -10,15 +10,20 @@
*******************************************************************************/
package at.medevit.elexis.outbox.ui;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import at.medevit.elexis.outbox.model.IOutboxElementService;
@Component
public class OutboxServiceComponent {
private static IOutboxElementService service;
public static IOutboxElementService getService(){
public static IOutboxElementService get(){
return service;
}
@Reference
public synchronized void setService(IOutboxElementService service){
OutboxServiceComponent.service = service;
}
......
/*******************************************************************************
* Copyright (c) 2014 MEDEVIT.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* T. Huster - initial API and implementation
*******************************************************************************/
package at.medevit.elexis.outbox.ui;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import ch.elexis.core.tasks.model.ITaskService;
@Component
public class TaskServiceComponent {
private static ITaskService service;
public static ITaskService get(){
return service;
}
@Reference
public synchronized void setService(ITaskService service){
TaskServiceComponent.service = service;
}
public synchronized void unsetService(ITaskService service){
if (TaskServiceComponent.service == service) {
TaskServiceComponent.service = null;
}
}
}
......@@ -54,7 +54,7 @@ public class CreateOutboxElementHandler extends AbstractHandler {
}
private boolean createOutboxElement(IPatient patient, IMandator mandant, IDocument document){
OutboxServiceComponent.getService().createOutboxElement(patient, mandant,
OutboxServiceComponent.get().createOutboxElement(patient, mandant,
OutboxElementType.DOC.getPrefix() + document.getId()
+ DocumentStore.ID_WITH_STOREID_SPLIT + document.getStoreId());
return true;
......
......@@ -21,7 +21,7 @@ public class CreateOutboxElementNoUiHandler extends AbstractHandler {
String dburi =
event.getParameter("at.medevit.elexis.outbox.ui.command.createElementNoUi.dburi");
if (StringUtils.isNotEmpty(dburi)) {
OutboxServiceComponent.getService().createOutboxElement(patient, mandant,
OutboxServiceComponent.get().createOutboxElement(patient, mandant,
OutboxElementType.DB.getPrefix() + dburi);
}
return null;
......
......@@ -24,7 +24,7 @@ public class OutboxDeleteHandler extends AbstractHandler implements IHandler {
for (Object iOutboxElement : iOutboxElements) {
if (iOutboxElement instanceof IOutboxElement) {
IOutboxElement el = (IOutboxElement) iOutboxElement;
OutboxServiceComponent.getService().deleteOutboxElement(el);
OutboxServiceComponent.get().deleteOutboxElement(el);
}
}
......
......@@ -126,7 +126,7 @@ public class OutboxSendHandler extends AbstractHandler implements IHandler {
attachmentsString)) {
for (Object iOutboxElement : iOutboxElements) {
if (iOutboxElement instanceof IOutboxElement) {
OutboxServiceComponent.getService().changeOutboxElementState(
OutboxServiceComponent.get().changeOutboxElementState(
(IOutboxElement) iOutboxElement, State.SENT);
}
}
......@@ -156,7 +156,7 @@ public class OutboxSendHandler extends AbstractHandler implements IHandler {
}
}
if (outboxElementSent) {
OutboxServiceComponent.getService()
OutboxServiceComponent.get()
.changeOutboxElementState((IOutboxElement) iOutboxElement, State.SENT);
} else {
warnings.append("\n");
......@@ -225,7 +225,7 @@ public class OutboxSendHandler extends AbstractHandler implements IHandler {
private Optional<File> createTempFile(IOutboxElement outboxElement){
try {
return OutboxServiceComponent.getService().createTempFileWithContents(attachmentsFolder,
return OutboxServiceComponent.get().createTempFileWithContents(attachmentsFolder,
outboxElement);
} catch (IOException e) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Fehler",
......
......@@ -130,7 +130,7 @@ public class OutboxView extends ViewPart {
addFilterActions(menuManager);
OutboxServiceComponent.getService().addUpdateListener(element -> {
OutboxServiceComponent.get().addUpdateListener(element -> {
Display.getDefault().asyncExec(new Runnable() {
public void run(){
contentProvider.refreshElement(element);
......@@ -185,7 +185,7 @@ public class OutboxView extends ViewPart {
}
private List<IOutboxElement> getOpenOutboxElements(){
List<IOutboxElement> openElements = OutboxServiceComponent.getService().getOutboxElements(
List<IOutboxElement> openElements = OutboxServiceComponent.get().getOutboxElements(
ContextServiceHolder.get().getActiveMandator().orElse(null), null,
IOutboxElementService.State.NEW);
return openElements;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment