Lines 24-32
Link Here
|
24 |
import java.util.ArrayList; |
24 |
import java.util.ArrayList; |
25 |
import java.util.Iterator; |
25 |
import java.util.Iterator; |
26 |
import java.text.MessageFormat; |
26 |
import java.text.MessageFormat; |
|
|
27 |
import java.util.List; |
27 |
import javax.swing.*; |
28 |
import javax.swing.*; |
28 |
import javax.swing.text.Keymap; |
29 |
import javax.swing.text.Keymap; |
29 |
import javax.swing.border.*; |
30 |
import javax.swing.border.*; |
|
|
31 |
import javax.swing.event.ChangeEvent; |
32 |
import javax.swing.event.ChangeListener; |
30 |
|
33 |
|
31 |
import org.openide.util.datatransfer.ExClipboard; |
34 |
import org.openide.util.datatransfer.ExClipboard; |
32 |
import org.openide.*; |
35 |
import org.openide.*; |
Lines 34-52
Link Here
|
34 |
import org.openide.loaders.*; |
37 |
import org.openide.loaders.*; |
35 |
import org.openide.actions.*; |
38 |
import org.openide.actions.*; |
36 |
import org.openide.cookies.SaveCookie; |
39 |
import org.openide.cookies.SaveCookie; |
37 |
import org.openide.cookies.ProjectCookie; |
|
|
38 |
import org.openide.debugger.Debugger; |
39 |
import org.openide.debugger.DebuggerNotFoundException; |
40 |
import org.openide.filesystems.*; |
40 |
import org.openide.filesystems.*; |
41 |
import org.openide.filesystems.FileSystem; |
41 |
import org.openide.filesystems.FileSystem; |
42 |
import org.openide.filesystems.JarFileSystem; |
42 |
import org.openide.filesystems.JarFileSystem; |
43 |
import org.openide.modules.Dependency; |
43 |
import org.openide.modules.Dependency; |
44 |
import org.openide.modules.SpecificationVersion; |
44 |
import org.openide.modules.SpecificationVersion; |
45 |
import org.openide.options.ControlPanel; |
|
|
46 |
import org.openide.windows.WindowManager; |
45 |
import org.openide.windows.WindowManager; |
47 |
import org.openide.windows.OutputWriter; |
46 |
import org.openide.windows.OutputWriter; |
48 |
import org.openide.windows.InputOutput; |
47 |
import org.openide.windows.InputOutput; |
49 |
import org.openide.windows.TopComponent; |
48 |
import org.openide.windows.TopComponent; |
|
|
49 |
import org.openide.windows.IOProvider; |
50 |
import org.openide.explorer.*; |
50 |
import org.openide.explorer.*; |
51 |
import org.openide.explorer.view.BeanTreeView; |
51 |
import org.openide.explorer.view.BeanTreeView; |
52 |
import org.openide.util.*; |
52 |
import org.openide.util.*; |
Lines 58-73
Link Here
|
58 |
import org.netbeans.core.output.OutputTabTerm; |
58 |
import org.netbeans.core.output.OutputTabTerm; |
59 |
import org.netbeans.core.windows.WindowManagerImpl; |
59 |
import org.netbeans.core.windows.WindowManagerImpl; |
60 |
import org.netbeans.core.execution.TopSecurityManager; |
60 |
import org.netbeans.core.execution.TopSecurityManager; |
|
|
61 |
import org.netbeans.core.modules.Module; |
61 |
import org.netbeans.core.perftool.StartLog; |
62 |
import org.netbeans.core.perftool.StartLog; |
62 |
import org.netbeans.core.modules.ModuleManager; |
63 |
import org.netbeans.core.modules.ModuleManager; |
63 |
import org.netbeans.core.modules.ModuleSystem; |
64 |
import org.netbeans.core.modules.ModuleSystem; |
|
|
65 |
import org.netbeans.core.projects.TrivialProjectManager; |
64 |
import org.netbeans.core.windows.util.WindowUtils; |
66 |
import org.netbeans.core.windows.util.WindowUtils; |
|
|
67 |
import org.openide.modules.ModuleInfo; |
68 |
import org.openide.util.lookup.InstanceContent; |
65 |
|
69 |
|
66 |
/** This class is a TopManager for Corona environment. |
70 |
/** This class is a TopManager for Corona environment. |
67 |
* |
71 |
* |
68 |
* @author Ales Novak, Jaroslav Tulach, Ian Formanek, Petr Hamernik, Jan Jancura, Jesse Glick |
72 |
* @author Ales Novak, Jaroslav Tulach, Ian Formanek, Petr Hamernik, Jan Jancura, Jesse Glick |
69 |
*/ |
73 |
*/ |
70 |
public abstract class NbTopManager extends TopManager { |
74 |
public abstract class NbTopManager /*extends TopManager*/ { |
71 |
/* masks to define the interactivity level */ |
75 |
/* masks to define the interactivity level */ |
72 |
|
76 |
|
73 |
/** initialize the main window? |
77 |
/** initialize the main window? |
Lines 88-101
Link Here
|
88 |
public static final int IL_ALL = 0xffff; |
92 |
public static final int IL_ALL = 0xffff; |
89 |
|
93 |
|
90 |
|
94 |
|
91 |
/** property for status text */ |
|
|
92 |
public static final String PROP_STATUS_TEXT = "statusText"; // NOI18N |
93 |
|
94 |
/** property for system class loader */ |
95 |
public static final String PROP_SYSTEM_CLASS_LOADER = "systemClassLoader"; // NOI18N |
96 |
/** property for current class loader */ |
97 |
public static final String PROP_CURRENT_CLASS_LOADER = "currentClassLoader"; // NOI18N |
98 |
|
99 |
/** stores main shortcut context*/ |
95 |
/** stores main shortcut context*/ |
100 |
private Keymap shortcutContext; |
96 |
private Keymap shortcutContext; |
101 |
|
97 |
|
Lines 110-124
Link Here
|
110 |
/** error manager */ |
106 |
/** error manager */ |
111 |
private static ErrorManager defaultErrorManager; |
107 |
private static ErrorManager defaultErrorManager; |
112 |
|
108 |
|
113 |
/** WWW browser window. */ |
|
|
114 |
private HtmlBrowser.BrowserComponent htmlViewer; |
115 |
|
116 |
/** ProjectOperation main variable */ |
117 |
static NbProjectOperation projectOperation; |
118 |
|
119 |
/** support for listeners */ |
120 |
private PropertyChangeSupport change = new PropertyChangeSupport (this); |
121 |
|
122 |
/** repository */ |
109 |
/** repository */ |
123 |
private Repository defaultRepository; |
110 |
private Repository defaultRepository; |
124 |
|
111 |
|
Lines 128-156
Link Here
|
128 |
/** status text */ |
115 |
/** status text */ |
129 |
private String statusText = " "; // NOI18N |
116 |
private String statusText = " "; // NOI18N |
130 |
|
117 |
|
131 |
/** the debugger listener listening on adding/removing debugger*/ |
|
|
132 |
private static LookupListener debuggerLsnr = null; |
133 |
/** the lookup query finding all registered debuggers */ |
134 |
private static Lookup.Result debuggerLkpRes = null; |
135 |
|
136 |
/** initializes properties about builds etc. */ |
118 |
/** initializes properties about builds etc. */ |
137 |
static { |
119 |
static { |
|
|
120 |
org.openide.filesystems.FileObject fo = null; |
138 |
// Set up module-versioning properties, which logger prints. |
121 |
// Set up module-versioning properties, which logger prints. |
139 |
Package p = Package.getPackage ("org.openide"); // NOI18N |
122 |
// The package here must be one which exists only in openide.jar, not openide-deprecated.jar: |
|
|
123 |
Object ignoreme = FileSystem.class; |
124 |
Package p = Package.getPackage ("org.openide.filesystems"); // NOI18N |
140 |
|
125 |
|
141 |
putSystemProperty ("org.openide.specification.version", p.getSpecificationVersion (), "3.12"); // NOI18N |
126 |
putSystemProperty ("org.openide.specification.version", p.getSpecificationVersion (), "3.14"); // NOI18N |
142 |
putSystemProperty ("org.openide.version", p.getImplementationVersion (), "OwnBuild"); // NOI18N |
127 |
putSystemProperty ("org.openide.version", p.getImplementationVersion (), "OwnBuild"); // NOI18N |
143 |
putSystemProperty ("org.openide.major.version", p.getSpecificationTitle (), "IDE/1"); // NOI18N |
128 |
putSystemProperty ("org.openide.major.version", p.getSpecificationTitle (), "IDE/1"); // NOI18N |
144 |
putSystemProperty ("netbeans.buildnumber", p.getImplementationVersion (), "OwnBuild"); // NOI18N |
129 |
putSystemProperty ("netbeans.buildnumber", p.getImplementationVersion (), "OwnBuild"); // NOI18N |
145 |
|
130 |
|
146 |
if (System.getProperties ().get ("org.openide.util.Lookup") == null) { // NOI18N |
|
|
147 |
// update the top manager to our main if it has not been provided yet |
148 |
System.getProperties().put ( |
149 |
"org.openide.util.Lookup", // NOI18N |
150 |
"org.netbeans.core.NbTopManager$Lkp" // NOI18N |
151 |
); |
152 |
} |
153 |
|
154 |
// Enforce JDK 1.3+ since we would not work without it. |
131 |
// Enforce JDK 1.3+ since we would not work without it. |
155 |
if (Dependency.JAVA_SPEC.compareTo(new SpecificationVersion("1.3")) < 0) { // NOI18N |
132 |
if (Dependency.JAVA_SPEC.compareTo(new SpecificationVersion("1.3")) < 0) { // NOI18N |
156 |
System.err.println("The IDE requires JDK 1.3 or higher to run."); // XXX I18N? |
133 |
System.err.println("The IDE requires JDK 1.3 or higher to run."); // XXX I18N? |
Lines 218-230
Link Here
|
218 |
public NbTopManager() { |
195 |
public NbTopManager() { |
219 |
instanceContent = new InstanceContent (); |
196 |
instanceContent = new InstanceContent (); |
220 |
instanceLookup = new AbstractLookup (instanceContent); |
197 |
instanceLookup = new AbstractLookup (instanceContent); |
221 |
register (ClassLoaderConvertor.CLASSLOADER, ClassLoaderConvertor.CLASSLOADER); |
198 |
if (!(Lookup.getDefault() instanceof Lkp)) { |
|
|
199 |
throw new ClassCastException("Wrong Lookup impl found: " + Lookup.getDefault()); |
200 |
} |
222 |
} |
201 |
} |
223 |
|
202 |
|
224 |
/** Getter for instance of this manager. |
203 |
/** Getter for instance of this manager. |
225 |
*/ |
204 |
*/ |
226 |
public static NbTopManager get () { |
205 |
public static NbTopManager get () { |
227 |
return (NbTopManager)TopManager.getDefault (); |
206 |
// return (NbTopManager)TopManager.getDefault (); |
|
|
207 |
return getNbTopManager(); |
208 |
} |
209 |
|
210 |
private static NbTopManager defaultTopManager; |
211 |
|
212 |
public static synchronized boolean isInitialized () { |
213 |
return defaultTopManager != null; |
214 |
} |
215 |
|
216 |
private static /*synchronized*/ NbTopManager getNbTopManager () { |
217 |
// synchronization check |
218 |
if (defaultTopManager != null) { |
219 |
return defaultTopManager; |
220 |
} |
221 |
|
222 |
// XXX double check like it was in TopManager, otherwise led to deadlock at |
223 |
// start, needs to be revised. |
224 |
synchronized(NbTopManager.class) { |
225 |
String className = System.getProperty( |
226 |
"org.openide.TopManager", // NOI18N |
227 |
"org.netbeans.core.Plain" // NOI18N |
228 |
); |
229 |
|
230 |
try { |
231 |
Class c = Class.forName(className); |
232 |
defaultTopManager = (NbTopManager)c.newInstance(); |
233 |
} catch (Exception ex) { |
234 |
ex.printStackTrace(); |
235 |
throw new IllegalStateException(); |
236 |
} |
237 |
|
238 |
// late initialization of the manager if needed |
239 |
if (defaultTopManager instanceof Runnable) { |
240 |
((Runnable)defaultTopManager).run (); |
241 |
} |
242 |
|
243 |
return defaultTopManager; |
244 |
} |
228 |
} |
245 |
} |
229 |
|
246 |
|
230 |
/** Test method to check whether some level of interactivity is enabled. |
247 |
/** Test method to check whether some level of interactivity is enabled. |
Lines 292-302
Link Here
|
292 |
|
309 |
|
293 |
/** Shows a specified HelpCtx in IDE's help window. |
310 |
/** Shows a specified HelpCtx in IDE's help window. |
294 |
* @param helpCtx thehelp to be shown |
311 |
* @param helpCtx thehelp to be shown |
|
|
312 |
* @deprecated Better to use org.netbeans.api.javahelp.Help |
295 |
*/ |
313 |
*/ |
296 |
public void showHelp(HelpCtx helpCtx) { |
314 |
public void showHelp(HelpCtx helpCtx) { |
297 |
// Awkward but should work. |
315 |
// Awkward but should work. |
298 |
try { |
316 |
try { |
299 |
Class c = systemClassLoader().loadClass("org.netbeans.api.javahelp.Help"); // NOI18N |
317 |
Class c = ((ClassLoader)Lookup.getDefault().lookup(ClassLoader.class)).loadClass("org.netbeans.api.javahelp.Help"); // NOI18N |
300 |
Object o = Lookup.getDefault().lookup(c); |
318 |
Object o = Lookup.getDefault().lookup(c); |
301 |
if (o != null) { |
319 |
if (o != null) { |
302 |
Method m = c.getMethod("showHelp", new Class[] {HelpCtx.class}); // NOI18N |
320 |
Method m = c.getMethod("showHelp", new Class[] {HelpCtx.class}); // NOI18N |
Lines 307-334
Link Here
|
307 |
// ignore - maybe javahelp module is not installed, not so strange |
325 |
// ignore - maybe javahelp module is not installed, not so strange |
308 |
} catch (Exception e) { |
326 |
} catch (Exception e) { |
309 |
// potentially more serious |
327 |
// potentially more serious |
310 |
getErrorManager().notify(ErrorManager.INFORMATIONAL, e); |
328 |
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); |
311 |
} |
329 |
} |
312 |
// Did not work. |
330 |
// Did not work. |
313 |
Toolkit.getDefaultToolkit().beep(); |
331 |
Toolkit.getDefaultToolkit().beep(); |
314 |
} |
332 |
} |
315 |
|
333 |
|
316 |
/** Provides support for www documents. |
334 |
public static final class NbURLDisplayer extends HtmlBrowser.URLDisplayer { |
317 |
* @param url Url of WWW document to be showen. |
335 |
/** WWW browser window. */ |
318 |
*/ |
336 |
HtmlBrowser.BrowserComponent htmlViewer; |
319 |
public void showUrl (URL url) { |
337 |
public void showURL(URL u) { |
320 |
if (htmlViewer == null) htmlViewer = new NbBrowser (); |
338 |
if (htmlViewer == null) htmlViewer = new NbBrowser (); |
321 |
|
339 |
((NbBrowser)htmlViewer).showUrl(u); |
322 |
((NbBrowser)htmlViewer).showUrl (url); |
340 |
} |
323 |
} |
341 |
} |
324 |
|
342 |
|
325 |
private static WindowManager wmgr = null; |
343 |
private static WindowManager wmgr = null; |
|
|
344 |
private static final Object windowManagerLock = new String("NbTopManager.windowManagerLock"); // NOI18N |
326 |
/** @return a window manager impl or null */ |
345 |
/** @return a window manager impl or null */ |
327 |
private static synchronized WindowManager getDefaultWindowManager() { |
346 |
private static WindowManager getDefaultWindowManager() { |
328 |
if (wmgr == null) { |
347 |
synchronized (windowManagerLock) { |
329 |
wmgr = (WindowManager)Lookup.getDefault().lookup(WindowManager.class); |
348 |
if (wmgr == null) { |
|
|
349 |
wmgr = (WindowManager)Lookup.getDefault().lookup(WindowManager.class); |
350 |
} |
351 |
return wmgr; |
330 |
} |
352 |
} |
331 |
return wmgr; |
|
|
332 |
} |
353 |
} |
333 |
/** @return the main window from the window manager impl or null */ |
354 |
/** @return the main window from the window manager impl or null */ |
334 |
static Frame getMainWindow() { |
355 |
static Frame getMainWindow() { |
Lines 354-359
Link Here
|
354 |
} |
375 |
} |
355 |
} |
376 |
} |
356 |
|
377 |
|
|
|
378 |
public static final class NbDialogDisplayer extends DialogDisplayer { |
379 |
|
357 |
/** Creates new dialog. |
380 |
/** Creates new dialog. |
358 |
*/ |
381 |
*/ |
359 |
public Dialog createDialog (final DialogDescriptor d) { |
382 |
public Dialog createDialog (final DialogDescriptor d) { |
Lines 370-389
Link Here
|
370 |
} |
393 |
} |
371 |
}); |
394 |
}); |
372 |
} |
395 |
} |
373 |
|
396 |
|
374 |
/** Opens specified project. Asks to save the previously opened project. |
|
|
375 |
* @exception IOException if error occurs accessing the project |
376 |
* @exception UserCancelException if the selection is interrupted by the user |
377 |
*/ |
378 |
public void openProject (ProjectCookie project) throws IOException, UserCancelException { |
379 |
if (ExitDialog.showDialog (null, true)) { |
380 |
NbProjectOperation.setOpeningProject (project); |
381 |
} |
382 |
else { |
383 |
throw new UserCancelException (); |
384 |
} |
385 |
} |
386 |
|
387 |
/** Notifies user by a dialog. |
397 |
/** Notifies user by a dialog. |
388 |
* @param descriptor description that contains needed informations |
398 |
* @param descriptor description that contains needed informations |
389 |
* @return the option that has been choosen in the notification |
399 |
* @return the option that has been choosen in the notification |
Lines 431-494
Link Here
|
431 |
}); |
441 |
}); |
432 |
} |
442 |
} |
433 |
|
443 |
|
434 |
/** Shows specified text in MainWindow's status line. |
|
|
435 |
* @param text the text to be shown |
436 |
*/ |
437 |
public final void setStatusText(String text) { |
438 |
if (text == null || text.length () == 0) { |
439 |
text = " "; // NOI18N |
440 |
} |
441 |
if (text.equals(statusText)) return; |
442 |
String old = statusText; |
443 |
statusText = text; |
444 |
setStatusTextImpl(text); |
445 |
firePropertyChange (PROP_STATUS_TEXT, old, text); |
446 |
} |
444 |
} |
447 |
protected abstract void setStatusTextImpl(String text); |
|
|
448 |
|
445 |
|
449 |
/** Getter for status text. |
446 |
/** Opens specified project. Asks to save the previously opened project. |
|
|
447 |
* @exception IOException if error occurs accessing the project |
448 |
* @exception UserCancelException if the selection is interrupted by the user |
450 |
*/ |
449 |
*/ |
451 |
public String getStatusText () { |
450 |
// public void openProject (ProjectCookie project) throws IOException, UserCancelException { |
452 |
return statusText; |
451 |
// if (ExitDialog.showDialog (null, true)) { |
453 |
} |
452 |
// NbProjectOperation.setOpeningProject (project); |
|
|
453 |
// } |
454 |
// else { |
455 |
// throw new UserCancelException (); |
456 |
// } |
457 |
// } |
454 |
|
458 |
|
455 |
/** Returns currently installed debugger or throws |
459 |
|
456 |
* DebuggerException (when no debugger is installed) |
460 |
public static final class NbStatusDisplayer extends org.openide.awt.StatusDisplayer { |
457 |
* @return currently installed debugger. |
461 |
private List listeners = null; |
458 |
*/ |
462 |
private String text = ""; // NOI18N |
459 |
public Debugger getDebugger () throws DebuggerNotFoundException { |
463 |
public void setStatusText(String text) { |
460 |
Iterator it = getDebuggerResult().allInstances().iterator(); |
464 |
ChangeListener[] _listeners; |
461 |
if (it.hasNext()) return (Debugger) it.next(); |
465 |
synchronized (this) { |
462 |
throw new DebuggerNotFoundException(); |
466 |
this.text = text; |
463 |
} |
467 |
if (listeners == null || listeners.isEmpty()) { |
464 |
|
468 |
_listeners = null; |
465 |
/** get the lookup query finding all registered debuggers */ |
469 |
} else { |
466 |
private synchronized Lookup.Result getDebuggerResult() { |
470 |
_listeners = (ChangeListener[])listeners.toArray(new ChangeListener[listeners.size()]); |
467 |
if (debuggerLkpRes == null) { |
|
|
468 |
debuggerLkpRes = Lookup.getDefault().lookup(new Lookup.Template(Debugger.class)); |
469 |
} |
470 |
return debuggerLkpRes; |
471 |
} |
472 |
|
473 |
/** fire property change PROP_DEBUGGER */ |
474 |
private void fireDebuggerChange() { |
475 |
firePropertyChange (PROP_DEBUGGER, null, null); |
476 |
} |
477 |
|
478 |
/** initialize listening on adding/removing debugger. */ |
479 |
private void initDebuggerListener() { |
480 |
Lookup.Result res; |
481 |
synchronized (this) { |
482 |
if (debuggerLsnr != null) return; |
483 |
res = getDebuggerResult(); |
484 |
debuggerLsnr = new LookupListener() { |
485 |
public void resultChanged(LookupEvent ev) { |
486 |
fireDebuggerChange(); |
487 |
} |
471 |
} |
488 |
}; |
472 |
} |
489 |
res.addLookupListener(debuggerLsnr); |
473 |
if (_listeners != null) { |
|
|
474 |
ChangeEvent e = new ChangeEvent(this); |
475 |
for (int i = 0; i < _listeners.length; i++) { |
476 |
_listeners[i].stateChanged(e); |
477 |
} |
478 |
} |
479 |
} |
480 |
public synchronized String getStatusText() { |
481 |
return text; |
482 |
} |
483 |
public synchronized void addChangeListener(ChangeListener l) { |
484 |
if (listeners == null) listeners = new ArrayList(); |
485 |
listeners.add(l); |
486 |
} |
487 |
public synchronized void removeChangeListener(ChangeListener l) { |
488 |
listeners.remove(l); |
490 |
} |
489 |
} |
491 |
res.allClasses(); |
|
|
492 |
} |
490 |
} |
493 |
|
491 |
|
494 |
/** Print output writer. |
492 |
/** Print output writer. |
Lines 505-510
Link Here
|
505 |
public InputOutput getIO(String name, boolean newIO) { |
503 |
public InputOutput getIO(String name, boolean newIO) { |
506 |
return OutputTabTerm.getIO (name, newIO); |
504 |
return OutputTabTerm.getIO (name, newIO); |
507 |
} |
505 |
} |
|
|
506 |
|
507 |
public static final class NbIOProvider extends IOProvider { |
508 |
public InputOutput getIO(String name, boolean newIO) { |
509 |
return NbTopManager.get().getIO(name, newIO); |
510 |
} |
511 |
public OutputWriter getStdOut() { |
512 |
return NbTopManager.get().getStdOut(); |
513 |
} |
514 |
} |
508 |
|
515 |
|
509 |
/** saves all opened objects */ |
516 |
/** saves all opened objects */ |
510 |
public void saveAll () { |
517 |
public void saveAll () { |
Lines 516-522
Link Here
|
516 |
dobj = modifs[i]; |
523 |
dobj = modifs[i]; |
517 |
SaveCookie sc = (SaveCookie)dobj.getCookie(SaveCookie.class); |
524 |
SaveCookie sc = (SaveCookie)dobj.getCookie(SaveCookie.class); |
518 |
if (sc != null) { |
525 |
if (sc != null) { |
519 |
TopManager.getDefault().setStatusText ( |
526 |
org.openide.awt.StatusDisplayer.getDefault().setStatusText ( |
520 |
java.text.MessageFormat.format ( |
527 |
java.text.MessageFormat.format ( |
521 |
NbBundle.getBundle (NbTopManager.class).getString ("CTL_FMT_SavingMessage"), |
528 |
NbBundle.getBundle (NbTopManager.class).getString ("CTL_FMT_SavingMessage"), |
522 |
new Object[] { dobj.getName () } |
529 |
new Object[] { dobj.getName () } |
Lines 538-547
Link Here
|
538 |
new Object[] { ((DataObject)ee.next()).getPrimaryFile().getName() } |
545 |
new Object[] { ((DataObject)ee.next()).getPrimaryFile().getName() } |
539 |
) |
546 |
) |
540 |
); |
547 |
); |
541 |
TopManager.getDefault ().notify (descriptor); |
548 |
org.openide.DialogDisplayer.getDefault().notify (descriptor); |
542 |
} |
549 |
} |
543 |
// notify user that everything is done |
550 |
// notify user that everything is done |
544 |
TopManager.getDefault().setStatusText( |
551 |
org.openide.awt.StatusDisplayer.getDefault().setStatusText( |
545 |
NbBundle.getBundle (NbTopManager.class).getString ("MSG_AllSaved")); |
552 |
NbBundle.getBundle (NbTopManager.class).getString ("MSG_AllSaved")); |
546 |
} |
553 |
} |
547 |
|
554 |
|
Lines 560-567
Link Here
|
560 |
// hide windows explicitly, they are of no use during exit process |
567 |
// hide windows explicitly, they are of no use during exit process |
561 |
WindowUtils.hideAllFrames(); |
568 |
WindowUtils.hideAllFrames(); |
562 |
try { |
569 |
try { |
563 |
// save project |
570 |
try { |
564 |
NbProjectOperation.storeLastProject (); |
571 |
LoaderPoolNode.store(); |
|
|
572 |
} catch (IOException ioe) { |
573 |
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe); |
574 |
} |
575 |
// save project, if applicable |
576 |
try { |
577 |
((TrivialProjectManager)Lookup.getDefault().lookup(TrivialProjectManager.class)).store(); |
578 |
} catch (IOException ioe) { |
579 |
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe); |
580 |
} |
581 |
// save window system, [PENDING] remove this after the winsys will |
582 |
// persist its state automaticaly |
583 |
((WindowManagerImpl)getDefaultWindowManager()).persistenceManager ().writeXML (); |
584 |
org.netbeans.core.projects.XMLSettingsHandler.saveOptions(); |
565 |
org.netbeans.core.projects.SessionManager.getDefault().close(); |
585 |
org.netbeans.core.projects.SessionManager.getDefault().close(); |
566 |
} catch (ThreadDeath td) { |
586 |
} catch (ThreadDeath td) { |
567 |
throw td; |
587 |
throw td; |
Lines 579-584
Link Here
|
579 |
} |
599 |
} |
580 |
} |
600 |
} |
581 |
} |
601 |
} |
|
|
602 |
|
603 |
public static final class NbLifecycleManager extends LifecycleManager { |
604 |
public void saveAll() { |
605 |
NbTopManager.get().saveAll(); |
606 |
} |
607 |
public void exit() { |
608 |
NbTopManager.get().exit(); |
609 |
} |
610 |
} |
582 |
|
611 |
|
583 |
/** Shows exit dialog for activated File system nodes |
612 |
/** Shows exit dialog for activated File system nodes |
584 |
* after unmounting filesystem(s) |
613 |
* after unmounting filesystem(s) |
Lines 591-653
Link Here
|
591 |
/** Get the module subsystem. */ |
620 |
/** Get the module subsystem. */ |
592 |
public abstract ModuleSystem getModuleSystem(); |
621 |
public abstract ModuleSystem getModuleSystem(); |
593 |
|
622 |
|
594 |
/** Obtains current up-to system classloader |
|
|
595 |
*/ |
596 |
public ClassLoader systemClassLoader () { |
597 |
ModuleSystem ms = getModuleSystem(); |
598 |
if (ms != null) { |
599 |
// #16265: do not go straight to ModuleManager |
600 |
return ms.getSystemClassLoader(); |
601 |
} else { |
602 |
// This can be called very early: if lookup asks for ClassLoader. |
603 |
// For now, just give the startup classloader. |
604 |
//System.err.println("Warning: giving out bogus systemClassLoader for now"); |
605 |
//Thread.dumpStack(); |
606 |
return NbTopManager.class.getClassLoader(); |
607 |
} |
608 |
} |
609 |
// Access from ModuleSystem and from subclasses when moduleSystem is created: |
610 |
public final void fireSystemClassLoaderChange() { |
611 |
//System.err.println("change: systemClassLoader -> " + systemClassLoader()); |
612 |
firePropertyChange(PROP_SYSTEM_CLASS_LOADER, null, null); |
613 |
Lkp.systemClassLoaderChanged(); // #26245 |
614 |
} |
615 |
|
616 |
/** Obtains current up-to data te classloader |
617 |
*/ |
618 |
public ClassLoader currentClassLoader () { |
619 |
ClassLoader l = ClassLoaderSupport.currentClassLoader (); |
620 |
if (l == null) { |
621 |
System.err.println("SHOULD NEVER HAPPEN: currentClassLoader==null"); // NOI18N |
622 |
l = systemClassLoader (); |
623 |
} |
624 |
return l; |
625 |
} |
626 |
// Access from ClassLoaderSupport: |
627 |
final void fireCurrentClassLoaderChange() { |
628 |
//System.err.println("change: currentClassLoader"); |
629 |
firePropertyChange(PROP_CURRENT_CLASS_LOADER, null, null); |
630 |
} |
631 |
|
632 |
|
633 |
|
634 |
/** Add listener */ |
635 |
public void addPropertyChangeListener (PropertyChangeListener l) { |
636 |
initDebuggerListener(); |
637 |
change.addPropertyChangeListener (l); |
638 |
} |
639 |
|
640 |
/** Removes the listener */ |
641 |
public void removePropertyChangeListener (PropertyChangeListener l) { |
642 |
change.removePropertyChangeListener (l); |
643 |
} |
644 |
|
645 |
/** Fires property change |
646 |
*/ |
647 |
public void firePropertyChange (String p, Object o, Object n) { |
648 |
change.firePropertyChange (p, o, n); |
649 |
} |
650 |
|
651 |
/** Someone running NonGuiMain might want to set this to true. |
623 |
/** Someone running NonGuiMain might want to set this to true. |
652 |
* This variable is read from CompilationEngineImpl to determine |
624 |
* This variable is read from CompilationEngineImpl to determine |
653 |
* whether to do synchronous compile. |
625 |
* whether to do synchronous compile. |
Lines 733-739
Link Here
|
733 |
((IDESettings)IDESettings.findObject (IDESettings.class, true)).removePropertyChangeListener (idePCL); |
705 |
((IDESettings)IDESettings.findObject (IDESettings.class, true)).removePropertyChangeListener (idePCL); |
734 |
idePCL = null; |
706 |
idePCL = null; |
735 |
} |
707 |
} |
736 |
NbTopManager.get ().htmlViewer = null; |
708 |
((NbURLDisplayer)HtmlBrowser.URLDisplayer.getDefault()).htmlViewer = null; |
737 |
return super.closeLast (); |
709 |
return super.closeLast (); |
738 |
} |
710 |
} |
739 |
|
711 |
|
Lines 767-773
Link Here
|
767 |
public void readExternal (ObjectInput in) throws IOException, ClassNotFoundException { |
739 |
public void readExternal (ObjectInput in) throws IOException, ClassNotFoundException { |
768 |
super.readExternal (in); |
740 |
super.readExternal (in); |
769 |
setListener (); |
741 |
setListener (); |
770 |
NbTopManager.get ().htmlViewer = this; |
742 |
((NbURLDisplayer)HtmlBrowser.URLDisplayer.getDefault()).htmlViewer = this; |
771 |
} |
743 |
} |
772 |
|
744 |
|
773 |
/** |
745 |
/** |
Lines 783-789
Link Here
|
783 |
String name = evt.getPropertyName (); |
755 |
String name = evt.getPropertyName (); |
784 |
if (name == null) return; |
756 |
if (name == null) return; |
785 |
if (name.equals (IDESettings.PROP_WWWBROWSER)) { |
757 |
if (name.equals (IDESettings.PROP_WWWBROWSER)) { |
786 |
NbTopManager.get ().htmlViewer = null; |
758 |
((NbURLDisplayer)HtmlBrowser.URLDisplayer.getDefault()).htmlViewer = null; |
787 |
if (idePCL != null) { |
759 |
if (idePCL != null) { |
788 |
((IDESettings)IDESettings.findObject (IDESettings.class, true)) |
760 |
((IDESettings)IDESettings.findObject (IDESettings.class, true)) |
789 |
.removePropertyChangeListener (idePCL); |
761 |
.removePropertyChangeListener (idePCL); |
Lines 795-801
Link Here
|
795 |
((IDESettings)IDESettings.findObject (IDESettings.class, true)).addPropertyChangeListener (idePCL); |
767 |
((IDESettings)IDESettings.findObject (IDESettings.class, true)).addPropertyChangeListener (idePCL); |
796 |
} |
768 |
} |
797 |
catch (Exception ex) { |
769 |
catch (Exception ex) { |
798 |
NbTopManager.get ().notifyException (ex); |
770 |
ErrorManager.getDefault().notify(ex); |
799 |
} |
771 |
} |
800 |
} |
772 |
} |
801 |
} |
773 |
} |
Lines 807-877
Link Here
|
807 |
private Task initTask; |
779 |
private Task initTask; |
808 |
/** thread that initialized the task and has to recieve good results */ |
780 |
/** thread that initialized the task and has to recieve good results */ |
809 |
private Thread initThread; |
781 |
private Thread initThread; |
|
|
782 |
/** currently effective ClassLoader */ |
783 |
private static ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); |
810 |
|
784 |
|
811 |
/** Initialize the lookup to delegate to NbTopManager. |
785 |
/** Initialize the lookup to delegate to NbTopManager. |
812 |
*/ |
786 |
*/ |
813 |
public Lkp () { |
787 |
public Lkp () { |
814 |
super (new Lookup[] { |
788 |
super (new Lookup[] { |
815 |
// #14722: pay attention also to META-INF/services/class.Name resources: |
789 |
// #14722: pay attention also to META-INF/services/class.Name resources: |
816 |
createMetaInfServicesLookup(false), |
790 |
createMetaInfServicesLookup(), |
|
|
791 |
Lookups.singleton(classLoader), |
817 |
}); |
792 |
}); |
818 |
} |
793 |
} |
819 |
|
794 |
|
820 |
/** @param modules if true, use module classloader, else not */ |
795 |
private static Lookup createMetaInfServicesLookup() { |
821 |
private static Lookup createMetaInfServicesLookup(boolean modules) { |
|
|
822 |
//System.err.println("cMISL: modules=" + modules); |
796 |
//System.err.println("cMISL: modules=" + modules); |
823 |
try { |
797 |
try { |
824 |
// XXX consider just making this a public class! |
798 |
// XXX consider just making this a public class! |
|
|
799 |
// or making Lookups.metaInfServices(ClassLoader) static utility method |
825 |
Class clazz = Class.forName("org.openide.util.MetaInfServicesLookup"); // NOI18N |
800 |
Class clazz = Class.forName("org.openide.util.MetaInfServicesLookup"); // NOI18N |
826 |
Constructor c = clazz.getDeclaredConstructor(new Class[] {ClassLoader.class}); |
801 |
Constructor c = clazz.getDeclaredConstructor(new Class[] {ClassLoader.class}); |
827 |
c.setAccessible(true); |
802 |
c.setAccessible(true); |
828 |
ClassLoader loader; |
803 |
return (Lookup)c.newInstance(new Object[] {classLoader}); |
829 |
if (modules) { |
|
|
830 |
loader = get().getModuleSystem().getManager().getClassLoader(); |
831 |
} else { |
832 |
loader = Lkp.class.getClassLoader(); |
833 |
} |
834 |
return (Lookup)c.newInstance(new Object[] {loader}); |
835 |
} catch (Exception e) { |
804 |
} catch (Exception e) { |
836 |
e.printStackTrace(); |
805 |
e.printStackTrace(); |
837 |
return Lookup.EMPTY; |
806 |
return Lookup.EMPTY; |
838 |
} |
807 |
} |
839 |
} |
808 |
} |
840 |
|
809 |
|
841 |
private static final class ConvertorListener |
810 |
/** Called when a system classloader changes. |
842 |
implements PropertyChangeListener { |
811 |
*/ |
843 |
public void propertyChange(PropertyChangeEvent evt) { |
812 |
public static final void systemClassLoaderChanged (ClassLoader nue) { |
844 |
if (evt == null || ModuleManager.PROP_ENABLED_MODULES.equals(evt.getPropertyName())) { |
813 |
if (classLoader != nue) { |
845 |
//System.err.println("modules changed; changing metaInfServicesLookup"); |
814 |
classLoader = nue; |
846 |
// Time to refresh META-INF/services/ lookup; modules turned on or off. |
815 |
Lkp l = (Lkp)Lookup.getDefault(); |
847 |
Lookup lookup = Lookup.getDefault(); |
816 |
Lookup[] delegates = l.getLookups(); |
848 |
if (lookup instanceof Lkp) { |
817 |
Lookup[] newDelegates = (Lookup[])delegates.clone(); |
849 |
Lkp lkp = (Lkp)lookup; |
818 |
// Replace classloader. |
850 |
Lookup[] old = lkp.getLookups(); |
819 |
newDelegates[0] = createMetaInfServicesLookup(); |
851 |
Lookup[] nue = (Lookup[])old.clone(); |
820 |
newDelegates[1] = Lookups.singleton(classLoader); |
852 |
nue[0] = createMetaInfServicesLookup(true); |
821 |
l.setLookups(newDelegates); |
853 |
lkp.setLookups(nue); |
|
|
854 |
//System.err.println("lookups: " + java.util.Arrays.asList(nue)); |
855 |
} |
856 |
/* just testing: |
857 |
{ |
858 |
try { |
859 |
Class c = get().systemClassLoader().loadClass("org.foo.Interface"); |
860 |
System.err.println("org.foo.Interface: " + Lookup.getDefault().lookup(new Lookup.Template(c)).allInstances()); |
861 |
} catch (Exception e) { |
862 |
System.err.println(e.toString()); |
863 |
} |
864 |
} |
865 |
*/ |
866 |
} |
867 |
} |
822 |
} |
868 |
} |
823 |
} |
869 |
|
824 |
|
870 |
/** Called when a system classloader changes. |
825 |
/** Called when modules are about to be turned on. |
871 |
*/ |
826 |
*/ |
872 |
public static final void systemClassLoaderChanged () { |
827 |
public static final void moduleClassLoadersUp() { |
873 |
NbTopManager.get ().unregister (ClassLoaderConvertor.CLASSLOADER, ClassLoaderConvertor.CLASSLOADER); |
828 |
Lkp l = (Lkp)Lookup.getDefault(); |
874 |
NbTopManager.get ().register (ClassLoaderConvertor.CLASSLOADER, ClassLoaderConvertor.CLASSLOADER); |
829 |
Lookup[] newDelegates = null; |
|
|
830 |
Lookup[] delegates = l.getLookups(); |
831 |
newDelegates = (Lookup[])delegates.clone(); |
832 |
newDelegates[0] = createMetaInfServicesLookup(); |
833 |
l.setLookups(newDelegates); |
875 |
} |
834 |
} |
876 |
|
835 |
|
877 |
/** When all module classes are accessible thru systemClassLoader, this |
836 |
/** When all module classes are accessible thru systemClassLoader, this |
Lines 912-918
Link Here
|
912 |
|
871 |
|
913 |
final void doInitializeLookup () { |
872 |
final void doInitializeLookup () { |
914 |
//System.err.println("doInitializeLookup"); |
873 |
//System.err.println("doInitializeLookup"); |
915 |
FileObject services = TopManager.getDefault().getRepository().getDefaultFileSystem().findResource("Services"); |
874 |
FileObject services = Repository.getDefault().getDefaultFileSystem() |
|
|
875 |
.findResource("Services"); |
916 |
Lookup nue; |
876 |
Lookup nue; |
917 |
if (services != null) { |
877 |
if (services != null) { |
918 |
StartLog.logProgress("Got Services folder"); // NOI18N |
878 |
StartLog.logProgress("Got Services folder"); // NOI18N |
Lines 925-949
Link Here
|
925 |
|
885 |
|
926 |
// extend the lookup |
886 |
// extend the lookup |
927 |
Lookup[] arr = new Lookup[] { |
887 |
Lookup[] arr = new Lookup[] { |
928 |
getLookups()[0], // metaInfServicesLookup; still keep classpath one till later... |
888 |
getLookups()[0], // metaInfServicesLookup |
|
|
889 |
getLookups()[1], // ClassLoader lookup |
890 |
// XXX figure out how to put this ahead of MetaInfServicesLookup (for NonGuiMain): |
929 |
NbTopManager.get ().getInstanceLookup (), |
891 |
NbTopManager.get ().getInstanceLookup (), |
930 |
nue, |
892 |
nue, |
931 |
NbTopManager.get().getModuleSystem().getManager().getModuleLookup(), |
893 |
NbTopManager.get().getModuleSystem().getManager().getModuleLookup() |
932 |
}; |
894 |
}; |
933 |
StartLog.logProgress ("prepared other Lookups"); // NOI18N |
895 |
StartLog.logProgress ("prepared other Lookups"); // NOI18N |
934 |
|
896 |
|
935 |
setLookups (arr); |
897 |
setLookups (arr); |
936 |
StartLog.logProgress ("Lookups set"); // NOI18N |
898 |
StartLog.logProgress ("Lookups set"); // NOI18N |
937 |
|
899 |
|
938 |
// Also listen for changes in modules, as META-INF/services/ would change: |
|
|
939 |
ModuleManager mgr = get().getModuleSystem().getManager(); |
940 |
ConvertorListener l = new ConvertorListener(); |
941 |
mgr.addPropertyChangeListener(l); |
942 |
if (!mgr.getEnabledModules().isEmpty()) { |
943 |
// Ready now. |
944 |
l.propertyChange(null); |
945 |
} |
946 |
|
947 |
//StartLog.logEnd ("NbTopManager$Lkp: initialization of FolderLookup"); // NOI18N |
900 |
//StartLog.logEnd ("NbTopManager$Lkp: initialization of FolderLookup"); // NOI18N |
948 |
|
901 |
|
949 |
synchronized (this) { |
902 |
synchronized (this) { |
Lines 965-996
Link Here
|
965 |
t.waitFinished(); |
918 |
t.waitFinished(); |
966 |
} |
919 |
} |
967 |
|
920 |
|
|
|
921 |
// Force module system to be initialize by looking up ModuleInfo. |
922 |
// Good for unit tests, etc. |
923 |
if (templ.getType() == ModuleInfo.class || templ.getType() == Module.class) { |
924 |
get(); |
925 |
} |
926 |
|
968 |
super.beforeLookup(templ); |
927 |
super.beforeLookup(templ); |
969 |
} |
928 |
} |
970 |
} |
929 |
} |
971 |
|
930 |
|
972 |
|
|
|
973 |
/** Special item for system class loader (which is dynamic). |
974 |
*/ |
975 |
private final static class ClassLoaderConvertor |
976 |
implements InstanceContent.Convertor { |
977 |
public static final ClassLoaderConvertor CLASSLOADER = new ClassLoaderConvertor (); |
978 |
|
979 |
public Object convert(Object obj) { |
980 |
return NbTopManager.get ().systemClassLoader(); |
981 |
} |
982 |
|
983 |
public String displayName(Object obj) { |
984 |
return id (obj); |
985 |
} |
986 |
|
987 |
public String id(Object obj) { |
988 |
return "TM[systemClassLoader"; // NOI18N |
989 |
} |
990 |
|
991 |
public Class type(Object obj) { |
992 |
return ClassLoader.class; |
993 |
} |
994 |
|
995 |
} // end of ClassLoaderConvertor |
996 |
} |
931 |
} |