KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > packageview > LibraryContainer


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.ui.packageview;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.runtime.IAdaptable;
17
18 import org.eclipse.jface.resource.ImageDescriptor;
19
20 import org.eclipse.jdt.core.IClasspathEntry;
21 import org.eclipse.jdt.core.IJavaProject;
22 import org.eclipse.jdt.core.IPackageFragmentRoot;
23 import org.eclipse.jdt.core.JavaModelException;
24
25 import org.eclipse.jdt.internal.ui.JavaPluginImages;
26
27 public class LibraryContainer extends PackageFragmentRootContainer {
28
29     public LibraryContainer(IJavaProject project) {
30         super(project);
31     }
32
33     public boolean equals(Object JavaDoc obj) {
34         if (obj instanceof LibraryContainer) {
35             LibraryContainer other = (LibraryContainer)obj;
36             return getJavaProject().equals(other.getJavaProject());
37         }
38         return false;
39     }
40
41     public int hashCode() {
42         return getJavaProject().hashCode();
43     }
44
45     public IAdaptable[] getChildren() {
46         return getPackageFragmentRoots();
47     }
48
49
50     public ImageDescriptor getImageDescriptor() {
51         return JavaPluginImages.DESC_OBJS_LIBRARY;
52     }
53
54     public String JavaDoc getLabel() {
55         return PackagesMessages.LibraryContainer_name;
56     }
57
58     /* (non-Javadoc)
59      * @see org.eclipse.jdt.internal.ui.packageview.PackageFragmentRootContainer#getPackageFragmentRoots()
60      */

61     public IPackageFragmentRoot[] getPackageFragmentRoots() {
62         List JavaDoc list= new ArrayList JavaDoc();
63         try {
64             IPackageFragmentRoot[] roots= getJavaProject().getPackageFragmentRoots();
65             for (int i= 0; i < roots.length; i++) {
66                 IPackageFragmentRoot root= roots[i];
67                 int classpathEntryKind= root.getRawClasspathEntry().getEntryKind();
68                 if (classpathEntryKind == IClasspathEntry.CPE_LIBRARY || classpathEntryKind == IClasspathEntry.CPE_VARIABLE) {
69                     list.add(root);
70                 }
71             }
72         } catch (JavaModelException e) {
73             // fall through
74
}
75         return (IPackageFragmentRoot[]) list.toArray(new IPackageFragmentRoot[list.size()]);
76     }
77 }
78
Popular Tags