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=027e7c626516ce627a17045ed98b22419caa39b3;hb=8908d07cc1fd6ac0a274c460bbd40652816ca054;hp=b00b41298f3b545f290307beb4488ad7fcb8f06f;hpb=0e2ff188c2e8ffac85739cccc3925e8bd82d7be9;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 b00b41298..027e7c626 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,3 +1,18 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.argeo.slc.client.ui.editors; import java.util.HashMap; @@ -6,10 +21,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 +40,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"; @@ -36,10 +55,12 @@ public class ProcessEditor extends FormEditor implements private ProcessController processController; private ProcessBuilderPage builderPage; - private ProcessLogPage logPage; + //private ProcessLogPage logPage; private ExecutionModulesManager modulesManager; + //private Boolean switchToLog = false; + @Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { @@ -96,7 +117,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 +126,67 @@ public class ProcessEditor extends FormEditor implements } doSave(null); try { + // show log +// if (switchToLog) +// setActivePage(logPage.getId()); + 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); + 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,8 +196,8 @@ public class ProcessEditor extends FormEditor implements builderPage = new ProcessBuilderPage(this, processNode); addPage(builderPage); firePropertyChange(PROP_DIRTY); - logPage = new ProcessLogPage(this); - addPage(logPage); +// logPage = new ProcessLogPage(this, processNode); +// addPage(logPage); } catch (PartInitException e) { throw new SlcException("Cannot add pages", e); } @@ -160,7 +235,7 @@ public class ProcessEditor extends FormEditor implements } public void addSteps(ExecutionProcess process, List steps) { - logPage.addSteps(steps); + // logPage.addSteps(steps); } /** Expects one session per editor. */