the definitive guide to netbeans platform - springer978-1-4302-2418-1/1.pdf · the definitive guide...

22
The Definitive Guide to NetBeans Platform ■■■ Heiko Böck

Upload: dangbao

Post on 08-Aug-2018

232 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

The Definitive Guide to NetBeans™ Platform

■ ■ ■

Heiko Böck

Page 2: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

The Definitive Guide to NetBeans™ Platform

Copyright © 2009 by Heiko Böck

All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.

ISBN-13 (pbk): 978-1-4302-2417-4

ISBN-13 (electronic): 978-1-4302-2418-1

Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1

Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.

Java™ and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc., in the US and other countries. Apress, Inc., is not affiliated with Sun Microsystems, Inc., and this book was written without endorsement from Sun Microsystems, Inc.

Lead Editor: Jim FreemanTechnical Reviewers: Jaroslav Tulach, Geertjan WielengaEditorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Tony Campbell, Gary

Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh

Project Manager: Douglas SulentaCopy Editor: Damon LarsonAssociate Production Director: Kari Brooks-CoponySenior Production Editor: Laura CheuCompositor: Ellie FountainProofreader: Nancy SixsmithIndexer: BIM Indexing & Proofreading ServicesArtist: Kinetic Publishing Services, LLCCover Designer: Kurt KramesManufacturing Director: Tom Debolski

Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail [email protected], or visit http://www.springeronline.com.

For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600, Berkeley, CA 94705. Phone 510-549-5930, fax 510-549-5939, e-mail [email protected], or visit http://www.apress.com.

Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at http://www.apress.com/info/bulksales.

The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work.

The source code for this book is available to readers at http://www.apress.com.

Page 3: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

Dedicated to the NetBeans Platform community

Page 4: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

v

Contents at a Glance

Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii

About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi

About the Technical Reviewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii

Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv

■CHAPTER 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

■CHAPTER 2 Structure of the NetBeans Platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

■CHAPTER 3 The Module System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

■CHAPTER 4 Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

■CHAPTER 5 User Interface Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

■CHAPTER 6 Lookup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

■CHAPTER 7 File Access and Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

■CHAPTER 8 Graphical Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

■CHAPTER 9 Reusable NetBeans Platform Components . . . . . . . . . . . . . . . . . . . . 175

■CHAPTER 10 Internationalization and Localization . . . . . . . . . . . . . . . . . . . . . . . . . 205

■CHAPTER 11 Real-World Application Development . . . . . . . . . . . . . . . . . . . . . . . . . 213

■CHAPTER 12 Updating a NetBeans Platform Application . . . . . . . . . . . . . . . . . . . . 219

■CHAPTER 13 Persistence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229

■CHAPTER 14 Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261

■CHAPTER 15 Extending the NetBeans IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269

■CHAPTER 16 From Eclipse RCP to the NetBeans Platform . . . . . . . . . . . . . . . . . . 279

■CHAPTER 17 Tips and Tricks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287

■CHAPTER 18 Example: MP3 Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297

■APPENDIX Important NetBeans Extension Points and Configuration DTDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331

■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337

Page 5: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

vii

Contents

Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii

About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi

About the Technical Reviewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii

Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv

■CHAPTER 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

What Is a Rich Client? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

What Is a Rich Client Platform? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Advantages of a Rich Client Platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Reduction in Development Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

User Interface Consistency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Updating. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Platform Independence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Reusability and Reliability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Characteristics of the NetBeans Platform . . . . . . . . . . . . . . . . . . . . . . . . . . 4

User Interface Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Data Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Customization Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Wizard Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Data Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Internationalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Help System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

■CHAPTER 2 Structure of the NetBeans Platform. . . . . . . . . . . . . . . . . . . . . . . . 7

NetBeans Platform Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

NetBeans Platform Distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

NetBeans Runtime Container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

Page 6: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

viii ■C O N T E N T S

NetBeans Classloader System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

Module Classloader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

System Classloader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

Original Classloader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

■CHAPTER 3 The Module System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

Module Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

