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
.layout
.GridData
;
36 import org
.eclipse
.swt
.widgets
.Composite
;
37 import org
.eclipse
.swt
.widgets
.Menu
;
38 import org
.eclipse
.swt
.widgets
.Table
;
39 import org
.eclipse
.swt
.widgets
.TableColumn
;
40 import org
.eclipse
.ui
.IWorkbench
;
41 import org
.eclipse
.ui
.IWorkbenchWindow
;
42 import org
.eclipse
.ui
.commands
.ICommandService
;
43 import org
.eclipse
.ui
.handlers
.IHandlerService
;
44 import org
.eclipse
.ui
.menus
.CommandContributionItem
;
45 import org
.eclipse
.ui
.menus
.CommandContributionItemParameter
;
46 import org
.eclipse
.ui
.part
.ViewPart
;
47 import org
.eclipse
.ui
.services
.IServiceLocator
;
49 public class ResultListView
extends ViewPart
{
50 private final static Log log
= LogFactory
.getLog(ResultListView
.class);
52 public static final String ID
= "org.argeo.slc.client.ui.resultListView";
54 private final static String DISPLAY_CMD_ID
= "org.argeo.slc.client.ui.displayResultDetails";
55 private final static String DISPLAY_AS_XLS_CMD_ID
= "com.capco.sparta.client.ui.displayResultDetailsWithExcel";
56 private final static String SAVE_AS_XLS_CMD_ID
= "com.capco.sparta.client.ui.saveResultAsExcelFile";
57 private final static String UUID_PARAM_ID
= "org.argeo.slc.client.commands.resultUuid";
58 private final static String NAME_PARAM_ID
= "org.argeo.slc.client.commands.resultName";
59 private final static String PLATFORM
= SWT
.getPlatform();
61 private final static SimpleDateFormat dateFormatter
= new SimpleDateFormat(
62 "MM/dd/yyyy 'at' HH:mm:ss");
64 private TableViewer viewer
;
65 private TreeTestResultCollectionDao testResultCollectionDao
;
67 private ResultAttributes selectedRa
;
69 public void createPartControl(Composite parent
) {
70 Table table
= createTable(parent
);
71 viewer
= new TableViewer(table
);
72 viewer
.setLabelProvider(new ViewLabelProvider());
73 viewer
.setContentProvider(new ViewContentProvider());
74 viewer
.setInput(getViewSite());
75 viewer
.addDoubleClickListener(new ViewDoubleClickListener());
76 viewer
.addSelectionChangedListener(new SelectionChangedListener());
78 // create the context menu
80 MenuManager menuManager
= new MenuManager();
81 Menu menu
= menuManager
.createContextMenu(viewer
.getControl());
82 menuManager
.addMenuListener(new IMenuListener() {
83 public void menuAboutToShow(IMenuManager manager
) {
84 contextMenuAboutToShow(manager
);
88 viewer
.getControl().setMenu(menu
);
89 getSite().registerContextMenu(menuManager
, viewer
);
92 protected Table
createTable(Composite parent
) {
93 int style
= SWT
.SINGLE
| SWT
.BORDER
| SWT
.H_SCROLL
| SWT
.V_SCROLL
94 | SWT
.FULL_SELECTION
| SWT
.HIDE_SELECTION
;
96 Table table
= new Table(parent
, style
);
97 // table.addMouseListener(new RightClickListener());
98 //GridData gridData = new GridData(GridData.FILL_BOTH);
99 //gridData.grabExcessVerticalSpace = true;
100 //gridData.grabExcessHorizontalSpace = true;
101 //gridData.horizontalSpan = 3;
102 //table.setLayoutData(gridData);
104 table
.setLinesVisible(true);
105 table
.setHeaderVisible(true);
107 TableColumn column
= new TableColumn(table
, SWT
.LEFT
, 0);
108 column
.setText("Test Case");
109 column
.setWidth(200);
111 column
= new TableColumn(table
, SWT
.LEFT
, 1);
112 column
.setText("Close Date");
113 column
.setWidth(120);
115 column
= new TableColumn(table
, SWT
.LEFT
, 2);
116 column
.setText("UUID");
117 column
.setWidth(300);
122 // TODO : Improve this methods.
123 // For now it is a workaround because we cannot dynamically update context
124 // menu to pass the UUID as command parameter
125 // public String[] getSelectedResult() {
126 // Object obj = ((IStructuredSelection) viewer.getSelection())
127 // .getFirstElement();
129 // String[] attributes = new String[2];
131 // if (obj == null || !(obj instanceof ResultAttributes))
134 // ResultAttributes ra = (ResultAttributes) obj;
135 // attributes[0] = ra.getUuid();
136 // attributes[1] = (ra.getAttributes().get("testCase") == null) ? null
137 // : ra.getAttributes().get("testCase");
138 // return attributes;
142 // View Specific inner class
145 class SelectionChangedListener
implements ISelectionChangedListener
{
146 public void selectionChanged(SelectionChangedEvent evt
) {
148 IStructuredSelection curSelection
= (IStructuredSelection
) evt
150 Object obj
= curSelection
.getFirstElement();
152 if (obj
instanceof ResultAttributes
) {
153 selectedRa
= (ResultAttributes
) obj
;
158 private void refreshCommand(IMenuManager menuManager
,
159 IServiceLocator locator
, String cmdId
, String label
, String iconPath
) {
160 IContributionItem ici
= menuManager
.find(cmdId
);
162 menuManager
.remove(ici
);
163 CommandContributionItemParameter contributionItemParameter
= new CommandContributionItemParameter(
164 locator
, null, cmdId
, SWT
.PUSH
);
167 contributionItemParameter
.label
= label
;
168 contributionItemParameter
.icon
= ClientUiPlugin
169 .getImageDescriptor(iconPath
);
171 Map
<String
, String
> params
= new HashMap
<String
, String
>();
172 params
.put(UUID_PARAM_ID
, selectedRa
.getUuid());
173 params
.put(NAME_PARAM_ID
,
174 (selectedRa
.getAttributes().get("testCase") == null) ?
null
175 : selectedRa
.getAttributes().get("testCase"));
176 contributionItemParameter
.parameters
= params
;
178 CommandContributionItem cci
= new CommandContributionItem(
179 contributionItemParameter
);
181 menuManager
.add(cci
);
184 private void contextMenuAboutToShow(IMenuManager menuManager
) {
186 IWorkbenchWindow window
= ClientUiPlugin
.getDefault().getWorkbench()
187 .getActiveWorkbenchWindow();
189 refreshCommand(menuManager
, window
, DISPLAY_CMD_ID
,
190 "Display as a tree", "icons/result_details.gif");
191 // We only show this command on windows OS
192 if (PLATFORM
.equals("win32") || PLATFORM
.equals("wpf")) {
193 refreshCommand(menuManager
, window
, DISPLAY_AS_XLS_CMD_ID
,
194 "Display with Excel", "icons/excel.png");
196 refreshCommand(menuManager
, window
, SAVE_AS_XLS_CMD_ID
,
197 "Save as Excel file", "icons/excel.png");
202 protected static class ViewContentProvider
implements
203 IStructuredContentProvider
{
205 public void inputChanged(Viewer arg0
, Object arg1
, Object arg2
) {
208 public void dispose() {
211 @SuppressWarnings("unchecked")
212 public Object
[] getElements(Object obj
) {
213 if (obj
instanceof List
) {
214 return ((List
<ResultAttributes
>) obj
).toArray();
216 return new Object
[0];
221 protected class ViewLabelProvider
extends LabelProvider
implements
222 ITableLabelProvider
{
223 public String
getColumnText(Object obj
, int index
) {
224 ResultAttributes ra
= (ResultAttributes
) obj
;
227 return (ra
.getAttributes().get("testCase") == null) ?
null : ra
228 .getAttributes().get("testCase");
230 // otherwise we get null pointer exception when the test is not
232 return (ra
.getCloseDate() == null) ?
null : dateFormatter
233 .format(ra
.getCloseDate());
240 public Image
getColumnImage(Object obj
, int index
) {
246 public void setFocus() {
247 viewer
.getControl().setFocus();
250 public void retrieveResults() {
252 List
<ResultAttributes
> lst
= testResultCollectionDao
253 .listResultAttributes(null);
254 if (log
.isTraceEnabled())
255 log
.trace("Result attributes count: " + lst
.size());
256 viewer
.setInput(lst
);
258 } catch (Exception e
) {
259 // TODO Auto-generated catch block
267 * The ResultAttributes expose a part of the information contained in the
268 * TreeTestResult, It has the same UUID as the corresponding treeTestResult.
270 class ViewDoubleClickListener
implements IDoubleClickListener
{
271 public void doubleClick(DoubleClickEvent evt
) {
272 Object obj
= ((IStructuredSelection
) evt
.getSelection())
275 if (obj
instanceof ResultAttributes
) {
276 ResultAttributes ra
= (ResultAttributes
) obj
;
277 IWorkbench iw
= ClientUiPlugin
.getDefault().getWorkbench();
278 IHandlerService handlerService
= (IHandlerService
) iw
279 .getService(IHandlerService
.class);
281 // get the command from plugin.xml
282 IWorkbenchWindow window
= iw
.getActiveWorkbenchWindow();
283 ICommandService cmdService
= (ICommandService
) window
284 .getService(ICommandService
.class);
285 Command cmd
= cmdService
286 .getCommand("org.argeo.slc.client.ui.displayResultDetails");
288 // log.debug("cmd : " + cmd);
289 ArrayList
<Parameterization
> parameters
= new ArrayList
<Parameterization
>();
292 IParameter iparam
= cmd
293 .getParameter("org.argeo.slc.client.commands.resultUuid");
295 Parameterization params
= new Parameterization(iparam
,
297 parameters
.add(params
);
299 // build the parameterized command
300 ParameterizedCommand pc
= new ParameterizedCommand(cmd
,
301 parameters
.toArray(new Parameterization
[parameters
304 // execute the command
305 handlerService
= (IHandlerService
) window
306 .getService(IHandlerService
.class);
307 handlerService
.executeCommand(pc
, null);
309 } catch (Exception e
) {
311 throw new SlcException("Problem while rendering result. "
319 public void setTestResultCollectionDao(
320 TreeTestResultCollectionDao testResultCollectionDao
) {
321 this.testResultCollectionDao
= testResultCollectionDao
;