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
.Table
;
31 import org
.eclipse
.swt
.widgets
.TableColumn
;
32 import org
.eclipse
.ui
.IWorkbench
;
33 import org
.eclipse
.ui
.IWorkbenchWindow
;
34 import org
.eclipse
.ui
.commands
.ICommandService
;
35 import org
.eclipse
.ui
.handlers
.IHandlerService
;
36 import org
.eclipse
.ui
.part
.ViewPart
;
38 public class ResultListView
extends ViewPart
{
39 private final static Log log
= LogFactory
.getLog(ResultListView
.class);
41 public static final String ID
= "org.argeo.slc.client.ui.resultListView";
43 private TableViewer viewer
;
45 private TreeTestResultCollectionDao testResultCollectionDao
;
47 public void createPartControl(Composite parent
) {
48 Table table
= createTable(parent
);
49 viewer
= new TableViewer(table
);
50 viewer
.setLabelProvider(new ViewLabelProvider());
51 viewer
.setContentProvider(new ViewContentProvider());
52 viewer
.setInput(getViewSite());
53 viewer
.addDoubleClickListener(new ViewDoubleClickListener());
55 // Context Menu for the end user to choose what kind of display he wants
56 // Problem to dynamically add parameters linked with the current
58 MenuManager menuManager
= new MenuManager();
59 Menu menu
= menuManager
.createContextMenu(viewer
.getControl());
60 viewer
.getControl().setMenu(menu
);
61 getSite().registerContextMenu(menuManager
, viewer
);
65 protected Table
createTable(Composite parent
) {
66 int style
= SWT
.SINGLE
| SWT
.BORDER
| SWT
.H_SCROLL
| SWT
.V_SCROLL
67 | SWT
.FULL_SELECTION
| SWT
.HIDE_SELECTION
;
69 Table table
= new Table(parent
, style
);
70 // table.addMouseListener(new RightClickListener());
71 GridData gridData
= new GridData(GridData
.FILL_BOTH
);
72 gridData
.grabExcessVerticalSpace
= true;
73 gridData
.grabExcessHorizontalSpace
= true;
74 gridData
.horizontalSpan
= 3;
75 table
.setLayoutData(gridData
);
77 table
.setLinesVisible(true);
78 table
.setHeaderVisible(true);
80 TableColumn column
= new TableColumn(table
, SWT
.LEFT
, 0);
81 column
.setText("Date");
84 column
= new TableColumn(table
, SWT
.LEFT
, 1);
85 column
.setText("UUID");
91 // TODO : Improve this method.
92 public String
getSelectedResult() {
93 Object obj
= ((IStructuredSelection
) viewer
.getSelection())
96 if (obj
== null || !(obj
instanceof ResultAttributes
))
99 return ((ResultAttributes
) obj
).getUuid();
102 // View Specific inner class
103 protected static class ViewContentProvider
implements
104 IStructuredContentProvider
{
106 public void inputChanged(Viewer arg0
, Object arg1
, Object arg2
) {
109 public void dispose() {
112 @SuppressWarnings("unchecked")
113 public Object
[] getElements(Object obj
) {
114 if (obj
instanceof List
) {
115 return ((List
<ResultAttributes
>) obj
).toArray();
117 return new Object
[0];
122 protected class ViewLabelProvider
extends LabelProvider
implements
123 ITableLabelProvider
{
124 public String
getColumnText(Object obj
, int index
) {
125 ResultAttributes ra
= (ResultAttributes
) obj
;
128 return getText(ra
.getCloseDate());
135 public Image
getColumnImage(Object obj
, int index
) {
141 public void setFocus() {
142 viewer
.getControl().setFocus();
145 public void retrieveResults() {
147 List
<ResultAttributes
> lst
= testResultCollectionDao
148 .listResultAttributes(null);
149 if (log
.isTraceEnabled())
150 log
.trace("Result attributes count: " + lst
.size());
151 viewer
.setInput(lst
);
153 } catch (Exception e
) {
154 // TODO Auto-generated catch block
162 * The ResultAttributes expose a part of the information contained in the
163 * TreeTestResult, It has the same UUID as the corresponding treeTestResult.
165 class ViewDoubleClickListener
implements IDoubleClickListener
{
166 public void doubleClick(DoubleClickEvent evt
) {
167 Object obj
= ((IStructuredSelection
) evt
.getSelection())
170 if (obj
instanceof ResultAttributes
) {
171 ResultAttributes ra
= (ResultAttributes
) obj
;
172 log
.debug("Double-clic on result with UUID" + ra
.getUuid());
174 IWorkbench iw
= ClientUiPlugin
.getDefault().getWorkbench();
175 IHandlerService handlerService
= (IHandlerService
) iw
176 .getService(IHandlerService
.class);
178 // get the command from plugin.xml
179 IWorkbenchWindow window
= iw
.getActiveWorkbenchWindow();
180 ICommandService cmdService
= (ICommandService
) window
181 .getService(ICommandService
.class);
182 Command cmd
= cmdService
183 .getCommand("org.argeo.slc.client.ui.displayResultDetails");
185 // log.debug("cmd : " + cmd);
186 ArrayList
<Parameterization
> parameters
= new ArrayList
<Parameterization
>();
189 IParameter iparam
= cmd
190 .getParameter("org.argeo.slc.client.commands.resultUuid");
192 Parameterization params
= new Parameterization(iparam
,
194 parameters
.add(params
);
196 // build the parameterized command
197 ParameterizedCommand pc
= new ParameterizedCommand(cmd
,
198 parameters
.toArray(new Parameterization
[parameters
201 // execute the command
202 handlerService
= (IHandlerService
) window
203 .getService(IHandlerService
.class);
204 handlerService
.executeCommand(pc
, null);
206 } catch (Exception e
) {
208 throw new SlcException("Problem while rendering result. "
216 public void setTestResultCollectionDao(
217 TreeTestResultCollectionDao testResultCollectionDao
) {
218 this.testResultCollectionDao
= testResultCollectionDao
;