Module Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

Regular. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Autoload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Eager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Module Manifest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

Module Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

Order of Entries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

Instance Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

Shadow Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

Settings Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

Creating and Using Your Own Contents . . . . . . . . . . . . . . . . . . . . . . . 29

Creating Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

Versioning and Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

Versioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

Defining Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

Lifecycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

Module Registry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

Using Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

Library Wrapper Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

Adding a Library to a Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

Page 7: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

■C O N T E N T S ix

■CHAPTER 4 Actions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

Providing Action Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

Always Enabled Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

CallableSystemAction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

CallbackSystemAction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

CookieAction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

General Context-Sensitive Action Classes . . . . . . . . . . . . . . . . . . . . . 55

Registering Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

Shortcuts and Mnemonics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

■CHAPTER 5 User Interface Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

Menu Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

Creating and Adding Menus and Menu Entries . . . . . . . . . . . . . . . . . 62

Inserting Separators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

Hiding Existing Menu Entries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

Creating a Custom Menu Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

Toolbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

Creating Toolbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

Configuring Toolbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

Modification by the User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

Creating Custom Toolbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

Using Custom Control Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

Window System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

Customization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

Window: TopComponent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

Docking Container: Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

Groups of Windows: TopComponentGroup . . . . . . . . . . . . . . . . . . . . 83

Status Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

Using the Status Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

Extending the Status Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

Page 8: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

x ■C O N T E N T S

Progress Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

Displaying the Progress of a Task . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

Displaying the Progress of Many Related Tasks . . . . . . . . . . . . . . . . 90

Integrating a Progress Bar into Your Component . . . . . . . . . . . . . . . 92

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

■CHAPTER 6 Lookup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

Services and Extension Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

Defining the Service Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

Loose Service Provisioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

Providing Multiple Service Implementations . . . . . . . . . . . . . . . . . . . 96

Ensuring Service Availability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

Global Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

Registering Service Providers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

Service Provider Configuration File. . . . . . . . . . . . . . . . . . . . . . . . . . 100

Services Folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101

Intermodule Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

Java Service Loader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

■CHAPTER 7 File Access and Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

File Systems API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110

Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

Data Systems API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

DataObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

DataObject Factory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121

DataLoader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121

Nodes API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124

Node Container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

Implementing Nodes and Children . . . . . . . . . . . . . . . . . . . . . . . . . . 126

Explorer & Property Sheet API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

Page 9: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

■C O N T E N T S xi

■CHAPTER 8 Graphical Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

Dialogs API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

Standard Dialogs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

Custom Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

Wizards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140

MultiViews API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151

Visual Library API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154

Structure of the Visual Library API . . . . . . . . . . . . . . . . . . . . . . . . . . 155

The Widget Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155

Events and Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159

The Scene: The Root Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

ObjectScene: Model-View Relationship . . . . . . . . . . . . . . . . . . . . . . 167

Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168

VMD: Visual Mobile Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173

■CHAPTER 9 Reusable NetBeans Platform Components . . . . . . . . . . . . . . 175

Help System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175

Creating and Integrating a Helpset . . . . . . . . . . . . . . . . . . . . . . . . . 175

Adding Links to Help Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178

Context-Sensitive Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179

Opening the Help System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180

Output Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180

Navigator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182

Properties Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186

Providing Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186

User-Defined Properties Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188

Options Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189

Providing an Options Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190

Settings Administration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194

Palette . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196

Defining and Adding Palette Components via the Layer File . . . . . 197

Creating a Palette from a Node Hierarchy . . . . . . . . . . . . . . . . . . . . 198

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204

Page 10: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

xii ■C O N T E N T S

■CHAPTER 10 Internationalization and Localization . . . . . . . . . . . . . . . . . . . . 205

String Literals in Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205

String Literals in the Manifest File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207

Internationalization of Help Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208

Internationalizing Other Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209

Graphics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209

Any File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209

Folders and Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210

Administration and Preparation of Localized Resources . . . . . . . . . . . . 211

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212

■CHAPTER 11 Real-World Application Development . . . . . . . . . . . . . . . . . . . . 213

Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213

