Add:
authorBruno Sinou <bsinou@argeo.org>
Thu, 4 Nov 2010 22:37:19 +0000 (22:37 +0000)
committerBruno Sinou <bsinou@argeo.org>
Thu, 4 Nov 2010 22:37:19 +0000 (22:37 +0000)
+ integer parameter support
+ commands to
   - clear the batch
   - launch it
   - remove on selected item

git-svn-id: https://svn.argeo.org/slc/trunk@3848 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

12 files changed:
eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/commands.xml
eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/views.xml
eclipse/plugins/org.argeo.slc.client.ui/plugin.xml
eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/commands/ClearBatchHandler.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/commands/EditRealizedFlowDetailsHandler.java
eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/commands/LaunchBatchHandler.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/commands/RemoveSelectedProcessFromBatchHandler.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/providers/ExecutionModulesContentProvider.java
eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/providers/ProcessParametersEditingSupport.java
eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ExecutionModulesView.java
eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessBuilderView.java
eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessParametersView.java

index 11aaf10948e938a71f5ce463228caf8699b32d91..a867733bb9c45c4ea65a3d613bffcd2ffa7a9b27 100644 (file)
                class="org.argeo.slc.client.ui.commands.ResultDetailsDisplayHandler"
                scope="prototype">
        </bean>
+       <bean id="org.argeo.slc.client.ui.launchBatch" class="org.argeo.slc.client.ui.commands.LaunchBatchHandler"
+               scope="prototype">
+       </bean>
+       <bean id="org.argeo.slc.client.ui.removeSelectedFromBatch"
+               class="org.argeo.slc.client.ui.commands.RemoveSelectedProcessFromBatchHandler"
+               scope="prototype">
+       </bean>
+       <bean id="org.argeo.slc.client.ui.clearBatch" class="org.argeo.slc.client.ui.commands.ClearBatchHandler"
+               scope="prototype">
+       </bean>
        <bean id="org.argeo.slc.client.ui.editRealizedFlowDetails"
                class="org.argeo.slc.client.ui.commands.EditRealizedFlowDetailsHandler"
                scope="prototype">
index b7055d14ad0729eb86784431542861195c6d3ca5..74b7d9262e2bf20fb2d40089fb68f788c02a463f 100644 (file)
@@ -43,6 +43,7 @@
                scope="prototype">
                <property name="processController" ref="processController" />
                <property name="oxmBean" ref="oxmBean" />
+               <property name="slcAgents" ref="slcAgents" />
        </bean>
 
        <bean id="org.argeo.slc.client.ui.processParametersView" class="org.argeo.slc.client.ui.views.ProcessParametersView"
index f4a8f87d4aa9d4e98e29f7bbd445b61ed70a8267..ed9362c4613a73ab996b4524546ee5a57bbd8bf0 100644 (file)
       <command
             defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
             id="org.argeo.slc.client.ui.refreshResultList"
-            name="RefreshResultList ">
+            name="RefreshResultList">
+      </command>
+      <command
+            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+            id="org.argeo.slc.client.ui.launchBatch"
+            name="LaunchBatch">
+      </command>
+      <command
+            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+            id="org.argeo.slc.client.ui.removeSelectedFromBatch"
+            name="RemoveSelectedFromBatch">
+      </command>
+      <command
+            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+            id="org.argeo.slc.client.ui.clearBatch"
+            name="ClearBatch">
       </command>
       <command
             defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
             </separator>
          </toolbar>
       </menuContribution>
+      <menuContribution
+            locationURI="toolbar:org.argeo.slc.client.ui.processBuilderView">
+         <command
+               commandId="org.argeo.slc.client.ui.launchBatch"
+               label="Launch Batch"
+               tooltip="Launch the batch built in the process builder view.">
+         </command>
+         <command
+               commandId="org.argeo.slc.client.ui.clearBatch"
+               label="Clear Batch"
+               tooltip="Clear the batch built in the process builder view.">
+         </command>
+         <command
+               commandId="org.argeo.slc.client.ui.removeSelectedFromBatch"
+               label="Remove Selected From Batch"
+               tooltip="Remove selected process from process builder view.">
+         </command>
+      </menuContribution>
    </extension>
-
 </plugin>
diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/commands/ClearBatchHandler.java b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/commands/ClearBatchHandler.java
new file mode 100644 (file)
index 0000000..eb6809c
--- /dev/null
@@ -0,0 +1,30 @@
+package org.argeo.slc.client.ui.commands;
+
+import org.argeo.slc.client.ui.views.ProcessBuilderView;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * 
+ * @author bsinou
+ * 
+ *         Remove all processes from the batch built in the ProcessBuilderView
+ * 
+ *         NOTE : only one batch is supported with this command, if more than
+ *         one batch is planned, this class must be updated with parameter.
+ */
+public class ClearBatchHandler extends AbstractHandler {
+       // private final static Log log =
+       // LogFactory.getLog(ClearBatchHandler.class);
+
+       public Object execute(ExecutionEvent event) throws ExecutionException {
+               ProcessBuilderView pbView = (ProcessBuilderView) HandlerUtil
+                               .getActiveWorkbenchWindow(event).getActivePage()
+                               .findView(ProcessBuilderView.ID);
+               pbView.clearBatch();
+               return null;
+       }
+
+}
index a21ac37a3c97a46c61310e8089b03163cb8a88d7..f26e29f47d61883925b4ce4d41f5f5a971c8e24c 100644 (file)
@@ -9,12 +9,16 @@ import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.ui.handlers.HandlerUtil;
 
 /**
- * Command handler to display and edit the attributes of a given Realizedflow.
- * The corresponding RealizedFlow is passed via command parameters and
- * unmarshalled with the oxmBean which is injected by Spring.
  * 
  * @author bsinou
  * 
+ *         Command handler to display and edit the attributes of a given
+ *         Realizedflow. The corresponding RealizedFlow is passed via command
+ *         parameters and unmarshalled with the oxmBean which is injected by
+ *         Spring.
+ * 
+ *         Note thet passing an index of -1 will cause the reset of the View
+ *         (used among others when removing processes from the batch).
  */
 
 public class EditRealizedFlowDetailsHandler extends AbstractHandler {
@@ -29,13 +33,18 @@ public class EditRealizedFlowDetailsHandler extends AbstractHandler {
                int index = new Integer(
                                event.getParameter("org.argeo.slc.client.commands.realizedFlowIndex"))
                                .intValue();
-               RealizedFlow rf = (RealizedFlow) oxmBean.unmarshal(rfAsXml);
-
                try {
                        ProcessParametersView ppView = (ProcessParametersView) HandlerUtil
                                        .getActiveWorkbenchWindow(event).getActivePage()
                                        .showView(ProcessParametersView.ID);
-                       ppView.setRealizedFlow(index, rf);
+
+                       if (index == -1)
+                               ppView.setRealizedFlow(-1, null);
+                       else {
+                               RealizedFlow rf = (RealizedFlow) oxmBean.unmarshal(rfAsXml);
+                               ppView.setRealizedFlow(index, rf);
+
+                       }
                } catch (Exception e) {
                        e.printStackTrace();
                }
diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/commands/LaunchBatchHandler.java b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/commands/LaunchBatchHandler.java
new file mode 100644 (file)
index 0000000..e770c34
--- /dev/null
@@ -0,0 +1,30 @@
+package org.argeo.slc.client.ui.commands;
+
+import org.argeo.slc.client.ui.views.ProcessBuilderView;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * 
+ * @author bsinou
+ * 
+ *         Launch the batch built in the ProcessBuilderView
+ * 
+ *         NOTE : only one batch is supported with this command, if more than
+ *         one batch is planned, this class must be updated with parameter.
+ */
+public class LaunchBatchHandler extends AbstractHandler {
+       // private final static Log log =
+       // LogFactory.getLog(LaunchBatchHandler.class);
+
+       public Object execute(ExecutionEvent event) throws ExecutionException {
+               ProcessBuilderView pbView = (ProcessBuilderView) HandlerUtil
+                               .getActiveWorkbenchWindow(event).getActivePage()
+                               .findView(ProcessBuilderView.ID);
+               pbView.launchBatch();
+               return null;
+       }
+
+}
diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/commands/RemoveSelectedProcessFromBatchHandler.java b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/commands/RemoveSelectedProcessFromBatchHandler.java
new file mode 100644 (file)
index 0000000..12e8de0
--- /dev/null
@@ -0,0 +1,31 @@
+package org.argeo.slc.client.ui.commands;
+
+import org.argeo.slc.client.ui.views.ProcessBuilderView;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * 
+ * @author bsinou
+ * 
+ *         Launch the batch built in the ProcessBuilderView
+ * 
+ *         NOTE : only one batch is supported with this command, if more than
+ *         one batch is planned, this class must be updated with parameter.
+ */
+
+public class RemoveSelectedProcessFromBatchHandler extends AbstractHandler {
+       // private final static Log log =
+       // LogFactory.getLog(RemoveSelectedProcessFromBatchHandler.class);
+
+       public Object execute(ExecutionEvent event) throws ExecutionException {
+               ProcessBuilderView pbView = (ProcessBuilderView) HandlerUtil
+                               .getActiveWorkbenchWindow(event).getActivePage()
+                               .findView(ProcessBuilderView.ID);
+               pbView.removeSelected();
+               return null;
+       }
+
+}
index 9f8d267257f56010b17f1413f991ea0ebc6f3b96..1278609bde2adfeddd15cf52b1877e0549230aac 100644 (file)
@@ -21,10 +21,10 @@ public class ExecutionModulesContentProvider implements ITreeContentProvider {
        private final static Log log = LogFactory
                        .getLog(ExecutionModulesContentProvider.class);
 
+       // IoC
        private List<SlcAgent> slcAgents;
 
        public Object[] getChildren(Object parent) {
-
                if (parent instanceof ExecutionModuleNode) {
                        ExecutionModuleNode executionModuleNode = (ExecutionModuleNode) parent;
                        ExecutionModuleDescriptor emd = executionModuleNode.getDescriptor();
@@ -96,16 +96,8 @@ public class ExecutionModulesContentProvider implements ITreeContentProvider {
                return getChildren(parent);
        }
 
-       public void setSlcAgents(List<SlcAgent> slcAgents) {
-               this.slcAgents = slcAgents// for (String flowName :
-                                                                       // executionModuleNode.getFlowDescriptors()
-               // .keySet()) {
-               // executionModuleNode.addChild(new FlowNode(flowName,
-               // executionModuleNode));
-               // }
-               ;
-       }
-
+       
+       
        public class AgentNode extends TreeParent {
                private final SlcAgent agent;
 
@@ -261,4 +253,9 @@ public class ExecutionModulesContentProvider implements ITreeContentProvider {
                }
 
        }
+       
+       // IoC
+       public void setSlcAgents(List<SlcAgent> slcAgents) {
+               this.slcAgents = slcAgents;
+       }
 }
index 1501964ef0d7c2864e45c57e4ff8e721f9339cac..847463e83a9dbf4951725430dca6a7ea42ec7d93 100644 (file)
@@ -26,8 +26,19 @@ import org.eclipse.jface.viewers.TextCellEditor;
 
 public class ProcessParametersEditingSupport extends EditingSupport {
 
-       private CellEditor editor;
-       private int column;
+       // private final static Log log = LogFactory
+       // .getLog(ProcessParametersEditingSupport.class);
+
+       private CellEditor strEditor;
+       private CellEditor nbEditor;
+       // private int column;
+
+       private final static String strType = "string", intType = "integer";
+
+       // different type of primitive
+       private static enum primitiveType {
+               strType, intType
+       };
 
        // So that we can update corresponding process
        private int curProcessIndex;
@@ -35,13 +46,15 @@ public class ProcessParametersEditingSupport extends EditingSupport {
 
        public ProcessParametersEditingSupport(ColumnViewer viewer, int column) {
                super(viewer);
-               editor = new TextCellEditor(((TableViewer) viewer).getTable());
-               this.column = column;
+               strEditor = new TextCellEditor(((TableViewer) viewer).getTable());
+               // nbEditor = new NumberCellEditor(((TableViewer) viewer).getTable());
+               // this.column = column;
        }
 
        @Override
        protected CellEditor getCellEditor(Object element) {
-               return editor;
+               // TODO return specific editor depending on the parameter type.
+               return strEditor;
        }
 
        @Override
@@ -55,10 +68,13 @@ public class ProcessParametersEditingSupport extends EditingSupport {
 
                if (objectWithName.obj instanceof PrimitiveAccessor) {
                        PrimitiveAccessor pv = (PrimitiveAccessor) objectWithName.obj;
-                       // we only handle string parameter in a first time
-                       if ("string".equals(pv.getType())) {
+                       // we only handle string & integer parameter in a first time
+                       if (strType.equals(pv.getType())) {
                                return pv.getValue();
                        }
+                       if (intType.equals(pv.getType())) {
+                               return ((Integer) pv.getValue()).toString();
+                       }
                }
                return "unsupported param type";
 
@@ -67,16 +83,22 @@ public class ProcessParametersEditingSupport extends EditingSupport {
        @Override
        protected void setValue(Object element, Object value) {
                ProcessParametersView.ObjectWithName objectWithName = (ProcessParametersView.ObjectWithName) element;
-
                if (objectWithName.obj instanceof PrimitiveAccessor) {
                        PrimitiveAccessor pv = (PrimitiveAccessor) objectWithName.obj;
                        // we only handle string parameter in a first time
-                       if ("string".equals(pv.getType())) {
+                       if (strType.equals(pv.getType())) {
                                pv.setValue(value);
                                pbView.updateParameter(curProcessIndex, objectWithName.name,
                                                objectWithName.obj);
-                               getViewer().update(element, null);
+                       } else if (intType.equals(pv.getType())) {
+
+                               String stVal = (String) value;
+                               Integer val = ("".equals(stVal)) ? new Integer(0)
+                                               : new Integer(stVal);
+                               pv.setValue(val);
+                               pbView.updateParameter(curProcessIndex, objectWithName.name, pv);
                        }
+                       getViewer().update(element, null);
                }
 
        }
index c6ba27b138688cbc09ee89a0db51d5330a0d2897..07df89af6dbdd9c2b8ff706f2595e2f0bdfbdb06 100644 (file)
@@ -152,13 +152,13 @@ public class ExecutionModulesView extends ViewPart {
                                        ExecutionModulesContentProvider.FlowNode flowNode = (ExecutionModulesContentProvider.FlowNode) selection
                                                        .getFirstElement();
 
-                                       // we still use property because the marshaller bean does
-                                       // not know the FlowNode Class
                                        Properties props = new Properties();
                                        flowNodeAsProperties(props, flowNode);
                                        props.setProperty("agentId", flowNode
                                                        .getExecutionModuleNode().getAgentNode().getAgent()
                                                        .getAgentUuid());
+                                       props.setProperty("host", flowNode.getExecutionModuleNode().getAgentNode()
+                                                       .getAgent().toString());
 
                                        ByteArrayOutputStream out = new ByteArrayOutputStream();
                                        try {
@@ -178,20 +178,23 @@ public class ExecutionModulesView extends ViewPart {
                        System.out.println("Finished Drag");
                }
 
-               private void flowNodeAsProperties(Properties props, FlowNode fn) {
-                       props.setProperty("moduleName", fn.getExecutionModuleNode()
+               protected void flowNodeAsProperties(Properties props, FlowNode fn) {
+
+                       RealizedFlow realizedFlow = new RealizedFlow();
+                       realizedFlow.setModuleName(fn.getExecutionModuleNode()
                                        .getDescriptor().getName());
-                       props.setProperty("moduleVersion", fn.getExecutionModuleNode()
+                       realizedFlow.setModuleVersion(fn.getExecutionModuleNode()
                                        .getDescriptor().getVersion());
-                       props.setProperty("flowName", fn.getFlowName());
+                       realizedFlow.setFlowDescriptor(fn.getExecutionFlowDescriptor());
 
-                       System.out.println("Execution Spec avant marshalling ??? ");
-                       System.out.println(fn.getExecutionFlowDescriptor());
-                       System.out.println(fn.getExecutionFlowDescriptor()
+                       // As we want to have the effective ExecutionSpec and not a
+                       // reference; we store it at the RealizeFlow level : thus the
+                       // marshaller will store the object and not only a reference.
+                       realizedFlow.setExecutionSpec(fn.getExecutionFlowDescriptor()
                                        .getExecutionSpec());
 
-                       props.setProperty("FlowDescriptorAsXml",
-                                       oxmBean.marshal(fn.getExecutionFlowDescriptor()));
+                       props.setProperty("RealizedFlowAsXml",
+                                       oxmBean.marshal(realizedFlow));
                        System.out
                                        .println(oxmBean.marshal(fn.getExecutionFlowDescriptor()));
 
index c7f103505f067c3a862b0ca36c5c51aba14b47e3..e0e5aec1696732eab0691038ee062fa9199aa2ce 100644 (file)
@@ -8,11 +8,12 @@ import java.util.Properties;
 import java.util.UUID;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.argeo.slc.SlcException;
 import org.argeo.slc.client.oxm.OxmInterface;
 import org.argeo.slc.client.ui.ClientUiPlugin;
 import org.argeo.slc.client.ui.controllers.ProcessController;
-import org.argeo.slc.execution.ExecutionFlowDescriptor;
 import org.argeo.slc.process.RealizedFlow;
 import org.argeo.slc.process.SlcExecution;
 import org.argeo.slc.runtime.SlcAgent;
@@ -55,7 +56,12 @@ import org.eclipse.ui.part.ViewPart;
  * 
  */
 public class ProcessBuilderView extends ViewPart {
+       private final static Log log = LogFactory.getLog(ProcessBuilderView.class);
+
        public static final String ID = "org.argeo.slc.client.ui.processBuilderView";
+       private static final String EDIT_CMD = "org.argeo.slc.client.ui.editRealizedFlowDetails";
+       private static final String FLOWASXML_PARAM = "org.argeo.slc.client.commands.realizedFlowAsXml";
+       private static final String INDEX_PARAM = "org.argeo.slc.client.commands.realizedFlowIndex";
 
        // private final static Log log =
        // LogFactory.getLog(ProcessBuilderView.class);
@@ -63,10 +69,16 @@ public class ProcessBuilderView extends ViewPart {
        private TableViewer viewer;
        private List<RealizedFlow> realizedFlows = new ArrayList<RealizedFlow>();
        private String currentAgentUuid = null;
+       private String host = null;
+
+       // TODO find a better way to get index of the current selected row
+       // used in removeSelected
+       private int curSelectedRow = -1;
 
        // IoC
        private OxmInterface oxmBean;
        private ProcessController processController;
+       private List<SlcAgent> slcAgents;
 
        public void createPartControl(Composite parent) {
                Table table = createTable(parent);
@@ -128,6 +140,97 @@ public class ProcessBuilderView extends ViewPart {
                curRealizedFlow.getFlowDescriptor().getValues().put(paramName, value);
        }
 
+       // clear the realizedFlow<List>
+       public void clearBatch() {
+               // we clear the list
+               realizedFlows = new ArrayList<RealizedFlow>();
+               curSelectedRow = -1;
+               refreshParameterview(null);
+               viewer.refresh();
+       }
+
+       // Remove the selected process from the batch
+       public void removeSelected() {
+               if (curSelectedRow == -1)
+                       return;
+               else
+                       realizedFlows.remove(curSelectedRow);
+               curSelectedRow = -1;
+               refreshParameterview(null);
+               viewer.refresh();
+       }
+
+       // calling this method with index =-1 will cause the reset of the view.
+       private void refreshParameterview(RealizedFlow rf) {
+               IWorkbench iw = ClientUiPlugin.getDefault().getWorkbench();
+               IHandlerService handlerService = (IHandlerService) iw
+                               .getService(IHandlerService.class);
+               try {
+                       // get the command from plugin.xml
+                       IWorkbenchWindow window = iw.getActiveWorkbenchWindow();
+                       ICommandService cmdService = (ICommandService) window
+                                       .getService(ICommandService.class);
+                       Command cmd = cmdService.getCommand(EDIT_CMD);
+
+                       ArrayList<Parameterization> parameters = new ArrayList<Parameterization>();
+
+                       IParameter iparam;
+                       Parameterization params;
+
+                       // The current index to be able to records changes on
+                       // parameters
+                       iparam = cmd.getParameter(INDEX_PARAM);
+                       params = new Parameterization(iparam,
+                                       (new Integer(curSelectedRow)).toString());
+                       parameters.add(params);
+
+                       if (curSelectedRow != -1) {
+                               // The current Realized flow marshalled as XML
+                               String result = oxmBean.marshal(rf);
+                               iparam = cmd.getParameter(FLOWASXML_PARAM);
+                               params = new Parameterization(iparam, result);
+                               parameters.add(params);
+                       }
+                       // build the parameterized command
+                       ParameterizedCommand pc = new ParameterizedCommand(cmd,
+                                       parameters.toArray(new Parameterization[parameters.size()]));
+
+                       // execute the command
+                       handlerService = (IHandlerService) window
+                                       .getService(IHandlerService.class);
+                       handlerService.executeCommand(pc, null);
+
+               } catch (Exception e) {
+                       e.printStackTrace();
+                       throw new SlcException("Problem while rendering result. "
+                                       + e.getMessage());
+               }
+
+       }
+
+       // Return the list of the processes to execute.
+       public void launchBatch() {
+               SlcExecution slcExecution = new SlcExecution();
+               slcExecution.setUuid(UUID.randomUUID().toString());
+
+               slcExecution.setRealizedFlows(realizedFlows);
+               slcExecution.setHost(host);
+
+               // TODO : insure that the concept has been well understood & the
+               // specification respected
+               SlcAgent curAgent;
+               for (int i = 0; i < slcAgents.size(); i++) {
+                       if (currentAgentUuid == null)
+                               throw new SlcException(
+                                               "Cannot launch a batch if no agent is specified");
+                       if (currentAgentUuid.equals(slcAgents.get(i).getAgentUuid())) {
+                               curAgent = slcAgents.get(i);
+                               processController.execute(curAgent, slcExecution);
+                               break;
+                       }
+               }
+       }
+
        // Specific Providers for the current view.
        protected class ViewContentProvider implements IStructuredContentProvider {
                public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
@@ -170,65 +273,8 @@ public class ProcessBuilderView extends ViewPart {
 
                        if (obj instanceof RealizedFlow) {
                                RealizedFlow rf = (RealizedFlow) obj;
-
-                               IWorkbench iw = ClientUiPlugin.getDefault().getWorkbench();
-                               IHandlerService handlerService = (IHandlerService) iw
-                                               .getService(IHandlerService.class);
-
-                               // TODO :
-                               // WARNING :
-                               // when marshalling an ExecutionFlowDescriptor, the Execution
-                               // Spec is set correctly,
-                               // but
-                               // when marshalling directly a realized flow, paramters are
-                               // stored under ExecutionFlowDescriptor.values
-                               String result = oxmBean.marshal(rf);
-
-                               // Passing parameters to the command
-                               try {
-                                       // get the command from plugin.xml
-                                       IWorkbenchWindow window = iw.getActiveWorkbenchWindow();
-                                       ICommandService cmdService = (ICommandService) window
-                                                       .getService(ICommandService.class);
-                                       Command cmd = cmdService
-                                                       .getCommand("org.argeo.slc.client.ui.editRealizedFlowDetails");
-
-                                       ArrayList<Parameterization> parameters = new ArrayList<Parameterization>();
-
-                                       IParameter iparam;
-                                       Parameterization params;
-
-                                       // The current index to be able to records changes on
-                                       // parameters
-                                       iparam = cmd
-                                                       .getParameter("org.argeo.slc.client.commands.realizedFlowIndex");
-                                       params = new Parameterization(iparam, (new Integer(
-                                                       realizedFlows.indexOf(rf))).toString());
-
-                                       parameters.add(params);
-
-                                       // The current Realized flow marshalled as XML
-                                       // See warning above
-                                       iparam = cmd
-                                                       .getParameter("org.argeo.slc.client.commands.realizedFlowAsXml");
-                                       params = new Parameterization(iparam, result);
-                                       parameters.add(params);
-
-                                       // build the parameterized command
-                                       ParameterizedCommand pc = new ParameterizedCommand(cmd,
-                                                       parameters.toArray(new Parameterization[parameters
-                                                                       .size()]));
-
-                                       // execute the command
-                                       handlerService = (IHandlerService) window
-                                                       .getService(IHandlerService.class);
-                                       handlerService.executeCommand(pc, null);
-
-                               } catch (Exception e) {
-                                       e.printStackTrace();
-                                       throw new SlcException("Problem while rendering result. "
-                                                       + e.getMessage());
-                               }
+                               curSelectedRow = realizedFlows.indexOf(rf);
+                               refreshParameterview(rf);
                        }
                }
        }
@@ -257,51 +303,28 @@ public class ProcessBuilderView extends ViewPart {
                        }
 
                        String agentId = props.getProperty("agentId");
-                       if (currentAgentUuid == null)
+                       if (currentAgentUuid == null) {
                                currentAgentUuid = agentId;
-                       else if (!currentAgentUuid.equals(agentId)) {
+                               host = props.getProperty("host");
+                       } else if (!currentAgentUuid.equals(agentId)) {
                                // TODO: as for now, we can only construct batch on a single
-                               // Agent,
-                               // must be upgraded to enable batch on various agent.
+                               // Agent, must be upgraded to enable batch on various agent.
                                throw new SlcException(
                                                "Cannot create batch on two (or more) distinct agents",
                                                null);
                                // return false;
                        }
 
-                       RealizedFlow rf = realizedFlowFromProperties(props);
+                       String fdXml = props.getProperty("RealizedFlowAsXml");
+                       if (fdXml == null)
+                               return false;
+                       RealizedFlow rf = (RealizedFlow) oxmBean.unmarshal(fdXml);
                        realizedFlows.add(rf);
 
                        getViewer().refresh();
                        return true;
                }
 
-               private RealizedFlow realizedFlowFromProperties(Properties props) {
-                       RealizedFlow rf = new RealizedFlow();
-                       rf.setModuleName(props.getProperty("moduleName"));
-                       rf.setModuleVersion(props.getProperty("moduleVersion"));
-                       String fdXml = props.getProperty("FlowDescriptorAsXml");
-                       if (fdXml != null) {
-                               Object o = oxmBean.unmarshal(fdXml);
-                               if (o instanceof ExecutionFlowDescriptor) {
-                                       rf.setFlowDescriptor((ExecutionFlowDescriptor) o);
-                                       System.out.println("instance of EFD !!!"
-                                                       + rf.getFlowDescriptor().toString());
-                                       System.out.println(rf.getFlowDescriptor()
-                                                       .getExecutionSpec());
-                                       return rf;
-                               }
-                       }
-                       // Else
-                       System.out
-                                       .println("***** WARNING : we should not be here; corresponding flow name"
-                                                       + props.getProperty("flowName"));
-                       ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor();
-                       efd.setName(props.getProperty("flowName"));
-                       rf.setFlowDescriptor(efd);
-                       return rf;
-               }
-
                @Override
                public boolean validateDrop(Object target, int operation,
                                TransferData transferType) {
@@ -310,6 +333,10 @@ public class ProcessBuilderView extends ViewPart {
        }
 
        // IoC
+       public void setSlcAgents(List<SlcAgent> slcAgents) {
+               this.slcAgents = slcAgents;
+       }
+
        public void setOxmBean(OxmInterface oxmBean) {
                this.oxmBean = oxmBean;
        }
index 4fabec13581bd3425b54f877039ecb271a4e8307..b45fb99815a618c8402bc73ba2257d049e547bf9 100644 (file)
@@ -4,6 +4,8 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.argeo.slc.client.ui.ClientUiPlugin;
 import org.argeo.slc.client.ui.providers.ProcessParametersEditingSupport;
 import org.argeo.slc.core.execution.PrimitiveAccessor;
@@ -32,14 +34,17 @@ import org.eclipse.ui.part.ViewPart;
  *         attribute to recall (and update ??) the various parameters.
  */
 public class ProcessParametersView extends ViewPart {
-       public static final String ID = "org.argeo.slc.client.ui.processParametersView";
+       private static final Log log = LogFactory
+                       .getLog(ProcessParametersView.class);
 
-       // class attribute
-       private Map<String, ExecutionSpecAttribute> parameters;
-       private RealizedFlow curRealizedFlow;
+       public static final String ID = "org.argeo.slc.client.ui.processParametersView";
 
-       // we should be using executionspecAttribute but for now we uses values.
+       // This map stores actual values set to default if existing at the begining
+       // and then the ones computed by the end user
        private Map<String, Object> values;
+       // This map stores the spec of the attributes used to offer the end user
+       // some choices.
+       private Map<String, ExecutionSpecAttribute> specAttributes;
 
        // We must keep a reference to the current EditingSupport so that we can
        // update the index of the process being updated
@@ -54,18 +59,17 @@ public class ProcessParametersView extends ViewPart {
                createColumns(viewer);
 
                // WARNING
-               // for the moment being, we support only one process builder at a time 
+               // for the moment being, we support only one process builder at a time
                // we set the corresponding view in the editor here.
                ProcessBuilderView pbView = (ProcessBuilderView) ClientUiPlugin
                                .getDefault().getWorkbench().getActiveWorkbenchWindow()
                                .getActivePage().findView(ProcessBuilderView.ID);
                ppEditingSupport.setCurrentProcessBuilderView(pbView);
-               
+
                viewer.setLabelProvider(new ViewLabelProvider());
                viewer.setContentProvider(new ViewContentProvider());
                viewer.setInput(getViewSite());
-               
-               
+
        }
 
        // This will create the columns for the table
@@ -91,22 +95,23 @@ public class ProcessParametersView extends ViewPart {
                Table table = viewer.getTable();
                table.setHeaderVisible(true);
                table.setLinesVisible(true);
-               
+
        }
 
        public void setFocus() {
                viewer.getControl().setFocus();
        }
 
-       // save and update a field when it looses the focus
-       // TODO implement this method.
-
        // set class attributes, refresh the lists of process paramaters to edit.
        public void setRealizedFlow(int index, RealizedFlow rf) {
-
-               // this.processIndex = index;
+               // force the cleaning of the view
+               if (index == -1) {
+                       viewer.setInput(null);
+                       return;
+               }
+               // we store the index of the edited Process in the editor so that it can
+               // save computed values.
                ppEditingSupport.setCurrentProcessIndex(index);
-               curRealizedFlow = rf;
 
                // TODO :
                // We should handle ExecutionSpec here. need to be improved.
@@ -117,6 +122,9 @@ public class ProcessParametersView extends ViewPart {
                // viewer.setInput(parameters);
 
                values = rf.getFlowDescriptor().getValues();
+               specAttributes = rf.getFlowDescriptor().getExecutionSpec()
+                               .getAttributes();
+
                if (values != null)
                        viewer.setInput(values);
                else
@@ -167,6 +175,8 @@ public class ProcessParametersView extends ViewPart {
                                                PrimitiveAccessor pa = (PrimitiveAccessor) own.obj;
                                                if ("string".equals(pa.getType()))
                                                        return (String) pa.getValue();
+                                               else if ("integer".equals(pa.getType()))
+                                                       return ((Integer) pa.getValue()).toString();
                                                else
                                                        return "Type " + pa.getType()
                                                                        + " not yet supported";
@@ -197,71 +207,4 @@ public class ProcessParametersView extends ViewPart {
                }
 
        }
-
-       // protected class ViewContentProvider implements IStructuredContentProvider
-       // {
-       // public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
-       // }
-       //
-       // public void dispose() {
-       // }
-       //
-       // // we cast the Map<String, ExecutionSpecAttribute> to List<Object>
-       // public Object[] getElements(Object obj) {
-       // if (obj instanceof Map && ((Map) obj).size() != 0) {
-       // List<ExecutionSpecAttributeWithName> list = new
-       // ArrayList<ExecutionSpecAttributeWithName>();
-       // Map<String, ExecutionSpecAttribute> map = (Map<String,
-       // ExecutionSpecAttribute>) obj;
-       // for (String key : map.keySet()) {
-       // list.add(new ExecutionSpecAttributeWithName(key, map
-       // .get(key)));
-       // }
-       // return list.toArray();
-       // } else {
-       // return new Object[0];
-       // }
-       // }
-       // }
-       //
-       // protected class ViewLabelProvider extends LabelProvider implements
-       // ITableLabelProvider {
-       //
-       // public String getColumnText(Object obj, int index) {
-       // // NOTE : the passed object is a line of the table !!!
-       //
-       // if (obj instanceof ExecutionSpecAttributeWithName) {
-       // ExecutionSpecAttributeWithName esaw = (ExecutionSpecAttributeWithName)
-       // obj;
-       // switch (index) {
-       // case 0:
-       // return esaw.name;
-       // case 1:
-       // return esaw.esa.getValue().toString();
-       // default:
-       // return getText(obj);
-       // }
-       // } else
-       // return getText(obj);
-       // }
-       //
-       // public Image getColumnImage(Object obj, int index) {
-       // return null;
-       // }
-       //
-       // }
-       //
-       // // We add an inner class to enrich the ExecutionSpecAttribute with a name
-       // // so that we can display it.
-       // private class ExecutionSpecAttributeWithName {
-       // public ExecutionSpecAttribute esa;
-       // public String name;
-       //
-       // public ExecutionSpecAttributeWithName(String name,
-       // ExecutionSpecAttribute esa) {
-       // this.name = name;
-       // this.esa = esa;
-       // }
-
-       // }
 }