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
.widgets
.Composite
;
34 import org
.eclipse
.swt
.widgets
.Table
;
35 import org
.eclipse
.swt
.widgets
.TableColumn
;
36 import org
.eclipse
.ui
.PartInitException
;
37 import org
.eclipse
.ui
.part
.ViewPart
;
40 * Display a list of processes that are to be launched as batch. For the moment
41 * being, only one agent by batch is enabled. The batch is constructed by
42 * dropping process from the ExecutionModuleView. Wrong type of data dropped in
43 * this view raises an error.
48 public class ProcessBuilderView
extends ViewPart
{
49 // private final static Log log =
50 // LogFactory.getLog(ProcessBuilderView.class);
52 public static final String ID
= "org.argeo.slc.client.ui.processBuilderView";
54 private TableViewer viewer
;
55 private List
<RealizedFlow
> realizedFlows
= new ArrayList
<RealizedFlow
>();
56 private String currentAgentUuid
= null;
57 private String host
= null;
59 // TODO find a better way to get index of the current selected row
60 // used in removeSelected
61 private int curSelectedRow
= -1;
64 private OxmInterface oxmBean
;
65 private ProcessController processController
;
66 private List
<SlcAgent
> slcAgents
;
68 public void createPartControl(Composite parent
) {
69 Table table
= createTable(parent
);
70 viewer
= new TableViewer(table
);
71 viewer
.setLabelProvider(new ViewLabelProvider());
72 viewer
.setContentProvider(new ViewContentProvider());
73 viewer
.addSelectionChangedListener(new SelectionChangedListener());
75 int operations
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
76 Transfer
[] tt
= new Transfer
[] { TextTransfer
.getInstance() };
77 viewer
.addDropSupport(operations
, tt
, new ViewDropListener(viewer
));
79 viewer
.setInput(getViewSite());
82 protected Table
createTable(Composite parent
) {
83 int style
= SWT
.SINGLE
| SWT
.BORDER
| SWT
.H_SCROLL
| SWT
.V_SCROLL
86 Table table
= new Table(parent
, style
);
88 table
.setLinesVisible(true);
89 table
.setHeaderVisible(true);
91 TableColumn column
= new TableColumn(table
, SWT
.LEFT
, 0);
92 column
.setText("Module");
95 column
= new TableColumn(table
, SWT
.LEFT
, 1);
96 column
.setText("Flow");
102 protected void execute() {
103 // TODO: use agent proxy to retrieve it
104 SlcAgent agent
= null;
105 SlcExecution slcExecution
= new SlcExecution();
106 slcExecution
.setUuid(UUID
.randomUUID().toString());
107 slcExecution
.setRealizedFlows(realizedFlows
);
108 processController
.execute(agent
, slcExecution
);
111 public void setFocus() {
112 viewer
.getControl().setFocus();
115 // update one of the parameter of a given RealizedFlow
116 public void updateParameter(int realizedFlowIndex
, String paramName
,
118 RealizedFlow curRealizedFlow
= realizedFlows
.get(realizedFlowIndex
);
119 curRealizedFlow
.getFlowDescriptor().getValues().put(paramName
, value
);
122 // clear the realizedFlow<List>
123 public void clearBatch() {
125 realizedFlows
= new ArrayList
<RealizedFlow
>();
127 refreshParameterview();
131 // Remove the selected process from the batch
132 public void removeSelected() {
133 if (curSelectedRow
== -1)
136 realizedFlows
.remove(curSelectedRow
);
138 refreshParameterview();
142 // calling this method with index =-1 will cause the reset of the view.
143 private void refreshParameterview() {
144 // We choose to directly access the view rather than going through
146 ProcessParametersView ppView
;
148 ppView
= (ProcessParametersView
) ClientUiPlugin
.getDefault()
149 .getWorkbench().getActiveWorkbenchWindow().getActivePage()
150 .showView(ProcessParametersView
.ID
);
152 if (curSelectedRow
== -1)
153 ppView
.setRealizedFlow(-1, null);
155 ppView
.setRealizedFlow(curSelectedRow
,
156 realizedFlows
.get(curSelectedRow
));
157 } catch (PartInitException e
) {
158 throw new SlcException(
159 "Cannot Retrieve ProcessParameterView to edit parameters of selected process",
164 // Launches the execution of listed realized flow with specified parameters.
165 public void launchBatch() {
166 SlcExecution slcExecution
= new SlcExecution();
167 slcExecution
.setUuid(UUID
.randomUUID().toString());
169 slcExecution
.setRealizedFlows(realizedFlows
);
170 slcExecution
.setHost(host
);
172 // TODO : insure that the concept has been well understood & the
173 // specification respected
175 for (int i
= 0; i
< slcAgents
.size(); i
++) {
176 if (currentAgentUuid
== null)
177 throw new SlcException(
178 "Cannot launch a batch if no agent is specified");
179 if (currentAgentUuid
.equals(slcAgents
.get(i
).getAgentUuid())) {
180 curAgent
= slcAgents
.get(i
);
181 processController
.execute(curAgent
, slcExecution
);
187 // Specific Providers for the current view.
188 protected class ViewContentProvider
implements IStructuredContentProvider
{
189 public void inputChanged(Viewer arg0
, Object arg1
, Object arg2
) {
192 public void dispose() {
195 public Object
[] getElements(Object obj
) {
196 return realizedFlows
.toArray();
200 protected class ViewLabelProvider
extends LabelProvider
implements
201 ITableLabelProvider
{
202 public String
getColumnText(Object obj
, int index
) {
203 RealizedFlow rf
= (RealizedFlow
) obj
;
206 return rf
.getModuleName();
208 return rf
.getFlowDescriptor().getName();
213 public Image
getColumnImage(Object obj
, int index
) {
219 // Parameter view is updated each time a new line is selected
220 class SelectionChangedListener
implements ISelectionChangedListener
{
221 public void selectionChanged(SelectionChangedEvent evt
) {
223 IStructuredSelection curSelection
= (IStructuredSelection
) evt
225 Object obj
= curSelection
.getFirstElement();
227 if (obj
instanceof RealizedFlow
) {
228 RealizedFlow rf
= (RealizedFlow
) obj
;
229 curSelectedRow
= realizedFlows
.indexOf(rf
);
230 refreshParameterview();
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 host
= props
.getProperty("host");
263 } else if (!currentAgentUuid
.equals(agentId
)) {
264 // TODO: as for now, we can only construct batch on a single
265 // Agent, must be upgraded to enable batch on various agent.
266 throw new SlcException(
267 "Cannot create batch on two (or more) distinct agents",
271 String fdXml
= props
.getProperty("RealizedFlowAsXml");
274 RealizedFlow rf
= (RealizedFlow
) oxmBean
.unmarshal(fdXml
);
275 realizedFlows
.add(rf
);
276 curSelectedRow
= realizedFlows
.indexOf(rf
);
277 refreshParameterview();
278 getViewer().refresh();
283 public boolean validateDrop(Object target
, int operation
,
284 TransferData transferType
) {
290 public void setSlcAgents(List
<SlcAgent
> slcAgents
) {
291 this.slcAgents
= slcAgents
;
294 public void setOxmBean(OxmInterface oxmBean
) {
295 this.oxmBean
= oxmBean
;
298 public void setProcessController(ProcessController processController
) {
299 this.processController
= processController
;