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