Author: stefanegli
Date: Thu Aug 29 15:38:34 2013
New Revision: 1518675

URL: http://svn.apache.org/r1518675
Log:
SLING-3009 : add a 'convert to sling/osgi bundle project' action to the 
context-menu for a Project under 'Configure' : sets the 'sling-bundle' facet

Added:
    
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleAction.java
   (with props)
Modified:
    sling/trunk/tooling/ide/eclipse-ui/plugin.xml
    
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConfigurationHelper.java
    
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.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=1518675&r1=1518674&r2=1518675&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/plugin.xml (original)
+++ sling/trunk/tooling/ide/eclipse-ui/plugin.xml Thu Aug 29 15:38:34 2013
@@ -341,7 +341,14 @@
             
class="org.apache.sling.ide.eclipse.ui.wizards.ConvertToContentPackageAction"
             menubarPath="org.eclipse.ui.projectConfigure/additions"
             enablesFor="+"
-            id="org.eclipse.pde.ui.ConvertedProjectWizard">
+            
id="org.apache.sling.ide.eclipse.ui.wizards.ConvertToContentPackageAction">
+       </action>
+         <action
+            label="Convert to Sling/OSGi 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>
          

Modified: 
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConfigurationHelper.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConfigurationHelper.java?rev=1518675&r1=1518674&r2=1518675&view=diff
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConfigurationHelper.java
 (original)
+++ 
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConfigurationHelper.java
 Thu Aug 29 15:38:34 2013
@@ -50,4 +50,11 @@ public class ConfigurationHelper {
                launchFile.create(in, true, monitor);
        }
 
+       public static void convertToBundleProject(IProject aBundleProject)
+                       throws CoreException {
+               IProjectFacet slingContentFacet = 
ProjectFacetsManager.getProjectFacet("sling.bundle");
+               IFacetedProject fp2 = 
ProjectFacetsManager.create(aBundleProject, true, null);
+               fp2.installProjectFacet(slingContentFacet.getLatestVersion(), 
null, null);
+       }
+
 }

Added: 
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/ConvertToBundleAction.java?rev=1518675&view=auto
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleAction.java
 (added)
+++ 
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleAction.java
 Thu Aug 29 15:38:34 2013
@@ -0,0 +1,129 @@
+/*
+ * 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.wizards;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.maven.model.Model;
+import org.apache.sling.ide.eclipse.core.internal.ProjectHelper;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+
+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) {
+                       final IProject project = (IProject) 
((IStructuredSelection) fSelection).getFirstElement();
+
+                       boolean confirmed = 
MessageDialog.openConfirm(getDisplay().getActiveShell(), "Convert to Sling/OSGi 
Bundle Project", 
+                                       "Confirm the conversion of this project 
to a Sling/OSGi Bundle Project");
+                       
+                       if (confirmed) {
+                               IRunnableWithProgress r = new 
IRunnableWithProgress() {
+                                       
+                                       @Override
+                                       public void run(IProgressMonitor 
monitor) throws InvocationTargetException,
+                                                       InterruptedException {
+                                               try {
+                                                       
ConfigurationHelper.convertToBundleProject(project);
+                                               } catch (CoreException e) {
+                                                       e.printStackTrace();
+                                                       
MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert 
project",
+                                                                       
e.getMessage());
+                                               }
+                                       }
+                               };
+                               try {
+                                       
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(r);
+                               } catch (Exception e) {
+                                       e.printStackTrace();
+                                       
MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert 
project",
+                                                       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;
+                       if (iss.toList().size()!=1) {
+                               action.setEnabled(false);
+                       } else {
+                               Object firstElement = iss.getFirstElement();
+                               if (firstElement!=null && (firstElement 
instanceof IProject)) {
+                                       final IProject project = (IProject) 
firstElement;
+                                       if 
(ProjectHelper.isBundleProject(project)) {
+                                               action.setEnabled(false);
+                                       } else {
+                                               Model mavenModel = 
MavenHelper.getMavenModel(project);
+                                               if 
("bundle".equals(mavenModel.getPackaging())) {
+                                                       action.setEnabled(true);
+                                               } else {
+                                                       
action.setEnabled(false);
+                                               }
+                                       }
+                               } else {
+                                       action.setEnabled(false);
+                               }
+                       }
+               } else {
+                       action.setEnabled(false);
+               }
+       }
+
+       public Display getDisplay() {
+               Display display = Display.getCurrent();
+               if (display == null)
+                       display = Display.getDefault();
+               return display;
+       }
+
+}

Propchange: 
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java?rev=1518675&r1=1518674&r2=1518675&view=diff
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java
 (original)
+++ 
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java
 Thu Aug 29 15:38:34 2013
@@ -49,9 +49,6 @@ import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.ui.INewWizard;
 import org.eclipse.ui.IWorkbench;
-import org.eclipse.wst.common.project.facet.core.IFacetedProject;
-import org.eclipse.wst.common.project.facet.core.IProjectFacet;
-import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
 import org.eclipse.wst.server.core.IModule;
 import org.eclipse.wst.server.core.IServer;
 import org.eclipse.wst.server.core.IServerWorkingCopy;
@@ -308,9 +305,7 @@ public abstract class AbstractNewSlingAp
 
        protected void configureBundleProject(IProject aBundleProject,
                        List<IProject> projects, IProgressMonitor monitor) 
throws CoreException {
-               IProjectFacet slingContentFacet = 
ProjectFacetsManager.getProjectFacet("sling.bundle");
-               IFacetedProject fp2 = 
ProjectFacetsManager.create(aBundleProject, true, null);
-               fp2.installProjectFacet(slingContentFacet.getLatestVersion(), 
null, null);
+               ConfigurationHelper.convertToBundleProject(aBundleProject);
        }
        
        protected void configureContentProject(IProject aContentProject,


Reply via email to