KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbjarproject > ui > logicalview > libraries > 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.j2ee.ejbjarproject.ui.logicalview.libraries;
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import javax.swing.Icon JavaDoc;
24 import org.openide.ErrorManager;
25 import org.openide.filesystems.FileObject;
26 import org.openide.filesystems.FileStateInvalidException;
27 import org.openide.filesystems.FileUtil;
28 import org.netbeans.api.project.SourceGroup;
29
30
31 /**
32  * LibrariesSourceGroup
33  * {@link SourceGroup} implementation passed to
34  * {@link org.netbeans.spi.java.project.support.ui.PackageView#createPackageView(SourceGroup)}
35  * @author Tomas Zezula
36  */

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

49     LibrariesSourceGroup (FileObject root, String JavaDoc displayName ) {
50         this (root, displayName, null, null);
51     }
52
53     /**
54      * Creates new LibrariesSourceGroup
55      * @param root the classpath root
56      * @param displayName the display name presented to user
57      * @param icon closed icon
58      * @param openIcon opened icon
59      */

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