DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Managing Data Residency, the Demo
  • Front-End: Cache Strategies You Should Know
  • Integrate Cucumber in Playwright With Java
  • Design Patterns for Microservices: Ambassador, Anti-Corruption Layer, and Backends for Frontends

Trending

  • Managing Data Residency, the Demo
  • Front-End: Cache Strategies You Should Know
  • Integrate Cucumber in Playwright With Java
  • Design Patterns for Microservices: Ambassador, Anti-Corruption Layer, and Backends for Frontends
  1. DZone
  2. Coding
  3. Tools
  4. Hooking into the NetBeans Platform Lifecycle

Hooking into the NetBeans Platform Lifecycle

Tom Wheeler user avatar by
Tom Wheeler
·
Aug. 22, 08 · News
Like (0)
Save
Tweet
Share
7.46K Views

Join the DZone community and get the full member experience.

Join For Free

One major difference between developing a NetBeans Platform application and a monolithic Java application is that there's no main method. This sometimes leaves developers wondering where they can insert their own code. This article describes some places where this is possible.

Although a bit drastic for most cases, you can replace the main class used to start NetBeans with your own class and then delegate back to NetBeans normal main class. This offers you a hook early in the startup sequence without having to modify the launchers or shell scripts.

Any module may provide a ModuleInstall class. The validate method will be called before your module is even loaded, so it's the first module-level hook typically available in the startup sequence. Note that many services and classes offered by the platform are unlikely to be initialized at this point.

A short time afterwards, the restored() method will be called on each ModuleInstall class. More services and classes will be initialized at this point than with the validate() method, but the GUI will probably not yet be realized. You can post some code to be executed when the UI is fully loaded like this:

    @Override
public void restored() {
WindowManager.getDefault().invokeWhenUIReady(
new Runnable() {
public void run() {
// any code here will be run with the UI is available
SomeTopComponent.findInstance().open();
}
});
}

Note that providing a ModuleInstall class will degrade overall startup time somewhat, but as long as you don't overuse ModuleInstall classes and take care to execute any long-running tasks from its methods in a background thread, you should be OK.

Another major class in platform development is the TopComponent class. It offers several method which allow you to hook into its lifecycle.

Here is the sequence of events you can hook into for when a TopComponent is opened:

  1. JComponent.addNotify
  2. TopComponent.componentOpened
  3. TopComponent.componentShowing
  4. TopComponent.componentActivated

When you set focus on a TopComponent, the componentActivated method is called. Likewise, the componentDeactivated method is called when focus is moved away from that TopComponent.

Here is the sequence of events you can hook into for when a TopComponent is closed:

  1. TopComponent.canClose
  2. JComponent.removeNotify
  3. TopComponent.componentHidden
  4. TopComponent.componentDeactivated
  5. TopComponent.componentClosed

Note that you can return false from TopComponent.canClose to prevent the TopComponent from being closed at all.

The ModuleInstall class offers two methods which let you plug into the exit sequence. The closing method is called first and requires that you return a boolean value. If true, then your module agrees to be closed, but if false, then you will prevent the exit sequence from continuing. The close method is called after all ModuleInstall classes return true from the closing method and is the final hook in which modules can participate in the application's lifecycle.

From http://wiki.netbeans.org/NetBeansDeveloperFAQ

 

NetBeans

Opinions expressed by DZone contributors are their own.

Trending

  • Managing Data Residency, the Demo
  • Front-End: Cache Strategies You Should Know
  • Integrate Cucumber in Playwright With Java
  • Design Patterns for Microservices: Ambassador, Anti-Corruption Layer, and Backends for Frontends

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: