01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.corext.buildpath;
11:
12: import java.util.ArrayList;
13: import java.util.Iterator;
14: import java.util.List;
15:
16: import org.eclipse.core.runtime.CoreException;
17: import org.eclipse.core.runtime.IPath;
18:
19: import org.eclipse.jdt.core.IClasspathEntry;
20: import org.eclipse.jdt.core.IJavaProject;
21:
22: import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListElement;
23:
24: public class CPJavaProject {
25:
26: public static CPJavaProject createFromExisting(
27: IJavaProject javaProject) throws CoreException {
28: List classpathEntries = ClasspathModifier
29: .getExistingEntries(javaProject);
30: return new CPJavaProject(classpathEntries, javaProject
31: .getOutputLocation());
32: }
33:
34: private final List fCPListElements;
35: private IPath fDefaultOutputLocation;
36:
37: public CPJavaProject(List cpListElements,
38: IPath defaultOutputLocation) {
39: fCPListElements = cpListElements;
40: fDefaultOutputLocation = defaultOutputLocation;
41: }
42:
43: public CPJavaProject createWorkingCopy() {
44: List newList = new ArrayList(fCPListElements.size());
45: for (Iterator iterator = fCPListElements.iterator(); iterator
46: .hasNext();) {
47: CPListElement element = (CPListElement) iterator.next();
48: newList.add(element.copy());
49: }
50: return new CPJavaProject(newList, fDefaultOutputLocation);
51: }
52:
53: public CPListElement get(int index) {
54: return (CPListElement) fCPListElements.get(index);
55: }
56:
57: public IClasspathEntry[] getClasspathEntries() {
58: IClasspathEntry[] result = new IClasspathEntry[fCPListElements
59: .size()];
60: int i = 0;
61: for (Iterator iterator = fCPListElements.iterator(); iterator
62: .hasNext();) {
63: CPListElement element = (CPListElement) iterator.next();
64: result[i] = element.getClasspathEntry();
65: i++;
66: }
67: return result;
68: }
69:
70: public CPListElement getCPElement(CPListElement element) {
71: return ClasspathModifier.getClasspathEntry(fCPListElements,
72: element);
73: }
74:
75: public List getCPListElements() {
76: return fCPListElements;
77: }
78:
79: public IPath getDefaultOutputLocation() {
80: return fDefaultOutputLocation;
81: }
82:
83: public IJavaProject getJavaProject() {
84: return ((CPListElement) fCPListElements.get(0))
85: .getJavaProject();
86: }
87:
88: public int indexOf(CPListElement element) {
89: return fCPListElements.indexOf(element);
90: }
91:
92: public void setDefaultOutputLocation(IPath path) {
93: fDefaultOutputLocation = path;
94: }
95: }
|