1 package org
.argeo
.slc
.client
.ui
.editors
;
6 import javax
.jcr
.Property
;
7 import javax
.jcr
.RepositoryException
;
8 import javax
.jcr
.Session
;
9 import javax
.jcr
.nodetype
.NodeType
;
11 import org
.argeo
.eclipse
.ui
.Error
;
12 import org
.argeo
.jcr
.JcrUtils
;
13 import org
.argeo
.slc
.SlcException
;
14 import org
.argeo
.slc
.client
.ui
.ClientUiPlugin
;
15 import org
.argeo
.slc
.client
.ui
.controllers
.ProcessController
;
16 import org
.argeo
.slc
.execution
.ExecutionProcess
;
17 import org
.argeo
.slc
.jcr
.SlcJcrUtils
;
18 import org
.argeo
.slc
.jcr
.SlcNames
;
19 import org
.argeo
.slc
.jcr
.SlcTypes
;
20 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
21 import org
.eclipse
.ui
.IEditorInput
;
22 import org
.eclipse
.ui
.IEditorSite
;
23 import org
.eclipse
.ui
.PartInitException
;
24 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
26 public class ProcessEditor
extends FormEditor
implements SlcTypes
, SlcNames
{
27 public final static String ID
= ClientUiPlugin
.ID
+ ".processEditor";
29 private Session session
;
30 private Node processNode
;
31 private ProcessController processController
;
33 private ProcessBuilderPage builderPage
;
34 private ProcessLogPage logPage
;
37 public void init(IEditorSite site
, IEditorInput input
)
38 throws PartInitException
{
39 super.init(site
, input
);
40 ProcessEditorInput pei
= (ProcessEditorInput
) input
;
41 String processPath
= pei
.getProcessPath();
43 if (processPath
!= null) {
44 if (!session
.itemExists(processPath
))
45 throw new SlcException("Process " + processPath
47 processNode
= session
.getNode(processPath
);
49 processNode
= newProcessNode(pei
);
51 setPartName(processNode
.getName());
52 } catch (RepositoryException e
) {
53 throw new SlcException("Cannot initialize editor for " + pei
, e
);
58 protected Node
newProcessNode(ProcessEditorInput pei
)
59 throws RepositoryException
{
60 String uuid
= UUID
.randomUUID().toString();
61 String processPath
= SlcJcrUtils
.createExecutionProcessPath(uuid
);
62 Node processNode
= JcrUtils
.mkdirs(session
, processPath
, SLC_PROCESS
);
63 processNode
.setProperty(SLC_UUID
, uuid
);
64 processNode
.setProperty(SLC_STATUS
, ExecutionProcess
.NEW
);
65 Node processFlow
= processNode
.addNode(SLC_FLOW
);
66 processFlow
.addMixin(SLC_REALIZED_FLOW
);
69 for (String path
: pei
.getInitialFlowPaths()) {
70 Node realizedFlow
= processFlow
.addNode(SLC_FLOW
);
71 realizedFlow
.addMixin(SLC_REALIZED_FLOW
);
72 Node address
= realizedFlow
.addNode(SLC_ADDRESS
,
74 address
.setProperty(Property
.JCR_PATH
, path
);
80 public boolean isDirty() {
81 if (getProcessStatus().equals(ExecutionProcess
.NEW
))
83 return super.isDirty();
86 protected String
getProcessStatus() {
88 return processNode
.getProperty(SLC_STATUS
).getString();
89 } catch (RepositoryException e
) {
90 throw new SlcException("Cannot retrieve status for " + processNode
,
96 public void dispose() {
97 JcrUtils
.logoutQuietly(session
);
100 /** Actually runs the process. */
101 public void process() {
102 // the modifications have to be saved before execution
104 processNode
.setProperty(SLC_STATUS
, ExecutionProcess
.SCHEDULED
);
105 } catch (RepositoryException e
) {
106 throw new SlcException("Cannot update status of " + processNode
, e
);
110 processController
.process(processNode
);
111 } catch (Exception e
) {
112 Error
.show("Execution of " + processNode
+ " failed", e
);
117 protected void addPages() {
119 builderPage
= new ProcessBuilderPage(this, processNode
);
120 addPage(builderPage
);
121 firePropertyChange(PROP_DIRTY
);
122 logPage
= new ProcessLogPage(this);
124 } catch (PartInitException e
) {
125 throw new SlcException("Cannot add pages", e
);
131 public void doSave(IProgressMonitor monitor
) {
133 String status
= processNode
.getProperty(SLC_STATUS
).getString();
134 if (status
.equals(ExecutionProcess
.NEW
))
135 processNode
.setProperty(SLC_STATUS
,
136 ExecutionProcess
.INITIALIZED
);
138 builderPage
.commit(true);
139 editorDirtyStateChanged();
140 } catch (RepositoryException e
) {
141 throw new SlcException("Cannot save " + processNode
, e
);
143 JcrUtils
.discardQuietly(session
);
148 public void doSaveAs() {
152 public boolean isSaveAsAllowed() {
156 /** Expects one session per editor. */
157 public void setSession(Session session
) {
158 this.session
= session
;
161 public void setProcessController(ProcessController processController
) {
162 this.processController
= processController
;