KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > clientproject > 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.j2ee.clientproject.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 /**
31  * LibrariesSourceGroup
32  * {@link SourceGroup} implementation passed to
33  * {@link org.netbeans.spi.java.project.support.ui.PackageView#createPackageView(SourceGroup)}
34  * @author Tomas Zezula
35  */

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

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

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