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%2FProcessEditor.java;h=b00b41298f3b545f290307beb4488ad7fcb8f06f;hb=0e2ff188c2e8ffac85739cccc3925e8bd82d7be9;hp=4da6f061a849061467a42c6281632a1579b46e3c;hpb=15fdf876a4dbb73b379f8c6c16d7d929955ade4d;p=gpl%2Fargeo-slc.git diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessEditor.java b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessEditor.java index 4da6f061a..b00b41298 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessEditor.java +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessEditor.java @@ -1,21 +1,24 @@ package org.argeo.slc.client.ui.editors; -import java.util.Calendar; -import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.UUID; import javax.jcr.Node; -import javax.jcr.Property; import javax.jcr.RepositoryException; import javax.jcr.Session; -import javax.jcr.nodetype.NodeType; +import org.argeo.eclipse.ui.Error; import org.argeo.jcr.JcrUtils; import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.ClientUiPlugin; import org.argeo.slc.client.ui.controllers.ProcessController; +import org.argeo.slc.execution.ExecutionModulesManager; import org.argeo.slc.execution.ExecutionProcess; -import org.argeo.slc.jcr.SlcJcrConstants; +import org.argeo.slc.execution.ExecutionProcessNotifier; +import org.argeo.slc.execution.ExecutionStep; +import org.argeo.slc.jcr.SlcJcrUtils; import org.argeo.slc.jcr.SlcNames; import org.argeo.slc.jcr.SlcTypes; import org.eclipse.core.runtime.IProgressMonitor; @@ -24,7 +27,8 @@ import org.eclipse.ui.IEditorSite; import org.eclipse.ui.PartInitException; import org.eclipse.ui.forms.editor.FormEditor; -public class ProcessEditor extends FormEditor implements SlcTypes, SlcNames { +public class ProcessEditor extends FormEditor implements + ExecutionProcessNotifier, SlcTypes, SlcNames { public final static String ID = ClientUiPlugin.ID + ".processEditor"; private Session session; @@ -33,7 +37,9 @@ public class ProcessEditor extends FormEditor implements SlcTypes, SlcNames { private ProcessBuilderPage builderPage; private ProcessLogPage logPage; - + + private ExecutionModulesManager modulesManager; + @Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { @@ -58,25 +64,30 @@ public class ProcessEditor extends FormEditor implements SlcTypes, SlcNames { protected Node newProcessNode(ProcessEditorInput pei) throws RepositoryException { - Calendar now = new GregorianCalendar(); String uuid = UUID.randomUUID().toString(); - String processPath = SlcJcrConstants.PROCESSES_BASE_PATH + '/' - + JcrUtils.dateAsPath(now, true) + uuid; + String processPath = SlcJcrUtils.createExecutionProcessPath(uuid); Node processNode = JcrUtils.mkdirs(session, processPath, SLC_PROCESS); processNode.setProperty(SLC_UUID, uuid); - processNode.setProperty(SLC_STATUS, ExecutionProcess.UNINITIALIZED); + processNode.setProperty(SLC_STATUS, ExecutionProcess.NEW); Node processFlow = processNode.addNode(SLC_FLOW); processFlow.addMixin(SLC_REALIZED_FLOW); + return processNode; + } + + @Override + public boolean isDirty() { + if (getProcessStatus().equals(ExecutionProcess.NEW)) + return true; + return super.isDirty(); + } - // add initial flows - for (String path : pei.getInitialFlowPaths()) { - Node realizedFlow = processFlow.addNode(SLC_FLOW); - realizedFlow.addMixin(SLC_REALIZED_FLOW); - Node address = realizedFlow.addNode(SLC_ADDRESS, - NodeType.NT_ADDRESS); - address.setProperty(Property.JCR_PATH, path); + protected String getProcessStatus() { + try { + return processNode.getProperty(SLC_STATUS).getString(); + } catch (RepositoryException e) { + throw new SlcException("Cannot retrieve status for " + processNode, + e); } - return processNode; } @Override @@ -93,7 +104,15 @@ public class ProcessEditor extends FormEditor implements SlcTypes, SlcNames { throw new SlcException("Cannot update status of " + processNode, e); } doSave(null); - processController.process(processNode); + try { + ExecutionProcess process = processController.process(processNode); + Map properties = new HashMap(); + properties.put(ExecutionModulesManager.SLC_PROCESS_ID, + process.getUuid()); + modulesManager.registerProcessNotifier(this, properties); + } catch (Exception e) { + Error.show("Execution of " + processNode + " failed", e); + } } @Override @@ -114,12 +133,12 @@ public class ProcessEditor extends FormEditor implements SlcTypes, SlcNames { public void doSave(IProgressMonitor monitor) { try { String status = processNode.getProperty(SLC_STATUS).getString(); - if (status.equals(ExecutionProcess.UNINITIALIZED)) + if (status.equals(ExecutionProcess.NEW)) processNode.setProperty(SLC_STATUS, ExecutionProcess.INITIALIZED); session.save(); builderPage.commit(true); - firePropertyChange(PROP_DIRTY); + editorDirtyStateChanged(); } catch (RepositoryException e) { throw new SlcException("Cannot save " + processNode, e); } finally { @@ -136,6 +155,14 @@ public class ProcessEditor extends FormEditor implements SlcTypes, SlcNames { return false; } + public void updateStatus(ExecutionProcess process, String oldStatus, + String newStatus) { + } + + public void addSteps(ExecutionProcess process, List steps) { + logPage.addSteps(steps); + } + /** Expects one session per editor. */ public void setSession(Session session) { this.session = session; @@ -145,4 +172,8 @@ public class ProcessEditor extends FormEditor implements SlcTypes, SlcNames { this.processController = processController; } + public void setModulesManager(ExecutionModulesManager modulesManager) { + this.modulesManager = modulesManager; + } + }