You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2016/02/20 22:05:56 UTC

svn commit: r1731459 - in /sling/trunk/tooling/ide/eclipse-ui: ./ src/org/apache/sling/ide/eclipse/ui/actions/ src/org/apache/sling/ide/eclipse/ui/internal/

Author: rombert
Date: Sat Feb 20 21:05:56 2016
New Revision: 1731459

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

Switch the delete and rename actions to be handlers.

Added:
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeDeleteHandler.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeRenameHandler.java
Removed:
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeDeleteAction.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeRenameAction.java
Modified:
    sling/trunk/tooling/ide/eclipse-ui/plugin.xml
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SelectionUtils.java

Modified: sling/trunk/tooling/ide/eclipse-ui/plugin.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/plugin.xml?rev=1731459&r1=1731458&r2=1731459&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/plugin.xml (original)
+++ sling/trunk/tooling/ide/eclipse-ui/plugin.xml Sat Feb 20 21:05:56 2016
@@ -345,6 +345,7 @@
    
    <extension
    		point="org.eclipse.ui.menus">
+   		<!-- Convert to ... contributions -->
    		<menuContribution
            locationURI="popup:org.eclipse.ui.projectConfigure?after=additions">
            <command
@@ -373,6 +374,7 @@
            </command>
            <command
                  commandId="org.apache.sling.ide.eclipse.ui.wizards.convertToBundleProjectCommand"
+                 icon="org.apache.sling.ide.eclipse-ui.command4"
                  label="Convert to Bundle Project...">
                  <!-- 
                  	don't enable for sling.content or sling.bundle projects
@@ -398,10 +400,41 @@
                  </visibleWhen>                 
            </command>
    		</menuContribution>
+   		
+   		<!-- Package Explorer contributions -->
+   		
+   		<menuContribution
+           locationURI="popup:org.eclipse.ui.popup.any?after=group.edit">
+           <command
+                 commandId="org.eclipse.ui.edit.delete">
+                 <visibleWhen
+                       checkEnabled="false">
+                     <iterate ifEmpty="false">
+                         <adapt
+                               type="org.apache.sling.ide.eclipse.ui.nav.model.JcrNode">
+                         </adapt> 	 
+                     </iterate>
+                 </visibleWhen>
+           </command>
+           <command
+                 commandId="org.eclipse.ui.edit.rename">
+                 <visibleWhen
+                       checkEnabled="false">
+                     <iterate ifEmpty="false">
+                         <adapt
+                               type="org.apache.sling.ide.eclipse.ui.nav.model.JcrNode">
+                         </adapt>
+                     </iterate>
+                 </visibleWhen>
+           </command>
+           
+        </menuContribution>
+        
    	</extension>
    	
    	<extension
    	      point="org.eclipse.ui.commands">
+   	      <!-- conversion commands -->
    	      <command
                 id="org.apache.sling.ide.eclipse.ui.wizards.convertToBundleProjectCommand"
                 defaultHandler="org.apache.sling.ide.eclipse.ui.wizards.ConvertToBundleProjectHandler"
@@ -412,6 +445,46 @@
                 defaultHandler="org.apache.sling.ide.eclipse.ui.wizards.ConvertToContentProjectHandler"
                 name="Convert to Content Project...">
    	      </command>
+   	      
+ 		  <!-- Node commands -->
+   	      <command
+   	      		id="org.apache.sling.ide.eclipse.ui.actions.jcrNodeDeleteHandler"
+   	      		defaultHandler="org.apache.sling.ide.eclipse.ui.actions.JcrNodeDeleteHandler"
+   	      		name="Delete Node...">
+         </command>   	      
+   	      <command
+   	      		id="org.apache.sling.ide.eclipse.ui.actions.jcrNodeRenameHandler"
+   	      		defaultHandler="org.apache.sling.ide.eclipse.ui.actions.JcrNodeRenameHandler"
+   	      		name="Rename Node...">
+         </command>   	      
+   	</extension>
+   	
+   	<extension
+   		point="org.eclipse.ui.handlers">
+   		
+   		<!-- handlers overiding standard commands: delete, rename, etc -->
+   		<handler
+           commandId="org.eclipse.ui.edit.delete"
+           class="org.apache.sling.ide.eclipse.ui.actions.JcrNodeDeleteHandler">
+           <activeWhen>
+             <iterate ifEmpty="false">
+             <adapt
+                   type="org.apache.sling.ide.eclipse.ui.nav.model.JcrNode">
+             </adapt>        
+             </iterate>        
+           </activeWhen>
+   		</handler>
+   		<handler
+           commandId="org.eclipse.ui.edit.rename"
+           class="org.apache.sling.ide.eclipse.ui.actions.JcrNodeRenameHandler">
+           <activeWhen>
+             <iterate ifEmpty="false">
+             <adapt
+                   type="org.apache.sling.ide.eclipse.ui.nav.model.JcrNode">
+             </adapt>        
+             </iterate>        
+           </activeWhen>
+   		</handler>
    	</extension>
 
    <extension
@@ -451,21 +524,6 @@
                menubarPath="common.new.menu/jcr">
          </action>
          <action
-               class="org.apache.sling.ide.eclipse.ui.actions.JcrNodeRenameAction"
-               id="org.apache.sling.ide.eclipse.ui.actions.JcrNodeRenameAction"
-               definitionId="org.eclipse.ui.edit.rename"
-               label="&amp;Rename..."
-               menubarPath="group.edit">
-         </action>
-         <action
-               class="org.apache.sling.ide.eclipse.ui.actions.JcrNodeDeleteAction"
-               definitionId="org.eclipse.ui.edit.delete"
-               icon="icons/ovr16/delete_obj.gif"
-               id="org.apache.sling.ide.eclipse.ui.actions.JcrNodeDeleteAction"
-               label="&amp;Delete..."
-               menubarPath="group.edit">
-         </action>
-         <action
                class="org.apache.sling.ide.eclipse.ui.actions.JcrNodePasteAction"
                definitionId="org.eclipse.ui.edit.paste"
                icon="icons/ovr16/paste_edit.gif"
