Introduction to the NetBeans Platform

advertisement
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
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
META-INF/manifest.mf
layer.xml
META-INF/services/*
*.class
Bundle.properties
●
Well-defined module dependencies
●
Lazy loading / Unloading
●
layer.xml for declarative registrations (file system)
●
Bundle.properties for internationalization
...
Module C
...
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
Window Mode
Global actions
TopComponent
with multiple instances
Singleton
TopComponent
10
File System (1)
Module A
Module B
X
X
Y
a
+
b
Result
X
Y
Z
c
d
+
...
Y
=
a
●
Declarative specifications of virtual folders
●
File system is union of file systems of all current modules
b
Z
c
d
and files
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
Reference to other file
<folder name="Menu">
<folder name="Window">
<file name="TestAction.shadow">
<attr name="originalFile"
stringvalue="Actions/Window/sample-TestAction.instance"/>
</file>
</folder>
</folder>
Reference to physical file
<folder name="Windows2">
<folder name="Components">
<file name="TopComponent.settings" url="TopComponentSettings.xml"/>
</folder>
</folder>
</filesystem>
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
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);
// empty list
// {2, 3}
// {2, 3}
// {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
disable action
no
enable action
interface SaveCookie {
void save();
}
on action invocation:
call s.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
Node
asks for
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
Introducing a new
SaveCookie
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
Download