Customization of Platform Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214

Customizing the Launcher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215

Distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216

Distribution As a ZIP Archive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216

Distribution via Java Web Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217

Mac OS X Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218

■CHAPTER 12 Updating a NetBeans Platform Application . . . . . . . . . . . . . . 219

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219

The Auto Update Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219

The NBM File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220

Update Centers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223

Localized NBM Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224

Configuring and Installing on the Client . . . . . . . . . . . . . . . . . . . . . . . . . . 225

New Update Center. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226

Automatically Installing Updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227

Page 11: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

■C O N T E N T S xiii

■CHAPTER 13 Persistence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229

Java DB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229

Integrating Java DB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229

Driver Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230

Creating and Using a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230

Shutting Down a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232

Database Development with the Help of the NetBeans IDE . . . . . . 232

Example Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235

Hibernate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245

Setting Up the Hibernate Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . 245

Structure of the Example Application . . . . . . . . . . . . . . . . . . . . . . . . 246

Configuring Hibernate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247

Mapping Objects to Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248

SessionFactory and Sessions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250

Saving and Loading Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251

Java Persistence API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253

Hibernate and the Java Persistence API . . . . . . . . . . . . . . . . . . . . . 253

Java Persistence Configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254

Entity Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255

EntityManagerFactory and EntityManager . . . . . . . . . . . . . . . . . . . . 257

Saving and Loading Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259

■CHAPTER 14 Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261

Creating a Web Service Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261

Using a Web Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267

■CHAPTER 15 Extending the NetBeans IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269

Palettes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269

Defining and Registering Palette Entries . . . . . . . . . . . . . . . . . . . . . 270

Creating and Registering a PaletteController. . . . . . . . . . . . . . . . . . 272

Expanding Existing Palettes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273

Task List API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277

Page 12: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

xiv ■C O N T E N T S

■CHAPTER 16 From Eclipse RCP to the NetBeans Platform . . . . . . . . . . . . . 279

The NetBeans IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279

Standard Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279

Handling Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280

From Eclipse Plugins to NetBeans Modules . . . . . . . . . . . . . . . . . . . . . . 280

Plugin: Lifecycle and Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281

Plugin Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282

Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283

Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283

Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284

Application Lifecycle. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284

Views and Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285

■CHAPTER 17 Tips and Tricks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287

Asynchronous Initialization of Graphic Components . . . . . . . . . . . . . . . . 287

Undo/Redo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289

Ending an Application’s Lifecycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291

WarmUp Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292

System Tray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293

Desktop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293

Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294

Logger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294

LogManager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295

Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295

Error Reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296

■CHAPTER 18 Example: MP3 Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297

Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297

Creating the NetBeans Platform Application . . . . . . . . . . . . . . . . . . . . . . 299

Support for MP3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299

Creating the JMF Module. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299

Registering the MP3 Plugin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300

MP3 File Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300

ID3 Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302

ID3 API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302

ID3 Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304

Page 13: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

■C O N T E N T S xv

Media Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307

Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308

MP3 Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309

Service Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309

Service Provider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311

Playback of MP3 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314

User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315

Playlist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318

Node View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318

Node Container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319

TopComponent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320

Drag-and-Drop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324

Saving the Playlist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329

■APPENDIX Important NetBeans Extension Points and Configuration DTDs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331

■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337

Page 14: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

xvii

Foreword

The best way to improve what you do is to find someone who will do it for you better than you could have done yourself. I’ve seen this principle in action over and over again. For example, it was fine designing the NetBeans IDE and NetBeans Platform on my own. Now, however, it is much better, since there are far more talented developers designing the various individual parts together. Similarly, I was OK writing documentation for the NetBeans Platform, but it is much better to have a group of enthusiastic people who produce tons of interesting tutorials and blogs on topics that I would never have thought up myself. Along the same lines, it was entertaining to contribute to a book about the NetBeans Platform. However, it is an order of magnitude better to see this one by Heiko! It is richer and more interesting. Plus, it covers topics that I never dreamed of covering myself.

