Developing Plug-Ins for NetBeans
-
Upload
elliando-dias -
Category
Technology
-
view
1.732 -
download
6
description
Transcript of Developing Plug-Ins for NetBeans
NetBeansTM Software Day at 2005 JavaOneSM Conference
Developing Plug-Ins for NetBeans
Tim BoudreauStaff EngineerSun Microsystems
NetBeansTM Software Day at 2005 JavaOneSM Conference
NetBeansTM Software Day at 2005 JavaOneSM Conference
Agenda
● NetBeans Overview● Plug-In Development Support● Architectural Background● Developing a Plug-In
NetBeansTM Software Day at 2005 JavaOneSM Conference
Modular Design
NetBeansTM Software Day at 2005 JavaOneSM Conference
Everything is a Plug-In
NetBeansTM Software Day at 2005 JavaOneSM Conference
● A jar file with some special manifest entries
OpenIDE-Module: org.netbeans.modules.project.ant/1
OpenIDE-Module-IDE-Dependencies: IDE/1 > 4.48
OpenIDE-Module-Specification-Version: 1.6
OpenIDE-Module-Implementation-Version: 050219
OpenIDE-Module-Public-Packages: org.netbeans.api.project.ant.*, org.ne
tbeans.spi.project.ant.*
OpenIDE-Module-Module-Dependencies: org.netbeans.modules.projectapi/1,
org.netbeans.modules.queries/1, org.openide.loaders
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/ant/Bun
dle.properties
What is a plug-in (module)
NetBeansTM Software Day at 2005 JavaOneSM Conference
● Module code-name
OpenIDE-Module: org.netbeans.modules.project.ant/1
OpenIDE-Module-IDE-Dependencies: IDE/1 > 4.48
OpenIDE-Module-Specification-Version: 1.6
OpenIDE-Module-Implementation-Version: 050219
OpenIDE-Module-Public-Packages: org.netbeans.api.project.ant.*, org.ne
tbeans.spi.project.ant.*
OpenIDE-Module-Module-Dependencies: org.netbeans.modules.projectapi/1,
org.netbeans.modules.queries/1, org.openide.loaders
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/ant/Bun
dle.properties
What is a plug-in (module)
NetBeansTM Software Day at 2005 JavaOneSM Conference
● What version of the main APIs does it need
OpenIDE-Module: org.netbeans.modules.project.ant/1
OpenIDE-Module-IDE-Dependencies: IDE/1 > 4.48
OpenIDE-Module-Specification-Version: 1.6
OpenIDE-Module-Implementation-Version: 050219
OpenIDE-Module-Public-Packages: org.netbeans.api.project.ant.*, org.ne
tbeans.spi.project.ant.*
OpenIDE-Module-Module-Dependencies: org.netbeans.modules.projectapi/1,
org.netbeans.modules.queries/1, org.openide.loaders
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/ant/Bun
dle.properties
What is a plug-in (module)
NetBeansTM Software Day at 2005 JavaOneSM Conference
● Modules have version numbers
OpenIDE-Module: org.netbeans.modules.project.ant/1
OpenIDE-Module-IDE-Dependencies: IDE/1 > 4.48
OpenIDE-Module-Specification-Version: 1.6
OpenIDE-Module-Implementation-Version: 050219
OpenIDE-Module-Public-Packages: org.netbeans.api.project.ant.*, org.ne
tbeans.spi.project.ant.*
OpenIDE-Module-Module-Dependencies: org.netbeans.modules.projectapi/1,
org.netbeans.modules.queries/1, org.openide.loaders
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/ant/Bun
dle.properties
What is a plug-in (module)
NetBeansTM Software Day at 2005 JavaOneSM Conference
● Modules can expose APIs
OpenIDE-Module: org.netbeans.modules.project.ant/1
OpenIDE-Module-IDE-Dependencies: IDE/1 > 4.48
OpenIDE-Module-Specification-Version: 1.6
OpenIDE-Module-Implementation-Version: 050219
OpenIDE-Module-Public-Packages: org.netbeans.api.project.ant.*, org.ne
tbeans.spi.project.ant.*
OpenIDE-Module-Module-Dependencies: org.netbeans.modules.projectapi/1,
org.netbeans.modules.queries/1, org.openide.loaders
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/ant/Bun
dle.properties
What is a plug-in (module)
NetBeansTM Software Day at 2005 JavaOneSM Conference
● Modules can use APIs from other modules
OpenIDE-Module: org.netbeans.modules.project.ant/1
OpenIDE-Module-IDE-Dependencies: IDE/1 > 4.48
OpenIDE-Module-Specification-Version: 1.6
OpenIDE-Module-Implementation-Version: 050219
OpenIDE-Module-Public-Packages: org.netbeans.api.project.ant.*, org.ne
tbeans.spi.project.ant.*
OpenIDE-Module-Module-Dependencies: org.netbeans.modules.projectapi/1,
org.netbeans.modules.queries/1, org.openide.loaders
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/ant/Bun
dle.properties
What is a plug-in (module)
NetBeansTM Software Day at 2005 JavaOneSM Conference
● Everything is localized
OpenIDE-Module: org.netbeans.modules.project.ant/1
OpenIDE-Module-IDE-Dependencies: IDE/1 > 4.48
OpenIDE-Module-Specification-Version: 1.6
OpenIDE-Module-Implementation-Version: 050219
OpenIDE-Module-Public-Packages: org.netbeans.api.project.ant.*, org.ne
tbeans.spi.project.ant.*
OpenIDE-Module-Module-Dependencies: org.netbeans.modules.projectapi/1,
org.netbeans.modules.queries/1, org.openide.loaders
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/ant/Bun
dle.properties
What is a plug-in (module)
NetBeansTM Software Day at 2005 JavaOneSM Conference
Anatomy of a Module
NetBeansTM Software Day at 2005 JavaOneSM Conference
● NetBeans Plugin Projects● New Plugin Template● API class templates● Build Plugins outside source tree– Deploy to
● Separate Binary● Platform-only Binary● Current IDE
DEMO: Creating a Plugin
Plugin Support in NetBeans 4.2
NetBeansTM Software Day at 2005 JavaOneSM Conference
How the Hello World module works
● Installs a layer file which– Is merged into the system (configuration) filesystem– Defines a virtual filesystem fragment– Installs an instance file
● Points to a standard Swing Action
NetBeansTM Software Day at 2005 JavaOneSM Conference
Filesystems API
● FileObjects: Abstraction over java.io.File– “Files” may not be on disk
● XML● Remote (FTP, NFS)● Database, etc.
– Support● Listening for changes● Ad-hoc “attributes” (key-value pairs)● Live in a FileSystem – a namespace
● Used for both config data + user's files
NetBeansTM Software Day at 2005 JavaOneSM Conference
Filesystems – virtual files
NetBeansTM Software Day at 2005 JavaOneSM Conference
XML Filesystems – very virtual files
NetBeansTM Software Day at 2005 JavaOneSM Conference
Layered Filesystem
NetBeansTM Software Day at 2005 JavaOneSM Conference
System (configuration) Filesystem
NetBeansTM Software Day at 2005 JavaOneSM Conference
A Tour of the System Filesystem
DEMO: Browsing the layer file and System FS
NetBeansTM Software Day at 2005 JavaOneSM Conference
DataObjects wrap Files
NetBeansTM Software Day at 2005 JavaOneSM Conference
DataSystems API
● DataObjects – wrap 1 or more FileObjects– “Typed” files – knows what the content is
● Different DataObject types for different MIME types– Programmatic access to file contents
● Structural or parsed representation of contents● Support for editing, etc.
● DataLoaders– Factories for DataObject– Recognize and claim FileObjects by extension or
contents
NetBeansTM Software Day at 2005 JavaOneSM Conference
DataSystems
NetBeansTM Software Day at 2005 JavaOneSM Conference
Nodes API
● Presentation layer on top of DataObjects – add– Icon, display name, menu actions, properties, child
nodes● Generic hierarchy API● Displayed to user with the Explorer API– Tree, List, Combo, Menu, TreeTable and other
views● Don't have to represent files
NetBeansTM Software Day at 2005 JavaOneSM Conference
From Files to Nodes
NetBeansTM Software Day at 2005 JavaOneSM Conference
Factory Relationships – Files to Nodes
NetBeansTM Software Day at 2005 JavaOneSM Conference
Lookup Patterns
● “Glue” between disparate APIs● Common pattern: To ask an object for an
implementation of some interface– SomeObject.getLookup().lookup (SomeIFace.class);– SomeObject.getCookie (SomeIFace.class);
NetBeansTM Software Day at 2005 JavaOneSM Conference
Lookup API
● A way to find objects (dependency injection)● Global singletons
● Lookup.getDefault().lookup (SomeInterface.class)
● Objects belonging to another object● node.getLookup().lookup (SomeInterface.class)● dataObject.getCookie (SomeInterface.class)
● Why lookup?● Lazy instantiation – create on demand● Evolution● Its hard to add/remove methods● Its easy to change what lives in an object's Lookup
NetBeansTM Software Day at 2005 JavaOneSM Conference
Global Lookup Registration
● Instance file in system filesystem:<folder name=”services”>
<file name=”org-foo-mymodule-MyService.instance”/>
</folder>
● META-INF/services entry in jar:● A single file that names the interface implemented
● META-INF/services/org.openide.ErrorManager
● With a single line of text naming the implementation class● com.mycom.mymodule.MyErrorManagerImpl
NetBeansTM Software Day at 2005 JavaOneSM Conference
getLookup() vs. getCookie()
● Newer idiom● someobject.getLookup().lookup (SomeClass.class)
● Older idiom● someobject.getCookie (SomeClass.class)
● Principle difference● Lookup is more generic● Objects in a Lookup don't have to implement the marker
interface Node.Cookie
NetBeansTM Software Day at 2005 JavaOneSM Conference
Povray
NetBeansTM Software Day at 2005 JavaOneSM ConferenceNetBeansTM Software Day at 2005 JavaOneSM Conference
Developing Plug-Ins for NetBeans
Tim BoudreauStaff EngineerSun Microsystems