Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Working XML: Creating a project

Adding new wizards to Eclipse

Return to article


Listing 6. The createProject() method
		
protected void createProject(IProgressMonitor monitor)
{
   monitor.beginTask(Resources.getString("eclipse.creatingproject"),50);
   try
   {
      IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
      monitor.subTask(Resources.getString("eclipse.creatingdirectories"));
      IProject project = root.getProject(namePage.getProjectName());
      IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName());
      if(!Platform.getLocation().equals(namePage.getLocationPath()))
         description.setLocation(namePage.getLocationPath());
      description.setNatureIds(new String[] { PluginConstants.NATURE_ID });
      ICommand command = description.newCommand();
      command.setBuilderName(PluginConstants.BUILDER_ID);
      description.setBuildSpec(new ICommand[] { command });
      project.create(description,monitor);
      monitor.worked(10);
      project.open(monitor);
      project.setPersistentProperty(PluginConstants.SOURCE_PROPERTY_NAME,"src");
      project.setPersistentProperty(PluginConstants.RULES_PROPERTY_NAME,"rules");
      project.setPersistentProperty(PluginConstants.PUBLISH_PROPERTY_NAME,"publish");
      project.setPersistentProperty(PluginConstants.BUILD_PROPERTY_NAME,"false");
      monitor.worked(10);
      IPath projectPath = project.getFullPath(),
            srcPath = projectPath.append("src"),
            rulesPath = projectPath.append("rules"),
            publishPath = projectPath.append("publish");
      IFolder srcFolder = root.getFolder(srcPath),
              rulesFolder = root.getFolder(rulesPath),
              publishFolder = root.getFolder(publishPath);
      createFolderHelper(srcFolder,monitor);
      createFolderHelper(rulesFolder,monitor);
      createFolderHelper(publishFolder,monitor);
      monitor.worked(10);
      monitor.subTask(Resources.getString("eclipse.creatingfiles"));
      IPath indexPath = srcPath.append("index.xml"),
            defaultPath = rulesPath.append("default.xsl");
      IFile indexFile = root.getFile(indexPath),
            defaultFile = root.getFile(defaultPath);
      Class clasz = getClass();
      InputStream indexIS = clasz.getResourceAsStream("/org/ananas/xm/eclipse/resources/index.xml"),
          defaultIS = clasz.getResourceAsStream("/org/ananas/xm/eclipse/resources/default.xsl");
      indexFile.create(indexIS,false,new SubProgressMonitor(monitor,10));
      defaultFile.create(defaultIS,false,new SubProgressMonitor(monitor,10));
   }
   catch(CoreException x)
   {
      reportError(x);
   }
   finally
   {
      monitor.done();
   }
}