Author: rombert
Date: Sat Feb 20 21:09:02 2016
New Revision: 1731465

URL: http://svn.apache.org/viewvc?rev=1731465&view=rev
Log:
SLING-4046 - Keyboard shortcuts do not work on content structure 

Convert the new node action to a handler.

Added:
    
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeHandler.java
      - copied, changed from r1731464, 
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeAction.java
Removed:
    
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeAction.java
Modified:
    sling/trunk/tooling/ide/eclipse-ui/plugin.xml

Modified: sling/trunk/tooling/ide/eclipse-ui/plugin.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/plugin.xml?rev=1731465&r1=1731464&r2=1731465&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/plugin.xml (original)
+++ sling/trunk/tooling/ide/eclipse-ui/plugin.xml Sat Feb 20 21:09:02 2016
@@ -440,6 +440,20 @@
                  </visibleWhen>
            </command>
         </menuContribution>
+
+        <!-- 'New' actions -->
+        <menuContribution
+              locationURI="popup:common.new.menu?after=new">
+              <command
+               
commandId="org.apache.sling.ide.eclipse.ui.actions.jcrNewNodeHandler"
+               icon="icons/obj16/sling_misc.gif"
+               label="&amp;Node">
+                 <visibleWhen
+                       checkEnabled="false">
+                                       <reference 
definitionId="org.apache.sling.ide.eclipse.jcrNode"/>
+                 </visibleWhen>
+              </command>              
+        </menuContribution>
         
         <!-- Other actions -->
         <menuContribution
@@ -524,6 +538,11 @@
                        
defaultHandler="org.apache.sling.ide.eclipse.ui.actions.JcrNodeImportContentHandler"
                        name="Import JCR content from server...">
          </command>
+             <command
+                       
id="org.apache.sling.ide.eclipse.ui.actions.jcrNewNodeHandler"
+                       
defaultHandler="org.apache.sling.ide.eclipse.ui.actions.JcrNewNodeHandler"
+                       name="Import JCR content from server...">
+         </command>
        </extension>
        
        <extension
@@ -559,60 +578,6 @@
            </activeWhen>
                </handler>
        </extension>
-
-   <extension
-         point="org.eclipse.ui.popupMenus">
-      <objectContribution
-            adaptable="true"
-            id="org.apache.sling.ide.eclipse.ui.pluginDomNodeToolSet"
-            objectClass="org.apache.sling.ide.eclipse.ui.nav.model.JcrNode">
-            <!-- explicitly adding the 'New' / common.new.menu as this does 
not show up for JcrNodes otherwise-->
-         <menu
-               id="common.new.menu"
-               label="New"
-               path="group.new">
-            <separator
-                  name="jcr">
-            </separator>
-         </menu>
-         <action
-               class="org.apache.sling.ide.eclipse.ui.actions.JcrNewNodeAction"
-               icon="icons/obj16/sling_misc.gif"
-               id="org.apache.sling.ide.eclipse.ui.nav.NewJcrNodeAction"
-               label="&amp;Node..."
-               menubarPath="common.new.menu/jcr">
-         </action>
-         <visibility>
-               <objectState
-                     name="domNode"
-                     value="true">
-               </objectState>
-         </visibility>
-      </objectContribution>
-   </extension>
-
-   <extension
-         id="org.apache.sling.ide.eclipse.ui.pluginNonJcrNodeToolSet"
-         point="org.eclipse.ui.popupMenus">
-      <objectContribution
-            adaptable="true"
-            id="org.apache.sling.ide.eclipse.ui.pluginNonJcrNodeToolSet"
-            objectClass="org.apache.sling.ide.eclipse.ui.nav.model.JcrNode">
-         <action
-               class="org.apache.sling.ide.eclipse.ui.actions.JcrNewNodeAction"
-               icon="icons/obj16/sling_misc.gif"
-               id="org.apache.sling.ide.eclipse.ui.nav.NewNonJcrNodeAction"
-               label="Node..."
-               menubarPath="common.new.menu/jcr">
-         </action>
-         <visibility>
-               <objectState
-                     name="nonDomNode"
-                     value="true">
-               </objectState>
-         </visibility>
-      </objectContribution>
-   </extension>
    
    <extension
          point="org.eclipse.ui.decorators">

Copied: 
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeHandler.java
 (from r1731464, 
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeAction.java)
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeHandler.java?p2=sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeHandler.java&p1=sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeAction.java&r1=1731464&r2=1731465&rev=1731465&view=diff
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeAction.java
 (original)
+++ 
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeHandler.java
 Sat Feb 20 21:09:02 2016
@@ -20,40 +20,41 @@ import javax.jcr.nodetype.NodeType;
 
 import org.apache.sling.ide.eclipse.core.ServerUtil;
 import org.apache.sling.ide.eclipse.ui.internal.Activator;
+import org.apache.sling.ide.eclipse.ui.internal.SelectionUtils;
 import org.apache.sling.ide.eclipse.ui.nav.model.JcrNode;
 import org.apache.sling.ide.transport.NodeTypeRegistry;
 import org.apache.sling.ide.transport.Repository;
 import org.apache.sling.ide.transport.RepositoryException;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.handlers.HandlerUtil;
 
-public class JcrNewNodeAction implements IObjectActionDelegate {
+public class JcrNewNodeHandler extends AbstractHandler {
 
-       private ISelection selection;
-       private Shell shell;
     private boolean doNotAskAgain;
 
-       public JcrNewNodeAction() {
-       }
-
-       @Override
-    public void run(IAction action) {
-        if (selection==null || !(selection instanceof IStructuredSelection)) {
-            return;
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        
+        ISelection sel = HandlerUtil.getCurrentSelection(event);
+        
+        JcrNode node = SelectionUtils.getFirst(sel, JcrNode.class);
+        if ( node == null ) {
+            return null;
         }
-        IStructuredSelection ss = (IStructuredSelection)selection;
-        JcrNode node = (JcrNode) ss.getFirstElement();
+        
+        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;
+            return null;
         }
         Repository repository = 
ServerUtil.getDefaultRepository(node.getProject());
         NodeTypeRegistry ntManager = (repository==null) ? null : 
repository.getNodeTypeRegistry();
@@ -72,7 +73,7 @@ public class JcrNewNodeAction implements
                 };
                 int choice = dialog.open();
                 if (choice <= 0) {
-                    return;
+                    return null;
                 }
                 if (choice==1) {
                     doNotAskAgain = true;
@@ -83,30 +84,21 @@ public class JcrNewNodeAction implements
         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;
+            return null;
         }
         
         try {
             final NewNodeDialog nnd = new NewNodeDialog(shell, node, 
ntManager);
             if (nnd.open() == IStatus.OK) {
                 node.createChild(nnd.getValue(), nnd.getChosenNodeType());
-                return;
+                return null;
             }
         } catch (RepositoryException e1) {
             Activator.getDefault().getPluginLogger().warn(
                     "Could not open NewNodeDialog due to "+e1, e1);
         }
         
+        return null;
     }
 
-       @Override
-       public void selectionChanged(IAction action, ISelection selection) {
-               this.selection = selection;
-       }
-
-       @Override
-       public void setActivePart(IAction action, IWorkbenchPart targetPart) {
-               this.shell = 
targetPart.getSite().getWorkbenchWindow().getShell();
-       }
-
 }


Reply via email to