Commit 0dcbb04d authored by Thomas Huster's avatar Thomas Huster

[20758] reworked outbox ui for elements with task descriptor object

parent d43a1ed4
Pipeline #15493 passed with stages
in 7 minutes and 20 seconds
......@@ -111,6 +111,18 @@
label="%command.label.6"
style="push">
</command>
<visibleWhen
checkEnabled="false">
<with
variable="selection">
<not>
<test
args="TaskDescriptor"
property="at.medevit.elexis.outbox.ui.propertytester.isObjectClass">
</test>
</not>
</with>
</visibleWhen>
</menu>
</menuContribution>
<menuContribution
......@@ -139,9 +151,9 @@
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="at.medevit.elexis.outbox.ui.propertytester.PropertyTester"
id="at.medevit.elexis.outbox.ui.propertytester.xdm"
id="at.medevit.elexis.outbox.ui.propertytester"
namespace="at.medevit.elexis.outbox.ui.propertytester"
properties="enabled"
properties="xdmEnabled, isObjectClass"
type="java.lang.Object">
</propertyTester>
</extension>
......@@ -152,7 +164,7 @@
commandId="at.medevit.elexis.outbox.ui.command.sendAsMailXDM">
<enabledWhen>
<test
property="at.medevit.elexis.outbox.ui.propertytester.enabled">
property="at.medevit.elexis.outbox.ui.propertytester.xdmEnabled">
</test>
</enabledWhen>
</handler>
......
......@@ -8,6 +8,8 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.LabelProvider;
......@@ -15,14 +17,18 @@ import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.IHandlerService;
import org.slf4j.LoggerFactory;
import at.medevit.elexis.outbox.model.IOutboxElement;
import at.medevit.elexis.outbox.model.IOutboxElementService.State;
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.model.tasks.TaskException;
import ch.elexis.core.tasks.model.ITaskDescriptor;
import ch.elexis.core.ui.icons.Images;
......@@ -91,9 +97,29 @@ public class CoreOutboxElementLabelProvider implements IOutboxElementUiProvider
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
// now try to call the send mail task command
try {
ICommandService commandService = (ICommandService) PlatformUI.getWorkbench()
.getService(ICommandService.class);
Command sendMailTaskCommand =
commandService.getCommand("ch.elexis.core.mail.ui.sendMailTask");
HashMap<String, String> params = new HashMap<String, String>();
params.put("ch.elexis.core.mail.ui.sendMailTaskDescriptorId",
taskDescriptor.getId());
ParameterizedCommand parametrizedCommmand =
ParameterizedCommand.generateCommand(sendMailTaskCommand, params);
Boolean success =
(Boolean) PlatformUI.getWorkbench().getService(IHandlerService.class)
.executeCommand(parametrizedCommmand, null);
if (success) {
OutboxServiceComponent.get().changeOutboxElementState(element,
State.SENT);
}
} catch (Exception ex) {
LoggerFactory.getLogger(getClass())
.warn("Send mail Task command not available", ex);
}
}
}
} else if (OutboxElementType.DOC.equals(elementType)) {
......@@ -173,4 +199,21 @@ public class CoreOutboxElementLabelProvider implements IOutboxElementUiProvider
return taskImage;
}
}
@Override
public void delete(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();
try {
TaskServiceComponent.get().removeTaskDescriptor(taskDescriptor);
} catch (TaskException e) {
LoggerFactory.getLogger(getClass()).warn("Error removing mail Task", e);
}
}
}
}
}
......@@ -12,6 +12,8 @@ import org.eclipse.ui.handlers.HandlerUtil;
import at.medevit.elexis.outbox.model.IOutboxElement;
import at.medevit.elexis.outbox.ui.OutboxServiceComponent;
import at.medevit.elexis.outbox.ui.part.provider.IOutboxElementUiProvider;
import at.medevit.elexis.outbox.ui.part.provider.OutboxElementUiExtension;
public class OutboxDeleteHandler extends AbstractHandler implements IHandler {
......@@ -23,16 +25,17 @@ public class OutboxDeleteHandler extends AbstractHandler implements IHandler {
List<?> iOutboxElements = ((StructuredSelection) selection).toList();
for (Object iOutboxElement : iOutboxElements) {
if (iOutboxElement instanceof IOutboxElement) {
OutboxElementUiExtension extension = new OutboxElementUiExtension();
IOutboxElement el = (IOutboxElement) iOutboxElement;
IOutboxElementUiProvider provider = extension.getProviderFor(el);
if (provider != null) {
provider.delete(el);
}
OutboxServiceComponent.get().deleteOutboxElement(el);
}
}
}
return null;
}
}
......@@ -60,4 +60,11 @@ public interface IOutboxElementUiProvider {
* @param element
*/
public void doubleClicked(IOutboxElement element);
/**
* Method called when element is deleted.
*
* @param element
*/
public default void delete(IOutboxElement element){};
}
......@@ -109,4 +109,8 @@ public class OutboxElementUiExtension {
provider.doubleClicked(element);
}
}
public IOutboxElementUiProvider getProviderFor(IOutboxElement element){
return getProvider(element);
}
}
......@@ -2,6 +2,11 @@ package at.medevit.elexis.outbox.ui.propertytester;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jface.viewers.TreeSelection;
import at.medevit.elexis.outbox.model.IOutboxElement;
public class PropertyTester extends org.eclipse.core.expressions.PropertyTester {
public PropertyTester(){
......@@ -9,26 +14,28 @@ public class PropertyTester extends org.eclipse.core.expressions.PropertyTester
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue){
if ("enabled".equals(property)) {
if (receiver instanceof TreeSelection) {
receiver = ((TreeSelection) receiver).getFirstElement();
}
if ("xdmEnabled".equals(property)) {
try {
if (receiver instanceof List<?>) {
List<?> receiverAsList = (List<?>) receiver;
// for (Object o : receiverAsList) {
// if (o instanceof OutboxElement) {
// OutboxElement outboxElement = (OutboxElement) o;
// String lbl = outboxElement.getLabel();
// // because of an issue in ehealth DocumentDescriptor we can only handle pdf and xml files.
// if (lbl == null || (!lbl.toLowerCase().endsWith(".xml")
// && !lbl.toLowerCase().endsWith(".pdf"))) {
// return false;
// }
// }
// }
return receiverAsList.size() > 0;
}
} catch (Exception ise) {
// do nothing, false is returned
}
} else if ("isObjectClass".equals(property)) {
if (StringUtils.isNotBlank((String) args[0])) {
String className = (String) args[0];
if (receiver instanceof IOutboxElement) {
Object object = ((IOutboxElement) receiver).getObject();
if (object != null) {
return object.getClass().getSimpleName().contains(className);
}
}
}
}
return false;
}
......
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