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
.action
.MenuManager
;
17 import org
.eclipse
.jface
.viewers
.DoubleClickEvent
;
18 import org
.eclipse
.jface
.viewers
.IDoubleClickListener
;
19 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
20 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
21 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
22 import org
.eclipse
.jface
.viewers
.LabelProvider
;
23 import org
.eclipse
.jface
.viewers
.TableViewer
;
24 import org
.eclipse
.jface
.viewers
.Viewer
;
25 import org
.eclipse
.swt
.SWT
;
26 import org
.eclipse
.swt
.graphics
.Image
;
27 import org
.eclipse
.swt
.layout
.GridData
;
28 import org
.eclipse
.swt
.widgets
.Composite
;
29 import org
.eclipse
.swt
.widgets
.Menu
;
30 import org
.eclipse
.swt
.widgets
.MenuItem
;
31 import org
.eclipse
.swt
.widgets
.Table
;
32 import org
.eclipse
.swt
.widgets
.TableColumn
;
33 import org
.eclipse
.ui
.IWorkbench
;
34 import org
.eclipse
.ui
.IWorkbenchWindow
;
35 import org
.eclipse
.ui
.commands
.ICommandService
;
36 import org
.eclipse
.ui
.handlers
.IHandlerService
;
37 import org
.eclipse
.ui
.part
.ViewPart
;
39 public class ResultListView
extends ViewPart
{
40 private final static Log log
= LogFactory
.getLog(ResultListView
.class);
42 public static final String ID
= "org.argeo.slc.client.ui.resultListView";
44 private TableViewer viewer
;
46 private TreeTestResultCollectionDao testResultCollectionDao
;
48 public void createPartControl(Composite parent
) {
49 Table table
= createTable(parent
);
50 viewer
= new TableViewer(table
);
51 viewer
.setLabelProvider(new ViewLabelProvider());
52 viewer
.setContentProvider(new ViewContentProvider());
53 viewer
.setInput(getViewSite());
54 viewer
.addDoubleClickListener(new ViewDoubleClickListener());
56 // Context Menu for the end user to choose what kind of display he wants
57 // Problem to dynamically add parameters linked with the current
59 MenuManager menuManager
= new MenuManager();
60 Menu menu
= menuManager
.createContextMenu(viewer
.getControl());
62 // unable excel commands if not on windows
63 MenuItem
[] items
= menu
.getItems();
64 String platform
= SWT
.getPlatform();
65 if (!(platform
.equals("win32") || platform
.equals("wpf"))) {
66 items
[1].setEnabled(false);
69 viewer
.getControl().setMenu(menu
);
70 getSite().registerContextMenu(menuManager
, viewer
);
73 protected Table
createTable(Composite parent
) {
74 int style
= SWT
.SINGLE
| SWT
.BORDER
| SWT
.H_SCROLL
| SWT
.V_SCROLL
75 | SWT
.FULL_SELECTION
| SWT
.HIDE_SELECTION
;
77 Table table
= new Table(parent
, style
);
78 // table.addMouseListener(new RightClickListener());
79 GridData gridData
= new GridData(GridData
.FILL_BOTH
);
80 gridData
.grabExcessVerticalSpace
= true;
81 gridData
.grabExcessHorizontalSpace
= true;
82 gridData
.horizontalSpan
= 3;
83 table
.setLayoutData(gridData
);
85 table
.setLinesVisible(true);
86 table
.setHeaderVisible(true);
88 TableColumn column
= new TableColumn(table
, SWT
.LEFT
, 0);
89 column
.setText("Date");
92 column
= new TableColumn(table
, SWT
.LEFT
, 1);
93 column
.setText("UUID");
99 // TODO : Improve this methods.
100 // For now it is a workaround because we cannot dynamically update context
101 // menu to pass the UUID as command parameter
102 public String
[] getSelectedResult() {
103 Object obj
= ((IStructuredSelection
) viewer
.getSelection())
106 String
[] attributes
= new String
[2];
108 if (obj
== null || !(obj
instanceof ResultAttributes
))
111 ResultAttributes ra
= (ResultAttributes
) obj
;
112 attributes
[0] = ra
.getUuid();
113 attributes
[1] = (ra
.getAttributes().get("testCase") == null) ?
null
114 : ra
.getAttributes().get("testCase");
119 // View Specific inner class
120 protected static class ViewContentProvider
implements
121 IStructuredContentProvider
{
123 public void inputChanged(Viewer arg0
, Object arg1
, Object arg2
) {
126 public void dispose() {
129 @SuppressWarnings("unchecked")
130 public Object
[] getElements(Object obj
) {
131 if (obj
instanceof List
) {
132 return ((List
<ResultAttributes
>) obj
).toArray();
134 return new Object
[0];
139 protected class ViewLabelProvider
extends LabelProvider
implements
140 ITableLabelProvider
{
141 public String
getColumnText(Object obj
, int index
) {
142 ResultAttributes ra
= (ResultAttributes
) obj
;
145 return getText(ra
.getCloseDate());
152 public Image
getColumnImage(Object obj
, int index
) {
158 public void setFocus() {
159 viewer
.getControl().setFocus();
162 public void retrieveResults() {
164 List
<ResultAttributes
> lst
= testResultCollectionDao
165 .listResultAttributes(null);
166 if (log
.isTraceEnabled())
167 log
.trace("Result attributes count: " + lst
.size());
168 viewer
.setInput(lst
);
170 } catch (Exception e
) {
171 // TODO Auto-generated catch block
179 * The ResultAttributes expose a part of the information contained in the
180 * TreeTestResult, It has the same UUID as the corresponding treeTestResult.
182 class ViewDoubleClickListener
implements IDoubleClickListener
{
183 public void doubleClick(DoubleClickEvent evt
) {
184 Object obj
= ((IStructuredSelection
) evt
.getSelection())
187 if (obj
instanceof ResultAttributes
) {
188 ResultAttributes ra
= (ResultAttributes
) obj
;
190 IWorkbench iw
= ClientUiPlugin
.getDefault().getWorkbench();
191 IHandlerService handlerService
= (IHandlerService
) iw
192 .getService(IHandlerService
.class);
194 // get the command from plugin.xml
195 IWorkbenchWindow window
= iw
.getActiveWorkbenchWindow();
196 ICommandService cmdService
= (ICommandService
) window
197 .getService(ICommandService
.class);
198 Command cmd
= cmdService
199 .getCommand("org.argeo.slc.client.ui.displayResultDetails");
201 // log.debug("cmd : " + cmd);
202 ArrayList
<Parameterization
> parameters
= new ArrayList
<Parameterization
>();
205 IParameter iparam
= cmd
206 .getParameter("org.argeo.slc.client.commands.resultUuid");
208 Parameterization params
= new Parameterization(iparam
,
210 parameters
.add(params
);
212 // build the parameterized command
213 ParameterizedCommand pc
= new ParameterizedCommand(cmd
,
214 parameters
.toArray(new Parameterization
[parameters
217 // execute the command
218 handlerService
= (IHandlerService
) window
219 .getService(IHandlerService
.class);
220 handlerService
.executeCommand(pc
, null);
222 } catch (Exception e
) {
224 throw new SlcException("Problem while rendering result. "
232 public void setTestResultCollectionDao(
233 TreeTestResultCollectionDao testResultCollectionDao
) {
234 this.testResultCollectionDao
= testResultCollectionDao
;