001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.core;
042:
043: import java.beans.PropertyEditorManager;
044: import java.io.File;
045: import java.io.InputStream;
046: import java.io.OutputStream;
047: import java.io.PrintWriter;
048: import org.netbeans.core.startup.Main;
049: import org.netbeans.core.startup.ManifestSection;
050: import org.netbeans.core.startup.StartLog;
051: import org.openide.filesystems.FileObject;
052: import org.openide.filesystems.Repository;
053: import org.openide.loaders.DataFolder;
054: import org.openide.util.Exceptions;
055: import org.openide.util.Lookup;
056:
057: /** Implements necessary callbacks from module system.
058: *
059: * @author Jaroslav Tulach
060: */
061: public final class CoreBridgeImpl extends
062: org.netbeans.core.startup.CoreBridge implements Runnable {
063: /** counts the number of CLI invocations */
064: private int numberOfCLIInvocations;
065:
066: protected void attachToCategory(Object category) {
067: ModuleActions.attachTo(category);
068: }
069:
070: protected void loadDefaultSection(
071: org.netbeans.core.startup.ManifestSection s,
072: org.openide.util.lookup.InstanceContent.Convertor<ManifestSection, Object> convertor,
073: boolean load) {
074: if (load) {
075: if (convertor != null) {
076: NbTopManager.get().register(s, convertor);
077: } else {
078: NbTopManager.get().register(s);
079: }
080: } else {
081: if (convertor != null) {
082: NbTopManager.get().unregister(s, convertor);
083: } else {
084: NbTopManager.get().unregister(s);
085: }
086: }
087: }
088:
089: protected void loadActionSection(ManifestSection.ActionSection s,
090: boolean load) throws Exception {
091: if (load) {
092: ModuleActions.add(s);
093: } else {
094: ModuleActions.remove(s);
095: }
096: }
097:
098: protected void loadLoaderSection(ManifestSection.LoaderSection s,
099: boolean load) throws Exception {
100: if (load) {
101: LoaderPoolNode.add(s);
102: } else {
103: LoaderPoolNode.remove((org.openide.loaders.DataLoader) s
104: .getInstance());
105: }
106: }
107:
108: protected void loaderPoolTransaction(boolean begin) {
109: if (begin) {
110: LoaderPoolNode.beginUpdates();
111: } else {
112: LoaderPoolNode.endUpdates();
113: }
114: }
115:
116: public void setStatusText(String status) {
117: org.openide.awt.StatusDisplayer.getDefault().setStatusText(
118: status);
119: }
120:
121: public void initializePlaf(Class uiClass, int uiFontSize,
122: java.net.URL themeURL) {
123: org.netbeans.swing.plaf.Startup.run(uiClass, uiFontSize,
124: themeURL);
125: }
126:
127: public org.openide.util.Lookup lookupCacheLoad() {
128: FileObject services = Repository.getDefault()
129: .getDefaultFileSystem().findResource("Services"); // NOI18N
130: if (services != null) {
131: StartLog.logProgress("Got Services folder"); // NOI18N
132: DataFolder servicesF;
133: try {
134: servicesF = DataFolder.findFolder(services);
135: } catch (RuntimeException e) {
136: Exceptions.printStackTrace(e);
137: return Lookup.EMPTY;
138: }
139: org.openide.loaders.FolderLookup f = new org.openide.loaders.FolderLookup(
140: servicesF, "SL["); // NOI18N
141: StartLog.logProgress("created FolderLookup"); // NOI18N
142: return f.getLookup();
143: } else {
144: return Lookup.EMPTY;
145: }
146: }
147:
148: public void cliUsage(PrintWriter printWriter) {
149: // nothing for now
150: }
151:
152: public int cli(String[] string, InputStream inputStream,
153: OutputStream outputStream, OutputStream errorStream,
154: File file) {
155: /*
156: try {
157: org.netbeans.api.sendopts.CommandLine.getDefault().parse(
158: string, inputStream, outputStream, file
159: );
160: for (int i = 0; i < string.length; i++) {
161: string[i] = null;
162: }
163: } catch (CommandException ex) {
164: ex.printStackTrace();
165: return ex.getExitCode();
166: }
167: */
168:
169: if (numberOfCLIInvocations++ == 0)
170: return 0;
171:
172: /*
173: for (int i = 0; i < args.length; i++) {
174: if ("--nofront".equals (args[i])) {
175: return 0;
176: }
177: }
178: */
179: javax.swing.SwingUtilities.invokeLater(this );
180:
181: return 0;
182: }
183:
184: public void run() {
185: java.awt.Frame f = org.openide.windows.WindowManager
186: .getDefault().getMainWindow();
187:
188: // makes sure the frame is visible
189: f.setVisible(true);
190: // uniconifies the frame if it is inconified
191: if ((f.getExtendedState() & java.awt.Frame.ICONIFIED) != 0) {
192: f.setExtendedState(~java.awt.Frame.ICONIFIED
193: & f.getExtendedState());
194: }
195: // moves it to front and requests focus
196: f.toFront();
197:
198: }
199:
200: public void registerPropertyEditors() {
201: doRegisterPropertyEditors();
202: }
203:
204: /**Flag to avoid multiple adds of the same path to the
205: * of PropertyEditorManager if multiple tests call
206: * registerPropertyEditors() */
207: private static boolean editorsRegistered = false;
208:
209: /** Register NB specific property editors.
210: * Allows property editor unit tests to work correctly without
211: * initializing full NetBeans environment.
212: * @since 1.98 */
213: private static final void doRegisterPropertyEditors() {
214: //issue 31879
215: if (editorsRegistered)
216: return;
217: String[] syspesp = PropertyEditorManager.getEditorSearchPath();
218: String[] nbpesp = new String[] {
219: "org.netbeans.beaninfo.editors", // NOI18N
220: "org.openide.explorer.propertysheet.editors", // NOI18N
221: };
222: String[] allpesp = new String[syspesp.length + nbpesp.length];
223: System.arraycopy(nbpesp, 0, allpesp, 0, nbpesp.length);
224: System.arraycopy(syspesp, 0, allpesp, nbpesp.length,
225: syspesp.length);
226: PropertyEditorManager.setEditorSearchPath(allpesp);
227: PropertyEditorManager.registerEditor(java.lang.Character.TYPE,
228: org.netbeans.beaninfo.editors.CharEditor.class);
229: PropertyEditorManager.registerEditor(String[].class,
230: org.netbeans.beaninfo.editors.StringArrayEditor.class);
231: // bugfix #28676, register editor for a property which type is array of data objects
232: PropertyEditorManager
233: .registerEditor(
234: org.openide.loaders.DataObject[].class,
235: org.netbeans.beaninfo.editors.DataObjectArrayEditor.class);
236: // use replacement hintable/internationalizable primitive editors - issues 20376, 5278
237: PropertyEditorManager.registerEditor(Integer.TYPE,
238: org.netbeans.beaninfo.editors.IntEditor.class);
239: PropertyEditorManager.registerEditor(Boolean.TYPE,
240: org.netbeans.beaninfo.editors.BoolEditor.class);
241: editorsRegistered = true;
242: }
243:
244: protected void loadSettings() {
245: }
246:
247: }
|