From: Bruno Sinou Date: Thu, 4 Nov 2010 16:25:26 +0000 (+0000) Subject: Implementation of a first draft of editorView for the process parameters. X-Git-Tag: argeo-slc-2.1.7~1130 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;ds=sidebyside;h=5d91de89b70a4ba96cd4d37c4fcc991118faf685;p=gpl%2Fargeo-slc.git Implementation of a first draft of editorView for the process parameters. Only string parameters are supported with this version. git-svn-id: https://svn.argeo.org/slc/trunk@3847 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/eclipse/plugins/org.argeo.slc.client.core/src/main/java/org/argeo/slc/client/contentprovider/ProcessDetailContentProvider.java b/eclipse/plugins/org.argeo.slc.client.core/src/main/java/org/argeo/slc/client/contentprovider/ProcessDetailContentProvider.java index a89c90752..497e29851 100644 --- a/eclipse/plugins/org.argeo.slc.client.core/src/main/java/org/argeo/slc/client/contentprovider/ProcessDetailContentProvider.java +++ b/eclipse/plugins/org.argeo.slc.client.core/src/main/java/org/argeo/slc/client/contentprovider/ProcessDetailContentProvider.java @@ -11,7 +11,8 @@ import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; /** - * Basic tree view of the chosen process details + * Basic tree view of the chosen process details. For now, only a basic list of + * details is displayed, not a tree. */ public class ProcessDetailContentProvider implements ITreeContentProvider { private final static Log log = LogFactory @@ -90,14 +91,6 @@ public class ProcessDetailContentProvider implements ITreeContentProvider { } public boolean hasChildren(Object parent) { - // if (parent instanceof TreeParent && ((TreeParent) parent).isLoaded()) - // { - // return ((TreeParent) parent).hasChildren(); - // } else if (parent instanceof AgentNode) { - // return true; - // } else if (parent instanceof ExecutionModuleNode) { - // return true; - // } return false; } @@ -109,7 +102,7 @@ public class ProcessDetailContentProvider implements ITreeContentProvider { public Object[] getElements(Object parent) { // return getChildren(parent); - // Here we must dupplicate the code otherwise the inner call to method + // Here we must duplicate the code otherwise the inner call to method // getChildren(parent); is not intercepted by AspectJ if (parent instanceof SlcExecution) { slcExecution = (SlcExecution) parent; @@ -130,148 +123,4 @@ public class ProcessDetailContentProvider implements ITreeContentProvider { } return null; } - - // public class AgentNode extends TreeParent { - // private final SlcAgent agent; - // - // public AgentNode(SlcAgent agent) { - // super(agent.toString()); - // this.agent = agent; - // } - - // public SlcAgent getAgent() { - // return agent; - // } - // } - - // public class ExecutionModuleNode extends TreeParent { - // private final AgentNode agentNode; - // private ExecutionModuleDescriptor descriptor; - // private Map flowDescriptors; - // - // public ExecutionModuleNode(AgentNode agentNode, - // ExecutionModuleDescriptor descriptor) { - // super(descriptor.toString()); - // this.agentNode = agentNode; - // this.descriptor = descriptor; - // - // } - // - // public AgentNode getAgentNode() { - // return agentNode; - // } - // - // public ExecutionModuleDescriptor getDescriptor() { - // return descriptor; - // } - // Object o = thisJoinPoint.getArgs()[0]; - - // public void cacheDescriptor(ExecutionModuleDescriptor descriptor) { - // this.descriptor = descriptor; - // - // SortedMap folderNodes = new TreeMap(); - // - // flowDescriptors = new HashMap(); - // for (ExecutionFlowDescriptor fd : descriptor.getExecutionFlows()) { - // // if (log.isTraceEnabled()) - // // log.trace("fd.path=" + fd.getPath() + ", fd.name=" - // // + fd.getName()); - // - // // find path and label - // String path; - // String label; - // int lastSlash = fd.getName().lastIndexOf('/'); - // if ((fd.getPath() == null || fd.getPath().trim().equals("")) - // && lastSlash >= 0) { - // path = fd.getName().substring(0, lastSlash); - // label = fd.getName().substring(lastSlash + 1); - // } else { - // path = fd.getPath(); - // label = fd.getName(); - // } - // // if (log.isTraceEnabled()) - // // log.trace("path=" + path + ", label=" + label); - // - // if (path == null || path.trim().equals("") - // || path.trim().equals("/")) { - // // directChildren.put(name, new FlowNode(name, this)); - // addChild(new FlowNode(label, fd.getName(), this)); - // } else { - // FolderNode folderNode = mkdirs(this, path, folderNodes); - // folderNode - // .addChild(new FlowNode(label, fd.getName(), this)); - // } - // - // flowDescriptors.put(fd.getName(), fd); - // } - // // TODO: make it readonly - // } - // - // protected FolderNode mkdirs(TreeParent root, String path, - // SortedMap folderNodes) { - // // Normalize - // if (path.charAt(0) != '/') - // path = '/' + path; - // if (path.charAt(path.length() - 1) == '/') - // path = path.substring(0, path.length() - 1); - // - // if (folderNodes.containsKey(path)) - // return folderNodes.get(path); - // - // int lastIndx = path.lastIndexOf('/'); - // String folderName; - // String parentPath; - // if (lastIndx >= 0) { - // folderName = path.substring(lastIndx + 1); - // parentPath = path.substring(0, lastIndx); - // } else { - // folderName = path; - // parentPath = ""; - // } - // - // TreeParent parent; - // if (parentPath.equals("")) - // parent = root; - // else - // parent = mkdirs(root, parentPath, folderNodes); - // FolderNode newFolder = new FolderNode(folderName); - // parent.addChild(newFolder); - // folderNodes.put(path, newFolder); - // return newFolder; - // } - // - // public Map getFlowDescriptors() { - // return flowDescriptors; - // } - // - // } - // - // public class FlowNode extends TreeObject { - // private final String flowName; - // private final ExecutionModuleNode executionModuleNode; - // - // public FlowNode(String label, String flowName, - // ExecutionModuleNode executionModuleNode) { - // super(label); - // this.flowName = flowName; - // this.executionModuleNode = executionModuleNode; - // } - // - // public String getFlowName() { - // return flowName; - // } - // - // public ExecutionModuleNode getExecutionModuleNode() { - // return executionModuleNode; - // } - // - // } - // - // public class FolderNode extends TreeParent { - // public FolderNode(String name) { - // super(name); - // } - // - // } } diff --git a/eclipse/plugins/org.argeo.slc.client.hibernate/META-INF/spring/osgi.xml b/eclipse/plugins/org.argeo.slc.client.hibernate/META-INF/spring/osgi.xml index 51602be3b..55bdfa70a 100644 --- a/eclipse/plugins/org.argeo.slc.client.hibernate/META-INF/spring/osgi.xml +++ b/eclipse/plugins/org.argeo.slc.client.hibernate/META-INF/spring/osgi.xml @@ -34,5 +34,9 @@ + + \ No newline at end of file diff --git a/eclipse/plugins/org.argeo.slc.client.oxm/.classpath b/eclipse/plugins/org.argeo.slc.client.oxm/.classpath new file mode 100644 index 000000000..54b896ef3 --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.client.oxm/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/eclipse/plugins/org.argeo.slc.client.oxm/.project b/eclipse/plugins/org.argeo.slc.client.oxm/.project new file mode 100644 index 000000000..02b4cb480 --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.client.oxm/.project @@ -0,0 +1,28 @@ + + + org.argeo.slc.client.oxm + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/eclipse/plugins/org.argeo.slc.client.rcp/slc-client-rcp.product b/eclipse/plugins/org.argeo.slc.client.rcp/slc-client-rcp.product index abb73be76..394124a21 100644 --- a/eclipse/plugins/org.argeo.slc.client.rcp/slc-client-rcp.product +++ b/eclipse/plugins/org.argeo.slc.client.rcp/slc-client-rcp.product @@ -143,7 +143,7 @@ - + @@ -157,8 +157,9 @@ - + + @@ -169,9 +170,10 @@ - - + + + @@ -232,11 +234,13 @@ + + diff --git a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/MANIFEST.MF b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/MANIFEST.MF index b025a7dd0..37b62245c 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/MANIFEST.MF +++ b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/MANIFEST.MF @@ -17,23 +17,24 @@ Import-Package: org.apache.commons.io;version="1.4.0", org.argeo.eclipse.spring, org.argeo.eclipse.ui, org.argeo.slc, - org.argeo.slc.build;version="0.13.0.SNAPSHOT-r3685", + org.argeo.slc.build, + org.argeo.slc.client.oxm, org.argeo.slc.core.attachment, - org.argeo.slc.core.runtime;version="0.13.0.SNAPSHOT-r3701", + org.argeo.slc.core.execution, + org.argeo.slc.core.runtime, org.argeo.slc.core.structure.tree, - org.argeo.slc.core.test.tree;version="0.13.0.SNAPSHOT-r3768", + org.argeo.slc.core.test.tree, org.argeo.slc.dao.process, org.argeo.slc.dao.test, - org.argeo.slc.dao.test.tree;version="0.13.0.SNAPSHOT-r3768", - org.argeo.slc.deploy;version="0.13.0.SNAPSHOT-r3724", - org.argeo.slc.execution;version="0.13.0.SNAPSHOT-r3685", + org.argeo.slc.dao.test.tree, + org.argeo.slc.deploy, + org.argeo.slc.execution, org.argeo.slc.msg.test.tree, - org.argeo.slc.process;version="0.13.0.SNAPSHOT-r3685", - org.argeo.slc.runtime;version="0.13.0.SNAPSHOT-r3685", - org.argeo.slc.services;version="0.13.0.SNAPSHOT-r3773", - org.argeo.slc.services.impl;version="0.13.0.SNAPSHOT-r3777", + org.argeo.slc.process, + org.argeo.slc.runtime, + org.argeo.slc.services, + org.argeo.slc.services.impl, org.argeo.slc.test, org.springframework.beans.factory, org.springframework.context, org.springframework.core.io.support - diff --git a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/commands.xml b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/commands.xml index c25bba7ef..11aaf1094 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/commands.xml +++ b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/commands.xml @@ -20,4 +20,9 @@ class="org.argeo.slc.client.ui.commands.ResultDetailsDisplayHandler" scope="prototype"> + + + diff --git a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/osgi.xml b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/osgi.xml index d77570ce0..e05a86585 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/osgi.xml +++ b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/osgi.xml @@ -19,17 +19,22 @@ + + + + - - - + + diff --git a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/views.xml b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/views.xml index 4cb9bc59b..b7055d14a 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/views.xml +++ b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/views.xml @@ -4,10 +4,12 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> + + - - + - + + class="org.argeo.slc.client.ui.providers.ExecutionModulesContentProvider"> - diff --git a/eclipse/plugins/org.argeo.slc.client.ui/plugin.xml b/eclipse/plugins/org.argeo.slc.client.ui/plugin.xml index d55bd5888..f4a8f87d4 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/plugin.xml +++ b/eclipse/plugins/org.argeo.slc.client.ui/plugin.xml @@ -81,6 +81,19 @@ name="Result UUID"> + + + + + + diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/commands/EditRealizedFlowDetailsHandler.java b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/commands/EditRealizedFlowDetailsHandler.java new file mode 100644 index 000000000..a21ac37a3 --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/commands/EditRealizedFlowDetailsHandler.java @@ -0,0 +1,50 @@ +package org.argeo.slc.client.ui.commands; + +import org.argeo.slc.client.oxm.OxmInterface; +import org.argeo.slc.client.ui.views.ProcessParametersView; +import org.argeo.slc.process.RealizedFlow; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +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 + * + */ + +public class EditRealizedFlowDetailsHandler extends AbstractHandler { + + // IoC + private OxmInterface oxmBean; + + public Object execute(ExecutionEvent event) throws ExecutionException { + // We pass Realized flow through command parameters as XML + String rfAsXml = event + .getParameter("org.argeo.slc.client.commands.realizedFlowAsXml"); + 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); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + // IoC + public void setOxmBean(OxmInterface oxmBean) { + this.oxmBean = oxmBean; + } + +} diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/providers/ExecutionModulesContentProvider.java b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/providers/ExecutionModulesContentProvider.java new file mode 100644 index 000000000..9f8d26725 --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/providers/ExecutionModulesContentProvider.java @@ -0,0 +1,264 @@ +package org.argeo.slc.client.ui.providers; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.eclipse.ui.TreeObject; +import org.argeo.eclipse.ui.TreeParent; +import org.argeo.slc.execution.ExecutionFlowDescriptor; +import org.argeo.slc.execution.ExecutionModuleDescriptor; +import org.argeo.slc.runtime.SlcAgent; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +public class ExecutionModulesContentProvider implements ITreeContentProvider { + private final static Log log = LogFactory + .getLog(ExecutionModulesContentProvider.class); + + private List slcAgents; + + public Object[] getChildren(Object parent) { + + if (parent instanceof ExecutionModuleNode) { + ExecutionModuleNode executionModuleNode = (ExecutionModuleNode) parent; + ExecutionModuleDescriptor emd = executionModuleNode.getDescriptor(); + + // Terminate the building of UI specific object emd + emd = executionModuleNode + .getAgentNode() + .getAgent() + .getExecutionModuleDescriptor(emd.getName(), + emd.getVersion()); + executionModuleNode.cacheDescriptor(emd); + + // This is not recursive, e.g. ExecutionModuleNode build a Tree of + // specific + // treeObject and cache it in the cacheDescriptor. + // Then we only have TreeObjects + return executionModuleNode.getChildren(); + } else if (parent instanceof AgentNode) { + AgentNode agentNode = (AgentNode) parent; + + if (log.isTraceEnabled()) + log.trace("Scan agent " + agentNode); + + agentNode.clearChildren(); + for (ExecutionModuleDescriptor desc : agentNode.getAgent() + .listExecutionModuleDescriptors()) { + agentNode.addChild(new ExecutionModuleNode(agentNode, desc)); + } + + return agentNode.getChildren(); + } else if (parent instanceof TreeParent) { + return ((TreeParent) parent).getChildren(); + } else if (parent instanceof FlowNode) { + return new Object[0]; + } else { + List agentNodes = new ArrayList(); + for (SlcAgent slcAgent : slcAgents) { + agentNodes.add(new AgentNode(slcAgent)); + } + return agentNodes.toArray(); + } + } + + public Object getParent(Object node) { + // if (node instanceof TreeObject) { + // return ((TreeObject) node).getParent(); + // } + return null; + } + + public boolean hasChildren(Object parent) { + if (parent instanceof TreeParent && ((TreeParent) parent).isLoaded()) { + return ((TreeParent) parent).hasChildren(); + } else if (parent instanceof AgentNode) { + return true; + } else if (parent instanceof ExecutionModuleNode) { + return true; + } + return false; + } + + public void inputChanged(Viewer v, Object oldInput, Object newInput) { + } + + public void dispose() { + } + + public Object[] getElements(Object parent) { + return getChildren(parent); + } + + public void setSlcAgents(List 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; + + public AgentNode(SlcAgent agent) { + super(agent.toString()); + this.agent = agent; + } + + public SlcAgent getAgent() { + return agent; + } + } + + public class ExecutionModuleNode extends TreeParent { + private final AgentNode agentNode; + private ExecutionModuleDescriptor descriptor; + private Map flowDescriptors; + + public ExecutionModuleNode(AgentNode agentNode, + ExecutionModuleDescriptor descriptor) { + super(descriptor.toString()); + this.agentNode = agentNode; + this.descriptor = descriptor; + + } + + public AgentNode getAgentNode() { + return agentNode; + } + + public ExecutionModuleDescriptor getDescriptor() { + return descriptor; + } + + public void cacheDescriptor(ExecutionModuleDescriptor descriptor) { + this.descriptor = descriptor; + + SortedMap folderNodes = new TreeMap(); + flowDescriptors = new HashMap(); + + for (ExecutionFlowDescriptor fd : descriptor.getExecutionFlows()) { + // Find, format and store path and label values for each flow + // descritor: + + // we format name of type path="" & name="path/toTest/Test" to : + // path="path/toTest/" name="Test" + String path; + String label; + int lastSlash = fd.getName().lastIndexOf('/'); + if ((fd.getPath() == null || fd.getPath().trim().equals("")) + && lastSlash >= 0) { + path = fd.getName().substring(0, lastSlash); + label = fd.getName().substring(lastSlash + 1); + } else { + path = fd.getPath(); + label = fd.getName(); + } + + if (path == null || path.trim().equals("") + || path.trim().equals("/")) { + // directChildren.put(name, new FlowNode(name, this)); + addChild(new FlowNode(label, fd.getName(), fd, this)); + } else { + FolderNode folderNode = mkdirs(this, path, folderNodes); + folderNode.addChild(new FlowNode(label, fd.getName(), fd, + this)); + } + + flowDescriptors.put(fd.getName(), fd); + } + // TODO: make it readonly + } + + protected FolderNode mkdirs(TreeParent root, String path, + SortedMap folderNodes) { + // Normalize + if (path.charAt(0) != '/') + path = '/' + path; + if (path.charAt(path.length() - 1) == '/') + path = path.substring(0, path.length() - 1); + + if (folderNodes.containsKey(path)) + return folderNodes.get(path); + + int lastIndx = path.lastIndexOf('/'); + String folderName; + String parentPath; + if (lastIndx >= 0) { + folderName = path.substring(lastIndx + 1); + parentPath = path.substring(0, lastIndx); + } else { + folderName = path; + parentPath = ""; + } + + TreeParent parent; + if (parentPath.equals("")) + parent = root; + else + parent = mkdirs(root, parentPath, folderNodes); + FolderNode newFolder = new FolderNode(folderName); + parent.addChild(newFolder); + folderNodes.put(path, newFolder); + return newFolder; + } + + public Map getFlowDescriptors() { + return flowDescriptors; + } + + } + + /** + * + * @author bsinou + * + * The implementation of a vernice of a given slc process. Note that + * we store the parent node (execution module node) & the + * ExecutionFlowDescriptor. + */ + public class FlowNode extends TreeObject { + + private final String flowName; + private final ExecutionModuleNode executionModuleNode; + private final ExecutionFlowDescriptor executionFlowDescriptor; + + public FlowNode(String label, String flowName, + ExecutionFlowDescriptor executionFlowDescriptor, + ExecutionModuleNode parent) { + super(label); + this.flowName = flowName; + this.executionFlowDescriptor = executionFlowDescriptor; + this.executionModuleNode = parent; + } + + public String getFlowName() { + return flowName; + } + + public ExecutionModuleNode getExecutionModuleNode() { + return executionModuleNode; + } + + public ExecutionFlowDescriptor getExecutionFlowDescriptor() { + return executionFlowDescriptor; + } + + } + + public class FolderNode extends TreeParent { + public FolderNode(String name) { + super(name); + } + + } +} diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/providers/ProcessParametersEditingSupport.java b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/providers/ProcessParametersEditingSupport.java new file mode 100644 index 000000000..1501964ef --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/providers/ProcessParametersEditingSupport.java @@ -0,0 +1,94 @@ +package org.argeo.slc.client.ui.providers; + +import org.argeo.slc.client.ui.views.ProcessBuilderView; +import org.argeo.slc.client.ui.views.ProcessParametersView; +import org.argeo.slc.core.execution.PrimitiveAccessor; +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.ColumnViewer; +import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TextCellEditor; + +/** + * + * @author bsinou + * + * This class implements the ability to edit and save various type of + * parameter of a given process. Parameter values are directly saved as + * soon as the focus on a given field is lost. + * + * + * Note that this EditingSupport is tightly coupled with both + * ProcessParametersView and ProcessBuilderView; it cannot serve as a + * generic EditingSupport as is. Note also that it assumes that the + * processes in ProcessBuilderView as stored as an ordered list. + */ + +public class ProcessParametersEditingSupport extends EditingSupport { + + private CellEditor editor; + private int column; + + // So that we can update corresponding process + private int curProcessIndex; + private ProcessBuilderView pbView; + + public ProcessParametersEditingSupport(ColumnViewer viewer, int column) { + super(viewer); + editor = new TextCellEditor(((TableViewer) viewer).getTable()); + this.column = column; + } + + @Override + protected CellEditor getCellEditor(Object element) { + return editor; + } + + @Override + protected boolean canEdit(Object element) { + return true; + } + + @Override + protected Object getValue(Object element) { + 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())) { + return pv.getValue(); + } + } + return "unsupported param type"; + + } + + @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())) { + pv.setValue(value); + pbView.updateParameter(curProcessIndex, objectWithName.name, + objectWithName.obj); + getViewer().update(element, null); + } + } + + } + + // Store the index of the process which parameters are being edited + public void setCurrentProcessIndex(int index) { + this.curProcessIndex = index; + } + + public void setCurrentProcessBuilderView( + ProcessBuilderView processbuilderView) { + this.pbView = processbuilderView; + } + +} diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ExecutionModulesContentProvider.java b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ExecutionModulesContentProvider.java deleted file mode 100644 index 365f04650..000000000 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ExecutionModulesContentProvider.java +++ /dev/null @@ -1,285 +0,0 @@ -package org.argeo.slc.client.ui.views; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.eclipse.ui.TreeObject; -import org.argeo.eclipse.ui.TreeParent; -import org.argeo.slc.SlcException; -import org.argeo.slc.execution.ExecutionFlowDescriptor; -import org.argeo.slc.execution.ExecutionModuleDescriptor; -import org.argeo.slc.runtime.SlcAgent; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.Viewer; - -public class ExecutionModulesContentProvider implements ITreeContentProvider { - private final static Log log = LogFactory - .getLog(ExecutionModulesContentProvider.class); - - private List slcAgents; - - public Object[] getChildren(Object parent) { - - if (parent instanceof ExecutionModuleNode) { - ExecutionModuleNode executionModuleNode = (ExecutionModuleNode) parent; - ExecutionModuleDescriptor emd = executionModuleNode.getDescriptor(); - - // Terminate the building of UI specific object emd - emd = executionModuleNode - .getAgentNode() - .getAgent() - .getExecutionModuleDescriptor(emd.getName(), - emd.getVersion()); - executionModuleNode.cacheDescriptor(emd); - - // This is not recursive, e.g. ExecutionModuleNode build a Tree of - // specific - // treeObject and cache it in the cacheDescriptor. - // Then we only have TreeObjects - return executionModuleNode.getChildren(); - } else if (parent instanceof AgentNode) { - AgentNode agentNode = (AgentNode) parent; - - if (log.isTraceEnabled()) - log.trace("Scan agent " + agentNode); - - agentNode.clearChildren(); - for (ExecutionModuleDescriptor desc : agentNode.getAgent() - .listExecutionModuleDescriptors()) { - agentNode.addChild(new ExecutionModuleNode(agentNode, desc)); - } - - return agentNode.getChildren(); - } else if (parent instanceof TreeParent) { - return ((TreeParent) parent).getChildren(); - } else if (parent instanceof FlowNode) { - return new Object[0]; - } else { - List agentNodes = new ArrayList(); - for (SlcAgent slcAgent : slcAgents) { - agentNodes.add(new AgentNode(slcAgent)); - } - return agentNodes.toArray(); - } - } - - public Object getParent(Object node) { - // if (node instanceof TreeObject) { - // return ((TreeObject) node).getParent(); - // } - return null; - } - - public boolean hasChildren(Object parent) { - if (parent instanceof TreeParent && ((TreeParent) parent).isLoaded()) { - return ((TreeParent) parent).hasChildren(); - } else if (parent instanceof AgentNode) { - return true; - } else if (parent instanceof ExecutionModuleNode) { - return true; - } - return false; - } - - public void inputChanged(Viewer v, Object oldInput, Object newInput) { - } - - public void dispose() { - } - - public Object[] getElements(Object parent) { - return getChildren(parent); - } - - public void setSlcAgents(List 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; - - public AgentNode(SlcAgent agent) { - super(agent.toString()); - this.agent = agent; - } - - public SlcAgent getAgent() { - return agent; - } - } - - public class ExecutionModuleNode extends TreeParent { - private final AgentNode agentNode; - private ExecutionModuleDescriptor descriptor; - private Map flowDescriptors; - - public ExecutionModuleNode(AgentNode agentNode, - ExecutionModuleDescriptor descriptor) { - super(descriptor.toString()); - this.agentNode = agentNode; - this.descriptor = descriptor; - - } - - public AgentNode getAgentNode() { - return agentNode; - } - - public ExecutionModuleDescriptor getDescriptor() { - return descriptor; - } - - public void cacheDescriptor(ExecutionModuleDescriptor descriptor) { - this.descriptor = descriptor; - - SortedMap folderNodes = new TreeMap(); - - flowDescriptors = new HashMap(); - for (ExecutionFlowDescriptor fd : descriptor.getExecutionFlows()) { - if (log.isTraceEnabled()) - log.trace("fd.path=" + fd.getPath() + ", fd.name=" - + fd.getName()); - Map values = fd.getValues(); - - if (values == null) - log.debug("No attribute for " + fd.getName()); - else - for (String key : values.keySet()) - log.debug(key + " - " + values.get(key)); - - // find path and label - String path; - String label; - int lastSlash = fd.getName().lastIndexOf('/'); - if ((fd.getPath() == null || fd.getPath().trim().equals("")) - && lastSlash >= 0) { - path = fd.getName().substring(0, lastSlash); - label = fd.getName().substring(lastSlash + 1); - } else { - path = fd.getPath(); - label = fd.getName(); - } - // if (log.isTraceEnabled()) - // log.trace("path=" + path + ", label=" + label); - - if (path == null || path.trim().equals("") - || path.trim().equals("/")) { - // directChildren.put(name, new FlowNode(name, this)); - addChild(new FlowNode(label, fd.getName(), fd.getValues(), - this)); - } else { - FolderNode folderNode = mkdirs(this, path, folderNodes); - // TODO : why do we add a reference to the parent ? - // Probably to differentiate 2 flow nodes with same name but - // distinct execution Node. TBC - folderNode.addChild(new FlowNode(label, fd.getName(), fd - .getValues(), this)); - - } - - flowDescriptors.put(fd.getName(), fd); - } - // TODO: make it readonly - } - - protected FolderNode mkdirs(TreeParent root, String path, - SortedMap folderNodes) { - // Normalize - if (path.charAt(0) != '/') - path = '/' + path; - if (path.charAt(path.length() - 1) == '/') - path = path.substring(0, path.length() - 1); - - if (folderNodes.containsKey(path)) - return folderNodes.get(path); - - int lastIndx = path.lastIndexOf('/'); - String folderName; - String parentPath; - if (lastIndx >= 0) { - folderName = path.substring(lastIndx + 1); - parentPath = path.substring(0, lastIndx); - } else { - folderName = path; - parentPath = ""; - } - - TreeParent parent; - if (parentPath.equals("")) - parent = root; - else - parent = mkdirs(root, parentPath, folderNodes); - FolderNode newFolder = new FolderNode(folderName); - parent.addChild(newFolder); - folderNodes.put(path, newFolder); - return newFolder; - } - - public Map getFlowDescriptors() { - return flowDescriptors; - } - - } - - public class FlowNode extends TreeObject { - private final String flowName; - private final ExecutionModuleNode executionModuleNode; - - // TODO : handle casting from various object type to String and reverse. - private final Map values; - - public FlowNode(String label, String flowName, - Map values, ExecutionModuleNode parent) { - super(label); - this.flowName = flowName; - this.values = values; - this.executionModuleNode = parent; - } - - public Map getValues() { - return values; - } - - public Object getValueByKey(String key) { - return values.get(key); - } - - public void setValueByKey(String key, Object value) { - if (values.get(key) == null) - throw new SlcException("Unsupported Parameter " + key - + " for FlowNode " + flowName); - else { - values.remove(key); - values.put(key, value); - } - } - - public String getFlowName() { - return flowName; - } - - public ExecutionModuleNode getExecutionModuleNode() { - return executionModuleNode; - } - - } - - public class FolderNode extends TreeParent { - public FolderNode(String name) { - super(name); - } - - } -} diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ExecutionModulesView.java b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ExecutionModulesView.java index 370ed3889..c6ba27b13 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ExecutionModulesView.java +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ExecutionModulesView.java @@ -4,15 +4,16 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.Properties; import java.util.UUID; import org.apache.commons.io.IOUtils; 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.client.ui.providers.ExecutionModulesContentProvider; +import org.argeo.slc.client.ui.providers.ExecutionModulesContentProvider.FlowNode; import org.argeo.slc.execution.ExecutionModuleDescriptor; import org.argeo.slc.process.RealizedFlow; import org.argeo.slc.process.SlcExecution; @@ -43,8 +44,9 @@ public class ExecutionModulesView extends ViewPart { private TreeViewer viewer; + // Ioc private IContentProvider contentProvider; - + private OxmInterface oxmBean; private ProcessController processController; public void createPartControl(Composite parent) { @@ -66,14 +68,6 @@ public class ExecutionModulesView extends ViewPart { return viewer; } - public void setContentProvider(IContentProvider contentProvider) { - this.contentProvider = contentProvider; - } - - public void setProcessController(ProcessController processController) { - this.processController = processController; - } - class ViewLabelProvider extends LabelProvider implements ITableLabelProvider { public String getColumnText(Object obj, int index) { @@ -153,13 +147,15 @@ public class ExecutionModulesView extends ViewPart { IStructuredSelection selection = (IStructuredSelection) viewer .getSelection(); if (selection.getFirstElement() instanceof ExecutionModulesContentProvider.FlowNode) { - + if (TextTransfer.getInstance().isSupportedType(event.dataType)) { ExecutionModulesContentProvider.FlowNode flowNode = (ExecutionModulesContentProvider.FlowNode) selection .getFirstElement(); - RealizedFlow rf = nodeAsRealizedFlow(flowNode); + + // we still use property because the marshaller bean does + // not know the FlowNode Class Properties props = new Properties(); - realizedFlowAsProperties(props, rf); + flowNodeAsProperties(props, flowNode); props.setProperty("agentId", flowNode .getExecutionModuleNode().getAgentNode().getAgent() .getAgentUuid()); @@ -182,31 +178,38 @@ public class ExecutionModulesView extends ViewPart { System.out.println("Finished Drag"); } - private RealizedFlow nodeAsRealizedFlow( - ExecutionModulesContentProvider.FlowNode flowNode) { - RealizedFlow rf = new RealizedFlow(); - rf.setModuleName(flowNode.getExecutionModuleNode().getDescriptor() - .getName()); - rf.setModuleVersion(flowNode.getExecutionModuleNode() + private void flowNodeAsProperties(Properties props, FlowNode fn) { + props.setProperty("moduleName", fn.getExecutionModuleNode() + .getDescriptor().getName()); + props.setProperty("moduleVersion", fn.getExecutionModuleNode() .getDescriptor().getVersion()); - ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(); - efd.setName(flowNode.getFlowName()); - efd.setValues(flowNode.getValues()); - rf.setFlowDescriptor(efd); - return rf; - } + props.setProperty("flowName", fn.getFlowName()); + + System.out.println("Execution Spec avant marshalling ??? "); + System.out.println(fn.getExecutionFlowDescriptor()); + System.out.println(fn.getExecutionFlowDescriptor() + .getExecutionSpec()); + + props.setProperty("FlowDescriptorAsXml", + oxmBean.marshal(fn.getExecutionFlowDescriptor())); + System.out + .println(oxmBean.marshal(fn.getExecutionFlowDescriptor())); - private void realizedFlowAsProperties(Properties props, RealizedFlow rf) { - props.setProperty("moduleName", rf.getModuleName()); - props.setProperty("moduleVersion", rf.getModuleVersion()); - props.setProperty("flowName", rf.getFlowDescriptor().getName()); - Map values = rf.getFlowDescriptor().getValues(); - if (values != null && values.size() > 0) - for (String key : values.keySet()) - props.setProperty("values-" + key, values.get(key) - .toString()); } } + // IoC + public void setContentProvider(IContentProvider contentProvider) { + this.contentProvider = contentProvider; + } + + public void setProcessController(ProcessController processController) { + this.processController = processController; + } + + public void setOxmBean(OxmInterface oxmBean) { + this.oxmBean = oxmBean; + } + } \ No newline at end of file diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessBuilderView.java b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessBuilderView.java index cd2546aeb..c7f103505 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessBuilderView.java +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessBuilderView.java @@ -9,14 +9,23 @@ import java.util.UUID; import org.apache.commons.io.IOUtils; 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; +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.IParameter; +import org.eclipse.core.commands.Parameterization; +import org.eclipse.core.commands.ParameterizedCommand; +import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerDropAdapter; @@ -30,8 +39,21 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.handlers.IHandlerService; import org.eclipse.ui.part.ViewPart; +/** + * Display a list of processes that are to be launched as batch. For the moment + * being, only one agent by batch is enabled. The batch is contructed by + * dropping process from the ExecutionModuleView. Wrong type of data dropped in + * this view might raise errors. + * + * @author bsinou + * + */ public class ProcessBuilderView extends ViewPart { public static final String ID = "org.argeo.slc.client.ui.processBuilderView"; @@ -39,10 +61,11 @@ public class ProcessBuilderView extends ViewPart { // LogFactory.getLog(ProcessBuilderView.class); private TableViewer viewer; - private List realizedFlows = new ArrayList(); - private String currentAgentUuid = null; + + // IoC + private OxmInterface oxmBean; private ProcessController processController; public void createPartControl(Composite parent) { @@ -50,9 +73,12 @@ public class ProcessBuilderView extends ViewPart { viewer = new TableViewer(table); viewer.setLabelProvider(new ViewLabelProvider()); viewer.setContentProvider(new ViewContentProvider()); + viewer.addSelectionChangedListener(new SelectionChangedListener()); + int operations = DND.DROP_COPY | DND.DROP_MOVE; Transfer[] tt = new Transfer[] { TextTransfer.getInstance() }; viewer.addDropSupport(operations, tt, new ViewDropListener(viewer)); + viewer.setInput(getViewSite()); } @@ -88,7 +114,6 @@ public class ProcessBuilderView extends ViewPart { SlcExecution slcExecution = new SlcExecution(); slcExecution.setUuid(UUID.randomUUID().toString()); slcExecution.setRealizedFlows(realizedFlows); - processController.execute(agent, slcExecution); } @@ -96,10 +121,14 @@ public class ProcessBuilderView extends ViewPart { viewer.getControl().setFocus(); } - public void setProcessController(ProcessController processController) { - this.processController = processController; + // update one of the parameter of a given RealizedFlow + public void updateParameter(int realizedFlowIndex, String paramName, + Object value) { + RealizedFlow curRealizedFlow = realizedFlows.get(realizedFlowIndex); + curRealizedFlow.getFlowDescriptor().getValues().put(paramName, value); } + // Specific Providers for the current view. protected class ViewContentProvider implements IStructuredContentProvider { public void inputChanged(Viewer arg0, Object arg1, Object arg2) { } @@ -131,6 +160,80 @@ public class ProcessBuilderView extends ViewPart { } + // Handle Events + class SelectionChangedListener implements ISelectionChangedListener { + public void selectionChanged(SelectionChangedEvent evt) { + + IStructuredSelection curSelection = (IStructuredSelection) evt + .getSelection(); + Object obj = curSelection.getFirstElement(); + + 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 parameters = new ArrayList(); + + 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()); + } + } + } + } + + // Implementation of the Drop Listener protected class ViewDropListener extends ViewerDropAdapter { public ViewDropListener(Viewer viewer) { @@ -139,14 +242,16 @@ public class ProcessBuilderView extends ViewPart { @Override public boolean performDrop(Object data) { - System.out.println(data); + Properties props = new Properties(); + + // TODO : Handle wrong type of dropped data ByteArrayInputStream in = new ByteArrayInputStream(data.toString() .getBytes()); try { props.load(in); } catch (IOException e) { - throw new SlcException("Cannot create read realized flow", e); + throw new SlcException("Cannot create read flow node", e); } finally { IOUtils.closeQuietly(in); } @@ -167,14 +272,6 @@ public class ProcessBuilderView extends ViewPart { RealizedFlow rf = realizedFlowFromProperties(props); realizedFlows.add(rf); - // Map descriptors = rf.getFlowDescriptor() - // .getValues(); - // if (descriptors != null && descriptors.size() > 0 ){ - // for (String key : descriptors.keySet()) { - // System.out.println("[" + key + "] " - // + descriptors.get(key).toString()); - // }} - getViewer().refresh(); return true; } @@ -183,6 +280,22 @@ public class ProcessBuilderView extends ViewPart { 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); @@ -193,9 +306,16 @@ public class ProcessBuilderView extends ViewPart { public boolean validateDrop(Object target, int operation, TransferData transferType) { return true; - } + } + + // IoC + public void setOxmBean(OxmInterface oxmBean) { + this.oxmBean = oxmBean; + } + public void setProcessController(ProcessController processController) { + this.processController = processController; } } diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessParametersView.java b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessParametersView.java index 9cff1f6df..4fabec135 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessParametersView.java +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessParametersView.java @@ -2,7 +2,13 @@ package org.argeo.slc.client.ui.views; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import org.argeo.slc.client.ui.ClientUiPlugin; +import org.argeo.slc.client.ui.providers.ProcessParametersEditingSupport; +import org.argeo.slc.core.execution.PrimitiveAccessor; +import org.argeo.slc.execution.ExecutionSpecAttribute; +import org.argeo.slc.process.RealizedFlow; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; @@ -15,21 +21,51 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Table; import org.eclipse.ui.part.ViewPart; +/** + * + * @author bsinou + * + * This view, directly linked with the ProcessBuilderView + * enables the display and editing the parameters of a given process. + * + * Note that for now we use ExecutionFlowDescriptor.values + * 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 TableViewer viewer; + // class attribute + private Map parameters; + private RealizedFlow curRealizedFlow; + + // we should be using executionspecAttribute but for now we uses values. + private Map values; + + // We must keep a reference to the current EditingSupport so that we can + // update the index of the process being updated + ProcessParametersEditingSupport ppEditingSupport; - private List parameters = new ArrayList(); + // view attributes + private TableViewer viewer; public void createPartControl(Composite parent) { viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); createColumns(viewer); + // WARNING + // 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 @@ -44,17 +80,53 @@ public class ProcessParametersView extends ViewPart { column.getColumn().setWidth(bounds[i]); column.getColumn().setResizable(true); column.getColumn().setMoveable(true); + if (i == 1) { + // we create the used EditingSupport and enable editing support + // for value Column + ppEditingSupport = new ProcessParametersEditingSupport(viewer, + i); + column.setEditingSupport(ppEditingSupport); + } } Table table = viewer.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); + } public void setFocus() { viewer.getControl().setFocus(); } - // Inner Classes + // 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; + ppEditingSupport.setCurrentProcessIndex(index); + curRealizedFlow = rf; + + // TODO : + // We should handle ExecutionSpec here. need to be improved. + // ExecutionSpec es = rf.getExecutionSpec(); + // if (es != null && es.getAttributes() != null) + // parameters = es.getAttributes(); + // if (parameters != null) + // viewer.setInput(parameters); + + values = rf.getFlowDescriptor().getValues(); + if (values != null) + viewer.setInput(values); + else + // No parameters to edit, we reset the view. + viewer.setInput(null); + + } + + // Inner Classes we should use ExecutionSpecAttribute instead of values + // see below protected class ViewContentProvider implements IStructuredContentProvider { public void inputChanged(Viewer arg0, Object arg1, Object arg2) { } @@ -62,16 +134,49 @@ public class ProcessParametersView extends ViewPart { public void dispose() { } + @SuppressWarnings("unchecked") + // we cast the Map to List public Object[] getElements(Object obj) { - return parameters.toArray(); + + if (obj instanceof Map && ((Map) obj).size() != 0) { + List list = new ArrayList(); + Map map = (Map) obj; + for (String key : map.keySet()) { + list.add(new ObjectWithName(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) { - String[] param = (String[]) obj; - return param[index]; + // NOTE : the passed object is a line of the table !!! + + if (obj instanceof ObjectWithName) { + ObjectWithName own = (ObjectWithName) obj; + switch (index) { + case 0: + return own.name; + case 1: + if (own.obj instanceof PrimitiveAccessor) { + PrimitiveAccessor pa = (PrimitiveAccessor) own.obj; + if ("string".equals(pa.getType())) + return (String) pa.getValue(); + else + return "Type " + pa.getType() + + " not yet supported"; + } else + return own.obj.toString(); + default: + return getText(obj); + } + } else + return getText(obj); } public Image getColumnImage(Object obj, int index) { @@ -79,4 +184,84 @@ public class ProcessParametersView extends ViewPart { } } + + // We add an inner class to enrich the ExecutionSpecAttribute with a name + // so that we can display it. + public class ObjectWithName { + public Object obj; + public String name; + + public ObjectWithName(String name, Object obj) { + this.name = name; + this.obj = obj; + } + + } + + // protected class ViewContentProvider implements IStructuredContentProvider + // { + // public void inputChanged(Viewer arg0, Object arg1, Object arg2) { + // } + // + // public void dispose() { + // } + // + // // we cast the Map to List + // public Object[] getElements(Object obj) { + // if (obj instanceof Map && ((Map) obj).size() != 0) { + // List list = new + // ArrayList(); + // Map map = (Map) 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; + // } + + // } } diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlowDescriptor.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlowDescriptor.java index 575886d9a..d9a3e6657 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlowDescriptor.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlowDescriptor.java @@ -19,6 +19,18 @@ package org.argeo.slc.execution; import java.io.Serializable; import java.util.Map; +/** + * + * @author bsinou + * + * This class implements the archetype of a given process. + * + * WARNING : for now both values and + * executionSpec which are rundundant are used. Should be + * improved in further version. Note also that a third redundant field, + * RealizedFlow.executionSpec is also to be cleaned. + * + */ public class ExecutionFlowDescriptor implements Serializable { private static final long serialVersionUID = 7101944857038041216L; private String name; diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionSpec.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionSpec.java index ab4de4fd3..899b76f96 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionSpec.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionSpec.java @@ -18,10 +18,16 @@ package org.argeo.slc.execution; import java.util.Map; +/** + * The class implementing this interface defines the map of attributes that are + * necessary for the corresponding ExecutionFlow. + * + * @author bsinou + */ public interface ExecutionSpec { public Map getAttributes(); public String getName(); - + public String getDescription(); } diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionSpecAttribute.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionSpecAttribute.java index 235171b1d..22d981f44 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionSpecAttribute.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionSpecAttribute.java @@ -16,6 +16,27 @@ package org.argeo.slc.execution; +/** + * + * This interface stands for one attribute of a given flow. + * + * We mainly have two implementations : + * + * + Primitive attributes (no predefined choice, the end user must compute a + * String, a Float, an Integer...) + * + * + RefSpecAttribute which enable two things + a reference to another object of + * the application context + the display of some choices among which the end + * user can choose. + * + * Note : + * + * @see org.argeo.slc.core.execution.PrimitiveUtils : this class offers some + * helper, among others to cast the various type of primitive attribute. + * + * @author bsinou + * + */ public interface ExecutionSpecAttribute { public Object getValue(); diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/RealizedFlow.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/RealizedFlow.java index 91eb54254..2869684f8 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/RealizedFlow.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/RealizedFlow.java @@ -38,8 +38,8 @@ public class RealizedFlow implements Serializable { public void setModuleName(String moduleName) { this.moduleName = moduleName; } - - public NameVersion getModuleNameVersion(){ + + public NameVersion getModuleNameVersion() { return new BasicNameVersion(getModuleName(), getModuleVersion()); } @@ -66,5 +66,4 @@ public class RealizedFlow implements Serializable { public void setExecutionSpec(ExecutionSpec executionSpec) { this.executionSpec = executionSpec; } - }