Sie sind auf Seite 1von 42

How to Simplify Building

Rich Clients in the Java™


Programming Language java.sun.com/javaone/sf

Jaroslav Tulach, Sun Microsystems


Rich Unger, Nuance
André Eickler, Nokia

SM
1 | 2004 JavaOne Conference | Session TS-1694
Write Rich Desktop Apps
While Saving Time and Money

Learn how to write and assemble rich


client Java™ technology-based desktop
applications while reusing many
developer-years invested in development
of the NetBeans™ platform

SM
2 | 2004 JavaOne Conference | Session TS-1694
Agenda

• The need for rich desktop clients


• Benefits of modular architecture
• Branding and customization
• Case Study—V-Builder
─ Reusing existing components
• Case Study—NetAct desktop
─ NetBeans platform as an ideal
J2EE™ platform client

SM
3 | 2004 JavaOne Conference | Session TS-1694
The Need for Rich Desktop Clients

• Web will not


do it all
─ Real-time
interaction
(dealing, monitoring)
─ Integration with
OS (sound, etc.)
• 100% Java technology counts
─ Ease of administration and distribution
─ Plain JFC/Swing may be too plain
• NetBeans Platform
─ The engine behind NetBeans IDE
SM
4 | 2004 JavaOne Conference | Session TS-1694
Demo
Small Introduction to NetBeans
IDE and Platform
SM
5 | 2004 JavaOne Conference | Session TS-1694
Costs Savings
The advantages of reusing NetBeans platform
• Avoid reinventing the wheel
─ Windowing, Menu, Toolbars, etc.
─ Modularization, Branding, Localization
• Concentrate on guts only
─ Write business logic, reuse the framework
• Assemble Applications from Components
─ A lot of existing components on netbeans.org
─ Designed in modular way

SM
6 | 2004 JavaOne Conference | Session TS-1694
Modularity of Components
Its importance for good UI application
• Discipline: Developers write cleaner code
• Final assembly of application is independent
• Solutions tailored to customer needs
• Much tighter UI tasks flow

Module
Module

Module

Module

Module
Application

Application

Application

Platform

SM
= UI task flow
7 | 2004 JavaOne Conference | Session TS-1694
Modularity in NetBeans
Modify your application to be NetBeans IDE module
• Module is any JAR file with enhanced manifest
Manifest-Version: 1.0
OpenIDE-Module: org.netbeans.modules.text/1
OpenIDE-Module-Specification-Version: 1.13

• What is this good for?


─ Identification of each library
─ Version specification
─ Dependencies

SM
8 | 2004 JavaOne Conference | Session TS-1694
Modularity in NetBeans
Dependencies between modules
OpenIDE-Module-Specification-Version: 1.13
OpenIDE-Module-Provides: EditorImpl
OpenIDE-Module-Module-Dependencies:
org.netbeans.api.spellchecker/1 > 1.3,
org.netbeans.core > 4.32
OpenIDE-Module-Requires: SpellImpl

• Types of modules
─ Regular
─ Autoload
─ Eager

SM
9 | 2004 JavaOne Conference | Session TS-1694
Modularity in NetBeans
Module Enablement and ClassLoader Hierarchy
• Dependencies influence runtime classpath
• A module can turn other modules on

org.netbeans.modules.text/1
Provides: EditorImpl org.netbeans.spellimpl
Requires: SpellImpl Provides: SpellImpl
Autoload

org.netbeans.api.spellchecker/1

org.netbeans.core
SM
10 | 2004 JavaOne Conference | Session TS-1694
Cooperation of Modules
Composition of UI Elements
• Menu, toolbar elements
─ Get merged together by the NetBeans framework
• Windows layout
• Registration solved by Layers
<folder name="Menu" >
<folder name="File" >
<file name="Open.instance" >
<attr instanceCreate=
"org.openide.actions.OpenAction" />
</file>
</folder>
</folder>

SM
11 | 2004 JavaOne Conference | Session TS-1694
Cooperation of Modules
Composition of Menu <folder name="Menu/File">
<file name="NewProject.instance" />
<file name="ImportProject.instance" />
<file name="Separator.instance" />
<file name="OpenProject.instance" />
<file name="OpenRecent.instance" />
<file name="CloseProject.instance" />
</folder>

<folder name="Menu/File">
<file name="NewFile.instance" />
<file name="Open.instance" />
</folder>

<folder name="Menu/File">
<attr name="NewProject.instance/NewFile.instance" boolvalue="true" />
<attr name="NewFile.instance/ImportProject.instance" boolvalue="true" />
<attr name="OpenProject.instance/Open.instance" />
<attr name="Open.instance/OpenRecent.instance" />
</folder>

Windows, Toolbars, etc. work in the same way


