KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > editor > options > AllOptionsNode


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.editor.options;
21
22 import java.beans.IntrospectionException JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import org.netbeans.modules.editor.NbEditorSettingsInitializer;
25 import org.openide.filesystems.FileChangeAdapter;
26 import org.openide.filesystems.FileChangeListener;
27 import org.openide.filesystems.FileEvent;
28 import org.openide.filesystems.FileObject;
29 import org.openide.filesystems.FileUtil;
30 import org.openide.filesystems.Repository;
31 import org.openide.nodes.BeanNode;
32 import org.openide.nodes.FilterNode;
33 import org.openide.nodes.Node;
34 import org.openide.util.HelpCtx;
35 import org.openide.util.NbBundle;
36
37 /** Node representing the Editor Settings main node.
38  *
39  * @author Martin Roskanin
40  * @since 08/2001
41  */

42 public class AllOptionsNode extends FilterNode {
43     
44     private static final String JavaDoc HELP_ID = "editing.global"; // !!! NOI18N
45

46     /** Creates new AllOptionsNode as BeanNode with Children.Array */
47     public AllOptionsNode() throws IntrospectionException JavaDoc {
48         super(new BeanNode(AllOptionsFolder.getDefault()), new EditorSubnodes());
49         NbEditorSettingsInitializer.init();
50     }
51     
52     /** Gets display name of all options node from bundle */
53     public String JavaDoc getDisplayName(){
54         return NbBundle.getMessage(AllOptionsNode.class, "OPTIONS_all"); //NOI18N
55
}
56
57     public String JavaDoc getShortDescription(){
58         return null;
59     }
60     
61     // #7925
62
public boolean canDestroy() {
63         return false;
64     }
65     
66     public HelpCtx getHelpCtx () {
67         return new HelpCtx (HELP_ID);
68     }
69     
70     /** Class representing subnodes of Editor Settings node.*/
71     private static class EditorSubnodes extends Children.Keys {
72
73         /** Listens to changes on the Modules folder */
74         private FileChangeListener moduleRegListener;
75         
76         /** Constructor.*/
77         EditorSubnodes() {
78             super();
79         }
80         
81         private void mySetKeys() {
82             setKeys(AllOptionsFolder.getDefault().getInstalledOptions());
83         }
84         
85         /** Called to notify that the children has lost all of its references to
86          * its nodes associated to keys and that the keys could be cleared without
87          * affecting any nodes (because nobody listens to that nodes).
88          * Overrides superclass method. */

89         protected void removeNotify () {
90             setKeys(new ArrayList JavaDoc());
91         }
92         
93         /** Called to notify that the children has been asked for children
94          * after and that they should set its keys. Overrides superclass method. */

95         protected void addNotify() {
96             mySetKeys();
97             
98             // listener
99
if(moduleRegListener == null) {
100                 moduleRegListener = new FileChangeAdapter() {
101                     public void fileChanged(FileEvent fe){
102                         mySetKeys();
103                     }
104                 };
105                 
106                 FileObject moduleRegistry = Repository.getDefault().getDefaultFileSystem().findResource("Modules"); //NOI18N
107

108                 if (moduleRegistry !=null){ //NOI18N
109
moduleRegistry.addFileChangeListener(
110                         FileUtil.weakFileChangeListener(moduleRegListener, moduleRegistry));
111                 }
112             }
113         }
114        
115         
116         /** Create nodes for a given key.
117          * @param key the key
118          * @return child nodes for this key or null if there should be no
119          * nodes for this key
120          */

121         protected Node[] createNodes(Object JavaDoc key) {
122             if(key == null)
123                 return null;
124
125             if(!(key instanceof Class JavaDoc))
126                 return null;
127             
128             BaseOptions baseOptions
129             = (BaseOptions)BaseOptions.findObject((Class JavaDoc)key, true);
130             
131             if (baseOptions == null) return null;
132             
133             return new Node[] {baseOptions.getMimeNode()/* #18678 */.cloneNode()};
134         }
135         
136     }
137     
138 }
139
Popular Tags