My first encounter with this book dates back to 2007 when Heiko finished his German version. I was asked to review the book’s content. However, as my German reading abilities are close to zero, my goal was more to read the sample Java code and ensure that correct patterns were used and described. It quickly became easy to see that everything was more than OK. Not only that, I could immediately see that the topics were extraordinary and that they brought new ideas into the NetBeans Platform world.

I am glad that Heiko’s interesting insights are now available to a broader audience. Thank you Heiko! Thank you too, dear English translators!

Jaroslav TulachNetBeans Team Member

One of the wonderful things about the NetBeans Platform is that it is impossible to run out of new things to do with it. For me, it has been an inexhaustible source of inspiration—and that is still true ten years after I first started working with it!

I have coauthored two books on the NetBeans Platform in the past, and when we were finishing up, there were always things we wished we had more time or space to cover. So there can never be enough books about it—every author has a different perspective on the topic.

To Heiko I offer my heartfelt thanks for shining his unique insight on the NetBeans Plat-form; to you, dear reader, I wish you happy coding and joy in learning to love a framework that I have helped to build, and that has been a labor of love for many years.

Tim BoudreauNetBeans Team Member

What I like most about this book is the number of interesting side roads you will find yourself traveling as Heiko takes you by the hand and helps you explore the NetBeans Platform. Many of the topics addressed here have not been addressed anywhere else—from persistence, to the Task List API, to the integration of JDK 6 features into NetBeans Platform applications. You will

Page 15: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

xviii ■F O R E W O R D

have a very hard time avoiding learning many new things here, regardless of the amount of experience and skills you bring to the table.

Over the past two or three years, the NetBeans Platform has seen a continual surge in popularity in companies around the world. This is in part because of its modular architecture, in combination with its reliance on the standard Swing UI toolkit. But, certainly, the growing adoption of the NetBeans Platform can also be attributed to the enthusiasm of its users. Without them, the book you’re now holding would certainly not have come to be. In fact, a small army from the NetBeans Platform community translated this book from scratch in the space of a single month. As one of them, I can say that I have learned an unlikely amount of details about the NetBeans Platform—details I would never otherwise have learned about. Many thanks to Heiko for this great book and for all the work that went into it, as well as all the work that went into updating it to 6.5!

Jim Freeman, the book’s editor in Prague, deserves high praise for his editing skills, as well as for his sage advice and encouragement to me personally, and for his living room and cups of hot coffee every morning for the duration of the translation project. Many thanks also to Michaela Freeman for being so supportive, too. Also, much gratitude to the team at Apress for their close cooperation and precision work throughout: Steve Anglin, Grace Wong, Douglas Sulenta, and Damon Larson. On a personal note, based on the experiences of the past months, Jim Freeman and Damon Larson are really very highly recommended technical editors indeed.

Finally, to the translators, who tirelessly slaved on their assigned chapters, I express my warm gratitude: Zane Cahill, Stefan Alexander Flemming, Matthias Holzinger, Peti Horozoglu, Martin Klähn, Pavel Kotlov, Christian Pervoelz, Christian Enrique Portilla Pauca, Sven Reimers, Johannes Strassmayr, and Fionn Ziegler.

Some of the translators share their experiences translating the book and learning about the NetBeans Platform in the following paragraphs.

Geertjan WielengaNetBeans Team Member

Having been a developer of NetBeans Platform applications for the last eight years, I am always on the lookout for more and better documentation. And then Heiko published his book! Without any high expectations, I started reading it to write a review, and was astonished by the wealth of information Heiko managed to cover. So, always looking for ways to contribute to the NetBeans Platform, I volunteered to take part in the translation project to make all this avail-able to a much broader audience.

If you’ve already read a book on the NetBeans Platform, you may ask yourself why you want to read this one. To make a long story short, it’s the unique and detailed content about the basics of the NetBeans Platform that makes this book surpass the others. You will learn about creating loosely coupled modules using the Lookup API, details of the module system, and how to create your own full-scale applications based on the NetBeans Platform.