SM
12 | 2004 JavaOne Conference | Session TS-1694
Cooperation of Modules
Exposing module state
• A module owns a Window, another an action
• Windows can have associated Context
• Selected window defines the global context
• UI Elements update its state according to it
• What is inside context?
─ Anything important (javax.swing.Document, etc.)
• What operations context need to support?
─ Changes of its content
─ Observability

SM
13 | 2004 JavaOne Conference | Session TS-1694
Cooperation of Modules
Exposing Window State
class MyWindow
extends org.openide.windows.TopComponent {
private JEditorPane pane;

public org.openide.util.Lookup getLookup () {


return Lookups.singleton(pane.getDocument())
}
}

SM
14 | 2004 JavaOne Conference | Session TS-1694
Cooperation of Modules
Querying and Listening to State
import org.openide.util.Utilities;

class MyInsertAction extends AbstractAction {


public void actionPerformed (ActionEvent ev) {
Lookup lkp = Utilities.actionGlobalContext();
Document doc = lkp.lookup (Document.class);
if (doc != null) {
doc.insertString (0, null, "Hello world!");
}
}
}

In similar way one can listen to changes in Lookup


using LookupListener.

SM
15 | 2004 JavaOne Conference | Session TS-1694
Cooperation of Modules
Generic Viewer—Explorer
• Presentation of tree hierarchies
─ Not only tree view, but many others
• Each Node has its own context
─ Can be queried and observed
• Modules can contribute to the hierarchy

SM
16 | 2004 JavaOne Conference | Session TS-1694
Branding and Customization

• Sun products are branded, L10N and A11Y


• Customization by selection of modules
• Overriding or masking resources
─ <file name="Open.instance" />
─ <file name="Open.instance_hidden" />

SM
17 | 2004 JavaOne Conference | Session TS-1694
Rich Unger

The Need for Rich Desktop Clients


Benefits of Modular Architecture
Branding and Customization
Case Study—V-Builder
Case Study—NetAct Desktop

SM
18 | 2004 JavaOne Conference | Session TS-1694
What Is V-Builder?
Voice User Interface (VUI) IDE
• Design telephone conversations
between a human and a computer
• Edit many file types
─ Call-flow design
─ Prompt (.wav)
─ Grammar (linguistic regular expression)
─ VoiceXML
• Run the application using vocal or
textual interactions

SM
19 | 2004 JavaOne Conference | Session TS-1694
What Is V-Builder?

SM
20 | 2004 JavaOne Conference | Session TS-1694
Challenges

• 5 developers
• IDEs not our core competency
─ VUI experts, not GUI experts
• High customer expectations
─ Source control
─ Syntax coloring/completion
─ Easy enough for non-programmers (and yet, speech
recognition is very complicated)

SM
21 | 2004 JavaOne Conference | Session TS-1694
Solution:

Netbeans Platform
Gives You

Free Stuff

SM
22 | 2004 JavaOne Conference | Session TS-1694
Source Control (VCS)

• Use org.openide.filesystems.FileObject
instead of java.io.File
─ Similar API
─ Wraps access in redirection layer
• Free support for multiple source
control systems
─ CVS
─ Subversion
─ SourceSafe
─ ClearCase
─ PVCS

SM
23 | 2004 JavaOne Conference | Session TS-1694
XML Editor
Declare a new MIME type
VoiceXMLDataLoader.java:

protected MultiDataObject createMultiObject


(FileObject primaryFile) {
return new XMLDataObject(primaryFile, this);
}

protected FileObject findPrimaryFile(FileObject fo) {


if (fo.isFolder())
return null;
if (fo.getMIMEType().equals(
"application/voicexml+xml"))
return fo;

return null;
}
SM
24 | 2004 JavaOne Conference | Session TS-1694
XML Editor

SM
25 | 2004 JavaOne Conference | Session TS-1694
Source Editor
GSL Files—a text file with a unique syntax
• Declare an org.netbeans.editor.Syntax subclass
(for completion and coloring)
• Add an EditorSupport cookie

SM
26 | 2004 JavaOne Conference | Session TS-1694
Context-Sensitive Help
Uses JavaHelpTM API
public HelpCtx getHelpCtx() {
return new HelpCtx(MyClass.class);
}

SM
27 | 2004 JavaOne Conference | Session TS-1694
Other Stuff...

• Update Center
• Templates
• Wizards
• Task list
• ANSI terminal
• ... And on, and on...

SM
28 | 2004 JavaOne Conference | Session TS-1694
Demo
Nuance V-Builder

SM
29 | 2004 JavaOne Conference | Session TS-1694
André Eickler

The Need for Rich Desktop Clients


Benefits of Modular Architecture
Branding and Customization
Case Study—V-Builder
Case Study—NetAct Desktop

