Package org.eclipse.core.resources

Examples of org.eclipse.core.resources.IProjectDescription


* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class NatureUtilities {
  public static void addNature(IProject project, String nature) {
    try {
      IProjectDescription description = project.getDescription();
      String[] prevNatures = description.getNatureIds();
      String[] newNatures = new String[prevNatures.length + 1];
      System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
      newNatures[prevNatures.length] = nature;
      description.setNatureIds(newNatures);
      project.setDescription(description, null);
    } catch (CoreException e) {
      e.printStackTrace();
    }
  }
View Full Code Here


    }
  }

  public static void removeNature(IProject project, String nature) {
    try {
      IProjectDescription description = project.getDescription();
      String[] prevNatures = description.getNatureIds();

      int found = 0;
      for (int i = 0; i < prevNatures.length; i++) {
        if (prevNatures[i].equals(nature)) {
          found = i;
          break;
        }
      }

      if (found != -1) {
        String[] newNatures = new String[prevNatures.length - 1];
        System.arraycopy(prevNatures, 0, newNatures, 0, found);
        System.arraycopy(prevNatures, found+1, newNatures, found, newNatures.length-found);
        description.setNatureIds(newNatures);
        project.setDescription(description, null);
      }
    } catch (CoreException e) {
      e.printStackTrace();
    }
View Full Code Here

        IPath newPath = null;
        if (!mainPage.useDefaults())
            newPath = mainPage.getLocationPath();

        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        final IProjectDescription description = workspace
                .newProjectDescription(newProjectHandle.getName());
        description.setLocation(newPath);
        addNatures(description);

        // create the new project operation
        WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
            protected void execute(IProgressMonitor monitor)
View Full Code Here

        IPath path = folder.getFullPath();
        project.setOutputLocation(path, null);
    }

    private void addJavaBuilder(IJavaProject project, IProgressMonitor monitor) throws CoreException {
        IProjectDescription description = project.getProject().getDescription();
        ICommand[] commands = description.getBuildSpec();
        ICommand[] newCommands = new ICommand[commands.length + 2];
        System.arraycopy(commands, 0, newCommands, 0, commands.length);

        ICommand javaCommand = description.newCommand();
        javaCommand.setBuilderName("org.eclipse.jdt.core.javabuilder");
        newCommands[commands.length] = javaCommand;
       
        ICommand droolsCommand = description.newCommand();
        droolsCommand.setBuilderName("org.drools.eclipse.droolsbuilder");
        newCommands[commands.length + 1] = droolsCommand;
       
        description.setBuildSpec(newCommands);
        project.getProject().setDescription(description, monitor);
    }
View Full Code Here

   * (non-Javadoc)
   *
   * @see org.eclipse.core.resources.IProjectNature#configure()
   */
  public void configure() throws CoreException {
    IProjectDescription desc = project.getDescription();
    ICommand[] commands = desc.getBuildSpec();

    for (int i = 0; i < commands.length; ++i) {
      if (commands[i].getBuilderName().equals(SampleBuilder.BUILDER_ID)) {
        return;
      }
    }

    ICommand[] newCommands = new ICommand[commands.length + 1];
    System.arraycopy(commands, 0, newCommands, 0, commands.length);
    ICommand command = desc.newCommand();
    command.setBuilderName(SampleBuilder.BUILDER_ID);
    newCommands[newCommands.length - 1] = command;
    desc.setBuildSpec(newCommands);
    project.setDescription(desc, null);
  }
View Full Code Here

   * (non-Javadoc)
   *
   * @see org.eclipse.core.resources.IProjectNature#deconfigure()
   */
  public void deconfigure() throws CoreException {
    IProjectDescription description = getProject().getDescription();
    ICommand[] commands = description.getBuildSpec();
    for (int i = 0; i < commands.length; ++i) {
      if (commands[i].getBuilderName().equals(SampleBuilder.BUILDER_ID)) {
        ICommand[] newCommands = new ICommand[commands.length - 1];
        System.arraycopy(commands, 0, newCommands, 0, i);
        System.arraycopy(commands, i + 1, newCommands, i,
            commands.length - i - 1);
        description.setBuildSpec(newCommands);
        return;
      }
    }
  }
View Full Code Here

    }
  }

  static void importExistingProject(IProject project, String location, String name) throws CoreException {
    IPath path = new Path(location).append(".project");
    IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription(path);
    description.setName(name);
    try {
      project.create(description, new NullProgressMonitor());
      project.open(IResource.BACKGROUND_REFRESH, new NullProgressMonitor());
      ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
    } catch (Exception e) {
View Full Code Here

            return xmlFolder;
    }
      

        private void setJavaNature() throws CoreException {
                IProjectDescription description= project.getDescription();
                description.setNatureIds(new String[] { JavaCore.NATURE_ID });
                project.setDescription(description, null);
        }
View Full Code Here

   * @param project
   *            to have sample nature added or removed
   */
  private void toggleNature(IProject project) {
    try {
      IProjectDescription description = project.getDescription();
      String[] natures = description.getNatureIds();

      for (int i = 0; i < natures.length; ++i) {
        if (FlashdoctorsNature.NATURE_ID.equals(natures[i])) {
          // Remove the nature
          String[] newNatures = new String[natures.length - 1];
          System.arraycopy(natures, 0, newNatures, 0, i);
          System.arraycopy(natures, i + 1, newNatures, i, natures.length - i - 1);
          description.setNatureIds(newNatures);
          project.setDescription(description, null);
          return;
        }
      }

      // Add the nature
      String[] newNatures = new String[natures.length + 1];
      System.arraycopy(natures, 0, newNatures, 0, natures.length);
      newNatures[natures.length] = FlashdoctorsNature.NATURE_ID;
      description.setNatureIds(newNatures);
      project.setDescription(description, null);
    } catch (CoreException e) {
      throw new RuntimeException(e.getMessage());
    }
  }
View Full Code Here

    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot myWorkspaceRoot = workspace.getRoot();

    final IProject newProjectHandle = myWorkspaceRoot.getProject(projectName);
    final IProjectDescription description = workspace.newProjectDescription(projectName);

    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
      protected void execute(IProgressMonitor monitor) throws CoreException {
        createProject(description, newProjectHandle, monitor);
      }
    };

    try {
      getContainer().run(true, true, operation);
    } catch (InterruptedException e) {
      throw new RuntimeException("InterruptedException::" + e.getMessage());
    } catch (InvocationTargetException e) {
      throw new RuntimeException("InvocationTargetException::" + e.getMessage());
    }

    // Add Flashdoctors Nature.
    String[] natures = description.getNatureIds();

    String[] newNatures = new String[natures.length + 1];
    System.arraycopy(natures, 0, newNatures, 0, natures.length);
    newNatures[natures.length] = FlashdoctorsNature.NATURE_ID;
    description.setNatureIds(newNatures);
    newProjectHandle.setDescription(description, null);

  }
View Full Code Here

TOP

Related Classes of org.eclipse.core.resources.IProjectDescription

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.