1 package org
.argeo
.slc
.client
.ui
.views
;
3 import java
.io
.ByteArrayInputStream
;
4 import java
.io
.IOException
;
5 import java
.util
.ArrayList
;
7 import java
.util
.Properties
;
10 import org
.apache
.commons
.io
.IOUtils
;
11 import org
.apache
.commons
.logging
.Log
;
12 import org
.apache
.commons
.logging
.LogFactory
;
13 import org
.argeo
.slc
.SlcException
;
14 import org
.argeo
.slc
.client
.oxm
.OxmInterface
;
15 import org
.argeo
.slc
.client
.ui
.ClientUiPlugin
;
16 import org
.argeo
.slc
.client
.ui
.controllers
.ProcessController
;
17 import org
.argeo
.slc
.process
.RealizedFlow
;
18 import org
.argeo
.slc
.process
.SlcExecution
;
19 import org
.argeo
.slc
.runtime
.SlcAgent
;
20 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
21 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
22 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
23 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
24 import org
.eclipse
.jface
.viewers
.LabelProvider
;
25 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
26 import org
.eclipse
.jface
.viewers
.TableViewer
;
27 import org
.eclipse
.jface
.viewers
.Viewer
;
28 import org
.eclipse
.jface
.viewers
.ViewerDropAdapter
;
29 import org
.eclipse
.swt
.SWT
;
30 import org
.eclipse
.swt
.dnd
.DND
;
31 import org
.eclipse
.swt
.dnd
.TextTransfer
;
32 import org
.eclipse
.swt
.dnd
.Transfer
;
33 import org
.eclipse
.swt
.dnd
.TransferData
;
34 import org
.eclipse
.swt
.graphics
.Image
;
35 import org
.eclipse
.swt
.layout
.GridData
;
36 import org
.eclipse
.swt
.widgets
.Composite
;
37 import org
.eclipse
.swt
.widgets
.Table
;
38 import org
.eclipse
.swt
.widgets
.TableColumn
;
39 import org
.eclipse
.ui
.PartInitException
;
40 import org
.eclipse
.ui
.part
.ViewPart
;
43 * Display a list of processes that are to be launched as batch. For the moment
44 * being, only one agent by batch is enabled. The batch is contructed by
45 * dropping process from the ExecutionModuleView. Wrong type of data dropped in
46 * this view might raise errors.
51 public class ProcessBuilderView
extends ViewPart
{
52 private final static Log log
= LogFactory
.getLog(ProcessBuilderView
.class);
54 public static final String ID
= "org.argeo.slc.client.ui.processBuilderView";
55 private static final String EDIT_CMD
= "org.argeo.slc.client.ui.editRealizedFlowDetails";
56 private static final String FLOWASXML_PARAM
= "org.argeo.slc.client.commands.realizedFlowAsXml";
57 private static final String INDEX_PARAM
= "org.argeo.slc.client.commands.realizedFlowIndex";
59 // private final static Log log =
60 // LogFactory.getLog(ProcessBuilderView.class);
62 private TableViewer viewer
;
63 private List
<RealizedFlow
> realizedFlows
= new ArrayList
<RealizedFlow
>();
64 private String currentAgentUuid
= null;
65 private String host
= null;
67 // TODO find a better way to get index of the current selected row
68 // used in removeSelected
69 private int curSelectedRow
= -1;
72 private OxmInterface oxmBean
;
73 private ProcessController processController
;
74 private List
<SlcAgent
> slcAgents
;
76 public void createPartControl(Composite parent
) {
77 Table table
= createTable(parent
);
78 viewer
= new TableViewer(table
);
79 viewer
.setLabelProvider(new ViewLabelProvider());
80 viewer
.setContentProvider(new ViewContentProvider());
81 viewer
.addSelectionChangedListener(new SelectionChangedListener());
83 int operations
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
84 Transfer
[] tt
= new Transfer
[] { TextTransfer
.getInstance() };
85 viewer
.addDropSupport(operations
, tt
, new ViewDropListener(viewer
));
87 viewer
.setInput(getViewSite());
90 protected Table
createTable(Composite parent
) {
91 int style
= SWT
.SINGLE
| SWT
.BORDER
| SWT
.H_SCROLL
| SWT
.V_SCROLL
92 | SWT
.FULL_SELECTION
| SWT
.HIDE_SELECTION
;
94 Table table
= new Table(parent
, style
);
96 GridData gridData
= new GridData(GridData
.FILL_BOTH
);
97 gridData
.grabExcessVerticalSpace
= true;
98 gridData
.grabExcessHorizontalSpace
= true;
99 gridData
.horizontalSpan
= 3;
100 table
.setLayoutData(gridData
);
102 table
.setLinesVisible(true);
103 table
.setHeaderVisible(true);
105 TableColumn column
= new TableColumn(table
, SWT
.LEFT
, 0);
106 column
.setText("Module");
107 column
.setWidth(200);
109 column
= new TableColumn(table
, SWT
.LEFT
, 1);
110 column
.setText("Flow");
111 column
.setWidth(200);
116 protected void execute() {
117 // TODO: use agent proxy to retrieve it
118 SlcAgent agent
= null;
119 SlcExecution slcExecution
= new SlcExecution();
120 slcExecution
.setUuid(UUID
.randomUUID().toString());
121 slcExecution
.setRealizedFlows(realizedFlows
);
122 processController
.execute(agent
, slcExecution
);
125 public void setFocus() {
126 viewer
.getControl().setFocus();
129 // update one of the parameter of a given RealizedFlow
130 public void updateParameter(int realizedFlowIndex
, String paramName
,
132 RealizedFlow curRealizedFlow
= realizedFlows
.get(realizedFlowIndex
);
133 curRealizedFlow
.getFlowDescriptor().getValues().put(paramName
, value
);
136 // clear the realizedFlow<List>
137 public void clearBatch() {
139 realizedFlows
= new ArrayList
<RealizedFlow
>();
141 refreshParameterview();
145 // Remove the selected process from the batch
146 public void removeSelected() {
147 if (curSelectedRow
== -1)
150 realizedFlows
.remove(curSelectedRow
);
152 refreshParameterview();
156 // calling this method with index =-1 will cause the reset of the view.
157 private void refreshParameterview() {
158 // We choose to directly access the view rather than going through
160 ProcessParametersView ppView
;
162 ppView
= (ProcessParametersView
) ClientUiPlugin
.getDefault()
163 .getWorkbench().getActiveWorkbenchWindow().getActivePage()
164 .showView(ProcessParametersView
.ID
);
166 if (curSelectedRow
== -1)
167 ppView
.setRealizedFlow(-1, null);
169 ppView
.setRealizedFlow(curSelectedRow
,
170 realizedFlows
.get(curSelectedRow
));
171 } catch (PartInitException e
) {
172 throw new SlcException(
173 "Cannot Retrieve ProcessParameterView to edit parameters of selected process",
178 // Return the list of the processes to execute.
179 public void launchBatch() {
180 SlcExecution slcExecution
= new SlcExecution();
181 slcExecution
.setUuid(UUID
.randomUUID().toString());
183 slcExecution
.setRealizedFlows(realizedFlows
);
184 slcExecution
.setHost(host
);
186 // TODO : insure that the concept has been well understood & the
187 // specification respected
189 for (int i
= 0; i
< slcAgents
.size(); i
++) {
190 if (currentAgentUuid
== null)
191 throw new SlcException(
192 "Cannot launch a batch if no agent is specified");
193 if (currentAgentUuid
.equals(slcAgents
.get(i
).getAgentUuid())) {
194 curAgent
= slcAgents
.get(i
);
195 processController
.execute(curAgent
, slcExecution
);
201 // Specific Providers for the current view.
202 protected class ViewContentProvider
implements IStructuredContentProvider
{
203 public void inputChanged(Viewer arg0
, Object arg1
, Object arg2
) {
206 public void dispose() {
209 public Object
[] getElements(Object obj
) {
210 return realizedFlows
.toArray();
214 protected class ViewLabelProvider
extends LabelProvider
implements
215 ITableLabelProvider
{
216 public String
getColumnText(Object obj
, int index
) {
217 RealizedFlow rf
= (RealizedFlow
) obj
;
220 return rf
.getModuleName();
222 return rf
.getFlowDescriptor().getName();
227 public Image
getColumnImage(Object obj
, int index
) {
234 class SelectionChangedListener
implements ISelectionChangedListener
{
235 public void selectionChanged(SelectionChangedEvent evt
) {
237 IStructuredSelection curSelection
= (IStructuredSelection
) evt
239 Object obj
= curSelection
.getFirstElement();
241 if (obj
instanceof RealizedFlow
) {
242 RealizedFlow rf
= (RealizedFlow
) obj
;
243 curSelectedRow
= realizedFlows
.indexOf(rf
);
244 refreshParameterview();
249 // Implementation of the Drop Listener
250 protected class ViewDropListener
extends ViewerDropAdapter
{
252 public ViewDropListener(Viewer viewer
) {
257 public boolean performDrop(Object data
) {
259 Properties props
= new Properties();
261 // TODO : Handle wrong type of dropped data
262 ByteArrayInputStream in
= new ByteArrayInputStream(data
.toString()
266 } catch (IOException e
) {
267 throw new SlcException("Cannot create read flow node", e
);
269 IOUtils
.closeQuietly(in
);
272 String agentId
= props
.getProperty("agentId");
273 if (currentAgentUuid
== null) {
274 currentAgentUuid
= agentId
;
275 host
= props
.getProperty("host");
276 } else if (!currentAgentUuid
.equals(agentId
)) {
277 // TODO: as for now, we can only construct batch on a single
278 // Agent, must be upgraded to enable batch on various agent.
279 throw new SlcException(
280 "Cannot create batch on two (or more) distinct agents",
285 String fdXml
= props
.getProperty("RealizedFlowAsXml");
288 RealizedFlow rf
= (RealizedFlow
) oxmBean
.unmarshal(fdXml
);
289 realizedFlows
.add(rf
);
290 curSelectedRow
= realizedFlows
.indexOf(rf
);
291 refreshParameterview();
292 getViewer().refresh();
297 public boolean validateDrop(Object target
, int operation
,
298 TransferData transferType
) {
304 public void setSlcAgents(List
<SlcAgent
> slcAgents
) {
305 this.slcAgents
= slcAgents
;
308 public void setOxmBean(OxmInterface oxmBean
) {
309 this.oxmBean
= oxmBean
;
312 public void setProcessController(ProcessController processController
) {
313 this.processController
= processController
;