]> git.argeo.org Git - gpl/argeo-slc.git/blob - eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ResultListView.java
-> add a new command to automatically refresh Result Test List
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.client.ui / src / org / argeo / slc / client / ui / views / ResultListView.java
1 package org.argeo.slc.client.ui.views;
2
3 import java.util.List;
4
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7 import org.argeo.slc.core.test.tree.ResultAttributes;
8 import org.argeo.slc.dao.test.tree.TreeTestResultCollectionDao;
9 import org.eclipse.jface.viewers.IStructuredContentProvider;
10 import org.eclipse.jface.viewers.ITableLabelProvider;
11 import org.eclipse.jface.viewers.LabelProvider;
12 import org.eclipse.jface.viewers.TableViewer;
13 import org.eclipse.jface.viewers.Viewer;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.graphics.Image;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Table;
19 import org.eclipse.swt.widgets.TableColumn;
20 import org.eclipse.ui.part.ViewPart;
21
22 public class ResultListView extends ViewPart {
23 private final static Log log = LogFactory.getLog(ResultListView.class);
24
25 public static final String ID = "org.argeo.slc.client.ui.resultListView";
26
27 private TableViewer viewer;
28
29 private TreeTestResultCollectionDao testResultCollectionDao;
30
31 public void createPartControl(Composite parent) {
32 Table table = createTable(parent);
33 viewer = new TableViewer(table);
34 viewer.setLabelProvider(new ViewLabelProvider());
35 viewer.setContentProvider(new ViewContentProvider());
36
37 viewer.setInput(getViewSite());
38 }
39
40 protected Table createTable(Composite parent) {
41 int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL
42 | SWT.FULL_SELECTION | SWT.HIDE_SELECTION;
43
44 Table table = new Table(parent, style);
45
46 GridData gridData = new GridData(GridData.FILL_BOTH);
47 gridData.grabExcessVerticalSpace = true;
48 gridData.grabExcessHorizontalSpace = true;
49 gridData.horizontalSpan = 3;
50 table.setLayoutData(gridData);
51
52 table.setLinesVisible(true);
53 table.setHeaderVisible(true);
54
55 TableColumn column = new TableColumn(table, SWT.LEFT, 0);
56 column.setText("Date");
57 column.setWidth(200);
58
59 column = new TableColumn(table, SWT.LEFT, 1);
60 column.setText("UUID");
61 column.setWidth(300);
62
63 return table;
64 }
65
66 protected static class ViewContentProvider implements IStructuredContentProvider {
67 // private List<ResultAttributes> lst;
68
69 public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
70 // if (arg2 instanceof List) {
71 // lst = (List<ResultAttributes>) arg2;
72 // log.trace("result count: " + lst.size());
73 // }
74 }
75
76 public void dispose() {
77 }
78
79 @SuppressWarnings("unchecked")
80 public Object[] getElements(Object obj) {
81 // if (lst == null)
82 // return new Object[0];
83 // else
84 // return lst.toArray();
85 if (obj instanceof List) {
86 return ((List<ResultAttributes>) obj).toArray();
87 } else {
88 return new Object[0];
89 }
90 // return
91 // testResultCollectionDao.listResultAttributes(null).toArray();
92 }
93 }
94
95 protected class ViewLabelProvider extends LabelProvider implements
96 ITableLabelProvider {
97 public String getColumnText(Object obj, int index) {
98 ResultAttributes ra = (ResultAttributes) obj;
99 switch (index) {
100 case 0:
101 return getText(ra.getCloseDate());
102 case 1:
103 return ra.getUuid();
104 }
105 return getText(obj);
106 }
107
108 public Image getColumnImage(Object obj, int index) {
109 return null;
110 }
111
112 }
113
114 public void setFocus() {
115 viewer.getControl().setFocus();
116 }
117
118 public void retrieveResults() {
119 try {
120 List<ResultAttributes> lst = testResultCollectionDao
121 .listResultAttributes(null);
122 if (log.isTraceEnabled())
123 log.trace("Result attributes count: " + lst.size());
124 viewer.setInput(lst);
125 // viewer.refresh();
126 } catch (Exception e) {
127 // TODO Auto-generated catch block
128 e.printStackTrace();
129 }
130 }
131
132 public void setTestResultCollectionDao(
133 TreeTestResultCollectionDao testResultCollectionDao) {
134 this.testResultCollectionDao = testResultCollectionDao;
135 }
136
137 }