1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package org.eclipse.jdt.internal.ui.javadocexport;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IPath;
18 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.jdt.core.IClasspathEntry;
21 import org.eclipse.jdt.core.IJavaProject;
23 import org.eclipse.jdt.ui.JavaUI;
25 import org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathSupport;
26 import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListElement;
29 public class JavadocLinkRef {
30 private final IJavaProject fProject;
31 private final IPath fContainerPath;
32 private IClasspathEntry fClasspathEntry;
34 public JavadocLinkRef(IPath containerPath, IClasspathEntry classpathEntry, IJavaProject project) {
35 fContainerPath= containerPath;
37 fClasspathEntry= classpathEntry;
40 public JavadocLinkRef(IJavaProject project) {
41 this(null, null, project);
44 public boolean isProjectRef() {
45 return fClasspathEntry == null;
48 public IPath getFullPath() {
49 return isProjectRef() ? fProject.getPath() : fClasspathEntry.getPath();
54 return JavaUI.getProjectJavadocLocation(fProject);
56 return JavaUI.getLibraryJavadocLocation(fClasspathEntry);
60 public void setURL(URL url, IProgressMonitor monitor) throws CoreException {
62 JavaUI.setProjectJavadocLocation(fProject, url);
64 CPListElement element= CPListElement.createFromExisting(fClasspathEntry, fProject);
65 String location= url != null ? url.toExternalForm() : null;
66 element.setAttribute(CPListElement.JAVADOC, location);
67 String[] changedAttributes= { CPListElement.JAVADOC };
68 BuildPathSupport.modifyClasspathEntry(null, element.getClasspathEntry(), changedAttributes, fProject, fContainerPath, fClasspathEntry.getReferencingEntry() != null, monitor);
69 fClasspathEntry= element.getClasspathEntry();
74 public boolean equals(Object obj) {
75 if (obj != null && obj.getClass().equals(getClass())) {
76 JavadocLinkRef other= (JavadocLinkRef) obj;
77 if (!fProject.equals(other.fProject) || isProjectRef() != other.isProjectRef()) {
80 if (!isProjectRef()) {
81 return fClasspathEntry.equals(other.fClasspathEntry);
90 public int hashCode() {
92 return fProject.hashCode();
94 return fProject.hashCode() + fClasspathEntry.hashCode();