@@ -511,7 +569,7 @@
          </visibility>
       </objectContribution>
    </extension>
-
+   
    <extension
          id="org.apache.sling.ide.eclipse.ui.pluginNonJcrNodeToolSet"
          point="org.eclipse.ui.popupMenus">
@@ -541,23 +599,6 @@
                menubarPath="jcr">
          </action>
          <action
-               class="org.apache.sling.ide.eclipse.ui.actions.JcrNodeRenameAction"
-               definitionId="org.eclipse.ui.edit.rename"
-               id="org.apache.sling.ide.eclipse.ui.actions.JcrNodeRenameAction"
-               label="&amp;Rename..."
-               menubarPath="group.edit"
-               toolbarPath="common.new.menu/jcr">
-         </action>
-         <action
-               class="org.apache.sling.ide.eclipse.ui.actions.JcrNodeDeleteAction"
-               definitionId="org.eclipse.ui.edit.delete"
-               icon="icons/ovr16/delete_obj.gif"
-               id="org.apache.sling.ide.eclipse.ui.actions.JcrNodeDeleteAction"
-               label="&amp;Delete..."
-               menubarPath="group.edit"
-               toolbarPath="common.new.menu/jcr">
-         </action>
-         <action
                class="org.apache.sling.ide.eclipse.ui.actions.JcrNodePasteAction"
                definitionId="org.eclipse.ui.edit.paste"
                icon="icons/ovr16/paste_edit.gif"
@@ -650,6 +691,7 @@
    </extension>
    <extension
          point="org.eclipse.ui.bindings">
+      <!-- Import/Export -->
       <key
             commandId="org.apache.sling.ide.commands.importContent"
             contextId="org.eclipse.ui.contexts.window"
@@ -661,7 +703,7 @@
             contextId="org.eclipse.ui.contexts.window"
             schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
             sequence="M1+M2+X">
-      </key>      
+      </key>
    </extension>
 
     <extension

Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeDeleteHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeDeleteHandler.java?rev=1731459&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeDeleteHandler.java (added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeDeleteHandler.java Sat Feb 20 21:05:56 2016
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.ui.actions;
+
+import org.apache.sling.ide.eclipse.ui.internal.SelectionUtils;
+import org.apache.sling.ide.eclipse.ui.nav.model.JcrNode;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class JcrNodeDeleteHandler extends AbstractHandler {
+
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+
+        ISelection selection = HandlerUtil.getCurrentSelection(event);
+
+        JcrNode node = SelectionUtils.getFirst(selection, JcrNode.class);
+
+        if (node == null) {
+            return null;
+        }
+
+        Shell shell = HandlerUtil.getActiveShellChecked(event);
+
+        if (!MessageDialog.openConfirm(shell, "Delete Node",
+                "Do you really want to delete '" + node.getLabel() + "'?")) {
+            return null;
+        }
+
+        node.delete();
+
+        return null;
+    }
+}
\ No newline at end of file

Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeRenameHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeRenameHandler.java?rev=1731459&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeRenameHandler.java (added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeRenameHandler.java Sat Feb 20 21:05:56 2016
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.ui.actions;
+
+import org.apache.sling.ide.eclipse.ui.internal.SelectionUtils;
+import org.apache.sling.ide.eclipse.ui.nav.model.JcrNode;
+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.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class JcrNodeRenameHandler extends AbstractHandler {
+
+    @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;
+        }
+
+        Shell shell = HandlerUtil.getActiveShell(event);
+
+        InputDialog id = new InputDialog(shell, "Change Node Name",
+                "Enter new name for node '" + node.getDescription() + "':", node.getLabel(),
+                NodeNameValidator.INSTANCE);
+
+        if (id.open() == IStatus.OK) {
+            node.rename(id.getValue());
+        }
+
+        return null;
+    }
+
+    static final class NodeNameValidator implements IInputValidator {
+
+        static final NodeNameValidator INSTANCE = new NodeNameValidator();
+
+        @Override
+        public String isValid(String newText) {
+            if (newText != null && newText.trim().length() > 0 && newText.trim().equals(newText)) {
+                return null;
+            } else {
+                return "Invalid input";
+            }
+        }
+    }
+
+}
\ No newline at end of file

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SelectionUtils.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SelectionUtils.java?rev=1731459&r1=1731458&r2=1731459&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SelectionUtils.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SelectionUtils.java Sat Feb 20 21:05:56 2016
@@ -22,6 +22,7 @@ import java.util.List;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.wst.server.core.IModule;
 import org.eclipse.wst.server.core.IServer;
@@ -65,6 +66,27 @@ public abstract class SelectionUtils {
 
         return servers;
 	}
+	
+    /**
+     * Returns the first object contained in the specified <tt>sel</tt>
+     * 
+     * @param selection the selection object
+     * @param type the type of the selected object
+     * @return the selected value, or <code>null</code>
+     */
+    @SuppressWarnings("unchecked") // cast guarded by type.isInstance
+    public static <T> T getFirst(ISelection selection, Class<T> type) {
+
+        if ( selection instanceof IStructuredSelection) {
+            Object selected = ((IStructuredSelection) selection).getFirstElement();
+            
+            if ( type.isInstance(selected)) {
+                return (T) selected;
+            }
+        }
+        
+        return null;
+    }	
 
     private SelectionUtils() {