]> 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
solving the hibernate transaction problem
[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
67 IStructuredContentProvider {
68 // private List<ResultAttributes> lst;
69
70 public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
71 // if (arg2 instanceof List) {
72 // lst = (List<ResultAttributes>) arg2;
73 // log.trace("result count: " + lst.size());
74 // }
75 }
76
77 public void dispose() {
78 }
79
80 @SuppressWarnings("unchecked")
81 public Object[] getElements(Object obj) {
82 // if (lst == null)
83 // return new Object[0];
84 // else
85 // return lst.toArray();
86 if (obj instanceof List) {
87 return ((List<ResultAttributes>) obj).toArray();
88 } else {
89 return new Object[0];
90 }
91 // return
92 // testResultCollectionDao.listResultAttributes(null).toArray();
93 }
94 }
95
96 protected class ViewLabelProvider extends LabelProvider implements
97 ITableLabelProvider {
98 public String getColumnText(Object obj, int index) {
99 ResultAttributes ra = (ResultAttributes) obj;
100 switch (index) {
101 case 0:
102 return getText(ra.getCloseDate());
103 case 1:
104 return ra.getUuid();
105 }
106 return getText(obj);
107 }
108
109 public Image getColumnImage(Object obj, int index) {
110 return null;
111 }
112
113 }
114
115 public void setFocus() {
116 viewer.getControl().setFocus();
117 }
118
119 public void retrieveResults() {
120 try {
121 List<ResultAttributes> lst = testResultCollectionDao
122 .listResultAttributes(null);
123 if (log.isTraceEnabled())
124 log.trace("Result attributes count: " + lst.size());
125 viewer.setInput(lst);
126 // viewer.refresh();
127 } catch (Exception e) {
128 // TODO Auto-generated catch block
129 e.printStackTrace();
130 }
131 }
132
133 // Ioc
134 public void setTestResultCollectionDao(
135 TreeTestResultCollectionDao testResultCollectionDao) {
136 this.testResultCollectionDao = testResultCollectionDao;
137 }
138
139 }