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:03:57 UTC

svn commit: r1731458 - in /sling/trunk/tooling/ide/eclipse-ui: ./ src/org/apache/sling/ide/eclipse/ui/wizards/

Author: rombert
Date: Sat Feb 20 21:03:57 2016
New Revision: 1731458

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

Switch 'Convert to ...' action to be commands.

Added:
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleProjectHandler.java
      - copied, changed from r1731455, sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleAction.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToContentProjectHandler.java
      - copied, changed from r1731455, sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToContentPackageAction.java
Removed:
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleAction.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToContentPackageAction.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=1731458&r1=1731457&r2=1731458&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/plugin.xml (original)
+++ sling/trunk/tooling/ide/eclipse-ui/plugin.xml Sat Feb 20 21:03:57 2016
@@ -342,30 +342,77 @@
             label="Sling Console">
       </consoleFactory>
    </extension>
+   
    <extension
-         point="org.eclipse.ui.popupMenus">
-      <objectContribution
-            objectClass="org.eclipse.core.resources.IProject"
-            adaptable="true"
-            id="org.apache.sling.ide.eclipse.ui.pluginProjectToolSet">
-
-         <action
-            label="Convert to Content Project..."
-            class="org.apache.sling.ide.eclipse.ui.wizards.ConvertToContentPackageAction"
-            menubarPath="org.eclipse.ui.projectConfigure/additions"
-            enablesFor="+"
-            id="org.apache.sling.ide.eclipse.ui.wizards.ConvertToContentPackageAction">
-      	</action>
-         <action
-            label="Convert to Bundle Project..."
-            class="org.apache.sling.ide.eclipse.ui.wizards.ConvertToBundleAction"
-            menubarPath="org.eclipse.ui.projectConfigure/additions"
-            enablesFor="+"
-            id="org.apache.sling.ide.eclipse.ui.wizards.ConvertToBundleAction">
-      	</action>
-      </objectContribution>
-         
-   </extension>
+   		point="org.eclipse.ui.menus">
+   		<menuContribution
+           locationURI="popup:org.eclipse.ui.projectConfigure?after=additions">
+           <command
+                 commandId="org.apache.sling.ide.eclipse.ui.wizards.convertToContentProjectCommand"
+                 label="Convert to Content Project...">
+                 <!-- 
+                   don't enable for sling.content or sling.bundle projects 
+                   Described in depth at http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fworkbench_cmd_expressions.htm
+                 -->
+                 <visibleWhen
+                       checkEnabled="false">
+                   	 <iterate ifEmpty="false">
+                   	   <instanceof value="org.eclipse.core.resources.IProject"/>
+                 	   <not>
+                   	   	  <or>
+                          	<test
+	        	    			property="org.eclipse.wst.common.project.facet.core.projectFacet" 
+	            				value="sling.content"/>
+                          	<test
+	        	    			property="org.eclipse.wst.common.project.facet.core.projectFacet" 
+	            				value="sling.bundle"/>
+	            		  </or>
+            			</not>
+                   	 </iterate>
+                 </visibleWhen>
+           </command>
+           <command
+                 commandId="org.apache.sling.ide.eclipse.ui.wizards.convertToBundleProjectCommand"
+                 label="Convert to Bundle Project...">
+                 <!-- 
+                 	don't enable for sling.content or sling.bundle projects
+                 	but require the Java nature
+             	 -->
+                 <visibleWhen
+                       checkEnabled="false">
+                   	 <iterate ifEmpty="false">
+                   	   <instanceof value="org.eclipse.core.resources.IProject"/>
+                   	   <test property="org.eclipse.core.resources.projectNature"
+                   	   		value="org.eclipse.jdt.core.javanature"/>
+                 	   <not>
+                   	   	  <or>
+                          	<test
+	        	    			property="org.eclipse.wst.common.project.facet.core.projectFacet" 
+	            				value="sling.content"/>
+                          	<test
+	        	    			property="org.eclipse.wst.common.project.facet.core.projectFacet" 
+	            				value="sling.bundle"/>
+	            		  </or>
+            			</not>
+                   	 </iterate>
+                 </visibleWhen>                 
+           </command>
+   		</menuContribution>
+   	</extension>
+   	
+   	<extension
+   	      point="org.eclipse.ui.commands">
+   	      <command
+                id="org.apache.sling.ide.eclipse.ui.wizards.convertToBundleProjectCommand"
+                defaultHandler="org.apache.sling.ide.eclipse.ui.wizards.ConvertToBundleProjectHandler"
+                name="Convert to Bundle Project...">
+   	      </command>
+   	      <command
+                id="org.apache.sling.ide.eclipse.ui.wizards.convertToContentProjectCommand"
+                defaultHandler="org.apache.sling.ide.eclipse.ui.wizards.ConvertToContentProjectHandler"
+                name="Convert to Content Project...">
+   	      </command>
+   	</extension>
 
    <extension
          point="org.eclipse.ui.popupMenus">