SM
30 | 2004 JavaOne Conference | Session TS-1694
What Is NetAct?
Nokia’s product for managing mobile networks
• Manages thousands of network elements,
tens of network element types, tens of vendors
• Contains configuration, monitoring,
reporting, planning, ...

BTS BSC
HLR/AuC
MSC/VLR EIR/SMSC

SS7 Mobile ISP


Network Operator Services Application
SGSN Servers
CC&B router/firewall
Charging
GPRS Gateway NMS
Border Gateway backbone Corporate
Customer
Application
Servers
Inter-PLMN GGSN router/firewall
network
Lawful Interception Internet
Gateway (LIG)

SM
31 | 2004 JavaOne Conference | Session TS-1694
What Are NetAct’s UI Challenges?
Seamless integration of large numbers
of management tools
• More than 70 user interface applications
in Nokia’s product (plus other vendor’s
applications)
• Daily management procedures easily
involve ten or more graphical tools
• Procedures vary largely between
network operators

SM
32 | 2004 JavaOne Conference | Session TS-1694
What Is NetAct’s Solution?
NetAct Desktop = NetBeans + J2EE + Navigation
• NetBeans Platform
─ Module concept, window system, ...
─ JFC/Swing compatibility (porting existing
Uis, third-party software)
• J2EE platform client support
─ Java Web Start software support
─ ...
• Navigation goodies
─ ExtensibleNode
─ Bookmarks

SM
33 | 2004 JavaOne Conference | Session TS-1694
Screenshot

SM
34 | 2004 JavaOne Conference | Session TS-1694
Java Web Start Software Support
Integration with NetBeans module system
• Module discovery servlet
─ Find all deployed NetBeans modules on a server
─ Dynamically generate JNLP file
• Classpath workaround
─ Java Web Start breaks NetBeans’ module system
by making all downloaded classes visible
─ All files in module jars get prefixed by a directory
to make them “invisible”
─ E.g., class "org.netbeans.api.enode.ExtensibleNode"
becomes
"enode/org/netbeans/api/enode/ExtensibleNode.class"
─ Special classloader resolves access to classes
SM
35 | 2004 JavaOne Conference | Session TS-1694
http://installer.netbeans.org/docs/jnlpInstaller2.html
Extensible Node
Simple pluggable navigation feature
• Modules declare actions offered for
particular nodes as part of their Layer file:
<folder name="ExtensibleNode" >
<folder name="Actions" >
<folder name="Network Element">
<file name=
"com-nokia-oss-ResetAction.instance"/>
</folder>
</folder>
</folder>

• Other modules can use ExtensibleNode to


display popup menus with all declared actions
─ E.g., network elements displayed in
any module will offer the “reset” action
SM
36 | 2004 JavaOne Conference | Session TS-1694
http://openidex.netbeans.org/source/browse/openidex/enode
Bookmarks
Web-style navigation for NetBeans platform
• Forward/backward navigation between
tool states
public interface NavigationEvent {
public void restoreState();
public TopComponent getTopComponent();
}

SM
37 | 2004 JavaOne Conference | Session TS-1694
http://contrib.netbeans.org/source/browse/contrib/bookmarks/
Bookmarks

• Bookmarking tool states as keyboard


shortcut, “Bookmarks” menu, toolbar entries

public interface BookmarkProvider {


public Bookmark createBookmark();
}

public interface Bookmark


extends Presenter.Menu, Presenter.Toolbar {
public String getName();
public void invoke();
}

SM
38 | 2004 JavaOne Conference | Session TS-1694
Demo
NetAct Desktop

SM
39 | 2004 JavaOne Conference | Session TS-1694
NetBeans Has All You Need to Efficiently
Develop Integrated Rich Clients

Visit http://www.netbeans.org
Visit http://www.nuance.com
Visit http://www.nokia.com

The NetBeans Day


Tuesday in Yerba Buena Theater
Meet NetBeans on BOFs and sessions
Building Great Looking Swing Apps, 1237
Wednesday 11:00 AM
What’s New With NetBeans IDE?, 3204
Wednesday 9:45 AM
Integrating Ant and NetBeans, 1598
Wednesday 8:30 PM
Meet the NetBeans™ Development Team, 2730
Wednesday 7:30 PM

40
Get free stuff from the Nokia booth, 1415
SM
| 2004 JavaOne Conference | Session TS-1694
Q&A
André Eickler, Nokia
Jaroslav Tulach, Sun Microsystems
Rich Unger, Nuance
SM
41 | 2004 JavaOne Conference | Session TS-1694
How to Simplify Building
Rich Clients in the Java™
Programming Language java.sun.com/javaone/sf

Jaroslav Tulach, Sun Microsystems


Rich Unger, Nuance
André Eickler, Nokia

SM
42 | 2004 JavaOne Conference | Session TS-1694

Das könnte Ihnen auch gefallen