From a08f6f6263b494808ea599ba139b76e7eb031d29 Mon Sep 17 00:00:00 2001 From: Bruno Sinou Date: Fri, 22 Oct 2010 15:14:13 +0000 Subject: [PATCH] Fix drag & drop and begin implementation of test parameters. git-svn-id: https://svn.argeo.org/slc/trunk@3844 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../META-INF/MANIFEST.MF | 3 +- .../META-INF/spring/osgi.xml | 12 +++ .../org.argeo.slc.client.rcp/plugin.xml | 4 +- .../rcp/ApplicationActionBarAdvisor.java | 3 +- .../rcp/ApplicationWorkbenchAdvisor.java | 2 +- .../ApplicationWorkbenchWindowAdvisor.java | 6 +- .../slc/client/rcp/commands/ExitHandler.java | 2 + .../META-INF/MANIFEST.MF | 5 +- .../META-INF/spring/osgi.xml | 2 +- .../META-INF/spring/views.xml | 5 ++ .../org.argeo.slc.client.ui/plugin.xml | 6 ++ .../commands/ResultDetailsDisplayHandler.java | 6 +- .../client/ui/perspectives/SlcExecution.java} | 15 ++-- .../ExecutionModulesContentProvider.java | 76 +++++++++++++---- .../client/ui/views/ExecutionModulesView.java | 29 ++++--- .../client/ui/views/ProcessBuilderView.java | 20 ++++- .../ui/views/ProcessDetailLabelProvider.java | 38 --------- .../client/ui/views/ProcessDetailView.java | 39 +++++++-- .../ui/views/ProcessParametersView.java | 82 +++++++++++++++++++ 19 files changed, 261 insertions(+), 94 deletions(-) create mode 100644 eclipse/plugins/org.argeo.slc.client.rcp/META-INF/spring/osgi.xml rename eclipse/plugins/{org.argeo.slc.client.rcp/src/org/argeo/slc/client/rcp/Perspective.java => org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/perspectives/SlcExecution.java} (68%) delete mode 100644 eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessDetailLabelProvider.java create mode 100644 eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessParametersView.java diff --git a/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/MANIFEST.MF b/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/MANIFEST.MF index 56d20f9cb..c59ffec61 100644 --- a/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/MANIFEST.MF +++ b/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/MANIFEST.MF @@ -8,7 +8,8 @@ Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Import-Package: org.argeo.slc.core.test.tree;version="0.13.0.SNAPSHOT-r3768", +Import-Package: org.argeo.slc.client.ui.perspectives, + org.argeo.slc.core.test.tree;version="0.13.0.SNAPSHOT-r3768", org.argeo.slc.execution;version="0.13.0.SNAPSHOT-r3770", org.argeo.slc.process;version="0.13.0.SNAPSHOT-r3770", org.argeo.slc.runtime;version="0.13.0.SNAPSHOT-r3770", diff --git a/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/spring/osgi.xml b/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/spring/osgi.xml new file mode 100644 index 000000000..4b7f32a5b --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/spring/osgi.xml @@ -0,0 +1,12 @@ + + + + Implements All RCP basic classes that are not SLC + dependent. + + \ No newline at end of file diff --git a/eclipse/plugins/org.argeo.slc.client.rcp/plugin.xml b/eclipse/plugins/org.argeo.slc.client.rcp/plugin.xml index b7ce60120..8b78bb368 100644 --- a/eclipse/plugins/org.argeo.slc.client.rcp/plugin.xml +++ b/eclipse/plugins/org.argeo.slc.client.rcp/plugin.xml @@ -15,8 +15,8 @@ point="org.eclipse.ui.perspectives"> + class="org.argeo.slc.client.ui.perspectives.SlcExecution" + id="org.argeo.slc.client.ui.perspectives.slcExecution"> - Implements SLC specific rcp uis. + Implements SLC specific RCP UIs. 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 0d2b0a3ac..4cb9bc59b 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 @@ -46,6 +46,11 @@ + + + + diff --git a/eclipse/plugins/org.argeo.slc.client.ui/plugin.xml b/eclipse/plugins/org.argeo.slc.client.ui/plugin.xml index 743dc915f..d55bd5888 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/plugin.xml +++ b/eclipse/plugins/org.argeo.slc.client.ui/plugin.xml @@ -37,6 +37,12 @@ allowMultiple="true" restorable="true"> + + slcAgents; public Object[] getChildren(Object parent) { + if (parent instanceof ExecutionModuleNode) { ExecutionModuleNode executionModuleNode = (ExecutionModuleNode) parent; ExecutionModuleDescriptor emd = executionModuleNode.getDescriptor(); - emd = executionModuleNode.getAgentNode().getAgent() + + // Terminate the building of UI specific object emd + emd = executionModuleNode + .getAgentNode() + .getAgent() .getExecutionModuleDescriptor(emd.getName(), emd.getVersion()); executionModuleNode.cacheDescriptor(emd); - // for (String flowName : executionModuleNode.getFlowDescriptors() - // .keySet()) { - // executionModuleNode.addChild(new FlowNode(flowName, - // executionModuleNode)); - // } + + // 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; @@ -92,7 +98,13 @@ public class ExecutionModulesContentProvider implements ITreeContentProvider { } public void setSlcAgents(List slcAgents) { - this.slcAgents = slcAgents; + this.slcAgents = slcAgents// for (String flowName : + // executionModuleNode.getFlowDescriptors() + // .keySet()) { + // executionModuleNode.addChild(new FlowNode(flowName, + // executionModuleNode)); + // } + ; } public class AgentNode extends TreeParent { @@ -136,9 +148,16 @@ public class ExecutionModulesContentProvider implements ITreeContentProvider { flowDescriptors = new HashMap(); for (ExecutionFlowDescriptor fd : descriptor.getExecutionFlows()) { - // if (log.isTraceEnabled()) - // log.trace("fd.path=" + fd.getPath() + ", fd.name=" - // + fd.getName()); + 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; @@ -158,11 +177,16 @@ public class ExecutionModulesContentProvider implements ITreeContentProvider { if (path == null || path.trim().equals("") || path.trim().equals("/")) { // directChildren.put(name, new FlowNode(name, this)); - addChild(new FlowNode(label, fd.getName(), this)); + addChild(new FlowNode(label, fd.getName(), fd.getValues(), + this)); } else { FolderNode folderNode = mkdirs(this, path, folderNodes); - folderNode - .addChild(new FlowNode(label, fd.getName(), this)); + // 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); @@ -213,11 +237,33 @@ public class ExecutionModulesContentProvider implements ITreeContentProvider { 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, - ExecutionModuleNode executionModuleNode) { + Map values, ExecutionModuleNode parent) { super(label); this.flowName = flowName; - this.executionModuleNode = executionModuleNode; + 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() { 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 0adc32835..370ed3889 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,12 +4,11 @@ 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.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.ClientUiPlugin; import org.argeo.slc.client.ui.controllers.ProcessController; @@ -37,8 +36,8 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; public class ExecutionModulesView extends ViewPart { - private final static Log log = LogFactory - .getLog(ExecutionModulesView.class); + // private final static Log log = LogFactory + // .getLog(ExecutionModulesView.class); public static final String ID = "org.argeo.slc.client.ui.executionModulesView"; @@ -142,15 +141,19 @@ public class ExecutionModulesView extends ViewPart { } class ViewDragListener implements DragSourceListener { - public void dragFinished(DragSourceEvent event) { - System.out.println("Finished Drag"); + + public void dragStart(DragSourceEvent event) { + System.out.println("Start Drag"); } public void dragSetData(DragSourceEvent event) { System.out.println("dragSetData: " + event); + // System.out.println("dataType: " + event.dataType); + IStructuredSelection selection = (IStructuredSelection) viewer .getSelection(); if (selection.getFirstElement() instanceof ExecutionModulesContentProvider.FlowNode) { + if (TextTransfer.getInstance().isSupportedType(event.dataType)) { ExecutionModulesContentProvider.FlowNode flowNode = (ExecutionModulesContentProvider.FlowNode) selection .getFirstElement(); @@ -166,8 +169,8 @@ public class ExecutionModulesView extends ViewPart { props.store(out, ""); event.data = new String(out.toByteArray()); } catch (IOException e) { - throw new SlcException("Cannot transfor realized flow", - e); + throw new SlcException( + "Cannot transform realized flow", e); } finally { IOUtils.closeQuietly(out); } @@ -175,8 +178,8 @@ public class ExecutionModulesView extends ViewPart { } } - public void dragStart(DragSourceEvent event) { - System.out.println("Start Drag"); + public void dragFinished(DragSourceEvent event) { + System.out.println("Finished Drag"); } private RealizedFlow nodeAsRealizedFlow( @@ -188,6 +191,7 @@ public class ExecutionModulesView extends ViewPart { .getDescriptor().getVersion()); ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(); efd.setName(flowNode.getFlowName()); + efd.setValues(flowNode.getValues()); rf.setFlowDescriptor(efd); return rf; } @@ -196,6 +200,11 @@ public class ExecutionModulesView extends ViewPart { 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()); } } 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 a587d1b5c..cd2546aeb 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 @@ -154,11 +154,27 @@ public class ProcessBuilderView extends ViewPart { String agentId = props.getProperty("agentId"); if (currentAgentUuid == null) currentAgentUuid = agentId; - else if (currentAgentUuid.equals(agentId)) - return false; + 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. + throw new SlcException( + "Cannot create batch on two (or more) distinct agents", + null); + // return false; + } 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; } diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessDetailLabelProvider.java b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessDetailLabelProvider.java deleted file mode 100644 index 0e4573ed9..000000000 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessDetailLabelProvider.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.argeo.slc.client.ui.views; - -import org.argeo.slc.process.SlcExecution; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.swt.graphics.Image; - -/** - * @author bsinou - * - * Fill ProcessDetail view. Deported in an external bundle so that main - * slc ui bundle does not depend on DB implementation. - */ -public class ProcessDetailLabelProvider extends LabelProvider implements - ITableLabelProvider { - public String getColumnText(Object obj, int index) { - // log.debug(sessionFactory.getClass().toString()); - - SlcExecution se = (SlcExecution) obj; - switch (index) { - - case 0: - return getText(se.getStartDate()); - case 1: - return se.getHost(); - case 2: - return se.getUuid(); - case 3: - return se.currentStep().getType(); - } - return getText(obj); - } - - public Image getColumnImage(Object obj, int index) { - return null; - } - -} diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessDetailView.java b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessDetailView.java index d08a45407..944207eb1 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessDetailView.java +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessDetailView.java @@ -3,9 +3,11 @@ package org.argeo.slc.client.ui.views; import org.argeo.slc.dao.process.SlcExecutionDao; import org.argeo.slc.process.SlcExecution; import org.eclipse.jface.viewers.IContentProvider; -import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.part.ViewPart; @@ -29,13 +31,13 @@ public class ProcessDetailView extends ViewPart { // IoC private IContentProvider contentProvider; - private ILabelProvider labelProvider; private SlcExecutionDao slcExecutionDao; public void createPartControl(Composite parent) { viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); viewer.setContentProvider(contentProvider); - viewer.setLabelProvider(labelProvider); + // viewer.setLabelProvider(labelProvider); + viewer.setLabelProvider(new ProcessDetailLabelProvider()); // viewer.setInput(getViewSite()); } @@ -56,15 +58,38 @@ public class ProcessDetailView extends ViewPart { this.uuid = uuid; } + // Inner Class + public class ProcessDetailLabelProvider extends LabelProvider implements + ITableLabelProvider { + public String getColumnText(Object obj, int index) { + // log.debug(sessionFactory.getClass().toString()); + + SlcExecution se = (SlcExecution) obj; + switch (index) { + + case 0: + return getText(se.getStartDate()); + case 1: + return se.getHost(); + case 2: + return se.getUuid(); + case 3: + return se.currentStep().getType(); + } + return getText(obj); + } + + public Image getColumnImage(Object obj, int index) { + return null; + } + + } + // IoC public void setContentProvider(IContentProvider contentProvider) { this.contentProvider = contentProvider; } - public void setLabelProvider(ILabelProvider labelProvider) { - this.labelProvider = labelProvider; - } - public void setSlcExecutionDao(SlcExecutionDao slcExecutionDao) { this.slcExecutionDao = slcExecutionDao; } 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 new file mode 100644 index 000000000..9cff1f6df --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessParametersView.java @@ -0,0 +1,82 @@ +package org.argeo.slc.client.ui.views; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.ui.part.ViewPart; + +public class ProcessParametersView extends ViewPart { + public static final String ID = "org.argeo.slc.client.ui.processParametersView"; + + private TableViewer viewer; + + private List parameters = new ArrayList(); + + public void createPartControl(Composite parent) { + viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL + | SWT.V_SCROLL | SWT.FULL_SELECTION); + createColumns(viewer); + + viewer.setLabelProvider(new ViewLabelProvider()); + viewer.setContentProvider(new ViewContentProvider()); + viewer.setInput(getViewSite()); + } + + // This will create the columns for the table + private void createColumns(TableViewer viewer) { + + String[] titles = { "Attribute name", "value" }; + int[] bounds = { 200, 200 }; + + for (int i = 0; i < titles.length; i++) { + TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE); + column.getColumn().setText(titles[i]); + column.getColumn().setWidth(bounds[i]); + column.getColumn().setResizable(true); + column.getColumn().setMoveable(true); + } + Table table = viewer.getTable(); + table.setHeaderVisible(true); + table.setLinesVisible(true); + } + + public void setFocus() { + viewer.getControl().setFocus(); + } + + // Inner Classes + protected class ViewContentProvider implements IStructuredContentProvider { + public void inputChanged(Viewer arg0, Object arg1, Object arg2) { + } + + public void dispose() { + } + + public Object[] getElements(Object obj) { + return parameters.toArray(); + } + } + + protected class ViewLabelProvider extends LabelProvider implements + ITableLabelProvider { + public String getColumnText(Object obj, int index) { + String[] param = (String[]) obj; + return param[index]; + } + + public Image getColumnImage(Object obj, int index) { + return null; + } + + } +} -- 2.39.2