1 package org
.argeo
.slc
.client
.ui
.editors
;
3 import java
.util
.Calendar
;
4 import java
.util
.GregorianCalendar
;
8 import javax
.jcr
.Property
;
9 import javax
.jcr
.RepositoryException
;
10 import javax
.jcr
.Session
;
11 import javax
.jcr
.nodetype
.NodeType
;
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
.ExecutionProcess
;
18 import org
.argeo
.slc
.jcr
.SlcJcrConstants
;
19 import org
.argeo
.slc
.jcr
.SlcNames
;
20 import org
.argeo
.slc
.jcr
.SlcTypes
;
21 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
22 import org
.eclipse
.ui
.IEditorInput
;
23 import org
.eclipse
.ui
.IEditorSite
;
24 import org
.eclipse
.ui
.PartInitException
;
25 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
27 public class ProcessEditor
extends FormEditor
implements SlcTypes
, SlcNames
{
28 public final static String ID
= ClientUiPlugin
.ID
+ ".processEditor";
30 private Session session
;
31 private Node processNode
;
32 private ProcessController processController
;
34 private ProcessBuilderPage builderPage
;
35 private ProcessLogPage logPage
;
38 public void init(IEditorSite site
, IEditorInput input
)
39 throws PartInitException
{
40 super.init(site
, input
);
41 ProcessEditorInput pei
= (ProcessEditorInput
) input
;
42 String processPath
= pei
.getProcessPath();
44 if (processPath
!= null) {
45 if (!session
.itemExists(processPath
))
46 throw new SlcException("Process " + processPath
48 processNode
= session
.getNode(processPath
);
50 processNode
= newProcessNode(pei
);
52 setPartName(processNode
.getName());
53 } catch (RepositoryException e
) {
54 throw new SlcException("Cannot initialize editor for " + pei
, e
);
59 protected Node
newProcessNode(ProcessEditorInput pei
)
60 throws RepositoryException
{
61 Calendar now
= new GregorianCalendar();
62 String uuid
= UUID
.randomUUID().toString();
63 String processPath
= SlcJcrConstants
.PROCESSES_BASE_PATH
+ '/'
64 + JcrUtils
.dateAsPath(now
, true) + uuid
;
65 Node processNode
= JcrUtils
.mkdirs(session
, processPath
, SLC_PROCESS
);
66 processNode
.setProperty(SLC_UUID
, uuid
);
67 processNode
.setProperty(SLC_STATUS
, ExecutionProcess
.UNINITIALIZED
);
68 Node processFlow
= processNode
.addNode(SLC_FLOW
);
69 processFlow
.addMixin(SLC_REALIZED_FLOW
);
72 for (String path
: pei
.getInitialFlowPaths()) {
73 Node realizedFlow
= processFlow
.addNode(SLC_FLOW
);
74 realizedFlow
.addMixin(SLC_REALIZED_FLOW
);
75 Node address
= realizedFlow
.addNode(SLC_ADDRESS
,
77 address
.setProperty(Property
.JCR_PATH
, path
);
83 public void dispose() {
84 JcrUtils
.logoutQuietly(session
);
87 /** Actually runs the process. */
88 public void process() {
89 // the modifications have to be saved before execution
91 processNode
.setProperty(SLC_STATUS
, ExecutionProcess
.SCHEDULED
);
92 } catch (RepositoryException e
) {
93 throw new SlcException("Cannot update status of " + processNode
, e
);
96 processController
.process(processNode
);
100 protected void addPages() {
102 builderPage
= new ProcessBuilderPage(this, processNode
);
103 addPage(builderPage
);
104 firePropertyChange(PROP_DIRTY
);
105 logPage
= new ProcessLogPage(this);
107 } catch (PartInitException e
) {
108 throw new SlcException("Cannot add pages", e
);
114 public void doSave(IProgressMonitor monitor
) {
116 String status
= processNode
.getProperty(SLC_STATUS
).getString();
117 if (status
.equals(ExecutionProcess
.UNINITIALIZED
))
118 processNode
.setProperty(SLC_STATUS
,
119 ExecutionProcess
.INITIALIZED
);
121 builderPage
.commit(true);
122 firePropertyChange(PROP_DIRTY
);
123 } catch (RepositoryException e
) {
124 throw new SlcException("Cannot save " + processNode
, e
);
126 JcrUtils
.discardQuietly(session
);
131 public void doSaveAs() {
135 public boolean isSaveAsAllowed() {
139 /** Expects one session per editor. */
140 public void setSession(Session session
) {
141 this.session
= session
;
144 public void setProcessController(ProcessController processController
) {
145 this.processController
= processController
;