public void run(IAction action) {
if (selection==null || !(selection instanceof IStructuredSelection)) {
return;
}
IStructuredSelection ss = (IStructuredSelection)selection;
JcrNode node = (JcrNode) ss.getFirstElement();
if (!node.canCreateChild()) {
MessageDialog.openInformation(shell, "Cannot create node",
"Node is not covered by the workspace filter as defined in filter.xml");
return;
}
Repository repository = ServerUtil.getDefaultRepository(node.getProject());
NodeTypeRegistry ntManager = (repository==null) ? null : repository.getNodeTypeRegistry();
if (ntManager == null) {
if (!doNotAskAgain) {
MessageDialog dialog = new MessageDialog(null, "Unable to validate node type", null,
"Unable to validate node types since project " + node.getProject().getName() + " is not associated with a server or the server is not started.",
MessageDialog.QUESTION_WITH_CANCEL,
new String[] {"Cancel", "Continue (do not ask again)", "Continue"}, 1) {
@Override
protected void configureShell(Shell shell) {
super.configureShell(shell);
setShellStyle(getShellStyle() | SWT.SHEET);
}
};
int choice = dialog.open();
if (choice <= 0) {
return;
}
if (choice==1) {
doNotAskAgain = true;
}
}
}
final NodeType nodeType = node.getNodeType();
if (nodeType!=null && nodeType.getName()!=null && nodeType.getName().equals("nt:file")) {
MessageDialog.openInformation(shell, "Cannot create node", "Node of type nt:file cannot have children");
return;
}
try {
final NewNodeDialog nnd = new NewNodeDialog(shell, node, ntManager);
if (nnd.open() == IStatus.OK) {
node.createChild(nnd.getValue(), nnd.getChosenNodeType());
return;
}
} catch (RepositoryException e1) {
Activator.getDefault().getPluginLogger().warn(
"Could not open NewNodeDialog due to "+e1, e1);