1 package org
.argeo
.slc
.akb
.ui
.commands
;
4 import javax
.jcr
.RepositoryException
;
5 import javax
.jcr
.Session
;
7 import org
.argeo
.jcr
.JcrUtils
;
8 import org
.argeo
.slc
.akb
.AkbException
;
9 import org
.argeo
.slc
.akb
.AkbService
;
10 import org
.argeo
.slc
.akb
.AkbTypes
;
11 import org
.argeo
.slc
.akb
.ui
.AkbUiPlugin
;
12 import org
.argeo
.slc
.akb
.ui
.dialogs
.AddItemDialog
;
13 import org
.argeo
.slc
.akb
.ui
.wizards
.CreateEnvInstanceWizard
;
14 import org
.eclipse
.core
.commands
.AbstractHandler
;
15 import org
.eclipse
.core
.commands
.ExecutionEvent
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.jface
.wizard
.WizardDialog
;
18 import org
.eclipse
.swt
.widgets
.Shell
;
19 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
22 * Opens corresponding wizard to create a new AKB Node
24 public class CreateAkbNode
extends AbstractHandler
{
25 public final static String ID
= AkbUiPlugin
.PLUGIN_ID
+ ".createAkbNode";
27 /* DEPENDENCY INJECTION */
28 private AkbService akbService
;
30 public final static String PARAM_PARENT_NODE_JCR_ID
= "param.parentNodeJcrId";
31 public final static String PARAM_NODE_TYPE
= "param.nodeType";
33 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
35 String parentNodeJcrId
= event
.getParameter(PARAM_PARENT_NODE_JCR_ID
);
36 String nodeType
= event
.getParameter(PARAM_NODE_TYPE
);
37 Session session
= null;
39 session
= akbService
.getRepository().login();
40 Node node
= createNewNode(HandlerUtil
.getActiveShell(event
),
41 session
, nodeType
, parentNodeJcrId
);
42 // no node has been created, return
45 } catch (RepositoryException e
) {
46 throw new AkbException("unexpected JCR error while opening "
47 + nodeType
+ " editor", e
);
49 JcrUtils
.logoutQuietly(session
);
54 private Node
createNewNode(Shell shell
, Session session
, String nodeType
,
55 String parentNodeJcrId
) throws RepositoryException
{
57 if (AkbTypes
.AKB_ITEM
.equals(nodeType
)) {
58 Node parNode
= session
.getNodeByIdentifier(parentNodeJcrId
);
59 AddItemDialog dialog
= new AddItemDialog(shell
, "Add new item",
62 node
= dialog
.getNewNode();
63 } else if (AkbTypes
.AKB_ENV
.equals(nodeType
)) {
64 CreateEnvInstanceWizard wizard
= new CreateEnvInstanceWizard(
66 WizardDialog dialog
= new WizardDialog(shell
, wizard
);
68 node
= wizard
.getCreatedNode();
72 // String name = SingleValue
75 // .getLabelForType(nodeSubtype == null ? nodeType
77 // "Please enter a name for the corresponding "
79 // .getLabelForType(nodeSubtype == null ? nodeType
83 // if (AkbTypes.AKB_ENV_TEMPLATE.equals(nodeType)) {
84 // node = akbService.createAkbTemplate(
85 // session.getNodeByIdentifier(parentNodeJcrId), name);
86 // } else if (AkbTypes.AKB_CONNECTOR_ALIAS.equals(nodeType)) {
87 // // the Jcr ID of the corresponding template must be passed to
88 // // create a new alias
89 // node = session.getNodeByIdentifier(parentNodeJcrId);
90 // akbService.createConnectorAlias(node, name, nodeSubtype);
92 // Node parentNode = session.getNodeByIdentifier(parentNodeJcrId);
93 // node = parentNode.addNode(name, nodeType);
94 // node.setProperty(Property.JCR_TITLE, name);
97 // corresponding node is saved but not checked in, in order to ease
103 public void setAkbService(AkbService akbService
) {
104 this.akbService
= akbService
;