KickJava   Java API By Example, From Geeks To Geeks.

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


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.PropertyChangeListener JavaDoc;
23 import java.beans.PropertyChangeSupport JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Hashtable JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import org.openide.cookies.InstanceCookie;
29 import org.openide.filesystems.Repository;
30 import org.openide.loaders.DataFolder;
31 import org.openide.loaders.DataObject;
32 import org.openide.util.TaskListener;
33
34
35 /** Folder of all installed BaseOptions subClasses, like JavaOptions,
36  * HTMLOptions ...
37  * Options can be initialized by XML layer for example JavaOptions are
38  * initialized via:
39  * <folder name="Editors">
40  * <folder name="Options">
41  * <folder name="Installed">
42  * <file name="org-netbeans-modules-editor-options-JavaOptions.instance">
43  * <attr name="instanceClass" stringvalue="org.netbeans.modules.editor.options.JavaOptions"/>
44  * <attr name="instanceCreate" methodvalue="org.netbeans.modules.editor.options.JavaOptions.JavaOptions"/>
45  * </file>
46  * </folder>
47  * </folder>
48  * </folder>
49  *
50  * @author Martin Roskanin
51  * @since 08/2001
52  */

53 public class InstalledOptionsFolder extends org.openide.loaders.FolderInstance
54 implements TaskListener{
55     
56     /** folder for itutor options XML files */
57     public static final String JavaDoc FOLDER = "Editors/Options/Installed"; // NOI18N
58

59     private static Map JavaDoc globalMPFolder = new HashMap JavaDoc();
60     
61     /** instance of this class */
62     private static InstalledOptionsFolder settingsFolder;
63     
64     /** Map of installed MIME Options */
65     private static Map JavaDoc installedOptions = new Hashtable JavaDoc();
66     
67     private static PropertyChangeSupport JavaDoc propertySupport;
68     
69     public static final String JavaDoc INSTALLED_OPTIONS = "installedOptions"; // NOI18N
70

71     private static Map JavaDoc installedOld = new HashMap JavaDoc();
72     
73     /** Creates new InstalledOptionsFolder */
74     private InstalledOptionsFolder(DataFolder fld) {
75         super(fld);
76         propertySupport = new PropertyChangeSupport JavaDoc( this );
77         addTaskListener(this);
78         recreate();
79     }
80     
81     /** Creates the only instance of InstalledOptionsFolder. */
82     public static synchronized InstalledOptionsFolder getDefault(){
83         if (settingsFolder!=null) return settingsFolder;
84         
85         org.openide.filesystems.FileObject f = Repository.getDefault().getDefaultFileSystem().
86         findResource(FOLDER);
87         if (f==null) return null;
88         
89         DataFolder df = DataFolder.findFolder(f);
90         if (df != null){
91             if (settingsFolder == null){
92                 settingsFolder = new InstalledOptionsFolder(df);
93                 return settingsFolder;
94             }
95         }
96         return null;
97     }
98     
99     /** Creates a new instance of XML files.
100      * In this folder are stored instances of MIME options like JavaOptions,
101      * HTMLOptions, PlainOptions ... */

102     protected Object JavaDoc createInstance(InstanceCookie[] cookies)
103     throws java.io.IOException JavaDoc, ClassNotFoundException JavaDoc {
104         for (int i = 0; i < cookies.length; i++) {
105             System.out.println("installing:"+cookies[i].instanceName()); // NOI18N
106
if (!installedOptions.containsKey(cookies[i].instanceName())){
107                 Object JavaDoc instance = cookies[i].instanceCreate();
108                 if (!(instance instanceof BaseOptions)){
109                     System.out.println("it is not instance of BO !!!"); // NOI18N
110
continue;
111                 }
112                 BaseOptions bop = (BaseOptions) instance;
113                 System.out.println("installed"); // NOI18N
114
installedOptions.put(bop.getKitClass(), bop);
115             }
116         }
117         return null;
118     }
119     
120     /** Adds listener to this folder */
121     public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
122         propertySupport.addPropertyChangeListener(listener);
123     }
124     
125     /** Removes listener from this folder */
126     public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
127         propertySupport.removePropertyChangeListener(listener);
128     }
129     
130     /** Some MIME options were added or removed, fire the event */
131     public void taskFinished(org.openide.util.Task task) {
132         propertySupport.firePropertyChange(INSTALLED_OPTIONS, installedOld, installedOptions);
133         installedOld.putAll(installedOptions);
134     }
135     
136 }
137
Popular Tags