Table Of ContentBOOKS FOR PROFESSIONALS BY PROFESSIONALS®
Böck
The Definitive Guide to NetBeans
RELATED
Platform 7
The Definitive Guide to NetBeans Platform 7 covers all the major APIs of the NetBeans
Platform in detail, with relevant code examples throughout. It focuses strongly on busi-
ness features such as how to use OSGi, how to add authentication/security, and how
modular architectures can save money by streamlining management and updates.
With The Definitive Guide to NetBeans Platform 7, you’ll learn how to:
• Start using the NetBeans Platform, with or without the IDE
• Set up a modular application using either Ant or Maven
• Work with the popular and powerful Visual Library, covering all its features in detail
• Reuse OSGI bundles within your NetBeans Platform application
• Distribute a modular application, with strategies for monetizing its modular architecture
The Definitive Guide to NetBeans Platform 7 begins by explaining what the platform
is and what needs it fulfills. Next, the book covers the major conceptual divisions of
the platform (actions, user interface, file IO, data persistence, internationalization sup-
port) in detail. In addition, author Heiko Böck leads you through the development of
a complete rich client application which demonstrates first-hand the techniques used
to develop a typical NetBeans business application. From initial draft to creating the
basic structure to implementing the application logic, you will build an MP3 manager
that integrates the Java Media Framework (JMF) as well as the Java DB database
system among others.
Inside this thorough, authoritative guide you will find the knowledge you need to
develop rich client applications with the NetBeans Platform.
Shelve in
Programming Languages/Java
User level:
Beginning–Advanced
SOURCE CODE ONLINE
www.apress.com
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
Contents at a Glance
About the Author.................................................................................................xxv
About the Translator..........................................................................................xxvi
About the Technical Reviewers........................................................................xxvii
Acknowledgments...........................................................................................xxviii
Introduction.......................................................................................................xxix
Part 1: Basics & Concepts: Basics of the NetBeans Platform.................................1
Chapter 1: Introduction...........................................................................................3
Chapter 2: Structure of the NetBeans Platform.....................................................9
Chapter 3: The NetBeans Module System.............................................................17
Chapter 4: The OSGi Framework...........................................................................49
Chapter 5: Lookup Concept...................................................................................57
Chapter 6: Actions................................................................................................75
Chapter 7: Data and Files......................................................................................87
Chapter 8: Tips and Tricks..................................................................................101
Part 2: Look & Feel: Developing User Interfaces ................................................107
Chapter 9: Menu Bar and Toolbar.......................................................................109
Chapter 10: Window System...............................................................................123
Chapter 11: Status Bar and Progress Bar...........................................................147
Chapter 12: Nodes and Explorer.........................................................................157
Chapter 13: Dialogs and Wizards........................................................................169
Chapter 14: Visual Library..................................................................................187
Chapter 15: Tips and Tricks................................................................................207
iii
CONTENTS AT A GLANCE
Part 3: Ready & Go: Using the NetBeans Platform Standard Modules................215
Chapter 16: Help System....................................................................................217
Chapter 17: Output Window................................................................................225
Chapter 18: Navigator.........................................................................................229
Chapter 19: Properties........................................................................................235
Chapter 20: Options and Settings.......................................................................241
Chapter 21: Palette.............................................................................................251
Part 4: Use & Extend: Advanced APIs of the NetBeans Platform & ID................261
Chapter 22: Palette API.......................................................................................263
Chapter 23: Task List API ...................................................................................269
Chapter 24: Quick Search API.............................................................................275
Chapter 25: Auto Update Services API................................................................279
Part 5: Server & Database: Enterprise Applications and the NetBeans Platform287
Chapter 26: Java DB...........................................................................................289
Chapter 27: Hibernate.........................................................................................307
Chapter 28: Java Persistence API......................................................................315
Chapter 29: MySQL and EclipseLink...................................................................321
Chapter 30: Web Services...................................................................................327
Chapter 31: Java Enterprise Edition and the NetBeans Platform.......................333
Chapter 32: RESTful Web Services......................................................................345
Chapter 33: Authentication and Multi-User Login.............................................353
Part 6: Pack & Ship: Adapting, Delivering, and Actualizing Applications..........369
Chapter 34: Internationalization and Localization..............................................371
Chapter 35: Branding and Packaging Application..............................................379
Chapter 36: Updating a NetBeans Platform Application.....................................389
Part 7: Test & Tooling: Developing and Testing NetBeans Platform Applications399
Chapter 37: Maven and the NetBeans Platform..................................................401
Chapter 38: Eclipse IDE and the NetBeans Platform...........................................415
Chapter 39: From Eclipse to NetBeans...............................................................423
iv
CONTENTS AT A GLANCE
Chapter 40: IntelliJ IDEA and the NetBeans Platform.........................................431
Chapter 41: NetBeans Swing GUI Builder ...........................................................439
Chapter 42: Testing NetBeans Platform Applications.........................................459
Chapter 43: Debugging with the NetBeans IDE...................................................481
Part 8: Play & More: Developing an MP3-Manager............................................493
Chapter 44: Sample Project: MP3 Manager........................................................493
Appendix.............................................................................................................529
Index...................................................................................................................537
v
Introduction
With this work in your hands, you hold the most current and the most comprehensive guide to the
Swing-based rich client platform, NetBeans Platform 7. This theme-rich client platform is highly topical.
In addition to the NetBeans Platform, Eclipse RCP is also a principal representative of this category. The
development of these two platforms was mainly driven by the NetBeans and Eclipse integrated
development environments (IDEs). Those two IDEs are based on their respective platforms and
represent a rich client application themselves. The NetBeans Platform is completely based on the Java
API with AWT and Swing and integrates the concepts of the Java Standard Edition (JSE), while the
Eclipse RCP with SWT and JFace builds more and more on its own approaches and concepts.
Rich client platforms are flexible and used mainly for their constantly increasing requirements for
applications and their architecture. One crucial aspect is their increased productivity and flexibility to be
able to equip a product depending on its intended usage and to adapt it to a market. This is especially
important for professional applications.
In my opinion, the NetBeans Platform is always worth using, even if an application is very small or
quite huge, because of the comprehensive support actually provided by the NetBeans IDE. It is also
already worth it because of the execution environment, and even more so because of the numerous APIs
that provide practical solutions for frequently occurring problems and challenges with client application
development. These solutions are very close to the practice and the application and increase
productivity a lot.
However, this assumption is based on one basic condition: professional knowledge and use of the
workings of the rich client platform. The application developer should at least know the main principles;
only then can the real advantages of increased productivity and greater software quality be achieved in
practice.
Many developers have assumed the platform was too complex, which is one of the main reasons the
rich client platforms have not yet been established as quasi-standards for client application
development. At first, developers may get the impression that there is a huge wall of APIs and concepts
to master. However, once you begin to learn more, you find that there are immense synergies and
simplifications possible, which make up for the challenges of the initial learning phase.
The NetBeans IDE simplifies both daily usage and developers’ learning curve by providing
comprehensive, helpful, and intuitive wizards. It is surely important that all NetBeans APIs and concepts
build on the APIs and concepts of the Java Standard Edition (JSE). That fact simplifies everyday
experiences with it and also facilitates the reuse of already existing components.
News of the NetBeans Platform
The NetBeans Platform 7 contains numerous innovations. One crucial innovation is the introduction of
Annotations. Actions, for example, do not have to derive from a special class anymore. Thus, actions can
be registered via annotations, and at the same time, actions can be added to a menu or to a toolbar, too.
Before, you had to assign two separate configuration files for top components. Now, top components are
registered via annotations and made public to the NetBeans Platform. Declarative information can now
be directly and decentrally provided because of using annotations. Annotations are well documented
xxix
INTRODUCTION
and are checked by the editor or respectively by the compiler;, information is provided in a simpler
manner and potential erratic entries in XML are avoided. Furthermore, the information is located
exactly at the position it refers to, so no additional files have to be managed. This also simplifies
refactoring and facilitates the NetBeans Platform’s independence of the NetBeans IDE. Bear in mind
that the necessary configuration files, or rather configuration entries, are created out of the annotations
at compile time. This means using annotations is not mandatory; you can also manually create the
necessary configuration as previously.
Whether or not you use annotations is a question of philosophy in the end, and also depends on the
project’s size and on your special needs. Of course, you can also look at the disadvantages of
annotations. For example, the meta-information is scattered in the source files. A central file might be
easier to adapt or to overlook.
The support of OSGi bundles is also a crucial innovation. Now OSGi bundles can be executed
parallel to NetBeans modules within the NetBeans Platform 7. For this purpose, the OSGi framework,
Felix or Equinox, is optionally integrated in the NetBeans Platform. It is also possible to convert the
NetBeans Platform modules into OSGi bundles. This innovation allows the use of numerous existing
OSGi bundles.
Out-of-the-box support of Maven can also be called an innovation. NetBeans Platform applications
can now be completely developed via Maven. With the NetBeans Maven plugin and the availability of all
NetBeans Platform modules in a public Maven repository, there is nothing that prevents using the
NetBeans Platform outside the NetBeans IDE.
How This Book Is Structured
This book is aimed at Java developers who want to develop client applications based on the NetBeans
Platform. No previous knowledge of rich client platforms is required. The main goal of this book is to
provide the basic ideas and functionalities of the NetBeans Platform close to actual practice and to
explain the very good support the NetBeans IDE provides for the development phase of your application
as well as the interfaces and advantages of the NetBeans Platform. In this way I hope to motivate you to
further use the NetBeans Platform—and to ask yourself why you have not been developing your
applications on the basis of a rich client platform already, especially once you recognize the numerous
advantages you could have benefited from in the past.
The separate chapters of the book are mostly independent of each other, in order to give you a way
to get directly into individual chapters, and to provide you an optimal manual for developing rich client
applications based on the NetBeans Platform. To keep the chapters clear and to facilitate direct access,
the explanations within this book are supported by small examples without referring to an overall
application. At the end of the book, I will show how to create a complete rich client application, from the
draft phase over creating the basic structure to implementing the application logic. I will explain this in a
tutorial-like format with the example of an MP3 manager. In this application you will integrate the Java
Media Framework (JMF) as well as the Java DB database system, among others.
Part 1 deals with the basic features and concepts of the NetBeans Platform. At first, you will learn
how a rich client is defined, which features a rich client platform generally contains, and which special
advantages the Netbeans Platform provides. Additionally, because the module-based nature is crucial, I
will cover both the NetBeans module system and the OSGi framework in the Part 1. The central topics of
Lookup, actions, and data management complete the first part with one chapter each.
Part 2 is completely devoted to developing user interfaces. This part mainly deals with the Window
System as well as the menu bar, toolbar, status bar, and progress bar. Due to the support of the Window
System, you can implement and easily manage your own windows. Connected to the data management,
which is explained in the first part, you will learn about the flexible node concept together with the
xxx
INTRODUCTION
Explorer API in a separate chapter. This part also covers developing dialogs and wizards as well as using
the powerful Visual Library API.
In Part 3 we will take a closer look at the standard modules of the NetBeans Platform which can be
used directly without great effort. This includes the help system, the output window, the navigator, the
properties window, the options dialog, and the palette module. I will explain how to use each of them in
a separate chapter.
Part 4 is about using the very helpful APIs of the NetBeans Platform and the NetBeans IDE. Actually,
you are not limited to the modules of the NetBeans Platform. One chapter explains how to use the
Palette API and another how to use the Task List API. Additionally, we will take a closer look at the Quick
Search and the Auto Update Services API by means of examples that are close to actual practice.
With Part 5 I put the NetBeans Platform in the context of databases and Java EE applications. First,
you will use the Java DB as a client-side database solution within a NetBeans Platform application. Using
Hibernate to facilitate accessing databases is covered in a following chapter. However, applying
Hibernate does not need to be dependent on a special object-relational mapping (ORM) framework. In a
later chapter, I will explain how to integrate the Java Persistence API (JPA) for this purpose. As an
alternative to Java DB and Hibernate, I will also go deeper into the MySQL database solution in
connection with EclipseLink. We will look at the topic of web services from both sides in this part: on the
one hand, it is about using any available web services using SOAP. On the other hand, it is about
connecting server-side Java EE applications using SOAP and REST-based web services. A final chapter
will answer questions concerning authentication of users and specific adaptation of the application.
In Part 6 you will learn which possibilities the NetBeans Platform provides concerning
internationalization and localization. Furthermore, this part covers the branding of the NetBeans
Platform as well as packing the whole application as a deliverable unit. In another chapter you will learn
about the update mechanism of the NetBeans Platform with which you can update your application in a
simple and transparent manner after delivering.
Part 7 of this book is about the different development and test tools of the NetBeans Platform or,
respectively, of the NetBeans IDE. First, it is about implementing NetBeans Platform applications using
the Maven build system. In another chapter you learn about how to develop NetBeans Platform
applications even within the Eclipse IDE using Maven. Additionally, one chapter will simplify changing
from the Eclipse IDE to the NetBeans IDE to develop NetBeans Platform applications. In addition to the
NetBeans and the Eclipse IDE, the IntelliJ IDEA can also be used to develop NetBeans Platform
applications. The NetBeans IDE provides a powerful GUI builder for the efficient development of user
interfaces. You will learn how to use it and how to debug and test your application in separate chapters.
Part 8 completes this guide with a fully functional example. In the course of this part, you develop
an MP3 manager application step by step. The previously described concepts and technologies come
together here and can be understood as in actual practice.
Downloading the Code
All examples and explanations in this book are based on Java 6 and NetBeans 7. You can download the
Java Development Kit (JDK 6) at http://java.oracle.com and NetBeans 7 at http://netbeans.org.
Each of the source code examples in this book can be downloaded from the Source Code/Download
area for this book on the Apress web site as a complete runnable NetBeans IDE project.
xxxi
PART 1
Basics & Concepts: Basics
of the NetBeans Platform
C H A P T E R 1
Introduction
This chapter introduces you to rich client development. In the process, you will learn what a rich client is
and how a rich client platform can help you. This chapter will also briefly touch on the main advantages
and characteristics of the NetBeans Platform.
What Is a Rich Client?
In a client server architecture the term rich client is used for clients where the data processing occurs
mainly on the client side. The client also provides the graphical user interface (GUI). Often rich clients
are applications that are extendable via plugins and modules. In this way, rich clients are able to solve
more than one problem.
Rich clients are typically developed on top of a framework. A framework offers a basic starting point
on top of which the user can assemble logically related parts of the application, which are called
modules. Ideally, unrelated solutions (such as those made available by different providers) can work
together, so that all the modules appear to have been created as one whole.
Above and beyond all that, rich clients have the advantage that they are easy to distribute and
update, such as via an automatic online update function within the client itself or through a mechanism
that enables the rich client to start over the Internet (for example, via Java Web Start).
Here’s an overview of the characteristics of a rich client:
• Flexible and modular application architecture
• Platform independence
• Adaptability to the end user
• Ability to work online as well as offline
• Simplified distribution to the end user
• Simplified updating of the client
What Is a Rich Client Platform?
A rich client platform is an application lifecycle environment, a basis for desktop applications. Most
desktop applications have similar features, such as menus, toolbars, status bars, progress visualizations,
3