KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > CoreUtility


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core;
12
13 import org.eclipse.core.resources.*;
14 import org.eclipse.core.runtime.*;
15
16
17 public class CoreUtility {
18
19     public static void addNatureToProject(IProject proj, String JavaDoc natureId,
20             IProgressMonitor monitor) throws CoreException {
21         IProjectDescription description = proj.getDescription();
22         String JavaDoc[] prevNatures = description.getNatureIds();
23         String JavaDoc[] newNatures = new String JavaDoc[prevNatures.length + 1];
24         System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
25         newNatures[prevNatures.length] = natureId;
26         description.setNatureIds(newNatures);
27         proj.setDescription(description, monitor);
28     }
29     
30     public static void createFolder(IFolder folder, boolean force,
31             boolean local, IProgressMonitor monitor) throws CoreException {
32         if (!folder.exists()) {
33             IContainer parent = folder.getParent();
34             if (parent instanceof IFolder) {
35                 createFolder((IFolder) parent, force, local, monitor);
36             }
37             folder.create(force, local, monitor);
38         }
39     }
40
41     public static void createProject(IProject project, IPath location,
42             IProgressMonitor monitor) throws CoreException {
43         if (!Platform.getLocation().equals(location)) {
44             IProjectDescription desc = project.getWorkspace()
45                     .newProjectDescription(project.getName());
46             desc.setLocation(location);
47             project.create(desc, monitor);
48         } else
49             project.create(monitor);
50     }
51 }
52
Popular Tags