KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > CoreBridgeImpl


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 package org.netbeans.core;
20
21 import java.beans.PropertyEditorManager JavaDoc;
22 import java.io.File JavaDoc;
23 import java.io.InputStream JavaDoc;
24 import java.io.OutputStream JavaDoc;
25 import java.io.PrintWriter JavaDoc;
26 import org.netbeans.core.startup.Main;
27 import org.netbeans.core.startup.ManifestSection;
28
29 /** Implements necessary callbacks from module system.
30  *
31  * @author Jaroslav Tulach
32  */

33 public final class CoreBridgeImpl extends org.netbeans.core.startup.CoreBridge
34 implements Runnable JavaDoc {
35     /** counts the number of CLI invocations */
36     private int numberOfCLIInvocations;
37
38
39     protected void attachToCategory (Object JavaDoc category) {
40         ModuleActions.attachTo(category);
41     }
42     
43     protected void loadDefaultSection (
44         org.netbeans.core.startup.ManifestSection s,
45         org.openide.util.lookup.InstanceContent.Convertor<ManifestSection,Object JavaDoc> convertor,
46         boolean load
47     ) {
48         if (load) {
49             if (convertor != null) {
50                 NbTopManager.get().register(s, convertor);
51             } else {
52                 NbTopManager.get().register(s);
53             }
54         } else {
55             if (convertor != null) {
56                 NbTopManager.get().unregister(s, convertor);
57             } else {
58                 NbTopManager.get().unregister(s);
59             }
60         }
61     }
62     
63     protected void loadActionSection(ManifestSection.ActionSection s, boolean load) throws Exception JavaDoc {
64         if (load) {
65             ModuleActions.add(s);
66         } else {
67             ModuleActions.remove(s);
68         }
69     }
70     
71     protected void loadLoaderSection(ManifestSection.LoaderSection s, boolean load) throws Exception JavaDoc {
72         if (load) {
73             LoaderPoolNode.add(s);
74         } else {
75             LoaderPoolNode.remove((org.openide.loaders.DataLoader)s.getInstance());
76         }
77     }
78     
79     protected void loaderPoolTransaction (boolean begin) {
80         if (begin) {
81             LoaderPoolNode.beginUpdates();
82         } else {
83             LoaderPoolNode.endUpdates();
84         }
85     }
86     
87     public void setStatusText (String JavaDoc status) {
88         org.openide.awt.StatusDisplayer.getDefault().setStatusText(status);
89     }
90
91     public void initializePlaf (Class JavaDoc uiClass, int uiFontSize, java.net.URL JavaDoc themeURL) {
92           org.netbeans.swing.plaf.Startup.run(uiClass, uiFontSize, themeURL);
93     }
94
95     public org.openide.util.Lookup lookupCacheLoad () {
96         return LookupCache.load ();
97     }
98     public void lookupCacheStore (org.openide.util.Lookup l) throws java.io.IOException JavaDoc {
99         LookupCache.store (l);
100     }
101
102     public void cliUsage(PrintWriter JavaDoc printWriter) {
103         // nothing for now
104
}
105
106     public int cli(
107         String JavaDoc[] string,
108         InputStream JavaDoc inputStream,
109         OutputStream JavaDoc outputStream,
110         OutputStream JavaDoc errorStream,
111         File JavaDoc file
112     ) {
113         /*
114         try {
115             org.netbeans.api.sendopts.CommandLine.getDefault().parse(
116                 string, inputStream, outputStream, file
117             );
118             for (int i = 0; i < string.length; i++) {
119                 string[i] = null;
120             }
121         } catch (CommandException ex) {
122             ex.printStackTrace();
123             return ex.getExitCode();
124         }
125          */

126         
127         if (numberOfCLIInvocations++ == 0) return 0;
128         
129         /*
130         for (int i = 0; i < args.length; i++) {
131             if ("--nofront".equals (args[i])) {
132                 return 0;
133             }
134         }
135          */

136         javax.swing.SwingUtilities.invokeLater (this);
137         
138         return 0;
139     }
140     
141     public void run () {
142         java.awt.Frame JavaDoc f = org.openide.windows.WindowManager.getDefault ().getMainWindow ();
143
144         // makes sure the frame is visible
145
f.setVisible(true);
146         // uniconifies the frame if it is inconified
147
if ((f.getExtendedState () & java.awt.Frame.ICONIFIED) != 0) {
148             f.setExtendedState (~java.awt.Frame.ICONIFIED & f.getExtendedState ());
149         }
150         // moves it to front and requests focus
151
f.toFront ();
152         
153     }
154
155     public void registerPropertyEditors() {
156         doRegisterPropertyEditors();
157     }
158
159     /**Flag to avoid multiple adds of the same path to the
160      * of PropertyEditorManager if multiple tests call
161      * registerPropertyEditors() */

162     private static boolean editorsRegistered=false;
163     /** Register NB specific property editors.
164      * Allows property editor unit tests to work correctly without
165      * initializing full NetBeans environment.
166      * @since 1.98 */

167     private static final void doRegisterPropertyEditors() {
168         //issue 31879
169
if (editorsRegistered) return;
170         String JavaDoc[] syspesp = PropertyEditorManager.getEditorSearchPath();
171         String JavaDoc[] nbpesp = new String JavaDoc[] {
172             "org.netbeans.beaninfo.editors", // NOI18N
173
"org.openide.explorer.propertysheet.editors", // NOI18N
174
};
175         String JavaDoc[] allpesp = new String JavaDoc[syspesp.length + nbpesp.length];
176         System.arraycopy(nbpesp, 0, allpesp, 0, nbpesp.length);
177         System.arraycopy(syspesp, 0, allpesp, nbpesp.length, syspesp.length);
178         PropertyEditorManager.setEditorSearchPath(allpesp);
179         PropertyEditorManager.registerEditor (java.lang.Character.TYPE, org.netbeans.beaninfo.editors.CharEditor.class);
180         PropertyEditorManager.registerEditor(String JavaDoc[].class, org.netbeans.beaninfo.editors.StringArrayEditor.class);
181         // bugfix #28676, register editor for a property which type is array of data objects
182
PropertyEditorManager.registerEditor(org.openide.loaders.DataObject[].class, org.netbeans.beaninfo.editors.DataObjectArrayEditor.class);
183         // use replacement hintable/internationalizable primitive editors - issues 20376, 5278
184
PropertyEditorManager.registerEditor (Integer.TYPE, org.netbeans.beaninfo.editors.IntEditor.class);
185         PropertyEditorManager.registerEditor (Boolean.TYPE, org.netbeans.beaninfo.editors.BoolEditor.class);
186         editorsRegistered = true;
187     }
188
189     protected void loadSettings() {}
190
191 }
192
Popular Tags