Thanks to Heiko for the effort he originally put into his book and the opportunity to be part of such an extraordinary project. We all owe Geertjan big, for being the one leading us, offering help, organizing, and pushing the translation effort.

Sven ReimersTranslator

Page 16: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

■F O R E W O R D xix

This book is a great source of information and will hopefully be as valuable for other developers as it was for me. I’m thankful for the opportunity to contribute to this project and hope all readers will have as much fun reading as I had translating!

Johannes StrassmayrTranslator

Confronted with the task of porting a big legacy application to the NetBeans Platform, I’ve read all the literature on the topic and found this particular book a great source of practical examples and well-structured information.

It was a pleasure to read this book, so I was really honored to be part of the translation team. I hope the English version will help even more people to find their way into the NetBeans Platform community.

Pavel KotlovTranslator

Translating this book was an interesting process—to do a good job, I had to take into account each aspect of the NetBeans Platform, as well as Java programming in general. This book is a good source of experience for programming in Java using the NetBeans IDE and the NetBeans Platform underneath it, which together provide many tools and components for working with Java. Combined with some practice and basic Java knowledge, this book will make you a better programmer.

Translating the chapters assigned to me, I learned a great deal about actions and compo-nents for building GUIs for Java applications—I’m confident that this book is a good reference for these topics.

Many thanks to Geertjan for giving me the chance to work on this translation. It has improved my translation abilities and allowed me to learn more about the NetBeans Platform. I look forward to hearing about readers’ enjoyment of this book!

Christian Portilla PaucaTranslator

I well remember the first time I read the German version of Heiko’s book because it was the moment when I really started understanding the ideas behind the most common NetBeans Platform patterns. So, I’m all the more happy to have been asked to help translate a part of my favorite NetBeans book into English.

It was a great experience to work on a team that managed to translate a whole book in just one month!

Stefan Alexander FlemmingTranslator

The book caught my attention during the development of a product based on the NetBeans Platform. It gave me good ideas for solving many challenges and ensuring better product quality. I improved my knowledge of the NetBeans module system while translating the book. It is an honor to have been involved in the translation process.

Page 17: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

xx ■F O R E W O R D

While translating, I gained a better understanding of the window system, especially regarding the layer.xml file and its relation to the System Filesystem. Additionally, I learned a lot about defining and managing dependencies between modules with different versions, as well as integrating modules into the NetBeans Platform.

Fionn ZieglerTranslator

Three years ago, I started an internship in a department developing a NetBeans Platform appli-cation. Not having encountered NetBeans at all up to that point, I had to familiarize myself with both the IDE and its platform. Once I realized how easy it is to develop applications with the NetBeans IDE, I bade goodbye to my dear old friend Eclipse and welcomed the NetBeans IDE with open arms! I was later integrated into the development team and brought up to speed amazingly quickly. About a year later, Heiko published his book, and even more concepts became clear to me.

Then came the day the community effort to translate Heiko’s book was announced. I volunteered my help to broaden the distribution of knowledge contained in this book to English-speaking readers and developers. After working on the chapter concerning the user interface, I realized that my understanding of the concepts conveyed had increased without my having been aware of it.

Heiko’s work putting this book together helped a lot of people to develop NetBeans Plat-form applications, myself included. Geertjan, as manager of this project, has done tremendous work bringing this project to fruition. We owe many thanks to Heiko and Geertjan for doing what they did. I am hopeful that you as a reader can learn as much as I did when I first began digging my claws into it all. And I hope you enjoy the experience while doing so!

Martin KlähnTranslator

I had seen testimonials to this book frequently pop up on mailing lists and blogs, so when the opportunity presented itself to support a translation, I could not resist the appeal to be associ-ated with this excellent book and a community project involving like-minded NetBeans Platform enthusiasts.

