1 package org
.argeo
.slc
.client
.ui
.editors
;
3 import java
.util
.HashMap
;
9 import javax
.jcr
.RepositoryException
;
10 import javax
.jcr
.Session
;
12 import org
.argeo
.eclipse
.ui
.Error
;
13 import org
.argeo
.jcr
.JcrUtils
;
14 import org
.argeo
.slc
.SlcException
;
15 import org
.argeo
.slc
.client
.ui
.ClientUiPlugin
;
16 import org
.argeo
.slc
.client
.ui
.controllers
.ProcessController
;
17 import org
.argeo
.slc
.execution
.ExecutionModulesManager
;
18 import org
.argeo
.slc
.execution
.ExecutionProcess
;
19 import org
.argeo
.slc
.execution
.ExecutionProcessNotifier
;
20 import org
.argeo
.slc
.execution
.ExecutionStep
;
21 import org
.argeo
.slc
.jcr
.SlcJcrUtils
;
22 import org
.argeo
.slc
.jcr
.SlcNames
;
23 import org
.argeo
.slc
.jcr
.SlcTypes
;
24 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
25 import org
.eclipse
.ui
.IEditorInput
;
26 import org
.eclipse
.ui
.IEditorSite
;
27 import org
.eclipse
.ui
.PartInitException
;
28 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
30 public class ProcessEditor
extends FormEditor
implements
31 ExecutionProcessNotifier
, SlcTypes
, SlcNames
{
32 public final static String ID
= ClientUiPlugin
.ID
+ ".processEditor";
34 private Session session
;
35 private Node processNode
;
36 private ProcessController processController
;
38 private ProcessBuilderPage builderPage
;
39 private ProcessLogPage logPage
;
41 private ExecutionModulesManager modulesManager
;
44 public void init(IEditorSite site
, IEditorInput input
)
45 throws PartInitException
{
46 super.init(site
, input
);
47 ProcessEditorInput pei
= (ProcessEditorInput
) input
;
48 String processPath
= pei
.getProcessPath();
50 if (processPath
!= null) {
51 if (!session
.itemExists(processPath
))
52 throw new SlcException("Process " + processPath
54 processNode
= session
.getNode(processPath
);
56 processNode
= newProcessNode(pei
);
58 setPartName(processNode
.getName());
59 } catch (RepositoryException e
) {
60 throw new SlcException("Cannot initialize editor for " + pei
, e
);
65 protected Node
newProcessNode(ProcessEditorInput pei
)
66 throws RepositoryException
{
67 String uuid
= UUID
.randomUUID().toString();
68 String processPath
= SlcJcrUtils
.createExecutionProcessPath(uuid
);
69 Node processNode
= JcrUtils
.mkdirs(session
, processPath
, SLC_PROCESS
);
70 processNode
.setProperty(SLC_UUID
, uuid
);
71 processNode
.setProperty(SLC_STATUS
, ExecutionProcess
.NEW
);
72 Node processFlow
= processNode
.addNode(SLC_FLOW
);
73 processFlow
.addMixin(SLC_REALIZED_FLOW
);
78 public boolean isDirty() {
79 if (getProcessStatus().equals(ExecutionProcess
.NEW
))
81 return super.isDirty();
84 protected String
getProcessStatus() {
86 return processNode
.getProperty(SLC_STATUS
).getString();
87 } catch (RepositoryException e
) {
88 throw new SlcException("Cannot retrieve status for " + processNode
,
94 public void dispose() {
95 JcrUtils
.logoutQuietly(session
);
98 /** Actually runs the process. */
99 public void process() {
100 // the modifications have to be saved before execution
102 processNode
.setProperty(SLC_STATUS
, ExecutionProcess
.SCHEDULED
);
103 } catch (RepositoryException e
) {
104 throw new SlcException("Cannot update status of " + processNode
, e
);
108 ExecutionProcess process
= processController
.process(processNode
);
109 Map
<String
, String
> properties
= new HashMap
<String
, String
>();
110 properties
.put(ExecutionModulesManager
.SLC_PROCESS_ID
,
112 modulesManager
.registerProcessNotifier(this, properties
);
113 } catch (Exception e
) {
114 Error
.show("Execution of " + processNode
+ " failed", e
);
119 protected void addPages() {
121 builderPage
= new ProcessBuilderPage(this, processNode
);
122 addPage(builderPage
);
123 firePropertyChange(PROP_DIRTY
);
124 logPage
= new ProcessLogPage(this);
126 } catch (PartInitException e
) {
127 throw new SlcException("Cannot add pages", e
);
133 public void doSave(IProgressMonitor monitor
) {
135 String status
= processNode
.getProperty(SLC_STATUS
).getString();
136 if (status
.equals(ExecutionProcess
.NEW
))
137 processNode
.setProperty(SLC_STATUS
,
138 ExecutionProcess
.INITIALIZED
);
140 builderPage
.commit(true);
141 editorDirtyStateChanged();
142 } catch (RepositoryException e
) {
143 throw new SlcException("Cannot save " + processNode
, e
);
145 JcrUtils
.discardQuietly(session
);
150 public void doSaveAs() {
154 public boolean isSaveAsAllowed() {
158 public void updateStatus(ExecutionProcess process
, String oldStatus
,
162 public void addSteps(ExecutionProcess process
, List
<ExecutionStep
> steps
) {
163 logPage
.addSteps(steps
);
166 /** Expects one session per editor. */
167 public void setSession(Session session
) {
168 this.session
= session
;
171 public void setProcessController(ProcessController processController
) {
172 this.processController
= processController
;
175 public void setModulesManager(ExecutionModulesManager modulesManager
) {
176 this.modulesManager
= modulesManager
;