01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 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.ui.javadocexport;
11:
12: import java.net.URL;
13:
14: import org.eclipse.core.runtime.CoreException;
15: import org.eclipse.core.runtime.IPath;
16: import org.eclipse.core.runtime.IProgressMonitor;
17:
18: import org.eclipse.jdt.core.IClasspathEntry;
19: import org.eclipse.jdt.core.IJavaProject;
20:
21: import org.eclipse.jdt.ui.JavaUI;
22:
23: import org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathSupport;
24: import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListElement;
25:
26: public class JavadocLinkRef {
27: private final IJavaProject fProject;
28: private final IPath fContainerPath;
29: private IClasspathEntry fClasspathEntry;
30:
31: public JavadocLinkRef(IPath containerPath,
32: IClasspathEntry classpathEntry, IJavaProject project) {
33: fContainerPath = containerPath;
34: fProject = project;
35: fClasspathEntry = classpathEntry;
36: }
37:
38: public JavadocLinkRef(IJavaProject project) {
39: this (null, null, project);
40: }
41:
42: public boolean isProjectRef() {
43: return fClasspathEntry == null;
44: }
45:
46: public IPath getFullPath() {
47: return isProjectRef() ? fProject.getPath() : fClasspathEntry
48: .getPath();
49: }
50:
51: public URL getURL() {
52: if (isProjectRef()) {
53: return JavaUI.getProjectJavadocLocation(fProject);
54: } else {
55: return JavaUI.getLibraryJavadocLocation(fClasspathEntry);
56: }
57: }
58:
59: public void setURL(URL url, IProgressMonitor monitor)
60: throws CoreException {
61: if (isProjectRef()) {
62: JavaUI.setProjectJavadocLocation(fProject, url);
63: } else {
64: CPListElement element = CPListElement.createFromExisting(
65: fClasspathEntry, fProject);
66: String location = url != null ? url.toExternalForm() : null;
67: element.setAttribute(CPListElement.JAVADOC, location);
68: String[] changedAttributes = { CPListElement.JAVADOC };
69: BuildPathSupport.modifyClasspathEntry(null, element
70: .getClasspathEntry(), changedAttributes, fProject,
71: fContainerPath, monitor);
72: fClasspathEntry = element.getClasspathEntry();
73: }
74: }
75:
76: public boolean equals(Object obj) {
77: if (obj != null && obj.getClass().equals(getClass())) {
78: JavadocLinkRef other = (JavadocLinkRef) obj;
79: if (!fProject.equals(other.fProject)
80: || isProjectRef() != other.isProjectRef()) {
81: return false;
82: }
83: if (!isProjectRef()) {
84: return !fClasspathEntry.equals(other.fClasspathEntry);
85: }
86: }
87: return false;
88: }
89:
90: public int hashCode() {
91: if (isProjectRef()) {
92: return fProject.hashCode();
93: } else {
94: return fProject.hashCode() + fClasspathEntry.hashCode();
95: }
96:
97: }
98: }
|