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
.argeo
.slc
.SlcException
;
12 import org
.argeo
.slc
.client
.oxm
.OxmInterface
;
13 import org
.argeo
.slc
.client
.ui
.ClientUiPlugin
;
14 import org
.argeo
.slc
.client
.ui
.controllers
.ProcessController
;
15 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptor
;
16 import org
.argeo
.slc
.process
.RealizedFlow
;
17 import org
.argeo
.slc
.process
.SlcExecution
;
18 import org
.argeo
.slc
.runtime
.SlcAgent
;
19 import org
.eclipse
.core
.commands
.Command
;
20 import org
.eclipse
.core
.commands
.IParameter
;
21 import org
.eclipse
.core
.commands
.Parameterization
;
22 import org
.eclipse
.core
.commands
.ParameterizedCommand
;
23 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
24 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
25 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
26 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
27 import org
.eclipse
.jface
.viewers
.LabelProvider
;
28 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
29 import org
.eclipse
.jface
.viewers
.TableViewer
;
30 import org
.eclipse
.jface
.viewers
.Viewer
;
31 import org
.eclipse
.jface
.viewers
.ViewerDropAdapter
;
32 import org
.eclipse
.swt
.SWT
;
33 import org
.eclipse
.swt
.dnd
.DND
;
34 import org
.eclipse
.swt
.dnd
.TextTransfer
;
35 import org
.eclipse
.swt
.dnd
.Transfer
;
36 import org
.eclipse
.swt
.dnd
.TransferData
;
37 import org
.eclipse
.swt
.graphics
.Image
;
38 import org
.eclipse
.swt
.layout
.GridData
;
39 import org
.eclipse
.swt
.widgets
.Composite
;
40 import org
.eclipse
.swt
.widgets
.Table
;
41 import org
.eclipse
.swt
.widgets
.TableColumn
;
42 import org
.eclipse
.ui
.IWorkbench
;
43 import org
.eclipse
.ui
.IWorkbenchWindow
;
44 import org
.eclipse
.ui
.commands
.ICommandService
;
45 import org
.eclipse
.ui
.handlers
.IHandlerService
;
46 import org
.eclipse
.ui
.part
.ViewPart
;
49 * Display a list of processes that are to be launched as batch. For the moment
50 * being, only one agent by batch is enabled. The batch is contructed by
51 * dropping process from the ExecutionModuleView. Wrong type of data dropped in
52 * this view might raise errors.
57 public class ProcessBuilderView
extends ViewPart
{
58 public static final String ID
= "org.argeo.slc.client.ui.processBuilderView";
60 // private final static Log log =
61 // LogFactory.getLog(ProcessBuilderView.class);
63 private TableViewer viewer
;
64 private List
<RealizedFlow
> realizedFlows
= new ArrayList
<RealizedFlow
>();
65 private String currentAgentUuid
= null;
68 private OxmInterface oxmBean
;
69 private ProcessController processController
;
71 public void createPartControl(Composite parent
) {
72 Table table
= createTable(parent
);
73 viewer
= new TableViewer(table
);
74 viewer
.setLabelProvider(new ViewLabelProvider());
75 viewer
.setContentProvider(new ViewContentProvider());
76 viewer
.addSelectionChangedListener(new SelectionChangedListener());
78 int operations
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
79 Transfer
[] tt
= new Transfer
[] { TextTransfer
.getInstance() };
80 viewer
.addDropSupport(operations
, tt
, new ViewDropListener(viewer
));
82 viewer
.setInput(getViewSite());
85 protected Table
createTable(Composite parent
) {
86 int style
= SWT
.SINGLE
| SWT
.BORDER
| SWT
.H_SCROLL
| SWT
.V_SCROLL
87 | SWT
.FULL_SELECTION
| SWT
.HIDE_SELECTION
;
89 Table table
= new Table(parent
, style
);
91 GridData gridData
= new GridData(GridData
.FILL_BOTH
);
92 gridData
.grabExcessVerticalSpace
= true;
93 gridData
.grabExcessHorizontalSpace
= true;
94 gridData
.horizontalSpan
= 3;
95 table
.setLayoutData(gridData
);
97 table
.setLinesVisible(true);
98 table
.setHeaderVisible(true);
100 TableColumn column
= new TableColumn(table
, SWT
.LEFT
, 0);
101 column
.setText("Module");
102 column
.setWidth(200);
104 column
= new TableColumn(table
, SWT
.LEFT
, 1);
105 column
.setText("Flow");
106 column
.setWidth(200);
111 protected void execute() {
112 // TODO: use agent proxy to retrieve it
113 SlcAgent agent
= null;
114 SlcExecution slcExecution
= new SlcExecution();
115 slcExecution
.setUuid(UUID
.randomUUID().toString());
116 slcExecution
.setRealizedFlows(realizedFlows
);
117 processController
.execute(agent
, slcExecution
);
120 public void setFocus() {
121 viewer
.getControl().setFocus();
124 // update one of the parameter of a given RealizedFlow
125 public void updateParameter(int realizedFlowIndex
, String paramName
,
127 RealizedFlow curRealizedFlow
= realizedFlows
.get(realizedFlowIndex
);
128 curRealizedFlow
.getFlowDescriptor().getValues().put(paramName
, value
);
131 // Specific Providers for the current view.
132 protected class ViewContentProvider
implements IStructuredContentProvider
{
133 public void inputChanged(Viewer arg0
, Object arg1
, Object arg2
) {
136 public void dispose() {
139 public Object
[] getElements(Object obj
) {
140 return realizedFlows
.toArray();
144 protected class ViewLabelProvider
extends LabelProvider
implements
145 ITableLabelProvider
{
146 public String
getColumnText(Object obj
, int index
) {
147 RealizedFlow rf
= (RealizedFlow
) obj
;
150 return rf
.getModuleName();
152 return rf
.getFlowDescriptor().getName();
157 public Image
getColumnImage(Object obj
, int index
) {
164 class SelectionChangedListener
implements ISelectionChangedListener
{
165 public void selectionChanged(SelectionChangedEvent evt
) {
167 IStructuredSelection curSelection
= (IStructuredSelection
) evt
169 Object obj
= curSelection
.getFirstElement();
171 if (obj
instanceof RealizedFlow
) {
172 RealizedFlow rf
= (RealizedFlow
) obj
;
174 IWorkbench iw
= ClientUiPlugin
.getDefault().getWorkbench();
175 IHandlerService handlerService
= (IHandlerService
) iw
176 .getService(IHandlerService
.class);
180 // when marshalling an ExecutionFlowDescriptor, the Execution
181 // Spec is set correctly,
183 // when marshalling directly a realized flow, paramters are
184 // stored under ExecutionFlowDescriptor.values
185 String result
= oxmBean
.marshal(rf
);
187 // Passing parameters to the command
189 // get the command from plugin.xml
190 IWorkbenchWindow window
= iw
.getActiveWorkbenchWindow();
191 ICommandService cmdService
= (ICommandService
) window
192 .getService(ICommandService
.class);
193 Command cmd
= cmdService
194 .getCommand("org.argeo.slc.client.ui.editRealizedFlowDetails");
196 ArrayList
<Parameterization
> parameters
= new ArrayList
<Parameterization
>();
199 Parameterization params
;
201 // The current index to be able to records changes on
204 .getParameter("org.argeo.slc.client.commands.realizedFlowIndex");
205 params
= new Parameterization(iparam
, (new Integer(
206 realizedFlows
.indexOf(rf
))).toString());
208 parameters
.add(params
);
210 // The current Realized flow marshalled as XML
213 .getParameter("org.argeo.slc.client.commands.realizedFlowAsXml");
214 params
= new Parameterization(iparam
, result
);
215 parameters
.add(params
);
217 // build the parameterized command
218 ParameterizedCommand pc
= new ParameterizedCommand(cmd
,
219 parameters
.toArray(new Parameterization
[parameters
222 // execute the command
223 handlerService
= (IHandlerService
) window
224 .getService(IHandlerService
.class);
225 handlerService
.executeCommand(pc
, null);
227 } catch (Exception e
) {
229 throw new SlcException("Problem while rendering result. "
236 // Implementation of the Drop Listener
237 protected class ViewDropListener
extends ViewerDropAdapter
{
239 public ViewDropListener(Viewer viewer
) {
244 public boolean performDrop(Object data
) {
246 Properties props
= new Properties();
248 // TODO : Handle wrong type of dropped data
249 ByteArrayInputStream in
= new ByteArrayInputStream(data
.toString()
253 } catch (IOException e
) {
254 throw new SlcException("Cannot create read flow node", e
);
256 IOUtils
.closeQuietly(in
);
259 String agentId
= props
.getProperty("agentId");
260 if (currentAgentUuid
== null)
261 currentAgentUuid
= agentId
;
262 else if (!currentAgentUuid
.equals(agentId
)) {
263 // TODO: as for now, we can only construct batch on a single
265 // must be upgraded to enable batch on various agent.
266 throw new SlcException(
267 "Cannot create batch on two (or more) distinct agents",
272 RealizedFlow rf
= realizedFlowFromProperties(props
);
273 realizedFlows
.add(rf
);
275 getViewer().refresh();
279 private RealizedFlow
realizedFlowFromProperties(Properties props
) {
280 RealizedFlow rf
= new RealizedFlow();
281 rf
.setModuleName(props
.getProperty("moduleName"));
282 rf
.setModuleVersion(props
.getProperty("moduleVersion"));
283 String fdXml
= props
.getProperty("FlowDescriptorAsXml");
285 Object o
= oxmBean
.unmarshal(fdXml
);
286 if (o
instanceof ExecutionFlowDescriptor
) {
287 rf
.setFlowDescriptor((ExecutionFlowDescriptor
) o
);
288 System
.out
.println("instance of EFD !!!"
289 + rf
.getFlowDescriptor().toString());
290 System
.out
.println(rf
.getFlowDescriptor()
291 .getExecutionSpec());
297 .println("***** WARNING : we should not be here; corresponding flow name"
298 + props
.getProperty("flowName"));
299 ExecutionFlowDescriptor efd
= new ExecutionFlowDescriptor();
300 efd
.setName(props
.getProperty("flowName"));
301 rf
.setFlowDescriptor(efd
);
306 public boolean validateDrop(Object target
, int operation
,
307 TransferData transferType
) {
313 public void setOxmBean(OxmInterface oxmBean
) {
314 this.oxmBean
= oxmBean
;
317 public void setProcessController(ProcessController processController
) {
318 this.processController
= processController
;