From 8a70a3ad35fda3a586149a0144659a06b8acd2a4 Mon Sep 17 00:00:00 2001 From: Bruno Sinou Date: Mon, 20 Sep 2010 17:16:55 +0000 Subject: [PATCH] -> add a new command to automatically refresh Result Test List -> add a new view to monitor Slc Execution git-svn-id: https://svn.argeo.org/slc/trunk@3780 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../META-INF/MANIFEST.MF | 5 +- .../META-INF/spring/rcp.xml | 6 +- .../org/argeo/slc/client/rcp/Perspective.java | 3 + .../META-INF/MANIFEST.MF | 7 +- .../META-INF/spring/osgi.xml | 4 + .../META-INF/spring/views.xml | 5 + .../org.argeo.slc.client.ui/plugin.xml | 14 ++ .../client/ui/commands/RefreshHandler.java | 24 +++ .../services/TestManagerServiceAdapter.java | 102 +++++++++++++ .../client/ui/views/SlcExecutionListView.java | 141 ++++++++++++++++++ .../RenderingResultController.java | 4 +- 11 files changed, 309 insertions(+), 6 deletions(-) create mode 100644 eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/commands/RefreshHandler.java create mode 100644 eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/services/TestManagerServiceAdapter.java create mode 100644 eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/SlcExecutionListView.java diff --git a/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/MANIFEST.MF b/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/MANIFEST.MF index bba972f65..ed9125eee 100644 --- a/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/MANIFEST.MF +++ b/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/MANIFEST.MF @@ -1,14 +1,15 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: SLC RCP -Bundle-SymbolicName: org.argeo.slc.client.rcp; singleton:=true +Bundle-SymbolicName: org.argeo.slc.client.rcp;singleton:=true Bundle-Version: 1.0.0.qualifier Bundle-Activator: org.argeo.slc.client.rcp.ClientRcpPlugin Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Import-Package: org.argeo.slc.client.ui.views, +Import-Package: org.argeo.slc.client.ui.services, + org.argeo.slc.client.ui.views, org.argeo.slc.core.test.tree;version="0.13.0.SNAPSHOT-r3768", org.argeo.slc.execution;version="0.13.0.SNAPSHOT-r3770", org.argeo.slc.process;version="0.13.0.SNAPSHOT-r3770", diff --git a/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/spring/rcp.xml b/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/spring/rcp.xml index 6d2268d07..adc8b5887 100644 --- a/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/spring/rcp.xml +++ b/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/spring/rcp.xml @@ -4,9 +4,13 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - + + + + diff --git a/eclipse/plugins/org.argeo.slc.client.rcp/src/org/argeo/slc/client/rcp/Perspective.java b/eclipse/plugins/org.argeo.slc.client.rcp/src/org/argeo/slc/client/rcp/Perspective.java index e3b0c4b1a..059a51da2 100644 --- a/eclipse/plugins/org.argeo.slc.client.rcp/src/org/argeo/slc/client/rcp/Perspective.java +++ b/eclipse/plugins/org.argeo.slc.client.rcp/src/org/argeo/slc/client/rcp/Perspective.java @@ -2,6 +2,7 @@ package org.argeo.slc.client.rcp; import org.argeo.slc.client.ui.views.ExecutionModulesView; import org.argeo.slc.client.ui.views.ResultListView; +import org.argeo.slc.client.ui.views.SlcExecutionListView; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IPerspectiveFactory; @@ -16,6 +17,8 @@ public class Perspective implements IPerspectiveFactory { IPageLayout.LEFT, 0.5f, editorArea); layout.addStandaloneView(ResultListView.ID, false, IPageLayout.RIGHT, 0.5f, editorArea); + layout.addStandaloneView(SlcExecutionListView.ID, false, + IPageLayout.BOTTOM, 0.5f, editorArea); } } diff --git a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/MANIFEST.MF b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/MANIFEST.MF index e49d35e8f..2e1862d64 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/MANIFEST.MF +++ b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/MANIFEST.MF @@ -7,24 +7,29 @@ Bundle-Activator: org.argeo.slc.client.ui.ClientUiPlugin Require-Bundle: org.eclipse.ui;resolution:=optional, org.eclipse.rap.ui;resolution:=optional, org.eclipse.core.runtime;resolution:=optional, - com.springsource.org.hibernate;resolution:=optional + com.springsource.org.hibernate;resolution:=optional, + org.argeo.slc.specs Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 Export-Package: org.argeo.slc.client.ui, org.argeo.slc.client.ui.actions, + org.argeo.slc.client.ui.services, org.argeo.slc.client.ui.views Import-Package: org.apache.commons.logging;version="1.1.1", org.argeo.eclipse.spring, org.argeo.eclipse.ui, org.argeo.slc.build;version="0.13.0.SNAPSHOT-r3685", + org.argeo.slc.core.attachment, org.argeo.slc.core.runtime;version="0.13.0.SNAPSHOT-r3701", org.argeo.slc.core.test.tree;version="0.13.0.SNAPSHOT-r3768", org.argeo.slc.dao.test.tree;version="0.13.0.SNAPSHOT-r3768", org.argeo.slc.deploy;version="0.13.0.SNAPSHOT-r3724", org.argeo.slc.execution;version="0.13.0.SNAPSHOT-r3685", + org.argeo.slc.msg.test.tree, org.argeo.slc.process;version="0.13.0.SNAPSHOT-r3685", org.argeo.slc.runtime;version="0.13.0.SNAPSHOT-r3685", org.argeo.slc.services;version="0.13.0.SNAPSHOT-r3773", + org.argeo.slc.test, org.hibernate.hql.ast, org.hibernate.jdbc, org.springframework.beans.factory, diff --git a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/osgi.xml b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/osgi.xml index 43a62e390..32cc6b9d5 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/osgi.xml +++ b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/osgi.xml @@ -6,8 +6,12 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> + + + + \ No newline at end of file diff --git a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/views.xml b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/views.xml index f6d9914d1..f718ccb52 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/views.xml +++ b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/views.xml @@ -14,6 +14,11 @@ scope="prototype"> + + + + diff --git a/eclipse/plugins/org.argeo.slc.client.ui/plugin.xml b/eclipse/plugins/org.argeo.slc.client.ui/plugin.xml index dd8c430dc..25b779488 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/plugin.xml +++ b/eclipse/plugins/org.argeo.slc.client.ui/plugin.xml @@ -15,6 +15,12 @@ class="org.argeo.eclipse.spring.SpringExtensionFactory" name="Results" restorable="true"> + + @@ -42,5 +48,13 @@ + + + + diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/commands/RefreshHandler.java b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/commands/RefreshHandler.java new file mode 100644 index 000000000..1ff034141 --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/commands/RefreshHandler.java @@ -0,0 +1,24 @@ +package org.argeo.slc.client.ui.commands; + +import org.argeo.slc.client.ui.views.ResultListView; +import org.argeo.slc.client.ui.views.SlcExecutionListView; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.handlers.HandlerUtil; + +public class RefreshHandler extends AbstractHandler { + + public Object execute(ExecutionEvent event) throws ExecutionException { + ResultListView view = (ResultListView) HandlerUtil + .getActiveWorkbenchWindow(event).getActivePage().findView( + ResultListView.ID); + view.retrieveResults(); + SlcExecutionListView selView = (SlcExecutionListView) HandlerUtil + .getActiveWorkbenchWindow(event).getActivePage().findView( + SlcExecutionListView.ID); + selView.retrieveResults(); + return null; + } + +} diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/services/TestManagerServiceAdapter.java b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/services/TestManagerServiceAdapter.java new file mode 100644 index 000000000..1b2684f70 --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/services/TestManagerServiceAdapter.java @@ -0,0 +1,102 @@ +package org.argeo.slc.client.ui.services; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.slc.SlcException; +import org.argeo.slc.client.ui.ClientUiPlugin; +import org.argeo.slc.core.attachment.Attachment; +import org.argeo.slc.core.attachment.SimpleAttachment; +import org.argeo.slc.core.test.tree.TreeTestResult; +import org.argeo.slc.core.test.tree.TreeTestResultListener; +import org.argeo.slc.msg.test.tree.AddTreeTestResultAttachmentRequest; +import org.argeo.slc.msg.test.tree.CloseTreeTestResultRequest; +import org.argeo.slc.msg.test.tree.CreateTreeTestResultRequest; +import org.argeo.slc.msg.test.tree.ResultPartRequest; +import org.argeo.slc.services.TestManagerService; +import org.argeo.slc.test.TestResultPart; +import org.eclipse.ui.handlers.IHandlerService; + +/** In memory access to a test manager service */ +public class TestManagerServiceAdapter implements TreeTestResultListener { + private static final Log log = LogFactory + .getLog(TestManagerServiceAdapter.class); + + private Boolean onlyOnClose = false; + + private TestManagerService testManagerService; + + public void resultPartAdded(TreeTestResult testResult, + TestResultPart testResultPart) { + if (onlyOnClose) + return; + + if (testResult.getResultParts().size() == 1 + && testResult.getResultParts().values().iterator().next() + .getParts().size() == 1) { + CreateTreeTestResultRequest req = new CreateTreeTestResultRequest( + testResult); + testManagerService.createTreeTestResult(req); + } else { + ResultPartRequest req = new ResultPartRequest(testResult); + testManagerService.addResultPart(req); + } + } + + public void close(TreeTestResult testResult) { + + if (onlyOnClose) { + CreateTreeTestResultRequest req = new CreateTreeTestResultRequest( + testResult); + testManagerService.createTreeTestResult(req); + } else { + CloseTreeTestResultRequest req = new CloseTreeTestResultRequest( + testResult); + testManagerService.closeTreeTestResult(req); + } + + // TODO : clean this -> pb of thread && commandID hardCoded. + // We force the refresh of the list view. + ClientUiPlugin.getDefault().getWorkbench().getDisplay().syncExec( + new Runnable() { + public void run() { + IHandlerService handlerService = (IHandlerService) ClientUiPlugin + .getDefault().getWorkbench().getService( + IHandlerService.class); + try { + handlerService + .executeCommand( + "org.argeo.slc.client.ui.RefreshResultList", + null); + } catch (Exception e) { + e.printStackTrace(); + throw new SlcException( + "Problem while rendering result. " + + e.getMessage()); + } + } + } + + ); + + } + + public void addAttachment(TreeTestResult testResult, Attachment attachment) { + if (onlyOnClose) + return; + AddTreeTestResultAttachmentRequest req = new AddTreeTestResultAttachmentRequest(); + req.setResultUuid(testResult.getUuid()); + req.setAttachment((SimpleAttachment) attachment); + testManagerService.addAttachment(req); + + } + + /** Publishes the test result only when it gets closed. */ + public void setOnlyOnClose(Boolean onlyOnClose) { + this.onlyOnClose = onlyOnClose; + } + + public void setTestManagerService(TestManagerService testManagerService) { + this.testManagerService = testManagerService; + } + +} diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/SlcExecutionListView.java b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/SlcExecutionListView.java new file mode 100644 index 000000000..959c69964 --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/SlcExecutionListView.java @@ -0,0 +1,141 @@ +package org.argeo.slc.client.ui.views; + +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.slc.core.test.tree.ResultAttributes; +import org.argeo.slc.dao.process.SlcExecutionDao; +import org.argeo.slc.process.SlcExecution; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.ui.part.ViewPart; + +public class SlcExecutionListView extends ViewPart { + private final static Log log = LogFactory + .getLog(SlcExecutionListView.class); + + public static final String ID = "org.argeo.slc.client.ui.SlcExecutionListView"; + + private TableViewer viewer; + + private SlcExecutionDao slcExecutionDao; + + public void createPartControl(Composite parent) { + Table table = createTable(parent); + viewer = new TableViewer(table); + viewer.setLabelProvider(new ViewLabelProvider()); + viewer.setContentProvider(new ViewContentProvider()); + + viewer.setInput(getViewSite()); + } + + protected Table createTable(Composite parent) { + int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL + | SWT.FULL_SELECTION | SWT.HIDE_SELECTION; + + Table table = new Table(parent, style); + + GridData gridData = new GridData(GridData.FILL_BOTH); + gridData.grabExcessVerticalSpace = true; + gridData.grabExcessHorizontalSpace = true; + gridData.horizontalSpan = 3; + table.setLayoutData(gridData); + + table.setLinesVisible(true); + table.setHeaderVisible(true); + + TableColumn column = new TableColumn(table, SWT.LEFT, 0); + column.setText("Date"); + column.setWidth(200); + + column = new TableColumn(table, SWT.LEFT, 1); + column.setText("Host"); + column.setWidth(100); + + column = new TableColumn(table, SWT.LEFT, 2); + column.setText("Id"); + column.setWidth(300); + + column = new TableColumn(table, SWT.LEFT, 3); + column.setText("Status"); + column.setWidth(100); + + return table; + } + + protected static class ViewContentProvider implements + IStructuredContentProvider { + + public void inputChanged(Viewer arg0, Object arg1, Object arg2) { + } + + public void dispose() { + } + + @SuppressWarnings("unchecked") + public Object[] getElements(Object obj) { + if (obj instanceof List) { + return ((List) obj).toArray(); + } else { + return new Object[0]; + } + } + } + + protected class ViewLabelProvider extends LabelProvider implements + ITableLabelProvider { + public String getColumnText(Object obj, int index) { + SlcExecution ra = (SlcExecution) obj; + switch (index) { + + case 0: + return getText(ra.getStartDate()); + case 1: + return ra.getHost(); + case 2: + return ra.getUuid(); + case 3: + return ra.currentStep().getType(); + } + return getText(obj); + } + + public Image getColumnImage(Object obj, int index) { + return null; + } + + } + + public void setFocus() { + viewer.getControl().setFocus(); + } + + public void retrieveResults() { + try { + List lst = slcExecutionDao.listSlcExecutions(); + + if (log.isTraceEnabled()) + log.trace("Result attributes count: " + lst.size()); + viewer.setInput(lst); + // viewer.refresh(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void setSlcExecutionDao(SlcExecutionDao slcExecutionDao) { + this.slcExecutionDao = slcExecutionDao; + } + +} diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/RenderingResultController.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/RenderingResultController.java index 1ebc4b8ab..c02ba99bb 100644 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/RenderingResultController.java +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/RenderingResultController.java @@ -32,8 +32,8 @@ import org.springframework.web.bind.annotation.RequestParam; @Controller public class RenderingResultController { - // private static final Log log = LogFactory - // .getLog(RenderingResultController.class); + // private static final Log log = + // LogFactory.getLog(RenderingResultController.class); public final static String MODELKEY_RESULT = "result"; -- 2.39.2