ROSPackageProjectCreate.java
Go to the documentation of this file.
00001 package org.best_of_robotics.bride.cdt.ros;
00002 
00003 import java.io.BufferedReader;
00004 import java.io.IOException;
00005 import java.io.InputStreamReader;
00006 import java.net.URI;
00007 
00008 import org.eclipse.cdt.core.CCorePlugin;
00009 import org.eclipse.cdt.core.CProjectNature;
00010 import org.eclipse.cdt.core.envvar.IContributedEnvironment;
00011 import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
00012 import org.eclipse.cdt.core.model.CoreModel;
00013 import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
00014 import org.eclipse.cdt.core.settings.model.ICProjectDescription;
00015 import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
00016 import org.eclipse.cdt.core.settings.model.WriteAccessException;
00017 import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
00018 import org.eclipse.core.resources.IContainer;
00019 import org.eclipse.core.resources.IFolder;
00020 import org.eclipse.core.resources.IProject;
00021 import org.eclipse.core.resources.IProjectDescription;
00022 import org.eclipse.core.resources.ResourcesPlugin;
00023 import org.eclipse.core.runtime.CoreException;
00024 import org.eclipse.core.runtime.IProgressMonitor;
00025 import org.eclipse.core.runtime.NullProgressMonitor;
00026 import org.eclipse.jface.viewers.IStructuredSelection;
00027 import org.eclipse.jface.wizard.Wizard;
00028 import org.eclipse.ui.INewWizard;
00029 import org.eclipse.ui.IWorkbench;
00030 import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
00031 import org.eclipse.cdt.managedbuilder.core.IBuilder;
00032 import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
00033 import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
00034 import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
00035 
00036 public class ROSPackageProjectCreate extends Wizard implements INewWizard {
00037         
00038         private WizardNewProjectCreationPage _pageOne;
00039 
00040 
00041         public ROSPackageProjectCreate() {
00042                 setWindowTitle("Create ROS Package Project");
00043         }
00044 
00045         @Override
00046         public void init(IWorkbench workbench, IStructuredSelection selection) {
00047                 // TODO Auto-generated method stub
00048 
00049         }
00050 
00051         @Override
00052         public boolean performFinish() {
00053                 
00054                 //Create new Project
00055                 String name = _pageOne.getProjectName();
00056             URI location = null;
00057             if (!_pageOne.useDefaults()) {
00058                 location = _pageOne.getLocationURI();
00059             } // else location == null
00060             
00061             
00062             
00063             IProject newProjectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
00064             IProject project = null;
00065         if (!newProjectHandle.exists()) {
00066             URI projectLocation = location;
00067             IProjectDescription desc = newProjectHandle.getWorkspace().newProjectDescription(newProjectHandle.getName());
00068             if (location != null && ResourcesPlugin.getWorkspace().getRoot().getLocationURI().equals(location)) {
00069                 projectLocation = null;
00070             }
00071  
00072             desc.setLocationURI(projectLocation);
00073             try {
00074                 project = CCorePlugin.getDefault().createCDTProject(desc, newProjectHandle, new NullProgressMonitor());
00075                 if (!newProjectHandle.isOpen()) {
00076                         newProjectHandle.open(null);
00077                 }
00078             } catch (CoreException e) {
00079                 e.printStackTrace();
00080             }
00081         }
00082         
00083         ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
00084                 ICProjectDescription des;
00085                 try {
00086                         des = mngr.createProjectDescription(project, false);
00087                         ManagedProject mProj = new ManagedProject(des);
00088         
00089                         Configuration cfg = new Configuration(mProj, null, "ros.configuration.id", "ROSConfiguration");
00090                         cfg.setBuildCommand("rosmake");
00091         
00092                         IBuilder bld = cfg.getEditableBuilder();
00093                         
00094                         //bld.setManagedBuildOn(false);
00095         
00096                         CConfigurationData data = cfg.getConfigurationData();
00097                         //Assert.assertNotNull(data);
00098                         des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
00099                         
00100                         mngr.setProjectDescription(project, des);
00101                         
00102 
00103                 } catch (WriteAccessException e1) {
00104                         // TODO Auto-generated catch block
00105                         e1.printStackTrace();
00106                 } catch (CoreException e1) {
00107                         // TODO Auto-generated catch block
00108                         e1.printStackTrace();
00109                 }
00110         
00111         //Add default folders
00112             try 
00113             {
00114         
00115             String[] paths = { "model" }; //$NON-NLS-1$ //$NON-NLS-2$
00116             for (String path : paths) {
00117                 IFolder etcFolders = project.getFolder(path);
00118                 if (!etcFolders.exists()) {
00119                         etcFolders.create(false, true, null);
00120                 }
00121             }
00122         } catch (CoreException e) {
00123             e.printStackTrace();
00124             project = null;
00125         }
00126                 return true;
00127         }
00128         @Override
00129         public void addPages() {
00130             super.addPages();
00131          
00132             _pageOne = new WizardNewProjectCreationPage("From Scratch Project Wizard");
00133             _pageOne.setTitle("From Scratch Project");
00134             _pageOne.setDescription("Create something from scratch.");
00135          
00136             addPage(_pageOne);
00137         }
00138 
00139 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends


bride_plugin_source
Author(s): Alexander Bubeck
autogenerated on Wed Aug 14 2013 10:06:09