KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > LibrariesSourceGroup


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project.ui;
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import javax.swing.Icon JavaDoc;
24 import org.netbeans.api.project.SourceGroup;
25 import org.openide.ErrorManager;
26 import org.openide.filesystems.FileObject;
27 import org.openide.filesystems.FileStateInvalidException;
28 import org.openide.filesystems.FileUtil;
29
30 // XXX this class is more or less copy-pasted from j2seproject.
31
// Get rid of it as soon as "some" Libraries Node API is provided.
32

33 /**
34  * LibrariesSourceGroup
35  * {@link SourceGroup} implementation passed to
36  * {@link org.netbeans.spi.java.project.support.ui.PackageView#createPackageView(SourceGroup)}
37  * @author Tomas Zezula
38  */

39 final class LibrariesSourceGroup implements SourceGroup {
40     
41     private final FileObject root;
42     private final String JavaDoc displayName;
43     private final Icon JavaDoc icon;
44     private final Icon JavaDoc openIcon;
45     
46     /**
47      * Creates new LibrariesSourceGroup
48      * @param root the classpath root
49      * @param displayName the display name presented to user
50      * @param icon closed icon
51      * @param openIcon opened icon
52      */

53     LibrariesSourceGroup(FileObject root, String JavaDoc displayName, Icon JavaDoc icon, Icon JavaDoc openIcon) {
54         assert root != null;
55         this.root = root;
56         this.displayName = displayName;
57         this.icon = icon;
58         this.openIcon = openIcon;
59     }
60     
61     public FileObject getRootFolder() {
62         return this.root;
63     }
64     
65     public String JavaDoc getName() {
66         try {
67             return root.getURL().toExternalForm();
68         } catch (FileStateInvalidException fsi) {
69             ErrorManager.getDefault().notify(fsi);
70             return root.toString();
71         }
72     }
73     
74     public String JavaDoc getDisplayName() {
75         return this.displayName;
76     }
77     
78     public Icon JavaDoc getIcon(boolean opened) {
79         return opened ? openIcon : icon;
80     }
81     
82     public boolean contains(FileObject file) throws IllegalArgumentException JavaDoc {
83         return root.equals(file) || FileUtil.isParentOf(root,file);
84     }
85     
86     public boolean equals(Object JavaDoc other) {
87         if (!(other instanceof LibrariesSourceGroup)) {
88             return false;
89         }
90         LibrariesSourceGroup osg = (LibrariesSourceGroup) other;
91         return displayName == null ? osg.displayName == null : displayName.equals(osg.displayName) &&
92                 root == null ? osg.root == null : root.equals(osg.root);
93     }
94     
95     public int hashCode() {
96         return ((displayName == null ? 0 : displayName.hashCode())<<16) | ((root==null ? 0 : root.hashCode()) & 0xffff);
97     }
98     
99     public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
100         //Not needed
101
}
102     
103     public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
104         //Not needed
105
}
106     
107 }
108
Popular Tags