1 package org
.argeo
.slc
.client
.ui
.editors
;
6 import javax
.jcr
.RepositoryException
;
7 import javax
.jcr
.Session
;
9 import org
.argeo
.eclipse
.ui
.Error
;
10 import org
.argeo
.jcr
.JcrUtils
;
11 import org
.argeo
.slc
.SlcException
;
12 import org
.argeo
.slc
.client
.ui
.ClientUiPlugin
;
13 import org
.argeo
.slc
.client
.ui
.controllers
.ProcessController
;
14 import org
.argeo
.slc
.execution
.ExecutionProcess
;
15 import org
.argeo
.slc
.jcr
.SlcJcrUtils
;
16 import org
.argeo
.slc
.jcr
.SlcNames
;
17 import org
.argeo
.slc
.jcr
.SlcTypes
;
18 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
19 import org
.eclipse
.ui
.IEditorInput
;
20 import org
.eclipse
.ui
.IEditorSite
;
21 import org
.eclipse
.ui
.PartInitException
;
22 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
24 public class ProcessEditor
extends FormEditor
implements SlcTypes
, SlcNames
{
25 public final static String ID
= ClientUiPlugin
.ID
+ ".processEditor";
27 private Session session
;
28 private Node processNode
;
29 private ProcessController processController
;
31 private ProcessBuilderPage builderPage
;
32 private ProcessLogPage logPage
;
35 public void init(IEditorSite site
, IEditorInput input
)
36 throws PartInitException
{
37 super.init(site
, input
);
38 ProcessEditorInput pei
= (ProcessEditorInput
) input
;
39 String processPath
= pei
.getProcessPath();
41 if (processPath
!= null) {
42 if (!session
.itemExists(processPath
))
43 throw new SlcException("Process " + processPath
45 processNode
= session
.getNode(processPath
);
47 processNode
= newProcessNode(pei
);
49 setPartName(processNode
.getName());
50 } catch (RepositoryException e
) {
51 throw new SlcException("Cannot initialize editor for " + pei
, e
);
56 protected Node
newProcessNode(ProcessEditorInput pei
)
57 throws RepositoryException
{
58 String uuid
= UUID
.randomUUID().toString();
59 String processPath
= SlcJcrUtils
.createExecutionProcessPath(uuid
);
60 Node processNode
= JcrUtils
.mkdirs(session
, processPath
, SLC_PROCESS
);
61 processNode
.setProperty(SLC_UUID
, uuid
);
62 processNode
.setProperty(SLC_STATUS
, ExecutionProcess
.NEW
);
63 Node processFlow
= processNode
.addNode(SLC_FLOW
);
64 processFlow
.addMixin(SLC_REALIZED_FLOW
);
69 public boolean isDirty() {
70 if (getProcessStatus().equals(ExecutionProcess
.NEW
))
72 return super.isDirty();
75 protected String
getProcessStatus() {
77 return processNode
.getProperty(SLC_STATUS
).getString();
78 } catch (RepositoryException e
) {
79 throw new SlcException("Cannot retrieve status for " + processNode
,
85 public void dispose() {
86 JcrUtils
.logoutQuietly(session
);
89 /** Actually runs the process. */
90 public void process() {
91 // the modifications have to be saved before execution
93 processNode
.setProperty(SLC_STATUS
, ExecutionProcess
.SCHEDULED
);
94 } catch (RepositoryException e
) {
95 throw new SlcException("Cannot update status of " + processNode
, e
);
99 processController
.process(processNode
);
100 } catch (Exception e
) {
101 Error
.show("Execution of " + processNode
+ " failed", e
);
106 protected void addPages() {
108 builderPage
= new ProcessBuilderPage(this, processNode
);
109 addPage(builderPage
);
110 firePropertyChange(PROP_DIRTY
);
111 logPage
= new ProcessLogPage(this);
113 } catch (PartInitException e
) {
114 throw new SlcException("Cannot add pages", e
);
120 public void doSave(IProgressMonitor monitor
) {
122 String status
= processNode
.getProperty(SLC_STATUS
).getString();
123 if (status
.equals(ExecutionProcess
.NEW
))
124 processNode
.setProperty(SLC_STATUS
,
125 ExecutionProcess
.INITIALIZED
);
127 builderPage
.commit(true);
128 editorDirtyStateChanged();
129 } catch (RepositoryException e
) {
130 throw new SlcException("Cannot save " + processNode
, e
);
132 JcrUtils
.discardQuietly(session
);
137 public void doSaveAs() {
141 public boolean isSaveAsAllowed() {
145 /** Expects one session per editor. */
146 public void setSession(Session session
) {
147 this.session
= session
;
150 public void setProcessController(ProcessController processController
) {
151 this.processController
= processController
;