1 package org
.argeo
.slc
.akb
.ui
.commands
;
4 import javax
.jcr
.Property
;
5 import javax
.jcr
.Repository
;
6 import javax
.jcr
.RepositoryException
;
7 import javax
.jcr
.Session
;
9 import org
.argeo
.eclipse
.ui
.dialogs
.SingleValue
;
10 import org
.argeo
.jcr
.JcrUtils
;
11 import org
.argeo
.slc
.akb
.AkbException
;
12 import org
.argeo
.slc
.akb
.AkbService
;
13 import org
.argeo
.slc
.akb
.AkbTypes
;
14 import org
.argeo
.slc
.akb
.ui
.AkbUiPlugin
;
15 import org
.argeo
.slc
.akb
.ui
.editors
.AkbConnectorAliasEditor
;
16 import org
.argeo
.slc
.akb
.ui
.editors
.AkbEnvTemplateEditor
;
17 import org
.argeo
.slc
.akb
.ui
.editors
.AkbNodeEditorInput
;
18 import org
.eclipse
.core
.commands
.AbstractHandler
;
19 import org
.eclipse
.core
.commands
.ExecutionEvent
;
20 import org
.eclipse
.core
.commands
.ExecutionException
;
21 import org
.eclipse
.ui
.IWorkbenchPage
;
22 import org
.eclipse
.ui
.PartInitException
;
23 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
26 * Opens or show an AKB specific node in a single repository / single workspace
27 * environment given some parameters, namely :
29 * <li>PARAM_NODE_JCR_ID: the corresponding JCR ID might be null to create a new
31 * <li>PARAM_NODE_TYPE: jcr type of the node to create</li>
32 * <li>PARAM_PARENT_NODE_JCR_ID: Only used in the case of the creation of a new
36 public class OpenAkbNodeEditor
extends AbstractHandler
{
37 public final static String ID
= AkbUiPlugin
.PLUGIN_ID
38 + ".openAkbNodeEditor";
40 /* DEPENDENCY INJECTION */
41 private Repository repository
;
42 private AkbService akbService
;
44 public final static String PARAM_NODE_JCR_ID
= "param.nodeJcrId";
45 public final static String PARAM_NODE_TYPE
= "param.nodeType";
46 public final static String PARAM_PARENT_NODE_JCR_ID
= "param.parentNodeJcrId";
48 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
50 String nodeType
= event
.getParameter(PARAM_NODE_TYPE
);
51 String nodeJcrId
= event
.getParameter(PARAM_NODE_JCR_ID
);
52 String parentNodeJcrId
= event
.getParameter(PARAM_PARENT_NODE_JCR_ID
);
54 Session session
= null;
56 // caches current Page
57 IWorkbenchPage currentPage
= HandlerUtil
.getActiveWorkbenchWindow(
58 event
).getActivePage();
60 session
= repository
.login();
63 if (nodeJcrId
== null)
64 if (parentNodeJcrId
== null)
65 throw new AkbException(
66 "Define a parent node to create a new node");
68 node
= createNewNode(session
, nodeType
, parentNodeJcrId
);
70 node
= session
.getNodeByIdentifier(nodeJcrId
);
72 // no node has been found or created, return
76 String editorId
= getEditorForNode(node
);
78 // no editor has been found, return silently
82 AkbNodeEditorInput eei
= new AkbNodeEditorInput(
83 node
.getIdentifier());
85 currentPage
.openEditor(eei
, editorId
);
86 } catch (PartInitException pie
) {
87 throw new AkbException(
88 "Unexpected PartInitException while opening akb node editor",
90 } catch (RepositoryException e
) {
91 throw new AkbException("unexpected JCR error while opening "
92 + nodeType
+ " editor", e
);
94 JcrUtils
.logoutQuietly(session
);
99 private Node
createNewNode(Session session
, String nodeType
,
100 String parentNodeJcrId
) throws RepositoryException
{
102 String name
= SingleValue
.ask("New name", "Create AKB item");
106 if (AkbTypes
.AKB_ENV_TEMPLATE
.equals(nodeType
)) {
107 node
= akbService
.createAkbTemplate(
108 session
.getNodeByIdentifier(parentNodeJcrId
), name
);
110 Node parentNode
= session
.getNodeByIdentifier(parentNodeJcrId
);
111 node
= parentNode
.addNode(name
, nodeType
);
112 node
.setProperty(Property
.JCR_TITLE
, name
);
114 // corresponding node is saved but not checked in, in order to ease
120 private String
getEditorForNode(Node node
) throws RepositoryException
{
121 String editorId
= null;
122 if (node
.isNodeType(AkbTypes
.AKB_CONNECTOR_ALIAS
))
123 editorId
= AkbConnectorAliasEditor
.ID
;
124 else if (node
.isNodeType(AkbTypes
.AKB_ENV_TEMPLATE
))
125 editorId
= AkbEnvTemplateEditor
.ID
;
127 // throw new AkbException("Editor is undefined for node " + node);
131 /* DEPENDENCY INJECTION */
132 public void setRepository(Repository repository
) {
133 this.repository
= repository
;
136 public void setAkbService(AkbService akbService
) {
137 this.akbService
= akbService
;