KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > buildpath > CPJavaProject


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

11 package org.eclipse.jdt.internal.corext.buildpath;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IPath;
19
20 import org.eclipse.jdt.core.IClasspathEntry;
21 import org.eclipse.jdt.core.IJavaProject;
22
23 import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListElement;
24
25 public class CPJavaProject {
26
27     public static CPJavaProject createFromExisting(IJavaProject javaProject) throws CoreException {
28         List JavaDoc classpathEntries= ClasspathModifier.getExistingEntries(javaProject);
29         return new CPJavaProject(classpathEntries, javaProject.getOutputLocation());
30     }
31
32     private final List JavaDoc fCPListElements;
33     private IPath fDefaultOutputLocation;
34
35     public CPJavaProject(List JavaDoc cpListElements, IPath defaultOutputLocation) {
36         fCPListElements= cpListElements;
37         fDefaultOutputLocation= defaultOutputLocation;
38     }
39
40     public CPJavaProject createWorkingCopy() {
41         List JavaDoc newList= new ArrayList JavaDoc(fCPListElements.size());
42         for (Iterator JavaDoc iterator= fCPListElements.iterator(); iterator.hasNext();) {
43             CPListElement element= (CPListElement)iterator.next();
44             newList.add(element.copy());
45         }
46         return new CPJavaProject(newList, fDefaultOutputLocation);
47     }
48
49     public CPListElement get(int index) {
50         return (CPListElement)fCPListElements.get(index);
51     }
52
53     public IClasspathEntry[] getClasspathEntries() {
54         IClasspathEntry[] result= new IClasspathEntry[fCPListElements.size()];
55         int i= 0;
56         for (Iterator JavaDoc iterator= fCPListElements.iterator(); iterator.hasNext();) {
57             CPListElement element= (CPListElement)iterator.next();
58             result[i]= element.getClasspathEntry();
59             i++;
60         }
61         return result;
62     }
63
64     public CPListElement getCPElement(CPListElement element) {
65         return ClasspathModifier.getClasspathEntry(fCPListElements, element);
66     }
67
68     public List JavaDoc getCPListElements() {
69         return fCPListElements;
70     }
71
72     public IPath getDefaultOutputLocation() {
73         return fDefaultOutputLocation;
74     }
75     
76     public IJavaProject getJavaProject() {
77         return ((CPListElement)fCPListElements.get(0)).getJavaProject();
78     }
79
80     public int indexOf(CPListElement element) {
81         return fCPListElements.indexOf(element);
82     }
83
84     public void setDefaultOutputLocation(IPath path) {
85         fDefaultOutputLocation= path;
86     }
87 }
88
Popular Tags