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:06:26 UTC

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

Author: rombert
Date: Sat Feb 20 21:06:26 2016
New Revision: 1731461

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

Switch the copy and paste actions to be handlers.

Added:
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/AbstractClipboardHandler.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeCopyHandler.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodePasteHandler.java
Removed:
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeCopyAction.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodePasteAction.java
Modified:
    sling/trunk/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF
    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/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF?rev=1731461&r1=1731460&r2=1731461&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF (original)
+++ sling/trunk/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF Sat Feb 20 21:06:26 2016
@@ -26,6 +26,7 @@ Import-Package: javax.jcr,
  org.apache.sling.ide.util,
  org.eclipse.core.commands,
  org.eclipse.core.commands.operations,
+ org.eclipse.core.expressions,
  org.eclipse.core.resources,
  org.eclipse.core.resources.mapping,
  org.eclipse.core.runtime;version="3.4.0",

Modified: sling/trunk/tooling/ide/eclipse-ui/plugin.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/plugin.xml?rev=1731461&r1=1731460&r2=1731461&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/plugin.xml (original)
+++ sling/trunk/tooling/ide/eclipse-ui/plugin.xml Sat Feb 20 21:06:26 2016
@@ -406,6 +406,28 @@
    		<menuContribution
            locationURI="popup:org.eclipse.ui.popup.any?after=group.edit">
            <command
+                 commandId="org.eclipse.ui.edit.copy">
+                 <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.paste">
+                 <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.delete">
                  <visibleWhen
                        checkEnabled="false">
@@ -427,7 +449,6 @@
                      </iterate>
                  </visibleWhen>
            </command>
-           
         </menuContribution>
         
    	</extension>
@@ -456,7 +477,17 @@
    	      		id="org.apache.sling.ide.eclipse.ui.actions.jcrNodeRenameHandler"
    	      		defaultHandler="org.apache.sling.ide.eclipse.ui.actions.JcrNodeRenameHandler"
    	      		name="Rename Node...">
-         </command>   	      
+         </command>
+   	      <command
+   	      		id="org.apache.sling.ide.eclipse.ui.actions.jcrNodeCopyHandler"
+   	      		defaultHandler="org.apache.sling.ide.eclipse.ui.actions.JcrNodeCopyHandler"
+   	      		name="Copy Node...">
+         </command>
+   	      <command
+   	      		id="org.apache.sling.ide.eclipse.ui.actions.jcrNodePasteHandler"
+   	      		defaultHandler="org.apache.sling.ide.eclipse.ui.actions.JcrNodePasteHandler"
+   	      		name="Paste Node...">
+         </command>
    	</extension>
    	
    	<extension
@@ -485,6 +516,28 @@
              </iterate>        
            </activeWhen>
    		</handler>
+   		<handler
+           commandId="org.eclipse.ui.edit.copy"
+           class="org.apache.sling.ide.eclipse.ui.actions.JcrNodeCopyHandler">
+           <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.paste"
+           class="org.apache.sling.ide.eclipse.ui.actions.JcrNodePasteHandler">
+           <activeWhen>
+             <iterate ifEmpty="false">
+             <adapt
+                   type="org.apache.sling.ide.eclipse.ui.nav.model.JcrNode">
+             </adapt>        
+             </iterate>        
+           </activeWhen>
+   		</handler>
    	</extension>
 
    <extension
@@ -523,22 +576,6 @@
                label="&amp;Node..."
                menubarPath="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"
-               id="org.apache.sling.ide.eclipse.ui.actions.JcrNodePasteAction"
-               label="&amp;Paste..."
-               menubarPath="group.edit">
-         </action>
-         <action
-               class="org.apache.sling.ide.eclipse.ui.actions.JcrNodeCopyAction"
-               icon="icons/ovr16/copy.gif"
-               id="org.apache.sling.ide.eclipse.ui.actions.JcrNodeCopyAction"
-               definitionId="org.eclipse.ui.edit.copy"
-               label="&amp;Copy..."
-               menubarPath="group.edit">
-         </action>
          <visibility>
                <objectState
                      name="domNode"
@@ -599,24 +636,6 @@
                menubarPath="jcr">
          </action>
          <action
