KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > javadocexport > JavadocLinkRef


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