package org.argeo.slc.akb.ui.commands;
import javax.jcr.Node;
+import javax.jcr.Property;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import org.argeo.eclipse.ui.dialogs.SingleValue;
import org.argeo.jcr.JcrUtils;
import org.argeo.slc.akb.AkbException;
+import org.argeo.slc.akb.AkbService;
import org.argeo.slc.akb.AkbTypes;
import org.argeo.slc.akb.ui.AkbUiPlugin;
-import org.argeo.slc.akb.ui.editors.AkbConnectorAliasEditor;
-import org.argeo.slc.akb.ui.editors.AkbEnvTemplateEditor;
+import org.argeo.slc.akb.ui.dialogs.AddItemDialog;
import org.argeo.slc.akb.ui.editors.AkbNodeEditorInput;
+import org.argeo.slc.akb.ui.editors.ConnectorAliasEditor;
+import org.argeo.slc.akb.ui.editors.EnvTemplateEditor;
+import org.argeo.slc.akb.ui.editors.JdbcQueryTemplateEditor;
+import org.argeo.slc.akb.ui.editors.SshCommandTemplateEditor;
+import org.argeo.slc.akb.ui.editors.SshFileTemplateEditor;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
/* DEPENDENCY INJECTION */
private Repository repository;
+ private AkbService akbService;
public final static String PARAM_NODE_JCR_ID = "param.nodeJcrId";
public final static String PARAM_NODE_TYPE = "param.nodeType";
Session session = null;
try {
+ // caches current Page
+ IWorkbenchPage currentPage = HandlerUtil.getActiveWorkbenchWindow(
+ event).getActivePage();
+
session = repository.login();
Node node = null;
else
node = session.getNodeByIdentifier(nodeJcrId);
+ // no node has been found or created, return
+ if (node == null)
+ return null;
+
String editorId = getEditorForNode(node);
+ // no editor has been found, return silently
+ if (editorId == null)
+ return null;
+
AkbNodeEditorInput eei = new AkbNodeEditorInput(
node.getIdentifier());
- HandlerUtil.getActiveWorkbenchWindow(event).getActivePage()
- .openEditor(eei, editorId);
+ currentPage.openEditor(eei, editorId);
} catch (PartInitException pie) {
throw new AkbException(
"Unexpected PartInitException while opening akb node editor",
private Node createNewNode(Session session, String nodeType,
String parentNodeJcrId) throws RepositoryException {
- Node parentNode = session.getNodeByIdentifier(parentNodeJcrId);
- Node node = parentNode.addNode("new", nodeType);
+ Node node = null;
+
+ if (AkbTypes.AKB_ITEM.equals(nodeType)) {
+ Node parNode = session.getNodeByIdentifier(parentNodeJcrId);
+ AddItemDialog dialog = new AddItemDialog(Display.getDefault()
+ .getActiveShell(), "Add new item", parNode);
+ dialog.open();
+ node = dialog.getNewNode();
+ } else {
+ String name = SingleValue.ask("New name", "Create AKB item");
+ if (name == null)
+ return null;
+ if (AkbTypes.AKB_ENV_TEMPLATE.equals(nodeType)) {
+ node = akbService.createAkbTemplate(
+ session.getNodeByIdentifier(parentNodeJcrId), name);
+ } else {
+ Node parentNode = session.getNodeByIdentifier(parentNodeJcrId);
+ node = parentNode.addNode(name, nodeType);
+ node.setProperty(Property.JCR_TITLE, name);
+ }
+ }
// corresponding node is saved but not checked in, in order to ease
// cancel actions.
session.save();
private String getEditorForNode(Node node) throws RepositoryException {
String editorId = null;
-
if (node.isNodeType(AkbTypes.AKB_CONNECTOR_ALIAS))
- editorId = AkbConnectorAliasEditor.ID;
+ editorId = ConnectorAliasEditor.ID;
else if (node.isNodeType(AkbTypes.AKB_ENV_TEMPLATE))
- editorId = AkbEnvTemplateEditor.ID;
- else
- throw new AkbException("Editor is undefined for node " + node);
+ editorId = EnvTemplateEditor.ID;
+ else if (node.isNodeType(AkbTypes.AKB_SSH_FILE))
+ editorId = SshFileTemplateEditor.ID;
+ else if (node.isNodeType(AkbTypes.AKB_SSH_COMMAND))
+ editorId = SshCommandTemplateEditor.ID;
+ else if (node.isNodeType(AkbTypes.AKB_JDBC_QUERY))
+ editorId = JdbcQueryTemplateEditor.ID;
+ // else
+ // throw new AkbException("Editor is undefined for node " + node);
return editorId;
}
public void setRepository(Repository repository) {
this.repository = repository;
}
+
+ public void setAkbService(AkbService akbService) {
+ this.akbService = akbService;
+ }
}
\ No newline at end of file