1 package org
.argeo
.slc
.client
.ui
.editors
;
3 import java
.util
.HashMap
;
9 import javax
.jcr
.NodeIterator
;
10 import javax
.jcr
.RepositoryException
;
11 import javax
.jcr
.Session
;
13 import org
.argeo
.eclipse
.ui
.ErrorFeedback
;
14 import org
.argeo
.jcr
.JcrUtils
;
15 import org
.argeo
.slc
.SlcException
;
16 import org
.argeo
.slc
.client
.ui
.ClientUiPlugin
;
17 import org
.argeo
.slc
.client
.ui
.controllers
.ProcessController
;
18 import org
.argeo
.slc
.execution
.ExecutionModulesManager
;
19 import org
.argeo
.slc
.execution
.ExecutionProcess
;
20 import org
.argeo
.slc
.execution
.ExecutionProcessNotifier
;
21 import org
.argeo
.slc
.execution
.ExecutionStep
;
22 import org
.argeo
.slc
.jcr
.SlcJcrUtils
;
23 import org
.argeo
.slc
.jcr
.SlcNames
;
24 import org
.argeo
.slc
.jcr
.SlcTypes
;
25 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
26 import org
.eclipse
.ui
.IEditorInput
;
27 import org
.eclipse
.ui
.IEditorSite
;
28 import org
.eclipse
.ui
.IWorkbenchPage
;
29 import org
.eclipse
.ui
.PartInitException
;
30 import org
.eclipse
.ui
.PlatformUI
;
31 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
33 /** Editor for an execution process. */
34 public class ProcessEditor
extends FormEditor
implements
35 ExecutionProcessNotifier
, SlcTypes
, SlcNames
{
36 public final static String ID
= ClientUiPlugin
.ID
+ ".processEditor";
38 private Session session
;
39 private Node processNode
;
40 private ProcessController processController
;
42 private ProcessBuilderPage builderPage
;
43 private ProcessLogPage logPage
;
45 private ExecutionModulesManager modulesManager
;
47 private Boolean switchToLog
= false;
50 public void init(IEditorSite site
, IEditorInput input
)
51 throws PartInitException
{
52 super.init(site
, input
);
53 ProcessEditorInput pei
= (ProcessEditorInput
) input
;
54 String processPath
= pei
.getProcessPath();
56 if (processPath
!= null) {
57 if (!session
.itemExists(processPath
))
58 throw new SlcException("Process " + processPath
60 processNode
= session
.getNode(processPath
);
62 processNode
= newProcessNode(pei
);
64 setPartName(processNode
.getName());
65 } catch (RepositoryException e
) {
66 throw new SlcException("Cannot initialize editor for " + pei
, e
);
71 protected Node
newProcessNode(ProcessEditorInput pei
)
72 throws RepositoryException
{
73 String uuid
= UUID
.randomUUID().toString();
74 String processPath
= SlcJcrUtils
.createExecutionProcessPath(uuid
);
75 Node processNode
= JcrUtils
.mkdirs(session
, processPath
, SLC_PROCESS
);
76 processNode
.setProperty(SLC_UUID
, uuid
);
77 processNode
.setProperty(SLC_STATUS
, ExecutionProcess
.NEW
);
78 Node processFlow
= processNode
.addNode(SLC_FLOW
);
79 processFlow
.addMixin(SLC_REALIZED_FLOW
);
84 public boolean isDirty() {
85 if (getProcessStatus().equals(ExecutionProcess
.NEW
))
87 return super.isDirty();
90 protected String
getProcessStatus() {
92 return processNode
.getProperty(SLC_STATUS
).getString();
93 } catch (RepositoryException e
) {
94 throw new SlcException("Cannot retrieve status for " + processNode
,
100 public void dispose() {
101 JcrUtils
.logoutQuietly(session
);
104 /** Actually runs the process. */
106 // the modifications have to be saved before execution
108 processNode
.setProperty(SLC_STATUS
, ExecutionProcess
.SCHEDULED
);
109 } catch (RepositoryException e
) {
110 throw new SlcException("Cannot update status of " + processNode
, e
);
116 setActivePage(logPage
.getId());
118 ExecutionProcess process
= processController
.process(processNode
);
119 Map
<String
, String
> properties
= new HashMap
<String
, String
>();
120 properties
.put(ExecutionModulesManager
.SLC_PROCESS_ID
,
122 modulesManager
.registerProcessNotifier(this, properties
);
123 } catch (Exception e
) {
124 ErrorFeedback
.show("Execution of " + processNode
+ " failed", e
);
129 processController
.kill(processNode
);
132 /** Opens a new editor with a copy of this process */
135 Node duplicatedNode
= duplicateProcess();
136 IWorkbenchPage activePage
= PlatformUI
.getWorkbench()
137 .getActiveWorkbenchWindow().getActivePage();
138 activePage
.openEditor(
139 new ProcessEditorInput(duplicatedNode
.getPath()),
142 } catch (Exception e1
) {
143 throw new SlcException("Cannot relaunch " + processNode
, e1
);
147 /** Duplicates the process */
148 protected Node
duplicateProcess() {
150 Session session
= processNode
.getSession();
151 String uuid
= UUID
.randomUUID().toString();
152 String destPath
= SlcJcrUtils
.createExecutionProcessPath(uuid
);
153 Node newNode
= JcrUtils
.mkdirs(session
, destPath
,
154 SlcTypes
.SLC_PROCESS
);
156 Node rootRealizedFlowNode
= newNode
.addNode(SLC_FLOW
);
158 JcrUtils
.copy(processNode
.getNode(SLC_FLOW
), rootRealizedFlowNode
);
160 newNode
.setProperty(SLC_UUID
, uuid
);
161 newNode
.setProperty(SLC_STATUS
, ExecutionProcess
.INITIALIZED
);
163 // reset realized flow status
164 // we just manage one level for the time being
165 NodeIterator nit
= rootRealizedFlowNode
.getNodes(SLC_FLOW
);
166 while (nit
.hasNext()) {
167 nit
.nextNode().setProperty(SLC_STATUS
,
168 ExecutionProcess
.INITIALIZED
);
173 } catch (RepositoryException e
) {
174 throw new SlcException("Cannot duplicate process", e
);
179 protected void addPages() {
181 builderPage
= new ProcessBuilderPage(this, processNode
);
182 addPage(builderPage
);
183 firePropertyChange(PROP_DIRTY
);
184 logPage
= new ProcessLogPage(this, processNode
);
186 } catch (PartInitException e
) {
187 throw new SlcException("Cannot add pages", e
);
193 public void doSave(IProgressMonitor monitor
) {
195 String status
= processNode
.getProperty(SLC_STATUS
).getString();
196 if (status
.equals(ExecutionProcess
.NEW
))
197 processNode
.setProperty(SLC_STATUS
,
198 ExecutionProcess
.INITIALIZED
);
200 builderPage
.commit(true);
201 editorDirtyStateChanged();
202 } catch (RepositoryException e
) {
203 throw new SlcException("Cannot save " + processNode
, e
);
205 JcrUtils
.discardQuietly(session
);
210 public void doSaveAs() {
214 public boolean isSaveAsAllowed() {
218 public void updateStatus(ExecutionProcess process
, String oldStatus
,
222 public void addSteps(ExecutionProcess process
, List
<ExecutionStep
> steps
) {
223 // logPage.addSteps(steps);
226 /** Expects one session per editor. */
227 public void setSession(Session session
) {
228 this.session
= session
;
231 public void setProcessController(ProcessController processController
) {
232 this.processController
= processController
;
235 public void setModulesManager(ExecutionModulesManager modulesManager
) {
236 this.modulesManager
= modulesManager
;