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
.ui
.ClientUiPlugin
;
13 import org
.argeo
.slc
.client
.ui
.controllers
.ProcessController
;
14 import org
.argeo
.slc
.process
.RealizedFlow
;
15 import org
.argeo
.slc
.process
.SlcExecution
;
16 import org
.argeo
.slc
.runtime
.SlcAgent
;
17 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
18 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
19 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
20 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
21 import org
.eclipse
.jface
.viewers
.LabelProvider
;
22 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
23 import org
.eclipse
.jface
.viewers
.TableViewer
;
24 import org
.eclipse
.jface
.viewers
.Viewer
;
25 import org
.eclipse
.jface
.viewers
.ViewerDropAdapter
;
26 import org
.eclipse
.swt
.SWT
;
27 import org
.eclipse
.swt
.dnd
.DND
;
28 import org
.eclipse
.swt
.dnd
.TextTransfer
;
29 import org
.eclipse
.swt
.dnd
.Transfer
;
30 import org
.eclipse
.swt
.dnd
.TransferData
;
31 import org
.eclipse
.swt
.graphics
.Image
;
32 import org
.eclipse
.swt
.widgets
.Composite
;
33 import org
.eclipse
.swt
.widgets
.Table
;
34 import org
.eclipse
.swt
.widgets
.TableColumn
;
35 import org
.eclipse
.ui
.PartInitException
;
36 import org
.eclipse
.ui
.part
.ViewPart
;
39 * Display a list of processes that are to be launched as batch. For the moment
40 * being, only one agent by batch is enabled. The batch is constructed by
41 * dropping process from the ExecutionModuleView. Wrong type of data dropped in
42 * this view raises an error.
47 public class ProcessBuilderView
extends ViewPart
{
48 // private final static Log log =
49 // LogFactory.getLog(ProcessBuilderView.class);
51 public static final String ID
= "org.argeo.slc.client.ui.processBuilderView";
53 private TableViewer viewer
;
54 private List
<RealizedFlow
> realizedFlows
= new ArrayList
<RealizedFlow
>();
55 private String currentAgentUuid
= null;
56 private String host
= null;
58 // TODO find a better way to get index of the current selected row
59 // used in removeSelected
60 private int curSelectedRow
= -1;
63 //private OxmInterface oxmBean;
64 private ProcessController processController
;
65 private List
<SlcAgent
> slcAgents
;
67 public void createPartControl(Composite parent
) {
68 Table table
= createTable(parent
);
69 viewer
= new TableViewer(table
);
70 viewer
.setLabelProvider(new ViewLabelProvider());
71 viewer
.setContentProvider(new ViewContentProvider());
72 viewer
.addSelectionChangedListener(new SelectionChangedListener());
74 int operations
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
75 Transfer
[] tt
= new Transfer
[] { TextTransfer
.getInstance() };
76 viewer
.addDropSupport(operations
, tt
, new ViewDropListener(viewer
));
78 viewer
.setInput(getViewSite());
81 protected Table
createTable(Composite parent
) {
82 int style
= SWT
.SINGLE
| SWT
.BORDER
| SWT
.H_SCROLL
| SWT
.V_SCROLL
85 Table table
= new Table(parent
, style
);
87 table
.setLinesVisible(true);
88 table
.setHeaderVisible(true);
90 TableColumn column
= new TableColumn(table
, SWT
.LEFT
, 0);
91 column
.setText("Module");
94 column
= new TableColumn(table
, SWT
.LEFT
, 1);
95 column
.setText("Flow");
101 protected void execute() {
102 // TODO: use agent proxy to retrieve it
103 SlcAgent agent
= null;
104 SlcExecution slcExecution
= new SlcExecution();
105 slcExecution
.setUuid(UUID
.randomUUID().toString());
106 slcExecution
.setRealizedFlows(realizedFlows
);
107 processController
.execute(agent
, slcExecution
);
110 public void setFocus() {
111 viewer
.getControl().setFocus();
114 // update one of the parameter of a given RealizedFlow
115 public void updateParameter(int realizedFlowIndex
, String paramName
,
117 RealizedFlow curRealizedFlow
= realizedFlows
.get(realizedFlowIndex
);
118 curRealizedFlow
.getFlowDescriptor().getValues().put(paramName
, value
);
121 // clear the realizedFlow<List>
122 public void clearBatch() {
124 realizedFlows
= new ArrayList
<RealizedFlow
>();
126 refreshParameterview();
130 // Remove the selected process from the batch
131 public void removeSelected() {
132 if (curSelectedRow
== -1)
135 realizedFlows
.remove(curSelectedRow
);
137 refreshParameterview();
141 // calling this method with index =-1 will cause the reset of the view.
142 private void refreshParameterview() {
143 // We choose to directly access the view rather than going through
145 ProcessParametersView ppView
;
147 ppView
= (ProcessParametersView
) ClientUiPlugin
.getDefault()
148 .getWorkbench().getActiveWorkbenchWindow().getActivePage()
149 .showView(ProcessParametersView
.ID
);
151 if (curSelectedRow
== -1)
152 ppView
.setRealizedFlow(-1, null);
154 ppView
.setRealizedFlow(curSelectedRow
,
155 realizedFlows
.get(curSelectedRow
));
156 } catch (PartInitException e
) {
157 throw new SlcException(
158 "Cannot Retrieve ProcessParameterView to edit parameters of selected process",
163 // Launches the execution of listed realized flow with specified parameters.
164 public void launchBatch() {
165 SlcExecution slcExecution
= new SlcExecution();
166 slcExecution
.setUuid(UUID
.randomUUID().toString());
168 slcExecution
.setRealizedFlows(realizedFlows
);
169 slcExecution
.setHost(host
);
171 // TODO : insure that the concept has been well understood & the
172 // specification respected
174 for (int i
= 0; i
< slcAgents
.size(); i
++) {
175 if (currentAgentUuid
== null)
176 throw new SlcException(
177 "Cannot launch a batch if no agent is specified");
178 if (currentAgentUuid
.equals(slcAgents
.get(i
).getAgentUuid())) {
179 curAgent
= slcAgents
.get(i
);
180 processController
.execute(curAgent
, slcExecution
);
186 // Specific Providers for the current view.
187 protected class ViewContentProvider
implements IStructuredContentProvider
{
188 public void inputChanged(Viewer arg0
, Object arg1
, Object arg2
) {
191 public void dispose() {
194 public Object
[] getElements(Object obj
) {
195 return realizedFlows
.toArray();
199 protected class ViewLabelProvider
extends LabelProvider
implements
200 ITableLabelProvider
{
201 public String
getColumnText(Object obj
, int index
) {
202 RealizedFlow rf
= (RealizedFlow
) obj
;
205 return rf
.getModuleName();
207 return rf
.getFlowDescriptor().getName();
212 public Image
getColumnImage(Object obj
, int index
) {
218 // Parameter view is updated each time a new line is selected
219 class SelectionChangedListener
implements ISelectionChangedListener
{
220 public void selectionChanged(SelectionChangedEvent evt
) {
222 IStructuredSelection curSelection
= (IStructuredSelection
) evt
224 Object obj
= curSelection
.getFirstElement();
226 if (obj
instanceof RealizedFlow
) {
227 RealizedFlow rf
= (RealizedFlow
) obj
;
228 curSelectedRow
= realizedFlows
.indexOf(rf
);
229 refreshParameterview();
235 // Implementation of the Drop Listener
236 protected class ViewDropListener
extends ViewerDropAdapter
{
238 public ViewDropListener(Viewer viewer
) {
243 public boolean performDrop(Object data
) {
245 Properties props
= new Properties();
247 // TODO : Handle wrong type of dropped data
248 ByteArrayInputStream in
= new ByteArrayInputStream(data
.toString()
252 } catch (IOException e
) {
253 throw new SlcException("Cannot create read flow node", e
);
255 IOUtils
.closeQuietly(in
);
258 String agentId
= props
.getProperty("agentId");
259 if (currentAgentUuid
== null) {
260 currentAgentUuid
= agentId
;
261 host
= props
.getProperty("host");
262 } else if (!currentAgentUuid
.equals(agentId
)) {
263 // TODO: as for now, we can only construct batch on a single
264 // Agent, must be upgraded to enable batch on various agent.
265 throw new SlcException(
266 "Cannot create batch on two (or more) distinct agents",
270 String fdXml
= props
.getProperty("RealizedFlowAsXml");
273 RealizedFlow rf
= null;//(RealizedFlow) oxmBean.unmarshal(fdXml);
274 realizedFlows
.add(rf
);
275 curSelectedRow
= realizedFlows
.indexOf(rf
);
276 refreshParameterview();
277 getViewer().refresh();
282 public boolean validateDrop(Object target
, int operation
,
283 TransferData transferType
) {
289 public void setSlcAgents(List
<SlcAgent
> slcAgents
) {
290 this.slcAgents
= slcAgents
;
293 // public void setOxmBean(OxmInterface oxmBean) {
294 // this.oxmBean = oxmBean;
297 public void setProcessController(ProcessController processController
) {
298 this.processController
= processController
;