1 package org
.argeo
.slc
.client
.ui
.views
;
3 import java
.util
.ArrayList
;
6 import org
.apache
.commons
.logging
.Log
;
7 import org
.apache
.commons
.logging
.LogFactory
;
8 import org
.argeo
.slc
.SlcException
;
9 import org
.argeo
.slc
.client
.ui
.ClientUiPlugin
;
10 import org
.argeo
.slc
.core
.test
.tree
.ResultAttributes
;
11 import org
.argeo
.slc
.dao
.test
.tree
.TreeTestResultCollectionDao
;
12 import org
.eclipse
.core
.commands
.Command
;
13 import org
.eclipse
.core
.commands
.IParameter
;
14 import org
.eclipse
.core
.commands
.Parameterization
;
15 import org
.eclipse
.core
.commands
.ParameterizedCommand
;
16 import org
.eclipse
.jface
.viewers
.DoubleClickEvent
;
17 import org
.eclipse
.jface
.viewers
.IDoubleClickListener
;
18 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
19 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
20 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
21 import org
.eclipse
.jface
.viewers
.LabelProvider
;
22 import org
.eclipse
.jface
.viewers
.TableViewer
;
23 import org
.eclipse
.jface
.viewers
.Viewer
;
24 import org
.eclipse
.swt
.SWT
;
25 import org
.eclipse
.swt
.graphics
.Image
;
26 import org
.eclipse
.swt
.layout
.GridData
;
27 import org
.eclipse
.swt
.widgets
.Composite
;
28 import org
.eclipse
.swt
.widgets
.Table
;
29 import org
.eclipse
.swt
.widgets
.TableColumn
;
30 import org
.eclipse
.ui
.IWorkbench
;
31 import org
.eclipse
.ui
.IWorkbenchWindow
;
32 import org
.eclipse
.ui
.commands
.ICommandService
;
33 import org
.eclipse
.ui
.handlers
.IHandlerService
;
34 import org
.eclipse
.ui
.part
.ViewPart
;
36 public class ResultListView
extends ViewPart
{
37 private final static Log log
= LogFactory
.getLog(ResultListView
.class);
39 public static final String ID
= "org.argeo.slc.client.ui.resultListView";
41 private TableViewer viewer
;
43 private TreeTestResultCollectionDao testResultCollectionDao
;
45 public void createPartControl(Composite parent
) {
46 Table table
= createTable(parent
);
47 viewer
= new TableViewer(table
);
48 viewer
.setLabelProvider(new ViewLabelProvider());
49 viewer
.setContentProvider(new ViewContentProvider());
50 viewer
.setInput(getViewSite());
51 viewer
.addDoubleClickListener(new ViewDoubleClickListener());
54 protected Table
createTable(Composite parent
) {
55 int style
= SWT
.SINGLE
| SWT
.BORDER
| SWT
.H_SCROLL
| SWT
.V_SCROLL
56 | SWT
.FULL_SELECTION
| SWT
.HIDE_SELECTION
;
58 Table table
= new Table(parent
, style
);
60 GridData gridData
= new GridData(GridData
.FILL_BOTH
);
61 gridData
.grabExcessVerticalSpace
= true;
62 gridData
.grabExcessHorizontalSpace
= true;
63 gridData
.horizontalSpan
= 3;
64 table
.setLayoutData(gridData
);
66 table
.setLinesVisible(true);
67 table
.setHeaderVisible(true);
69 TableColumn column
= new TableColumn(table
, SWT
.LEFT
, 0);
70 column
.setText("Date");
73 column
= new TableColumn(table
, SWT
.LEFT
, 1);
74 column
.setText("UUID");
80 // View Specific inner class
81 protected static class ViewContentProvider
implements
82 IStructuredContentProvider
{
84 public void inputChanged(Viewer arg0
, Object arg1
, Object arg2
) {
87 public void dispose() {
90 @SuppressWarnings("unchecked")
91 public Object
[] getElements(Object obj
) {
92 if (obj
instanceof List
) {
93 return ((List
<ResultAttributes
>) obj
).toArray();
100 protected class ViewLabelProvider
extends LabelProvider
implements
101 ITableLabelProvider
{
102 public String
getColumnText(Object obj
, int index
) {
103 ResultAttributes ra
= (ResultAttributes
) obj
;
106 return getText(ra
.getCloseDate());
113 public Image
getColumnImage(Object obj
, int index
) {
119 public void setFocus() {
120 viewer
.getControl().setFocus();
123 public void retrieveResults() {
125 List
<ResultAttributes
> lst
= testResultCollectionDao
126 .listResultAttributes(null);
127 if (log
.isTraceEnabled())
128 log
.trace("Result attributes count: " + lst
.size());
129 viewer
.setInput(lst
);
131 } catch (Exception e
) {
132 // TODO Auto-generated catch block
139 * The ResultAttributes expose a part of the information contained in the
140 * TreeTestResult, It has the same UUID as the corresponding treeTestResult.
142 class ViewDoubleClickListener
implements IDoubleClickListener
{
143 public void doubleClick(DoubleClickEvent evt
) {
144 Object obj
= ((IStructuredSelection
) evt
.getSelection())
147 if (obj
instanceof ResultAttributes
) {
148 ResultAttributes ra
= (ResultAttributes
) obj
;
149 log
.debug("Double-clic on result with UUID" + ra
.getUuid());
151 IWorkbench iw
= ClientUiPlugin
.getDefault().getWorkbench();
152 IHandlerService handlerService
= (IHandlerService
) iw
153 .getService(IHandlerService
.class);
155 // get the command from plugin.xml
156 IWorkbenchWindow window
= iw
.getActiveWorkbenchWindow();
157 ICommandService cmdService
= (ICommandService
) window
158 .getService(ICommandService
.class);
159 Command cmd
= cmdService
160 .getCommand("org.argeo.slc.client.ui.displayResultDetails");
162 // log.debug("cmd : " + cmd);
163 ArrayList
<Parameterization
> parameters
= new ArrayList
<Parameterization
>();
166 IParameter iparam
= cmd
167 .getParameter("org.argeo.slc.client.commands.resultUuid");
169 Parameterization params
= new Parameterization(iparam
,
171 parameters
.add(params
);
173 // build the parameterized command
174 ParameterizedCommand pc
= new ParameterizedCommand(cmd
,
175 parameters
.toArray(new Parameterization
[parameters
178 // execute the command
179 handlerService
= (IHandlerService
) window
180 .getService(IHandlerService
.class);
181 handlerService
.executeCommand(pc
, null);
183 } catch (Exception e
) {
185 throw new SlcException("Problem while rendering result. "
193 public void setTestResultCollectionDao(
194 TreeTestResultCollectionDao testResultCollectionDao
) {
195 this.testResultCollectionDao
= testResultCollectionDao
;