Introduction to the NetBeans Platform Institute for System Software Johannes Kepler University Linz, Austria http://ssw.jku.at Thomas Wuerthinger wuerthinger@ssw.jku.at 1
NetBeans IDE (Java, C/C++, PHP, JavaScript, Groovy, Ruby,...) Rich Client Platform Only Java (Swing) Supported by Sun Microsystems Important Concepts: Modules Filesystem Lookup Nodes and Actions 2
Sources of Information NetBeans source code (http://www.netbeans.org/downloads/zip.html) API Javadoc (http://bits.netbeans.org/dev/javadoc/index.html) Planet NetBeans (http://planetnetbeans.org/de/index.html) Numerous NetBeans bloggers (e.g. http://blogs.sun.com/geertjan/) 3
Architecture (1) NetBeans IDE NetBeans Platform NetBeans Application Swing / JDK Java VM 4
Architecture (2) NetBeans IDE NetBeans Application NetBeans Platform Swing / JDK Java VM 5
Deployment NetBeans IDE NetBeans Application NetBeans Platform Swing / JDK Java VM Standalone: Deployment including required platform / IDE modules Plugin: Deployment only with user-defined modules 6
Module System Module Suite (= Deployment Unit) Module A (= JAR File) META-INF/manifest.mf layer.xml META-INF/services/* *.class Bundle.properties Module B... Module C... Well-defined module dependencies Lazy loading / Unloading layer.xml for declarative registrations (file system) Bundle.properties for internationalization 7
Information Hiding Public packages are explicitely defined in manifest.mf (project.xml). Module A Module B Implementation Public API 8
Module Dependencies Modules can only use classes of modules they explicitely depend on. Module A Module B No circles! Module C 9
Window System Global actions Window Mode TopComponent with multiple instances Singleton TopComponent 10
File System (1) Module A Module B Result X X X Y Y Z + +... = Y Z a b c d a b c d Declarative specifications of virtual folders and files File system is union of file systems of all current modules 11
File System (2) <filesystem> <folder name="actions"> <folder name="window"> <file name="testaction.instance"> <attr name="displayname" value="test"/> </file> </folder> </folder> Reference to Java class <folder name="menu"> Reference to other file <folder name="window"> <file name="testaction.shadow"> <attr name="originalfile" stringvalue="actions/window/sample-testaction.instance"/> </file> </folder> </folder> <folder name="windows2"> <folder name="components"> <file name="topcomponent.settings" url="topcomponentsettings.xml"/> </folder> </folder> Reference to physical file </filesystem> Use.instance_hidden to hide existing entries 12
File System (3) ROOT Actions Menu Window2 TestAction.instance displayname= Test TestAction.shadow TestTopComponent.settings Java Class TestAction File TopComponentSettings.xml 13
Lookup System Container of Java object instances lookup all instances of X.class x1, x2 Lookup x1 y x2 a InstanceContent content = new InstanceContent(); Lookup lookup = new AbstractLookup(content); Collection<? extends Integer> result; result = lookup.lookupall(integer.class); content.add(2); content.add(3); result = lookup.lookupall(integer.class); content.add("vier"); result = lookup.lookupall(integer.class); Collection c = lookup.lookupall(object.class); content.remove(3); result = lookup.lookupall(integer.class); // empty list // {2, 3} // {2, 3} // {2, 3, "vier"} // {2} 14
Lookup Example Usage give me a SaveCookie SaveAction s == null? s Editor yes disable action no enable action on action invocation: call s.save() interface SaveCookie { void save(); } 15
Proxy Lookups Lookup Lookup is union of delegates to one of Lookup Lookup Frequently used lookups in NetBeans Lookup.getDefault() is the global lookup Utilities.actionsGlobalContext() delegates to lookup of current active window Lookup of a view (e.g. ListView, TreeView) delegates to lookup of current selected item 16
Dependency Removal TextFilter WordEngine UpperCaseFilter File META-INF/services/at.ssw.TextFilter at.ssw.uppercasefilter TextFilter filter = Lookup.getDefault().lookup(TextFilter.class); String s = filter.process("test"); 17
Lookup Listening Lookup.Result<Integer> result = lookup.lookupresult(integer.class); result.addlookuplistener(new MyLookupListener()); class MyLookupListener { public void resultchanged(lookupevent e) { Lookup.Result<Integer> result = (Lookup.Result<Integer>)e.getSource(); System.out.println("Lookup changed!"); } for (Integer i : result.allinstances()) { System.out.println(i); } } 18
Explorer and Nodes API TopComponent TreeTableView ExplorerManager Node Children 19
JavaBeans Specification of a JavaBean - via special public Java methods (Introspection) - via BeanInfo object JavaBeans expose Properties and Events Persistence 20
Nodes and Actions (1)? extends Cookie provides in lookup asks for Node Action 21
Nodes and Actions (2) Action accesses Lookup Utilities.actionsGlobalContext delegates Lookup of active top component delegates Lookup of ExplorerManager delegates Lookup of selected Nodes is provided by Node 22
Backward Compability (1) SaveAction uses ISaveablePart IEditorPart AbstractTextEditor extends MyTextEditor Introducing a new method in save interface? SaveAction uses SaveCookie SaveCookieImpl provides MyTopComponent 23
Backward Compability (2) SaveAction SaveAction2 ISaveablePart ISaveablePart2 IEditorPart IEditorPart2 AbstractTextEditor AbstractTextEditor2 cannot extend both! MyTextEditor 24
Backward Compability (3) SaveAction SaveAction2 SaveCookie SaveCookie2 SaveCookieImpl SaveCookieImpl2 can provide both! MyTopComponent 25