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
;
48 public void init(IEditorSite site
, IEditorInput input
)
49 throws PartInitException
{
50 super.init(site
, input
);
51 ProcessEditorInput pei
= (ProcessEditorInput
) input
;
52 String processPath
= pei
.getProcessPath();
54 if (processPath
!= null) {
55 if (!session
.itemExists(processPath
))
56 throw new SlcException("Process " + processPath
58 processNode
= session
.getNode(processPath
);
60 processNode
= newProcessNode(pei
);
62 setPartName(processNode
.getName());
63 } catch (RepositoryException e
) {
64 throw new SlcException("Cannot initialize editor for " + pei
, e
);
69 protected Node
newProcessNode(ProcessEditorInput pei
)
70 throws RepositoryException
{
71 String uuid
= UUID
.randomUUID().toString();
72 String processPath
= SlcJcrUtils
.createExecutionProcessPath(uuid
);
73 Node processNode
= JcrUtils
.mkdirs(session
, processPath
, SLC_PROCESS
);
74 processNode
.setProperty(SLC_UUID
, uuid
);
75 processNode
.setProperty(SLC_STATUS
, ExecutionProcess
.NEW
);
76 Node processFlow
= processNode
.addNode(SLC_FLOW
);
77 processFlow
.addMixin(SLC_REALIZED_FLOW
);
82 public boolean isDirty() {
83 if (getProcessStatus().equals(ExecutionProcess
.NEW
))
85 return super.isDirty();
88 protected String
getProcessStatus() {
90 return processNode
.getProperty(SLC_STATUS
).getString();
91 } catch (RepositoryException e
) {
92 throw new SlcException("Cannot retrieve status for " + processNode
,
98 public void dispose() {
99 JcrUtils
.logoutQuietly(session
);
102 /** Actually runs the process. */
104 // the modifications have to be saved before execution
106 processNode
.setProperty(SLC_STATUS
, ExecutionProcess
.SCHEDULED
);
107 } catch (RepositoryException e
) {
108 throw new SlcException("Cannot update status of " + processNode
, e
);
113 setActivePage(logPage
.getId());
115 ExecutionProcess process
= processController
.process(processNode
);
116 Map
<String
, String
> properties
= new HashMap
<String
, String
>();
117 properties
.put(ExecutionModulesManager
.SLC_PROCESS_ID
,
119 modulesManager
.registerProcessNotifier(this, properties
);
120 } catch (Exception e
) {
121 ErrorFeedback
.show("Execution of " + processNode
+ " failed", e
);
126 processController
.kill(processNode
);
129 /** Opens a new editor with a copy of this process */
132 Node duplicatedNode
= duplicateProcess();
133 IWorkbenchPage activePage
= PlatformUI
.getWorkbench()
134 .getActiveWorkbenchWindow().getActivePage();
135 activePage
.openEditor(
136 new ProcessEditorInput(duplicatedNode
.getPath()),
139 } catch (Exception e1
) {
140 throw new SlcException("Cannot relaunch " + processNode
, e1
);
144 /** Duplicates the process */
145 protected Node
duplicateProcess() {
147 Session session
= processNode
.getSession();
148 String uuid
= UUID
.randomUUID().toString();
149 String destPath
= SlcJcrUtils
.createExecutionProcessPath(uuid
);
150 Node newNode
= JcrUtils
.mkdirs(session
, destPath
,
151 SlcTypes
.SLC_PROCESS
);
153 Node rootRealizedFlowNode
= newNode
.addNode(SLC_FLOW
);
155 JcrUtils
.copy(processNode
.getNode(SLC_FLOW
), rootRealizedFlowNode
);
157 newNode
.setProperty(SLC_UUID
, uuid
);
158 newNode
.setProperty(SLC_STATUS
, ExecutionProcess
.INITIALIZED
);
160 // reset realized flow status
161 // we just manage one level for the time being
162 NodeIterator nit
= rootRealizedFlowNode
.getNodes(SLC_FLOW
);
163 while (nit
.hasNext()) {
164 nit
.nextNode().setProperty(SLC_STATUS
,
165 ExecutionProcess
.INITIALIZED
);
170 } catch (RepositoryException e
) {
171 throw new SlcException("Cannot duplicate process", e
);
176 protected void addPages() {
178 builderPage
= new ProcessBuilderPage(this, processNode
);
179 addPage(builderPage
);
180 firePropertyChange(PROP_DIRTY
);
181 logPage
= new ProcessLogPage(this, processNode
);
183 } catch (PartInitException e
) {
184 throw new SlcException("Cannot add pages", e
);
190 public void doSave(IProgressMonitor monitor
) {
192 String status
= processNode
.getProperty(SLC_STATUS
).getString();
193 if (status
.equals(ExecutionProcess
.NEW
))
194 processNode
.setProperty(SLC_STATUS
,
195 ExecutionProcess
.INITIALIZED
);
197 builderPage
.commit(true);
198 editorDirtyStateChanged();
199 } catch (RepositoryException e
) {
200 throw new SlcException("Cannot save " + processNode
, e
);
202 JcrUtils
.discardQuietly(session
);
207 public void doSaveAs() {
211 public boolean isSaveAsAllowed() {
215 public void updateStatus(ExecutionProcess process
, String oldStatus
,
219 public void addSteps(ExecutionProcess process
, List
<ExecutionStep
> steps
) {
220 // logPage.addSteps(steps);
223 /** Expects one session per editor. */
224 public void setSession(Session session
) {
225 this.session
= session
;
228 public void setProcessController(ProcessController processController
) {
229 this.processController
= processController
;
232 public void setModulesManager(ExecutionModulesManager modulesManager
) {
233 this.modulesManager
= modulesManager
;