]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessEditor.java
Improve UI
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.client.ui / src / main / java / org / argeo / slc / client / ui / editors / ProcessEditor.java
index b00b41298f3b545f290307beb4488ad7fcb8f06f..a355ff7d952d3b46413e6dd09362d6fb39f98da2 100644 (file)
@@ -6,10 +6,11 @@ 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;
@@ -24,9 +25,12 @@ 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;
 
+/** Editor for an execution process. */
 public class ProcessEditor extends FormEditor implements
                ExecutionProcessNotifier, SlcTypes, SlcNames {
        public final static String ID = ClientUiPlugin.ID + ".processEditor";
@@ -96,7 +100,7 @@ public class ProcessEditor extends FormEditor implements
        }
 
        /** Actually runs the process. */
-       public void process() {
+       void process() {
                // the modifications have to be saved before execution
                try {
                        processNode.setProperty(SLC_STATUS, ExecutionProcess.SCHEDULED);
@@ -105,13 +109,66 @@ public class ProcessEditor extends FormEditor implements
                }
                doSave(null);
                try {
+                       // show log
+                       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);
                }
        }
 
@@ -121,7 +178,7 @@ public class ProcessEditor extends FormEditor implements
                        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);
@@ -160,7 +217,7 @@ public class ProcessEditor extends FormEditor implements
        }
 
        public void addSteps(ExecutionProcess process, List<ExecutionStep> steps) {
-               logPage.addSteps(steps);
+               // logPage.addSteps(steps);
        }
 
        /** Expects one session per editor. */