]> git.argeo.org Git - gpl/argeo-slc.git/blob - eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessListView.java
Introduce process builder view with drag and drop
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.client.ui / src / org / argeo / slc / client / ui / views / ProcessListView.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.process.SlcExecutionDao;
9 import org.argeo.slc.process.SlcExecution;
10 import org.eclipse.jface.viewers.IStructuredContentProvider;
11 import org.eclipse.jface.viewers.ITableLabelProvider;
12 import org.eclipse.jface.viewers.LabelProvider;
13 import org.eclipse.jface.viewers.TableViewer;
14 import org.eclipse.jface.viewers.Viewer;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.graphics.Image;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Table;
20 import org.eclipse.swt.widgets.TableColumn;
21 import org.eclipse.ui.part.ViewPart;
22
23 public class ProcessListView extends ViewPart {
24 private final static Log log = LogFactory
25 .getLog(ProcessListView.class);
26
27 public static final String ID = "org.argeo.slc.client.ui.processListView";
28
29 private TableViewer viewer;
30
31 private SlcExecutionDao slcExecutionDao;
32
33 public void createPartControl(Composite parent) {
34 Table table = createTable(parent);
35 viewer = new TableViewer(table);
36 viewer.setLabelProvider(new ViewLabelProvider());
37 viewer.setContentProvider(new ViewContentProvider());
38
39 viewer.setInput(getViewSite());
40 }
41
42 protected Table createTable(Composite parent) {
43 int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL
44 | SWT.FULL_SELECTION | SWT.HIDE_SELECTION;
45
46 Table table = new Table(parent, style);
47
48 GridData gridData = new GridData(GridData.FILL_BOTH);
49 gridData.grabExcessVerticalSpace = true;
50 gridData.grabExcessHorizontalSpace = true;
51 gridData.horizontalSpan = 3;
52 table.setLayoutData(gridData);
53
54 table.setLinesVisible(true);
55 table.setHeaderVisible(true);
56
57 TableColumn column = new TableColumn(table, SWT.LEFT, 0);
58 column.setText("Date");
59 column.setWidth(200);
60
61 column = new TableColumn(table, SWT.LEFT, 1);
62 column.setText("Host");
63 column.setWidth(100);
64
65 column = new TableColumn(table, SWT.LEFT, 2);
66 column.setText("Id");
67 column.setWidth(300);
68
69 column = new TableColumn(table, SWT.LEFT, 3);
70 column.setText("Status");
71 column.setWidth(100);
72
73 return table;
74 }
75
76 protected static class ViewContentProvider implements
77 IStructuredContentProvider {
78
79 public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
80 }
81
82 public void dispose() {
83 }
84
85 @SuppressWarnings("unchecked")
86 public Object[] getElements(Object obj) {
87 if (obj instanceof List) {
88 return ((List<ResultAttributes>) obj).toArray();
89 } else {
90 return new Object[0];
91 }
92 }
93 }
94
95 protected class ViewLabelProvider extends LabelProvider implements
96 ITableLabelProvider {
97 public String getColumnText(Object obj, int index) {
98 SlcExecution ra = (SlcExecution) obj;
99 switch (index) {
100
101 case 0:
102 return getText(ra.getStartDate());
103 case 1:
104 return ra.getHost();
105 case 2:
106 return ra.getUuid();
107 case 3:
108 return ra.currentStep().getType();
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<SlcExecution> lst = slcExecutionDao.listSlcExecutions();
126
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 public void setSlcExecutionDao(SlcExecutionDao slcExecutionDao) {
138 this.slcExecutionDao = slcExecutionDao;
139 }
140
141 }