<<

Introduction to the NetBeans Platform

Institute for System Software Thomas Wuerthinger Johannes Kepler University Linz, Austria [email protected] http://ssw.jku.at 1 NetBeans

● IDE (, /C++, PHP, JavaScript, Groovy, Ruby, ...)

● Only Java ()

● Supported by

Important Concepts:

● Modules

● Filesystem

● Lookup

● Nodes and Actions

2 Sources of Information

● NetBeans source code (http://www.netbeans.org/downloads/zip.html)

● API (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 Application NetBeans Platform

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) Module B Module C META-INF/manifest.mf ...... layer. META-INF/services/* *.class Bundle.properties

● 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

No circles! Module B

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 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)

Reference to Java class

Reference to other file Reference to physical file

Use .instance_hidden to hide existing entries

12 File System (3)

ROOT

Actions Menu Window2

TestAction.instance TestAction.shadow TestTopComponent.settings

displayName=“Test“

Java Class File TestAction TopComponentSettings.xml

13 Lookup System

Container of Java object instances

lookup all instances of X.class Lookup

x1, x2 x1 y x2 a

InstanceContent content = new InstanceContent(); Lookup lookup = new AbstractLookup(content);

Collection result; result = lookup.lookupAll(Integer.class); // empty list content.add(2); content.add(3); result = lookup.lookupAll(Integer.class); // {2, 3} content.add("vier"); result = lookup.lookupAll(Integer.class); // {2, 3} Collection c = lookup.lookupAll(Object.class); // {2, 3, "vier"} content.remove(3); result = lookup.lookupAll(Integer.class); // {2} 14 Lookup Example Usage

give me a SaveCookie

SaveAction Editor s s == null ?

yes no

interface SaveCookie { void save(); disable action enable action } on action invocation: call s.save()

15 Proxy Lookups

Lookup

is union of Lookup Lookup delegates to one of

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 result = lookup.lookupResult(Integer.class); result.addLookupListener(new MyLookupListener());

class MyLookupListener {

public void resultChanged(LookupEvent e) {

Lookup.Result result = (Lookup.Result)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 SaveAction

uses uses

ISaveablePart SaveCookie Introducing a new method in save IEditorPart interface? SaveCookieImpl provides

AbstractTextEditor MyTopComponent

extends MyTextEditor

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