Fortunately, part of my assignment was the Visual Library API, a feature set I never had the opportunity to use before, so the task was also a great learning experience. At the outset, I thought the Visual Library API would be complex with a steep learning curve. However, Heiko shows how quick and easy it is to visualize structures, while highlighting important concepts (such as tools that give rise to contextual actions) and providing useful tips (such as exporting representations to PNG image files).

Hopefully you will enjoy the read as much as I have, and discover a great deal from the experience!

Zane CahillTranslator

Page 18: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

xxi

About the Author

■HEIKO BÖCK is pursuing his master’s degree in informatics at TUM, a tech-nical university in Munich, Germany. He is the author of the book from which this English version was translated. He is a highly respected member of the NetBeans Platform’s developer community, and is a member of the NetBeans Dream Team.

Page 19: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

xxii

About the Technical Reviewers

■JAROSLAV TULACH cofounded the NetBeans project, and remains a leading guardian of the NetBeans APIs. He is the author of Practical API Design: Confessions of a Java Framework Architect (Apress, 2008) and coauthor of Rich Client Programming: Plugging into the NetBeans Platform (Prentice Hall PTR, 2007). He lives in Prague, in the Czech Republic, where he continues to work as a member of the NetBeans team.

■GEERTJAN WIELENGA is the technical writer responsible for the documenta-tion relating to the NetBeans APIs. He writes the tutorials and JavaHelp topics relating to this area of the NetBeans project. Like Jaroslav, he coau-thored Rich Client Programming: Plugging into the NetBeans Platform, and he lives in Prague and works as a member of the NetBeans team.

Page 20: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

xxiii

Acknowledgments

I am very pleased that the original German book is now available in English and thus to a worldwide readership! After long consideration, I almost wanted to reject the concept of a translation project due to lack of time and the enormous expense involved. But then, fortu-nately, Geertjan Wielenga joined the game, managing to get 11 other industrious translators on board. By joining forces, the book was translated within a single month. What I had considered impossible came true within a few weeks.

For this success, I would like to especially thank Geertjan. Through his hard work, the project was programmed for success from the beginning. In the same way, I would like to express my gratitude to the translators for their passionate cooperation. Many thanks also go to Jim Freeman, the editor of the translation project. Last but not least, I offer many thanks to all participating Apress employees for their great cooperation.

And you, dear reader: I wish you a lot of fun discovering the world of the NetBeans Platform with its numerous features, as well as a lot of success in implementing your projects!

Heiko Böck

Page 21: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

xxiv

Introduction

Over the past several years, rich client desktop platforms have gradually increased in popu-larity. Leading this trend have been the NetBeans Platform and the Eclipse RCP. The popularization of these desktop platforms has been primarily driven by their related IDEs, which are based on these platforms, providing tools for applications developed on top of their infrastructures. While the Eclipse RCP bases itself, via SWT and JFace, on homegrown idioms and concepts, the NetBeans Platform relies completely on the standard Java APIs, via AWT and Swing, fully integrating the official concepts of the Java Standard Edition.

In the desktop world, rich client platforms are used first and foremost because of the archi-tecture and flexibility they offer to continually growing applications. A significant factor is the increased productivity and flexibility in being able to assemble an application for one purpose and then reassemble it for a different purpose without much extra work, thanks to their flexible modular architecture. Especially for large and professional applications, these concerns are of particular relevance.

It is my opinion that all desktop applications stand to gain from basing themselves on a rich client platform, regardless of their size. The case for this argument can be made by looking, in particular, at the lifecycle management offered by rich client platforms, together with their rich set of APIs, which provide out-of-the-box solutions for the daily challenges faced by desktop application developers. These solutions are tailored specifically to the demands of these kinds of developers, as a result increasing productivity significantly. However, the universal relevance of rich client platforms requires an appropriate handling of the related concepts. At the very least, the developer needs to be comfortable with the main idioms of the platform in question. Only then can the real advantages in increased productivity and improved quality be realized.

