package org.argeo.slc.client.ui.editors;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.UUID;
import javax.jcr.Node;
+import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
-import org.argeo.eclipse.ui.Error;
+import org.argeo.eclipse.ui.ErrorFeedback;
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.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;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.editor.FormEditor;
-public class ProcessEditor extends FormEditor implements SlcTypes, SlcNames {
+/** Editor for an execution process. */
+public class ProcessEditor extends FormEditor implements
+ ExecutionProcessNotifier, SlcTypes, SlcNames {
public final static String ID = ClientUiPlugin.ID + ".processEditor";
private Session session;
private ProcessBuilderPage builderPage;
private ProcessLogPage logPage;
+ private ExecutionModulesManager modulesManager;
+
+ private Boolean switchToLog = false;
+
@Override
public void init(IEditorSite site, IEditorInput input)
throws PartInitException {
}
/** Actually runs the process. */
- public void process() {
+ void process() {
// the modifications have to be saved before execution
try {
processNode.setProperty(SLC_STATUS, ExecutionProcess.SCHEDULED);
}
doSave(null);
try {
- processController.process(processNode);
+ // show log
+ if (switchToLog)
+ setActivePage(logPage.getId());
+
+ ExecutionProcess process = processController.process(processNode);
+ Map<String, String> properties = new HashMap<String, String>();
+ properties.put(ExecutionModulesManager.SLC_PROCESS_ID,
+ process.getUuid());
+ modulesManager.registerProcessNotifier(this, properties);
} catch (Exception e) {
- Error.show("Execution of " + processNode + " failed", e);
+ ErrorFeedback.show("Execution of " + processNode + " failed", e);
+ }
+ }
+
+ void kill() {
+ processController.kill(processNode);
+ }
+
+ /** Opens a new editor with a copy of this process */
+ void relaunch() {
+ try {
+ Node duplicatedNode = duplicateProcess();
+ IWorkbenchPage activePage = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage();
+ activePage.openEditor(
+ new ProcessEditorInput(duplicatedNode.getPath()),
+ ProcessEditor.ID);
+ close(false);
+ } catch (Exception e1) {
+ throw new SlcException("Cannot relaunch " + processNode, e1);
+ }
+ }
+
+ /** Duplicates the process */
+ protected Node duplicateProcess() {
+ try {
+ Session session = processNode.getSession();
+ String uuid = UUID.randomUUID().toString();
+ String destPath = SlcJcrUtils.createExecutionProcessPath(uuid);
+ Node newNode = JcrUtils.mkdirs(session, destPath,
+ SlcTypes.SLC_PROCESS);
+
+ Node rootRealizedFlowNode = newNode.addNode(SLC_FLOW);
+ // copy node
+ JcrUtils.copy(processNode.getNode(SLC_FLOW), rootRealizedFlowNode);
+
+ newNode.setProperty(SLC_UUID, uuid);
+ newNode.setProperty(SLC_STATUS, ExecutionProcess.INITIALIZED);
+
+ // reset realized flow status
+ // we just manage one level for the time being
+ NodeIterator nit = rootRealizedFlowNode.getNodes(SLC_FLOW);
+ while (nit.hasNext()) {
+ nit.nextNode().setProperty(SLC_STATUS,
+ ExecutionProcess.INITIALIZED);
+ }
+
+ session.save();
+ return newNode;
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot duplicate process", e);
}
}
builderPage = new ProcessBuilderPage(this, processNode);
addPage(builderPage);
firePropertyChange(PROP_DIRTY);
- logPage = new ProcessLogPage(this);
+ logPage = new ProcessLogPage(this, processNode);
addPage(logPage);
} catch (PartInitException e) {
throw new SlcException("Cannot add pages", e);
return false;
}
+ public void updateStatus(ExecutionProcess process, String oldStatus,
+ String newStatus) {
+ }
+
+ public void addSteps(ExecutionProcess process, List<ExecutionStep> steps) {
+ // logPage.addSteps(steps);
+ }
+
/** Expects one session per editor. */
public void setSession(Session session) {
this.session = session;
this.processController = processController;
}
+ public void setModulesManager(ExecutionModulesManager modulesManager) {
+ this.modulesManager = modulesManager;
+ }
+
}