]> git.argeo.org Git - gpl/argeo-slc.git/blob - eclipse/plugins/runtime/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/ResultListView.java
+ refactor to separate runtime and module project under eclipse plugin.
[gpl/argeo-slc.git] / eclipse / plugins / runtime / org.argeo.slc.client.ui / src / main / java / org / argeo / slc / client / ui / views / ResultListView.java
1 package org.argeo.slc.client.ui.views;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
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;
35
36 public class ResultListView extends ViewPart {
37 private final static Log log = LogFactory.getLog(ResultListView.class);
38
39 public static final String ID = "org.argeo.slc.client.ui.resultListView";
40
41 private TableViewer viewer;
42
43 private TreeTestResultCollectionDao testResultCollectionDao;
44
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());
52 }
53
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;
57
58 Table table = new Table(parent, style);
59
60 GridData gridData = new GridData(GridData.FILL_BOTH);
61 gridData.grabExcessVerticalSpace = true;
62 gridData.grabExcessHorizontalSpace = true;
63 gridData.horizontalSpan = 3;
64 table.setLayoutData(gridData);
65
66 table.setLinesVisible(true);
67 table.setHeaderVisible(true);
68
69 TableColumn column = new TableColumn(table, SWT.LEFT, 0);
70 column.setText("Date");
71 column.setWidth(200);
72
73 column = new TableColumn(table, SWT.LEFT, 1);
74 column.setText("UUID");
75 column.setWidth(300);
76
77 return table;
78 }
79
80 // View Specific inner class
81 protected static class ViewContentProvider implements
82 IStructuredContentProvider {
83
84 public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
85 }
86
87 public void dispose() {
88 }
89
90 @SuppressWarnings("unchecked")
91 public Object[] getElements(Object obj) {
92 if (obj instanceof List) {
93 return ((List<ResultAttributes>) obj).toArray();
94 } else {
95 return new Object[0];
96 }
97 }
98 }
99
100 protected class ViewLabelProvider extends LabelProvider implements
101 ITableLabelProvider {
102 public String getColumnText(Object obj, int index) {
103 ResultAttributes ra = (ResultAttributes) obj;
104 switch (index) {
105 case 0:
106 return getText(ra.getCloseDate());
107 case 1:
108 return ra.getUuid();
109 }
110 return getText(obj);
111 }
112
113 public Image getColumnImage(Object obj, int index) {
114 return null;
115 }
116
117 }
118
119 public void setFocus() {
120 viewer.getControl().setFocus();
121 }
122
123 public void retrieveResults() {
124 try {
125 List<ResultAttributes> lst = testResultCollectionDao
126 .listResultAttributes(null);
127 if (log.isTraceEnabled())
128 log.trace("Result attributes count: " + lst.size());
129 viewer.setInput(lst);
130 // viewer.refresh();
131 } catch (Exception e) {
132 // TODO Auto-generated catch block
133 e.printStackTrace();
134 }
135 }
136
137 // Handle Events
138 /**
139 * The ResultAttributes expose a part of the information contained in the
140 * TreeTestResult, It has the same UUID as the corresponding treeTestResult.
141 */
142 class ViewDoubleClickListener implements IDoubleClickListener {
143 public void doubleClick(DoubleClickEvent evt) {
144 Object obj = ((IStructuredSelection) evt.getSelection())
145 .getFirstElement();
146
147 if (obj instanceof ResultAttributes) {
148 ResultAttributes ra = (ResultAttributes) obj;
149 log.debug("Double-clic on result with UUID" + ra.getUuid());
150
151 IWorkbench iw = ClientUiPlugin.getDefault().getWorkbench();
152 IHandlerService handlerService = (IHandlerService) iw
153 .getService(IHandlerService.class);
154 try {
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");
161
162 // log.debug("cmd : " + cmd);
163 ArrayList<Parameterization> parameters = new ArrayList<Parameterization>();
164
165 // get the parameter
166 IParameter iparam = cmd
167 .getParameter("org.argeo.slc.client.commands.resultUuid");
168
169 Parameterization params = new Parameterization(iparam,
170 ra.getUuid());
171 parameters.add(params);
172
173 // build the parameterized command
174 ParameterizedCommand pc = new ParameterizedCommand(cmd,
175 parameters.toArray(new Parameterization[parameters
176 .size()]));
177
178 // execute the command
179 handlerService = (IHandlerService) window
180 .getService(IHandlerService.class);
181 handlerService.executeCommand(pc, null);
182
183 } catch (Exception e) {
184 e.printStackTrace();
185 throw new SlcException("Problem while rendering result. "
186 + e.getMessage());
187 }
188 }
189 }
190 }
191
192 // Ioc
193 public void setTestResultCollectionDao(
194 TreeTestResultCollectionDao testResultCollectionDao) {
195 this.testResultCollectionDao = testResultCollectionDao;
196 }
197
198 }