The supposed complexity of rich client platform concepts is one of the central reasons why such platforms have, so far anyway, not been adopted as a de facto standard in the development of desktop applications. At the outset, developers often have the impression of standing in the foothills of an overwhelming mountain of new APIs and concepts. However, once developers integrate these APIs and concepts into their mental toolbox, a surprisingly expansive vista of synergies and simplifications is suddenly available, making the learning curve a worthwhile expense.

Consider the most recent enhancements in the Java Platform in relation to desktop appli-cations, such as the improved desktop integration and the performance enhancements, and then examine the plans for the Java Platform in the future. When you do so, you’ll notice that the Java Platform is moving in directions that rich client desktop platforms have been exploring from their very beginnings. When I refer to the future, I am referring in particular to the Java Module System (JSR 277), which promises to bring the central concepts of rich client platform development to the Java Platform.

Finally, I’d like to include a note on the NetBeans IDE in relation to the NetBeans Platform. The IDE provides, via its thorough and helpful wizards, effective support for developers getting started with application development on this particular rich client platform. Important for an

Page 22: The Definitive Guide to NetBeans Platform - Springer978-1-4302-2418-1/1.pdf · The Definitive Guide to NetBeans™ Platform ... eBook versions and licenses are also available for

■I N T R O D U C T I O N xxv

easy start is that many of the APIs and concepts you will learn about are directly derived from the Java SE API. Thanks to these factors, you will be able to get started with the NetBeans Plat-form quite quickly. Reuse of components across different applications will then also rapidly become a possibility.

How This Book Is StructuredThis book is aimed at Java developers wanting to create desktop applications on top of the NetBeans Platform. No knowledge of the NetBeans Platform is assumed. The primary goal of this book is the practical explanation of the basic concepts and functionalities of the NetBeans Platform. In the process, you will be introduced to the great support for this kind of develop-ment offered by the NetBeans IDE. You will hopefully begin asking yourself why you haven’t been developing your desktop applications on top of a platform all along! At the very least, you will learn about the many advantages you could have benefited from in your past Java programming activities.

Firstly, the book discusses the definition of rich clients and rich client platforms. The argu-ment for the general usefulness of these concepts culminates with an examination of the advantages of rich client platforms in general and the NetBeans Platform in particular.

Next, you are introduced to the architecture of the NetBeans Platform. You’ll learn how a rich client application is structured, how your application’s business logic is integrated into the NetBeans Platform, and how to efficiently use the NetBeans Platform concepts and compo-nents. You’ll also be shown how to make your applications user- and locale-specific, how to distribute them, and how to update them after distribution.

An important discussion relating to rich client development is that of persistence. This book dives into this topic in some detail, introducing you to the Java Persistence API in combi-nation with Hibernate, as well as with Java DB.

The desktop integration possibilities offered by Java 6 are explained as well. The powerful Visual Library API, which has belonged to the NetBeans Platform since version 6.0, is examined closely, as is the increasingly relevant topic of web services.

This book discusses the similarities and differences between Eclipse RCP and the NetBeans Platform, and walks you through the migration of an existing Eclipse RCP application to the NetBeans Platform.

The individual chapters are structured such that they are as loosely tied to each other as possible. The intent is for you to be able to dive directly into a chapter, without having to be too familiar with the preceding or following parts. I think you will find this approach optimal for the development of rich client applications on top of the NetBeans Platform. To give a practical perspective to each chapter, and to let you use their contents immediately, the explanations in the book are accompanied by small examples, rather than a large overarching application that spans the whole book. At the end of the book, a complete application on the NetBeans Platform is described in some detail, from its starting point to the implementation of business logic, in a tutorial-like format, describing the creation of an MP3 Manager. In this application, you’ll inte-grate the Java Media Framework together with a Java DB database.

All the examples and explanations in this book are based on Java 6, together with the NetBeans Platform 6.5, although Java 5 should in most cases be sufficient, too. You can obtain the Java Development Kit from http://java.sun.com, and you can download the NetBeans IDE from http://netbeans.org. You can download the examples as complete NetBeans projects from the Source Code section of the Apress web site, at http://apress.com.