1 package org
.argeo
.slc
.client
.ui
.views
;
3 import java
.text
.SimpleDateFormat
;
4 import java
.util
.ArrayList
;
5 import java
.util
.HashMap
;
9 import org
.apache
.commons
.logging
.Log
;
10 import org
.apache
.commons
.logging
.LogFactory
;
11 import org
.argeo
.slc
.SlcException
;
12 import org
.argeo
.slc
.client
.ui
.ClientUiPlugin
;
13 import org
.argeo
.slc
.core
.test
.tree
.ResultAttributes
;
14 import org
.argeo
.slc
.dao
.test
.tree
.TreeTestResultCollectionDao
;
15 import org
.eclipse
.core
.commands
.Command
;
16 import org
.eclipse
.core
.commands
.IParameter
;
17 import org
.eclipse
.core
.commands
.Parameterization
;
18 import org
.eclipse
.core
.commands
.ParameterizedCommand
;
19 import org
.eclipse
.jface
.action
.IContributionItem
;
20 import org
.eclipse
.jface
.action
.IMenuListener
;
21 import org
.eclipse
.jface
.action
.IMenuManager
;
22 import org
.eclipse
.jface
.action
.MenuManager
;
23 import org
.eclipse
.jface
.viewers
.DoubleClickEvent
;
24 import org
.eclipse
.jface
.viewers
.IDoubleClickListener
;
25 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
26 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
27 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
28 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
29 import org
.eclipse
.jface
.viewers
.LabelProvider
;
30 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
31 import org
.eclipse
.jface
.viewers
.TableViewer
;
32 import org
.eclipse
.jface
.viewers
.Viewer
;
33 import org
.eclipse
.swt
.SWT
;
34 import org
.eclipse
.swt
.graphics
.Image
;
35 import org
.eclipse
.swt
.widgets
.Composite
;
36 import org
.eclipse
.swt
.widgets
.Menu
;
37 import org
.eclipse
.swt
.widgets
.Table
;
38 import org
.eclipse
.swt
.widgets
.TableColumn
;
39 import org
.eclipse
.ui
.IWorkbench
;
40 import org
.eclipse
.ui
.IWorkbenchWindow
;
41 import org
.eclipse
.ui
.commands
.ICommandService
;
42 import org
.eclipse
.ui
.handlers
.IHandlerService
;
43 import org
.eclipse
.ui
.menus
.CommandContributionItem
;
44 import org
.eclipse
.ui
.menus
.CommandContributionItemParameter
;
45 import org
.eclipse
.ui
.part
.ViewPart
;
46 import org
.eclipse
.ui
.services
.IServiceLocator
;
48 public class ResultListView
extends ViewPart
{
49 private final static Log log
= LogFactory
.getLog(ResultListView
.class);
51 public static final String ID
= "org.argeo.slc.client.ui.resultListView";
53 private final static String DISPLAY_CMD_ID
= "org.argeo.slc.client.ui.displayResultDetails";
54 private final static String DISPLAY_AS_XLS_CMD_ID
= "com.capco.sparta.client.ui.displayResultDetailsWithExcel";
55 private final static String SAVE_AS_XLS_CMD_ID
= "com.capco.sparta.client.ui.saveResultAsExcelFile";
56 private final static String UUID_PARAM_ID
= "org.argeo.slc.client.commands.resultUuid";
57 private final static String NAME_PARAM_ID
= "org.argeo.slc.client.commands.resultName";
58 private final static String PLATFORM
= SWT
.getPlatform();
60 private final static SimpleDateFormat dateFormatter
= new SimpleDateFormat(
61 "MM/dd/yyyy 'at' HH:mm:ss");
63 private TableViewer viewer
;
64 private TreeTestResultCollectionDao testResultCollectionDao
;
66 private ResultAttributes selectedRa
;
68 public void createPartControl(Composite parent
) {
69 Table table
= createTable(parent
);
70 viewer
= new TableViewer(table
);
71 viewer
.setLabelProvider(new ViewLabelProvider());
72 viewer
.setContentProvider(new ViewContentProvider());
73 viewer
.setInput(getViewSite());
74 viewer
.addDoubleClickListener(new ViewDoubleClickListener());
75 viewer
.addSelectionChangedListener(new SelectionChangedListener());
77 // create the context menu
79 MenuManager menuManager
= new MenuManager();
80 Menu menu
= menuManager
.createContextMenu(viewer
.getControl());
81 menuManager
.addMenuListener(new IMenuListener() {
82 public void menuAboutToShow(IMenuManager manager
) {
83 contextMenuAboutToShow(manager
);
87 viewer
.getControl().setMenu(menu
);
88 getSite().registerContextMenu(menuManager
, viewer
);
91 protected Table
createTable(Composite parent
) {
92 int style
= SWT
.SINGLE
| SWT
.BORDER
| SWT
.H_SCROLL
| SWT
.V_SCROLL
94 // does not function with RAP, commented for the moment being
95 // | SWT.HIDE_SELECTION;
97 Table table
= new Table(parent
, style
);
98 // table.addMouseListener(new RightClickListener());
99 // GridData gridData = new GridData(GridData.FILL_BOTH);
100 // gridData.grabExcessVerticalSpace = true;
101 // gridData.grabExcessHorizontalSpace = true;
102 // gridData.horizontalSpan = 3;
103 // table.setLayoutData(gridData);
105 table
.setLinesVisible(true);
106 table
.setHeaderVisible(true);
108 TableColumn column
= new TableColumn(table
, SWT
.LEFT
, 0);
109 column
.setText("Test Case");
110 column
.setWidth(200);
112 column
= new TableColumn(table
, SWT
.LEFT
, 1);
113 column
.setText("Close Date");
114 column
.setWidth(120);
116 column
= new TableColumn(table
, SWT
.LEFT
, 2);
117 column
.setText("UUID");
118 column
.setWidth(300);
123 // TODO : Improve this methods.
124 // For now it is a workaround because we cannot dynamically update context
125 // menu to pass the UUID as command parameter
126 // public String[] getSelectedResult() {
127 // Object obj = ((IStructuredSelection) viewer.getSelection())
128 // .getFirstElement();
130 // String[] attributes = new String[2];
132 // if (obj == null || !(obj instanceof ResultAttributes))
135 // ResultAttributes ra = (ResultAttributes) obj;
136 // attributes[0] = ra.getUuid();
137 // attributes[1] = (ra.getAttributes().get("testCase") == null) ? null
138 // : ra.getAttributes().get("testCase");
139 // return attributes;
143 // View Specific inner class
146 class SelectionChangedListener
implements ISelectionChangedListener
{
147 public void selectionChanged(SelectionChangedEvent evt
) {
149 IStructuredSelection curSelection
= (IStructuredSelection
) evt
151 Object obj
= curSelection
.getFirstElement();
153 if (obj
instanceof ResultAttributes
) {
154 selectedRa
= (ResultAttributes
) obj
;
159 private void refreshCommand(IMenuManager menuManager
,
160 IServiceLocator locator
, String cmdId
, String label
, String iconPath
) {
161 IContributionItem ici
= menuManager
.find(cmdId
);
163 menuManager
.remove(ici
);
164 CommandContributionItemParameter contributionItemParameter
= new CommandContributionItemParameter(
165 locator
, null, cmdId
, SWT
.PUSH
);
168 contributionItemParameter
.label
= label
;
169 contributionItemParameter
.icon
= ClientUiPlugin
170 .getImageDescriptor(iconPath
);
172 Map
<String
, String
> params
= new HashMap
<String
, String
>();
173 params
.put(UUID_PARAM_ID
, selectedRa
.getUuid());
174 params
.put(NAME_PARAM_ID
,
175 (selectedRa
.getAttributes().get("testCase") == null) ?
null
176 : selectedRa
.getAttributes().get("testCase"));
177 contributionItemParameter
.parameters
= params
;
179 CommandContributionItem cci
= new CommandContributionItem(
180 contributionItemParameter
);
182 menuManager
.add(cci
);
185 private void contextMenuAboutToShow(IMenuManager menuManager
) {
187 IWorkbenchWindow window
= ClientUiPlugin
.getDefault().getWorkbench()
188 .getActiveWorkbenchWindow();
190 refreshCommand(menuManager
, window
, DISPLAY_CMD_ID
,
191 "Display as a tree", "icons/result_details.gif");
192 // We only show this command on windows OS
193 if (PLATFORM
.equals("win32") || PLATFORM
.equals("wpf")) {
194 refreshCommand(menuManager
, window
, DISPLAY_AS_XLS_CMD_ID
,
195 "Display with Excel", "icons/excel.png");
197 refreshCommand(menuManager
, window
, SAVE_AS_XLS_CMD_ID
,
198 "Save as Excel file", "icons/excel.png");
203 protected static class ViewContentProvider
implements
204 IStructuredContentProvider
{
206 public void inputChanged(Viewer arg0
, Object arg1
, Object arg2
) {
209 public void dispose() {
212 @SuppressWarnings("unchecked")
213 public Object
[] getElements(Object obj
) {
214 if (obj
instanceof List
) {
215 return ((List
<ResultAttributes
>) obj
).toArray();
217 return new Object
[0];
222 protected class ViewLabelProvider
extends LabelProvider
implements
223 ITableLabelProvider
{
224 public String
getColumnText(Object obj
, int index
) {
225 ResultAttributes ra
= (ResultAttributes
) obj
;
228 return (ra
.getAttributes().get("testCase") == null) ?
null : ra
229 .getAttributes().get("testCase");
231 // otherwise we get null pointer exception when the test is not
233 return (ra
.getCloseDate() == null) ?
null : dateFormatter
234 .format(ra
.getCloseDate());
241 public Image
getColumnImage(Object obj
, int index
) {
247 public void setFocus() {
248 viewer
.getControl().setFocus();
251 public void retrieveResults() {
253 List
<ResultAttributes
> lst
= testResultCollectionDao
254 .listResultAttributes(null);
255 if (log
.isTraceEnabled())
256 log
.trace("Result attributes count: " + lst
.size());
257 viewer
.setInput(lst
);
259 } catch (Exception e
) {
260 // TODO Auto-generated catch block
268 * The ResultAttributes expose a part of the information contained in the
269 * TreeTestResult, It has the same UUID as the corresponding treeTestResult.
271 class ViewDoubleClickListener
implements IDoubleClickListener
{
272 public void doubleClick(DoubleClickEvent evt
) {
273 Object obj
= ((IStructuredSelection
) evt
.getSelection())
276 if (obj
instanceof ResultAttributes
) {
277 ResultAttributes ra
= (ResultAttributes
) obj
;
278 IWorkbench iw
= ClientUiPlugin
.getDefault().getWorkbench();
279 IHandlerService handlerService
= (IHandlerService
) iw
280 .getService(IHandlerService
.class);
282 // get the command from plugin.xml
283 IWorkbenchWindow window
= iw
.getActiveWorkbenchWindow();
284 ICommandService cmdService
= (ICommandService
) window
285 .getService(ICommandService
.class);
286 Command cmd
= cmdService
287 .getCommand("org.argeo.slc.client.ui.displayResultDetails");
289 // log.debug("cmd : " + cmd);
290 ArrayList
<Parameterization
> parameters
= new ArrayList
<Parameterization
>();
293 IParameter iparam
= cmd
294 .getParameter("org.argeo.slc.client.commands.resultUuid");
296 Parameterization params
= new Parameterization(iparam
,
298 parameters
.add(params
);
300 // build the parameterized command
301 ParameterizedCommand pc
= new ParameterizedCommand(cmd
,
302 parameters
.toArray(new Parameterization
[parameters
305 // execute the command
306 handlerService
= (IHandlerService
) window
307 .getService(IHandlerService
.class);
308 handlerService
.executeCommand(pc
, null);
310 } catch (Exception e
) {
312 throw new SlcException("Problem while rendering result. "
320 public void setTestResultCollectionDao(
321 TreeTestResultCollectionDao testResultCollectionDao
) {
322 this.testResultCollectionDao
= testResultCollectionDao
;