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
.swt
.widgets
.Label
;
23 import org
.eclipse
.ui
.IEditorInput
;
24 import org
.eclipse
.ui
.IEditorSite
;
25 import org
.eclipse
.ui
.PartInitException
;
26 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
28 public class ProcessEditor
extends FormEditor
implements SlcTypes
, SlcNames
{
29 public final static String ID
= ClientUiPlugin
.ID
+ ".processEditor";
31 private Session session
;
32 private Node processNode
;
33 private ProcessController processController
;
35 private ProcessBuilderPage builderPage
;
36 private ProcessLogPage logPage
;
39 public void init(IEditorSite site
, IEditorInput input
)
40 throws PartInitException
{
41 super.init(site
, input
);
42 ProcessEditorInput pei
= (ProcessEditorInput
) input
;
43 String processPath
= pei
.getProcessPath();
45 if (processPath
!= null) {
46 if (!session
.itemExists(processPath
))
47 throw new SlcException("Process " + processPath
49 processNode
= session
.getNode(processPath
);
51 processNode
= newProcessNode(pei
);
53 setPartName(processNode
.getName());
54 } catch (RepositoryException e
) {
55 throw new SlcException("Cannot initialize editor for " + pei
, e
);
60 protected Node
newProcessNode(ProcessEditorInput pei
)
61 throws RepositoryException
{
62 Calendar now
= new GregorianCalendar();
63 String uuid
= UUID
.randomUUID().toString();
64 String processPath
= SlcJcrConstants
.PROCESSES_BASE_PATH
+ '/'
65 + JcrUtils
.dateAsPath(now
, true) + uuid
;
66 Node processNode
= JcrUtils
.mkdirs(session
, processPath
, SLC_PROCESS
);
67 processNode
.setProperty(SLC_UUID
, uuid
);
68 processNode
.setProperty(SLC_STATUS
, ExecutionProcess
.UNINITIALIZED
);
69 Node processFlow
= processNode
.addNode(SLC_FLOW
);
70 processFlow
.addMixin(SLC_REALIZED_FLOW
);
73 for (String path
: pei
.getInitialFlowPaths()) {
74 Node realizedFlow
= processFlow
.addNode(SLC_FLOW
);
75 realizedFlow
.addMixin(SLC_REALIZED_FLOW
);
76 Node address
= realizedFlow
.addNode(SLC_ADDRESS
,
78 address
.setProperty(Property
.JCR_PATH
, path
);
84 public void dispose() {
85 JcrUtils
.logoutQuietly(session
);
88 /** Actually runs the process. */
89 public void process() {
90 // the modifications have to be saved before execution
92 processNode
.setProperty(SLC_STATUS
, ExecutionProcess
.SCHEDULED
);
93 } catch (RepositoryException e
) {
94 throw new SlcException("Cannot update status of " + processNode
, e
);
97 processController
.process(processNode
);
101 protected void addPages() {
103 builderPage
= new ProcessBuilderPage(this, processNode
);
104 addPage(builderPage
);
105 firePropertyChange(PROP_DIRTY
);
106 logPage
= new ProcessLogPage(this);
108 } catch (PartInitException e
) {
109 throw new SlcException("Cannot add pages", e
);
115 public void doSave(IProgressMonitor monitor
) {
117 String status
= processNode
.getProperty(SLC_STATUS
).getString();
118 if (status
.equals(ExecutionProcess
.UNINITIALIZED
))
119 processNode
.setProperty(SLC_STATUS
,
120 ExecutionProcess
.INITIALIZED
);
122 builderPage
.commit(true);
123 firePropertyChange(PROP_DIRTY
);
124 } catch (RepositoryException e
) {
125 throw new SlcException("Cannot save " + processNode
, e
);
127 JcrUtils
.discardQuietly(session
);
132 public void doSaveAs() {
136 public boolean isSaveAsAllowed() {
140 /** Expects one session per editor. */
141 public void setSession(Session session
) {
142 this.session
= session
;
145 public void setProcessController(ProcessController processController
) {
146 this.processController
= processController
;