Copied: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleProjectHandler.java (from r1731455, sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleAction.java)
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleProjectHandler.java?p2=sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleProjectHandler.java&p1=sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleAction.java&r1=1731455&r2=1731458&rev=1731458&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleAction.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleProjectHandler.java Sat Feb 20 21:03:57 2016
@@ -18,19 +18,20 @@ package org.apache.sling.ide.eclipse.ui.
 
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 
 import org.apache.sling.ide.eclipse.core.ConfigurationHelper;
 import org.apache.sling.ide.eclipse.core.internal.ProjectHelper;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.viewers.ISelection;
@@ -38,30 +39,17 @@ import org.eclipse.jface.viewers.IStruct
 import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.swt.custom.BusyIndicator;
 import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
 
-public class ConvertToBundleAction implements IObjectActionDelegate {
-
-	private ISelection fSelection;
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction,
-	 *      org.eclipse.ui.IWorkbenchPart)
-	 */
-	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
-	 */
-	public void run(IAction action) {
-		if (fSelection instanceof IStructuredSelection) {
+public class ConvertToBundleProjectHandler extends AbstractHandler {
+    
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        
+        ISelection selection = HandlerUtil.getCurrentSelection(event);
+        
+		if (selection instanceof IStructuredSelection) {
 			List<IProject> applicableProjects = new LinkedList<>();
 			IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
 			for (IProject p : allProjects) {
@@ -69,7 +57,7 @@ public class ConvertToBundleAction imple
 					applicableProjects.add(p);
 				}
 			}
-			Object[] elems = ((IStructuredSelection) fSelection).toArray();
+			Object[] elems = ((IStructuredSelection) selection).toArray();
 			List<IProject> initialSelection = new ArrayList<>(elems.length);
 
 			for (Object elem : elems) {
@@ -100,12 +88,12 @@ public class ConvertToBundleAction imple
 			});
 			if (dialog.getReturnCode()!=WizardDialog.OK) {
 				// user did not click OK
-				return;
+				return null;
 			}
 			final List<IProject> selectedProjects = wizard.getSelectedProjects();
 			if (selectedProjects == null || selectedProjects.size()==0) {
 				// no project was selected
-				return;
+			    return null;
 			}
 			IRunnableWithProgress r = new IRunnableWithProgress() {
 				
@@ -131,44 +119,8 @@ public class ConvertToBundleAction imple
 						e.getMessage());
 			}
 		}
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
-	 *      org.eclipse.jface.viewers.ISelection)
-	 */
-	public void selectionChanged(IAction action, ISelection selection) {
-		fSelection = selection;
-		if (selection instanceof IStructuredSelection) {
-			final IStructuredSelection iss = (IStructuredSelection) selection;
-			Iterator<?> it = iss.iterator();
-			if (!it.hasNext()) {
-				action.setEnabled(false);
-				return;
-			}
-			while(it.hasNext()) {
-				Object elem = it.next();
-				if (elem!=null && (elem instanceof IProject)) {
-					final IProject project = (IProject) elem;
-					if (ProjectHelper.isBundleProject(project) || ProjectHelper.isContentProject(project)) {
-						action.setEnabled(false);
-						return;
-					} else {
-					    // SLING-3651 : always show action -
-					    //              allows to provide more filter detail infos
-						continue;
-					}
-				} else {
-					action.setEnabled(false);
-					return;
-				}
-			}
-			action.setEnabled(true);
-		} else {
-			action.setEnabled(false);
-		}
+		
+		return null;
 	}
 
 	public Display getDisplay() {

Copied: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToContentProjectHandler.java (from r1731455, sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToContentPackageAction.java)
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToContentProjectHandler.java?p2=sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToContentProjectHandler.java&p1=sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToContentPackageAction.java&r1=1731455&r2=1731458&rev=1731458&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToContentPackageAction.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToContentProjectHandler.java Sat Feb 20 21:03:57 2016
@@ -18,11 +18,13 @@ package org.apache.sling.ide.eclipse.ui.
 
 import java.lang.reflect.InvocationTargetException;
 import java.util.Arrays;
-import java.util.Iterator;
 
 import org.apache.sling.ide.eclipse.core.ConfigurationHelper;
 import org.apache.sling.ide.eclipse.core.internal.ProjectHelper;
 import org.apache.sling.ide.eclipse.ui.internal.Activator;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
@@ -31,7 +33,6 @@ import org.eclipse.core.runtime.CoreExce
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.resource.ImageDescriptor;
@@ -40,38 +41,24 @@ import org.eclipse.jface.viewers.IStruct
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.viewers.ViewerFilter;
 import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.dialogs.ContainerSelectionDialog;
 import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
 import org.eclipse.ui.dialogs.ISelectionStatusValidator;
+import org.eclipse.ui.handlers.HandlerUtil;
 import org.eclipse.ui.model.BaseWorkbenchContentProvider;
 import org.eclipse.ui.model.IWorkbenchAdapter;
 import org.eclipse.ui.model.WorkbenchLabelProvider;
 
-public class ConvertToContentPackageAction implements IObjectActionDelegate {
+public class ConvertToContentProjectHandler extends AbstractHandler {
+    
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        
+        ISelection selection = HandlerUtil.getCurrentSelection(event);
 
-    private ISelection fSelection;
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.
-     * action.IAction, org.eclipse.ui.IWorkbenchPart)
-     */
-    public void setActivePart(IAction action, IWorkbenchPart targetPart) {
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
-     */
-    public void run(IAction action) {
-        if (fSelection instanceof IStructuredSelection) {
-            final IProject project = (IProject) ((IStructuredSelection) fSelection)
+        if (selection instanceof IStructuredSelection) {
+            final IProject project = (IProject) ((IStructuredSelection) selection)
                     .getFirstElement();
 
             ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(
@@ -195,45 +182,8 @@ public class ConvertToContentPackageActi
                 }
             }
         }
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action
-     * .IAction, org.eclipse.jface.viewers.ISelection)
-     */
-    public void selectionChanged(IAction action, ISelection selection) {
-        fSelection = selection;
-        if (selection instanceof IStructuredSelection) {
-            final IStructuredSelection iss = (IStructuredSelection) selection;
-            Iterator<?> it = iss.iterator();
-            if (!it.hasNext()) {
-                action.setEnabled(false);
-                return;
-            }
-            while (it.hasNext()) {
-                Object elem = it.next();
-                if (elem != null && (elem instanceof IProject)) {
-                    final IProject project = (IProject) elem;
-                    if (ProjectHelper.isContentProject(project) || ProjectHelper.isBundleProject(project)) {
-                        action.setEnabled(false);
-                        return;
-                    } else {
-                        // SLING-3651 : always show action -
-                        //              allows to provide more filter detail infos
-                        continue;
-                    }
-                } else {
-                    action.setEnabled(false);
-                    return;
-                }
-            }
-            action.setEnabled(true);
-        } else {
-            action.setEnabled(false);
-        }
+        
+        return null;
     }
 
     public Display getDisplay() {