public Object execute()

in eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeHandler.java [43:102]


    public Object execute(ExecutionEvent event) throws ExecutionException {
        
        ISelection sel = HandlerUtil.getCurrentSelection(event);
        
        JcrNode node = SelectionUtils.getFirst(sel, JcrNode.class);
        if ( node == null ) {
            return null;
        }
        
        Shell shell = HandlerUtil.getActiveShell(event);
        
        if (!node.canCreateChild()) {
            MessageDialog.openInformation(shell, "Cannot create node",
                    "Node is not covered by the workspace filter as defined in filter.xml");
            return null;
        }
        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 null;
                }
                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 null;
        }
        
        try {
            final NewNodeDialog nnd = new NewNodeDialog(shell, node, ntManager);
            if (nnd.open() == IStatus.OK) {
                node.createChild(nnd.getValue(), nnd.getChosenNodeType());
                return null;
            }
        } catch (RepositoryException e1) {
            Activator.getDefault().getPluginLogger().warn(
                    "Could not open NewNodeDialog due to "+e1, e1);
        }
        
        return null;
    }