-               class="org.apache.sling.ide.eclipse.ui.actions.JcrNodePasteAction"
-               definitionId="org.eclipse.ui.edit.paste"
-               icon="icons/ovr16/paste_edit.gif"
-               id="org.apache.sling.ide.eclipse.ui.actions.JcrNodePasteAction"
-               label="&amp;Paste..."
-               menubarPath="group.edit"
-               toolbarPath="common.new.menu/jcr">
-         </action>
-         <action
-               class="org.apache.sling.ide.eclipse.ui.actions.JcrNodeCopyAction"
-               definitionId="org.eclipse.ui.edit.copy"
-               icon="icons/ovr16/copy.gif"
-               id="org.apache.sling.ide.eclipse.ui.actions.JcrNodeCopyAction"
-               label="&amp;Copy..."
-               menubarPath="group.edit"
-               toolbarPath="common.new.menu/jcr">
-         </action>
-         <action
                class="org.apache.sling.ide.eclipse.ui.actions.OpenHtmlInBrowserAction"
                icon="platform:/plugin/org.eclipse.ui.browser/icons/obj16/internal_browser.gif"
                id="org.apache.sling.ide.eclipse.ui.actionsOpenHtmlInBrowserAction"

Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/AbstractClipboardHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/AbstractClipboardHandler.java?rev=1731461&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/AbstractClipboardHandler.java (added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/AbstractClipboardHandler.java Sat Feb 20 21:06:26 2016
@@ -0,0 +1,66 @@
+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.viewers.ISelection;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public abstract class AbstractClipboardHandler extends AbstractHandler {
+
+    private Clipboard clipboard;
+
+    public AbstractClipboardHandler() {
+        super();
+    }
+
+    @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;
+        }
+        
+        execute0(node);
+    
+        return null;
+    }
+
+    @Override
+    public void setEnabled(Object evaluationContext) {
+        
+        ISelection sel = SelectionUtils.getSelectionFromEvaluationContext(evaluationContext);
+        
+        JcrNode node = SelectionUtils.getFirst(sel, JcrNode.class);
+        
+        setBaseEnabled(node != null && isEnabledFor(node));
+    }
+
+    @Override
+    public void dispose() {
+        super.dispose();
+        
+        if ( clipboard != null ) {
+            clipboard.dispose();
+        }
+    }
+    
+    protected Clipboard clipboard() {
+        if ( clipboard == null ) {
+            clipboard = new Clipboard(null);
+        }
+        
+        return clipboard;
+    }
+    
+    protected abstract void execute0(JcrNode node);
+    
+    protected abstract boolean isEnabledFor(JcrNode node);
+
+}
\ No newline at end of file

Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeCopyHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeCopyHandler.java?rev=1731461&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeCopyHandler.java (added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeCopyHandler.java Sat Feb 20 21:06:26 2016
@@ -0,0 +1,32 @@
+/*
+ * 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.nav.model.JcrNode;
+
+/** 'Copy JCR node' action **/
+public class JcrNodeCopyHandler extends AbstractClipboardHandler {
+
+    protected void execute0(JcrNode node) {
+        node.copyToClipboard(clipboard());
+    }
+    
+    @Override
+    protected boolean isEnabledFor(JcrNode node) {
+        return node.canBeCopiedToClipboard();
+    }
+}
\ No newline at end of file

Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodePasteHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodePasteHandler.java?rev=1731461&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodePasteHandler.java (added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodePasteHandler.java Sat Feb 20 21:06:26 2016
@@ -0,0 +1,33 @@
+/*
+ * 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.nav.model.JcrNode;
+
+/** 'Paste JCR node' action **/
+public class JcrNodePasteHandler extends AbstractClipboardHandler {
+    
+    @Override
+    protected void execute0(JcrNode node) {
+        node.pasteFromClipboard(clipboard());
+    }
+    
+    @Override
+    protected boolean isEnabledFor(JcrNode node) {
+        return node.canBePastedTo(clipboard());
+    }
+}
\ 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=1731461&r1=1731460&r2=1731461&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:06:26 2016
@@ -20,10 +20,12 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
+import org.eclipse.core.expressions.IEvaluationContext;
 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.ui.ISources;
 import org.eclipse.wst.server.core.IModule;
 import org.eclipse.wst.server.core.IServer;
 import org.eclipse.wst.server.core.ServerCore;
@@ -86,7 +88,21 @@ public abstract class SelectionUtils {
         }
         
         return null;
-    }	
+    }
+    
+    public static ISelection getSelectionFromEvaluationContext(Object evaluationContext) {
+        if ( !(evaluationContext instanceof IEvaluationContext)) {
+            return null;
+        }
+        
+        IEvaluationContext ctx = (IEvaluationContext) evaluationContext;
+        Object selection = ctx.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
+        if ( !(selection instanceof ISelection)) {
+            return null;
+        }
+        
+        return (ISelection) selection;
+    }
 
     private SelectionUtils() {