X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=eclipse%2Fplugins%2Forg.argeo.slc.client.ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Feditors%2FProcessBuilderPage.java;h=a5d8676de2a5d479ff16e5600e0f1884b57fa5a9;hb=a8a48e55e668909147b8ebef6b5d52f0fa1eab84;hp=c373bbb8ccf6c7a1ba19a975cca3406f205f6393;hpb=b9677d2472658530dff02c90ba23725fc80f1c67;p=gpl%2Fargeo-slc.git diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java index c373bbb8c..a5d8676de 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java @@ -3,6 +3,8 @@ package org.argeo.slc.client.ui.editors; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.UUID; import javax.jcr.Node; @@ -12,12 +14,11 @@ import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.nodetype.NodeType; import javax.jcr.observation.Event; -import javax.jcr.observation.EventIterator; import javax.jcr.observation.EventListener; import javax.jcr.observation.ObservationManager; +import javax.jcr.query.Query; +import javax.jcr.query.QueryManager; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.argeo.ArgeoException; import org.argeo.eclipse.ui.jcr.AsyncUiEventListener; import org.argeo.jcr.JcrUtils; @@ -70,9 +71,10 @@ import org.eclipse.ui.forms.editor.FormPage; import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.ScrolledForm; -public class ProcessBuilderPage extends FormPage implements SlcNames, SlcTypes { +public class ProcessBuilderPage extends FormPage implements SlcNames { public final static String ID = "processBuilderPage"; - private final static Log log = LogFactory.getLog(ProcessBuilderPage.class); + // private final static Log log = + // LogFactory.getLog(ProcessBuilderPage.class); private Node processNode; @@ -111,8 +113,8 @@ public class ProcessBuilderPage extends FormPage implements SlcNames, SlcTypes { getManagedForm().addPart(formPart); // observation - statusObserver = new AsyncUiEventListener() { - protected void onEventInUiThread(EventIterator events) { + statusObserver = new AsyncUiEventListener(form.getDisplay()) { + protected void onEventInUiThread(List events) { statusChanged(); } }; @@ -297,7 +299,8 @@ public class ProcessBuilderPage extends FormPage implements SlcNames, SlcTypes { Session session = processNode.getSession(); String uuid = UUID.randomUUID().toString(); String destPath = SlcJcrUtils.createExecutionProcessPath(uuid); - Node newNode = JcrUtils.mkdirs(session, destPath, SLC_PROCESS); + Node newNode = JcrUtils.mkdirs(session, destPath, + SlcTypes.SLC_PROCESS); JcrUtils.copy(processNode, newNode); // session.getWorkspace().copy(processNode.getPath(), destPath); // Node newNode = session.getNode(destPath); @@ -344,32 +347,46 @@ public class ProcessBuilderPage extends FormPage implements SlcNames, SlcTypes { * @param path * the path of the flow */ - public void addFlow(String path) { + protected void addFlow(String path) { try { Node flowNode = processNode.getSession().getNode(path); Node realizedFlowNode = processNode.getNode(SLC_FLOW).addNode( SLC_FLOW); - realizedFlowNode.addMixin(SLC_REALIZED_FLOW); + realizedFlowNode.addMixin(SlcTypes.SLC_REALIZED_FLOW); Node address = realizedFlowNode.addNode(SLC_ADDRESS, NodeType.NT_ADDRESS); address.setProperty(Property.JCR_PATH, path); // copy spec attributes Node specAttrsBase; - if (flowNode.hasProperty(SLC_SPEC)) - specAttrsBase = flowNode.getProperty(SLC_SPEC).getNode(); - else + if (flowNode.hasProperty(SLC_SPEC)) { + Node executionSpecNode = flowNode.getProperty(SLC_SPEC) + .getNode(); + specAttrsBase = executionSpecNode; + String executionSpecName = executionSpecNode.getProperty( + SLC_NAME).getString(); + realizedFlowNode.setProperty(SLC_SPEC, executionSpecName); + } else specAttrsBase = flowNode; specAttrs: for (NodeIterator nit = specAttrsBase.getNodes(); nit .hasNext();) { Node specAttrNode = nit.nextNode(); + String attrName = specAttrNode.getName(); if (!specAttrNode .isNodeType(SlcTypes.SLC_EXECUTION_SPEC_ATTRIBUTE)) continue specAttrs; Node realizedAttrNode = realizedFlowNode.addNode(specAttrNode .getName()); JcrUtils.copy(specAttrNode, realizedAttrNode); + + // ovveride with flow value + if (flowNode.hasNode(attrName)) { + // assuming this is a primitive + realizedAttrNode.setProperty(SLC_VALUE, + flowNode.getNode(attrName).getProperty(SLC_VALUE) + .getValue()); + } } flowsViewer.refresh(); @@ -461,7 +478,8 @@ public class ProcessBuilderPage extends FormPage implements SlcNames, SlcTypes { // TODO optimize based on data type? Object value = PrimitiveUtils.convert(type, specAttrNode .getProperty(SLC_VALUE).getString()); - log.debug(specAttrNode + ", type=" + type + ", value=" + value); + // log.debug(specAttrNode + ", type=" + type + ", value=" + + // value); return value; } return null; @@ -518,7 +536,7 @@ public class ProcessBuilderPage extends FormPage implements SlcNames, SlcTypes { public String getText(Object element) { Node node = (Node) element; try { - if (node.isNodeType(SLC_REALIZED_FLOW)) { + if (node.isNodeType(SlcTypes.SLC_REALIZED_FLOW)) { if (node.hasNode(SLC_ADDRESS)) { String path = node.getNode(SLC_ADDRESS) .getProperty(Property.JCR_PATH).getString(); @@ -536,7 +554,7 @@ public class ProcessBuilderPage extends FormPage implements SlcNames, SlcTypes { public Image getImage(Object element) { Node node = (Node) element; try { - if (node.isNodeType(SLC_REALIZED_FLOW)) { + if (node.isNodeType(SlcTypes.SLC_REALIZED_FLOW)) { return SlcImages.FLOW; } } catch (RepositoryException e) { @@ -560,6 +578,7 @@ public class ProcessBuilderPage extends FormPage implements SlcNames, SlcTypes { } } + /** Manages drop event. */ class FlowsDropListener extends ViewerDropAdapter { public FlowsDropListener(Viewer viewer) { @@ -569,8 +588,31 @@ public class ProcessBuilderPage extends FormPage implements SlcNames, SlcTypes { @Override public boolean performDrop(Object data) { String path = data.toString(); - addFlow(path); - return true; + try { + // either a node or a whole directory was dragged + QueryManager qm = processNode.getSession().getWorkspace() + .getQueryManager(); + String statement = "SELECT * FROM [" + + SlcTypes.SLC_EXECUTION_FLOW + + "] WHERE ISDESCENDANTNODE(['" + path + + "']) OR ISSAMENODE(['" + path + "'])"; + // log.debug(statement); + Query query = qm.createQuery(statement, Query.JCR_SQL2); + + // order paths + SortedSet paths = new TreeSet(); + for (NodeIterator nit = query.execute().getNodes(); nit + .hasNext();) { + paths.add(nit.nextNode().getPath()); + } + + for (String p : paths) { + addFlow(p); + } + return true; + } catch (RepositoryException e) { + throw new SlcException("Cannot query flows under " + path, e); + } } @Override