]> 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/ProcessListView.java
Finalise excel support for windows
[gpl/argeo-slc.git] / eclipse / plugins / runtime / org.argeo.slc.client.ui / src / main / java / org / argeo / slc / client / ui / views / ProcessListView.java
1 package org.argeo.slc.client.ui.views;
2
3 import java.util.ArrayList;
4
5 import org.argeo.slc.SlcException;
6 import org.argeo.slc.client.ui.ClientUiPlugin;
7 import org.argeo.slc.dao.process.SlcExecutionDao;
8 import org.argeo.slc.process.SlcExecution;
9 import org.eclipse.core.commands.Command;
10 import org.eclipse.core.commands.IParameter;
11 import org.eclipse.core.commands.Parameterization;
12 import org.eclipse.core.commands.ParameterizedCommand;
13 import org.eclipse.jface.viewers.DoubleClickEvent;
14 import org.eclipse.jface.viewers.IDoubleClickListener;
15 import org.eclipse.jface.viewers.IStructuredContentProvider;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.jface.viewers.ITableLabelProvider;
18 import org.eclipse.jface.viewers.TableViewer;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.layout.GridData;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Table;
23 import org.eclipse.swt.widgets.TableColumn;
24 import org.eclipse.ui.IWorkbench;
25 import org.eclipse.ui.IWorkbenchWindow;
26 import org.eclipse.ui.commands.ICommandService;
27 import org.eclipse.ui.handlers.IHandlerService;
28 import org.eclipse.ui.part.ViewPart;
29
30 /**
31 * This class display the list of all processes that have run in the
32 * corresponding agent. Currently, the local agent.
33 *
34 * @author bsinou
35 *
36 */
37 public class ProcessListView extends ViewPart {
38 // private final static Log log = LogFactory.getLog(ProcessListView.class);
39
40 public static final String ID = "org.argeo.slc.client.ui.processListView";
41
42 private TableViewer viewer;
43
44 // IoC
45 private SlcExecutionDao slcExecutionDao;
46 private ITableLabelProvider tableLabelProvider;
47 private IStructuredContentProvider structuredContentProvider;
48
49 public void createPartControl(Composite parent) {
50 Table table = createTable(parent);
51 viewer = new TableViewer(table);
52 viewer.setLabelProvider(tableLabelProvider);
53 viewer.setContentProvider(structuredContentProvider);
54 viewer.setInput(getViewSite());
55 viewer.addDoubleClickListener(new ViewDoubleClickListener());
56
57 }
58
59 protected Table createTable(Composite parent) {
60 int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL
61 | SWT.FULL_SELECTION | SWT.HIDE_SELECTION;
62
63 Table table = new Table(parent, style);
64
65 GridData gridData = new GridData(GridData.FILL_BOTH);
66 gridData.grabExcessVerticalSpace = true;
67 gridData.grabExcessHorizontalSpace = true;
68 gridData.horizontalSpan = 3;
69 table.setLayoutData(gridData);
70
71 table.setLinesVisible(true);
72 table.setHeaderVisible(true);
73
74 TableColumn column = new TableColumn(table, SWT.LEFT, 0);
75 column.setText("Date");
76 column.setWidth(200);
77
78 column = new TableColumn(table, SWT.LEFT, 1);
79 column.setText("Host");
80 column.setWidth(100);
81
82 column = new TableColumn(table, SWT.LEFT, 2);
83 column.setText("Id");
84 column.setWidth(300);
85
86 column = new TableColumn(table, SWT.LEFT, 3);
87 column.setText("Status");
88 column.setWidth(100);
89
90 return table;
91 }
92
93 public void setFocus() {
94 viewer.getControl().setFocus();
95 }
96
97 public void retrieveResults() {
98 viewer.setInput(slcExecutionDao.listSlcExecutions());
99 }
100
101 // Handle Events
102 class ViewDoubleClickListener implements IDoubleClickListener {
103 public void doubleClick(DoubleClickEvent evt) {
104 Object obj = ((IStructuredSelection) evt.getSelection())
105 .getFirstElement();
106
107 if (obj instanceof SlcExecution) {
108 SlcExecution se = (SlcExecution) obj;
109
110 IWorkbench iw = ClientUiPlugin.getDefault().getWorkbench();
111 IHandlerService handlerService = (IHandlerService) iw
112 .getService(IHandlerService.class);
113 try {
114 // get the command from plugin.xml
115 IWorkbenchWindow window = iw.getActiveWorkbenchWindow();
116 ICommandService cmdService = (ICommandService) window
117 .getService(ICommandService.class);
118 Command cmd = cmdService
119 .getCommand("org.argeo.slc.client.ui.displayProcessDetails");
120
121 ArrayList<Parameterization> parameters = new ArrayList<Parameterization>();
122
123 // get the parameter
124 IParameter iparam = cmd
125 .getParameter("org.argeo.slc.client.commands.processUuid");
126 Parameterization params = new Parameterization(iparam, se
127 .getUuid()); // "testUUID");//
128 parameters.add(params);
129
130 // build the parameterized command
131 ParameterizedCommand pc = new ParameterizedCommand(cmd,
132 parameters.toArray(new Parameterization[parameters
133 .size()]));
134
135 // execute the command
136 handlerService = (IHandlerService) window
137 .getService(IHandlerService.class);
138 handlerService.executeCommand(pc, null);
139
140 } catch (Exception e) {
141 e.printStackTrace();
142 throw new SlcException("Problem while rendering result. "
143 + e.getMessage());
144 }
145 }
146 }
147 }
148
149 // IoC
150 public void setSlcExecutionDao(SlcExecutionDao slcExecutionDao) {
151 this.slcExecutionDao = slcExecutionDao;
152 }
153
154 public void setTableLabelProvider(ITableLabelProvider tableLabelProvider) {
155 this.tableLabelProvider = tableLabelProvider;
156 }
157
158 public void setStructuredContentProvider(
159 IStructuredContentProvider structuredContentProvider) {
160 this.structuredContentProvider = structuredContentProvider;
161 }
162
163 }