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
.process
.RealizedFlow
;
16 import org
.argeo
.slc
.process
.SlcExecution
;
17 import org
.argeo
.slc
.runtime
.SlcAgent
;
18 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
19 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
20 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
21 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
22 import org
.eclipse
.jface
.viewers
.LabelProvider
;
23 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
24 import org
.eclipse
.jface
.viewers
.TableViewer
;
25 import org
.eclipse
.jface
.viewers
.Viewer
;
26 import org
.eclipse
.jface
.viewers
.ViewerDropAdapter
;
27 import org
.eclipse
.swt
.SWT
;
28 import org
.eclipse
.swt
.dnd
.DND
;
29 import org
.eclipse
.swt
.dnd
.TextTransfer
;
30 import org
.eclipse
.swt
.dnd
.Transfer
;
31 import org
.eclipse
.swt
.dnd
.TransferData
;
32 import org
.eclipse
.swt
.graphics
.Image
;
33 import org
.eclipse
.swt
.layout
.GridData
;
34 import org
.eclipse
.swt
.widgets
.Composite
;
35 import org
.eclipse
.swt
.widgets
.Table
;
36 import org
.eclipse
.swt
.widgets
.TableColumn
;
37 import org
.eclipse
.ui
.PartInitException
;
38 import org
.eclipse
.ui
.part
.ViewPart
;
41 * Display a list of processes that are to be launched as batch. For the moment
42 * being, only one agent by batch is enabled. The batch is contructed by
43 * dropping process from the ExecutionModuleView. Wrong type of data dropped in
44 * this view might raise errors.
49 public class ProcessBuilderView
extends ViewPart
{
50 // private final static Log log =
51 // LogFactory.getLog(ProcessBuilderView.class);
53 public static final String ID
= "org.argeo.slc.client.ui.processBuilderView";
55 // private final static Log log =
56 // LogFactory.getLog(ProcessBuilderView.class);
58 private TableViewer viewer
;
59 private List
<RealizedFlow
> realizedFlows
= new ArrayList
<RealizedFlow
>();
60 private String currentAgentUuid
= null;
61 private String host
= null;
63 // TODO find a better way to get index of the current selected row
64 // used in removeSelected
65 private int curSelectedRow
= -1;
68 private OxmInterface oxmBean
;
69 private ProcessController processController
;
70 private List
<SlcAgent
> slcAgents
;
72 public void createPartControl(Composite parent
) {
73 Table table
= createTable(parent
);
74 viewer
= new TableViewer(table
);
75 viewer
.setLabelProvider(new ViewLabelProvider());
76 viewer
.setContentProvider(new ViewContentProvider());
77 viewer
.addSelectionChangedListener(new SelectionChangedListener());
79 int operations
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
80 Transfer
[] tt
= new Transfer
[] { TextTransfer
.getInstance() };
81 viewer
.addDropSupport(operations
, tt
, new ViewDropListener(viewer
));
83 viewer
.setInput(getViewSite());
86 protected Table
createTable(Composite parent
) {
87 int style
= SWT
.SINGLE
| SWT
.BORDER
| SWT
.H_SCROLL
| SWT
.V_SCROLL
88 | SWT
.FULL_SELECTION
| SWT
.HIDE_SELECTION
;
90 Table table
= new Table(parent
, style
);
92 // GridData gridData = new GridData(GridData.FILL_BOTH);
93 // gridData.grabExcessVerticalSpace = true;
94 // gridData.grabExcessHorizontalSpace = true;
95 // gridData.horizontalSpan = 3;
96 // table.setLayoutData(gridData);
98 table
.setLinesVisible(true);
99 table
.setHeaderVisible(true);
101 TableColumn column
= new TableColumn(table
, SWT
.LEFT
, 0);
102 column
.setText("Module");
103 column
.setWidth(200);
105 column
= new TableColumn(table
, SWT
.LEFT
, 1);
106 column
.setText("Flow");
107 column
.setWidth(200);
112 protected void execute() {
113 // TODO: use agent proxy to retrieve it
114 SlcAgent agent
= null;
115 SlcExecution slcExecution
= new SlcExecution();
116 slcExecution
.setUuid(UUID
.randomUUID().toString());
117 slcExecution
.setRealizedFlows(realizedFlows
);
118 processController
.execute(agent
, slcExecution
);
121 public void setFocus() {
122 viewer
.getControl().setFocus();
125 // update one of the parameter of a given RealizedFlow
126 public void updateParameter(int realizedFlowIndex
, String paramName
,
128 RealizedFlow curRealizedFlow
= realizedFlows
.get(realizedFlowIndex
);
129 curRealizedFlow
.getFlowDescriptor().getValues().put(paramName
, value
);
132 // clear the realizedFlow<List>
133 public void clearBatch() {
135 realizedFlows
= new ArrayList
<RealizedFlow
>();
137 refreshParameterview();
141 // Remove the selected process from the batch
142 public void removeSelected() {
143 if (curSelectedRow
== -1)
146 realizedFlows
.remove(curSelectedRow
);
148 refreshParameterview();
152 // calling this method with index =-1 will cause the reset of the view.
153 private void refreshParameterview() {
154 // We choose to directly access the view rather than going through
156 ProcessParametersView ppView
;
158 ppView
= (ProcessParametersView
) ClientUiPlugin
.getDefault()
159 .getWorkbench().getActiveWorkbenchWindow().getActivePage()
160 .showView(ProcessParametersView
.ID
);
162 if (curSelectedRow
== -1)
163 ppView
.setRealizedFlow(-1, null);
165 ppView
.setRealizedFlow(curSelectedRow
,
166 realizedFlows
.get(curSelectedRow
));
167 } catch (PartInitException e
) {
168 throw new SlcException(
169 "Cannot Retrieve ProcessParameterView to edit parameters of selected process",
174 // Return the list of the processes to execute.
175 public void launchBatch() {
176 SlcExecution slcExecution
= new SlcExecution();
177 slcExecution
.setUuid(UUID
.randomUUID().toString());
179 slcExecution
.setRealizedFlows(realizedFlows
);
180 slcExecution
.setHost(host
);
182 // TODO : insure that the concept has been well understood & the
183 // specification respected
185 for (int i
= 0; i
< slcAgents
.size(); i
++) {
186 if (currentAgentUuid
== null)
187 throw new SlcException(
188 "Cannot launch a batch if no agent is specified");
189 if (currentAgentUuid
.equals(slcAgents
.get(i
).getAgentUuid())) {
190 curAgent
= slcAgents
.get(i
);
191 processController
.execute(curAgent
, slcExecution
);
197 // Specific Providers for the current view.
198 protected class ViewContentProvider
implements IStructuredContentProvider
{
199 public void inputChanged(Viewer arg0
, Object arg1
, Object arg2
) {
202 public void dispose() {
205 public Object
[] getElements(Object obj
) {
206 return realizedFlows
.toArray();
210 protected class ViewLabelProvider
extends LabelProvider
implements
211 ITableLabelProvider
{
212 public String
getColumnText(Object obj
, int index
) {
213 RealizedFlow rf
= (RealizedFlow
) obj
;
216 return rf
.getModuleName();
218 return rf
.getFlowDescriptor().getName();
223 public Image
getColumnImage(Object obj
, int index
) {
230 class SelectionChangedListener
implements ISelectionChangedListener
{
231 public void selectionChanged(SelectionChangedEvent evt
) {
233 IStructuredSelection curSelection
= (IStructuredSelection
) evt
235 Object obj
= curSelection
.getFirstElement();
237 if (obj
instanceof RealizedFlow
) {
238 RealizedFlow rf
= (RealizedFlow
) obj
;
239 curSelectedRow
= realizedFlows
.indexOf(rf
);
240 refreshParameterview();
246 // Implementation of the Drop Listener
247 protected class ViewDropListener
extends ViewerDropAdapter
{
249 public ViewDropListener(Viewer viewer
) {
254 public boolean performDrop(Object data
) {
256 Properties props
= new Properties();
258 // TODO : Handle wrong type of dropped data
259 ByteArrayInputStream in
= new ByteArrayInputStream(data
.toString()
263 } catch (IOException e
) {
264 throw new SlcException("Cannot create read flow node", e
);
266 IOUtils
.closeQuietly(in
);
269 String agentId
= props
.getProperty("agentId");
270 if (currentAgentUuid
== null) {
271 currentAgentUuid
= agentId
;
272 host
= props
.getProperty("host");
273 } else if (!currentAgentUuid
.equals(agentId
)) {
274 // TODO: as for now, we can only construct batch on a single
275 // Agent, must be upgraded to enable batch on various agent.
276 throw new SlcException(
277 "Cannot create batch on two (or more) distinct agents",
282 String fdXml
= props
.getProperty("RealizedFlowAsXml");
285 RealizedFlow rf
= (RealizedFlow
) oxmBean
.unmarshal(fdXml
);
286 realizedFlows
.add(rf
);
287 curSelectedRow
= realizedFlows
.indexOf(rf
);
288 refreshParameterview();
289 getViewer().refresh();
294 public boolean validateDrop(Object target
, int operation
,
295 TransferData transferType
) {
301 public void setSlcAgents(List
<SlcAgent
> slcAgents
) {
302 this.slcAgents
= slcAgents
;
305 public void setOxmBean(OxmInterface oxmBean
) {
306 this.oxmBean
= oxmBean
;
309 public void setProcessController(ProcessController processController
) {
310 this.processController
= processController
;