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
);
71 public boolean isDirty() {
72 if (getProcessStatus().equals(ExecutionProcess
.NEW
))
74 return super.isDirty();
77 protected String
getProcessStatus() {
79 return processNode
.getProperty(SLC_STATUS
).getString();
80 } catch (RepositoryException e
) {
81 throw new SlcException("Cannot retrieve status for " + processNode
,
87 public void dispose() {
88 JcrUtils
.logoutQuietly(session
);
91 /** Actually runs the process. */
92 public void process() {
93 // the modifications have to be saved before execution
95 processNode
.setProperty(SLC_STATUS
, ExecutionProcess
.SCHEDULED
);
96 } catch (RepositoryException e
) {
97 throw new SlcException("Cannot update status of " + processNode
, e
);
101 processController
.process(processNode
);
102 } catch (Exception e
) {
103 Error
.show("Execution of " + processNode
+ " failed", e
);
108 protected void addPages() {
110 builderPage
= new ProcessBuilderPage(this, processNode
);
111 addPage(builderPage
);
112 firePropertyChange(PROP_DIRTY
);
113 logPage
= new ProcessLogPage(this);
115 } catch (PartInitException e
) {
116 throw new SlcException("Cannot add pages", e
);
122 public void doSave(IProgressMonitor monitor
) {
124 String status
= processNode
.getProperty(SLC_STATUS
).getString();
125 if (status
.equals(ExecutionProcess
.NEW
))
126 processNode
.setProperty(SLC_STATUS
,
127 ExecutionProcess
.INITIALIZED
);
129 builderPage
.commit(true);
130 editorDirtyStateChanged();
131 } catch (RepositoryException e
) {
132 throw new SlcException("Cannot save " + processNode
, e
);
134 JcrUtils
.discardQuietly(session
);
139 public void doSaveAs() {
143 public boolean isSaveAsAllowed() {
147 /** Expects one session per editor. */
148 public void setSession(Session session
) {
149 this.session
= session
;
152 public void setProcessController(ProcessController processController
) {
153 this.processController
= processController
;