]> git.argeo.org Git - gpl/argeo-slc.git/blob - eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/services/TestManagerServiceAdapter.java
1b2684f70599135f0722769216ecd619c5f80f3c
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.client.ui / src / org / argeo / slc / client / ui / services / TestManagerServiceAdapter.java
1 package org.argeo.slc.client.ui.services;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.argeo.slc.SlcException;
6 import org.argeo.slc.client.ui.ClientUiPlugin;
7 import org.argeo.slc.core.attachment.Attachment;
8 import org.argeo.slc.core.attachment.SimpleAttachment;
9 import org.argeo.slc.core.test.tree.TreeTestResult;
10 import org.argeo.slc.core.test.tree.TreeTestResultListener;
11 import org.argeo.slc.msg.test.tree.AddTreeTestResultAttachmentRequest;
12 import org.argeo.slc.msg.test.tree.CloseTreeTestResultRequest;
13 import org.argeo.slc.msg.test.tree.CreateTreeTestResultRequest;
14 import org.argeo.slc.msg.test.tree.ResultPartRequest;
15 import org.argeo.slc.services.TestManagerService;
16 import org.argeo.slc.test.TestResultPart;
17 import org.eclipse.ui.handlers.IHandlerService;
18
19 /** In memory access to a test manager service */
20 public class TestManagerServiceAdapter implements TreeTestResultListener {
21 private static final Log log = LogFactory
22 .getLog(TestManagerServiceAdapter.class);
23
24 private Boolean onlyOnClose = false;
25
26 private TestManagerService testManagerService;
27
28 public void resultPartAdded(TreeTestResult testResult,
29 TestResultPart testResultPart) {
30 if (onlyOnClose)
31 return;
32
33 if (testResult.getResultParts().size() == 1
34 && testResult.getResultParts().values().iterator().next()
35 .getParts().size() == 1) {
36 CreateTreeTestResultRequest req = new CreateTreeTestResultRequest(
37 testResult);
38 testManagerService.createTreeTestResult(req);
39 } else {
40 ResultPartRequest req = new ResultPartRequest(testResult);
41 testManagerService.addResultPart(req);
42 }
43 }
44
45 public void close(TreeTestResult testResult) {
46
47 if (onlyOnClose) {
48 CreateTreeTestResultRequest req = new CreateTreeTestResultRequest(
49 testResult);
50 testManagerService.createTreeTestResult(req);
51 } else {
52 CloseTreeTestResultRequest req = new CloseTreeTestResultRequest(
53 testResult);
54 testManagerService.closeTreeTestResult(req);
55 }
56
57 // TODO : clean this -> pb of thread && commandID hardCoded.
58 // We force the refresh of the list view.
59 ClientUiPlugin.getDefault().getWorkbench().getDisplay().syncExec(
60 new Runnable() {
61 public void run() {
62 IHandlerService handlerService = (IHandlerService) ClientUiPlugin
63 .getDefault().getWorkbench().getService(
64 IHandlerService.class);
65 try {
66 handlerService
67 .executeCommand(
68 "org.argeo.slc.client.ui.RefreshResultList",
69 null);
70 } catch (Exception e) {
71 e.printStackTrace();
72 throw new SlcException(
73 "Problem while rendering result. "
74 + e.getMessage());
75 }
76 }
77 }
78
79 );
80
81 }
82
83 public void addAttachment(TreeTestResult testResult, Attachment attachment) {
84 if (onlyOnClose)
85 return;
86 AddTreeTestResultAttachmentRequest req = new AddTreeTestResultAttachmentRequest();
87 req.setResultUuid(testResult.getUuid());
88 req.setAttachment((SimpleAttachment) attachment);
89 testManagerService.addAttachment(req);
90
91 }
92
93 /** Publishes the test result only when it gets closed. */
94 public void setOnlyOnClose(Boolean onlyOnClose) {
95 this.onlyOnClose = onlyOnClose;
96 }
97
98 public void setTestManagerService(TestManagerService testManagerService) {
99 this.testManagerService = testManagerService;
100 }
101
102 }