| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head> |
| <title>NetBeans Platform Selection Tutorial Using Maven</title> |
| <link rel="stylesheet" type="text/css" href="https://netbeans.org/netbeans.css"/> |
| <meta name="AUDIENCE" content="NBUSER"/> |
| <meta name="TYPE" content="ARTICLE"/> |
| <meta name="EXPIRES" content="N"/> |
| <meta name="indexed" content="y"/> |
| <meta name="description" content="A short demonstration of how to use Maven to create and run a NetBeans Platform Module Suite."/> |
| <!-- Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. --> |
| <!-- Use is subject to license terms.--> |
| </head> |
| <body> |
| |
| <h1>NetBeans Platform Selection Tutorial Using Maven</h1> |
| |
| <p>This document demonstrates how to create a NetBeans Platform Module Suite from Maven archetypes |
| and build and install the suite in your installation of the IDE. |
| In this tutorial you will create a Maven module suite project that contains three NetBeans modules as sub-projects. |
| The Maven project that contains the sub-projects is a simple POM project that declares how the suite is compiled |
| and the installation target. |
| |
| </p> |
| |
| <p class="tips">This document is based on the Ant-based <a href="https://platform.netbeans.org/tutorials/nbm-selection-1.html">NetBeans Selection Management Tutorial</a> |
| and illustrates some of the differences between using Ant and Maven to develop NetBeans Platform module suites. |
| After you understand some of the differences, you can easily proceed through other |
| tutorials on the the <a href="https://netbeans.org/kb/trails/platform.html">NetBeans Platform Learning Trail</a>.</p> |
| |
| <p><b>Contents</b></p> |
| <p><img src="../images/articles/81/netbeans-stamp.png" class="stamp" width="114" height="114" alt="Content on this page applies to NetBeans IDE 7.2" title="Content on this page applies to NetBeans IDE 7.2"/></p> |
| |
| <ul class="toc"> |
| <li><a href="#01">Creating the NetBeans Platform Application</a></li> |
| <li><a href="#02">Creating an API</a></li> |
| <li><a href="#03">Listening to the Selection</a></li> |
| <li><a href="#04">Publishing a Selected Object</a></li> |
| <li><a href="#05">Building and Running the Application</a></li> |
| <li><a href="#06">Changing Selected Objects Dynamically</a></li> |
| </ul> |
| |
| <p><b>To follow this tutorial, you need the software and resources listed in the following table.</b></p> |
| |
| <table> |
| <tbody> |
| <tr> |
| <th class="tblheader" scope="col">Software or Resource</th> |
| <th class="tblheader" scope="col">Version Required</th> |
| </tr> |
| <tr> |
| <td class="tbltd1"><a href="https://netbeans.org/downloads/index.html">NetBeans IDE</a></td> |
| <td class="tbltd1">version 7.2</td> |
| </tr> |
| <tr> |
| <td class="tbltd1"><a href="http://java.sun.com/javase/downloads/index.jsp">Java Developer Kit (JDK)</a></td> |
| <td class="tbltd1">version 7 or above</td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <p><strong class="notes">Note:</strong> You do not need to download Maven because it |
| is bundled with the IDE. Optionally, use your own download of Maven, in which |
| case use the Options window to configure your Maven settings.</p> |
| |
| <p class="notes"><b>Note:</b> This is <u>not</u> a beginners tutorial. Before starting this tutorial, it is important that you familiarize yourself with |
| the following introductory Maven documentation:</p> |
| <ul> |
| <li><a href="http://wiki.netbeans.org/MavenBestPractices">Best Practices for Maven in NetBeans IDE</a></li> |
| <li><a href="http://www.sonatype.com/books/maven-book/reference/introduction.html">Chapter 1. Introducing Apache Maven</a> |
| (from <a href="http://www.sonatype.com/books/maven-book/reference/public-book.html">Maven: The Definitive Guide</a>)</li> |
| <li><a href="https://platform.netbeans.org/tutorials/nbm-maven-commandline.html">NetBeans Platform Command Line Tutorial</a></li> |
| <li><a href="https://platform.netbeans.org/tutorials/tutorials/nbm-maven-quickstart.html">NetBeans Platform Quick Start Using Maven</a></li> |
| </ul> |
| |
| <!-- =================================================================== --> |
| <!-- +++++++++++++++ Configuring Maven +++++++++++++++++++++++++++++++++ --> |
| <!-- |
| <h2><a name="config"></a>Using Maven with the IDE</h2> |
| <p>If this is your first Maven project you will want to familiarize yourself with the Maven configuration settings |
| and the Maven Repository Browser.</p> |
| |
| <div class="indent"> |
| <a name="config1"></a> |
| <h3>Configuring Maven Options</h3> |
| <p>You can use the Maven tab in the Options window to configure the behavior of Maven in the IDE and to check |
| that your configuration is correct.</p> |
| |
| <ol> |
| <li>Select the Miscellaneous category in the Options window and click the Maven tab.</li> |
| <li>Specify the location of your local Maven installation (requires 2.0.9 or newer).</li> |
| <li>Confirm that the location of the local Maven repository is correct.</li> |
| <li>Click OK.</li> |
| </ol> |
| <p>In most cases, if your Maven configuration is typical the information in the Options window should already be correct.</p> |
| |
| <p class="notes"><strong>Note.</strong> Maven support is activated as part of the Java SE feature set. |
| If the Maven tab is not available in the Options window, confirm that Java SE is activated by creating a Java application.</p> |
| |
| <h3><a name="config2"></a>Viewing the Maven Repositories</h3> |
| <p>The artifacts that are used by Maven to build all your projects are stored in your local Maven repository. |
| When an artifact is declared as a project dependency, the artifact is downloaded to your local repository |
| from one of the registered remote repositories if it is not already installed.</p> |
| |
| <p>The NetBeans repository and several well-known indexed Maven repositories are registered and listed in the Repository Browser window by default. |
| The NetBeans repository contains most of the public artifacts necessary for you to build your project. |
| You can use the Maven Repository Browser to view the contents of your local and remote repositories. |
| You can expand the Local Repository node to see the artifacts that are present locally. |
| The artifacts listed under the NetBeans repository nodes can be added as project dependencies, but not all of |
| them are present locally. They are only added to the Local Repository when they are declared as project |
| dependencies.</p> |
| |
| <p>To open the Maven Repository Browser:</p> |
| <ul> |
| <li>Choose Window > Other > Maven Repository Browser from the main menu.<br/> |
| <img src="../images/tutorials/maven-quickstart68/maven-nbm-netbeans-repo.png" alt="Screenshot of Maven Repository Browser" title="Screenshot of Maven Repository Browser" class="margin-around b-all" /> |
| |
| </li> |
| </ul> |
| </div>--> |
| |
| |
| |
| <!-- =================================================================== --> |
| <!-- +++++++++++++++++++ Creating the Module Suite +++++++++++++++++++++ --> |
| |
| <h2><a name="01"></a>Creating the NetBeans Platform Application</h2> |
| <p>In this section you use the New Project wizard to create a |
| NetBeans Platform Module Suite from a Maven archetype. |
| The wizard will create a POM project that will contain the module projects. |
| In the wizard you will also create a module as a sub-project of the suite. |
| </p> |
| |
| <div class="indent"> |
| |
| <ol> |
| <li><p>Open the New Project wizard and select |
| NetBeans Application in the Maven category:</p> |
| <p><img src="../images/tutorials/maven-crud/72/pic1.png" alt="Screenshot of Projects window" title="Screenshot of Projects window" class="margin-around b-all" /> |
| </p> |
| <p>Click Next.</p> |
| </li> |
| <li><p>Type <strong>MavenSelectionSuite</strong> for the Project Name:</p> |
| <p><img src="../images/tutorials/maven-suite/72/pic2.png" alt="Screenshot of Projects window" title="Screenshot of Projects window" class="margin-around b-all" /> |
| </p> |
| <p>Click Next.</p> |
| </li> |
| <li><p>Choose the NetBeans API version |
| you want to use. Select Create Module Project and type <strong>MyAPI</strong> for |
| the module name:</p> |
| <p><img src="../images/tutorials/maven-suite/72/pic3.png" alt="Screenshot of Projects window" title="Screenshot of Projects window" class="margin-around b-all" /> |
| </p> |
| <p>Click Finish.</p> |
| <p>When you click Finish, the IDE creates a |
| Maven reactor project, together with subprojects |
| for branding, NetBeans Platform application actions, |
| and the API module:</p> |
| <p><img src="../images/tutorials/maven-suite/72/pic4.png" alt="Screenshot of Projects window" title="Screenshot of Projects window" /> |
| </p> |
| </li> |
| </ol> |
| |
| </div> |
| |
| |
| |
| <p><b>MavenSelectionSuite-parent</b> is a reactor project which is a |
| container for sub-projects, in this case NetBeans Module projects. |
| The reactor project does not contain any source files. As you can see from the screenshot |
| above, the reactor provides a |
| list of the modules that will be included when you build the project. |
| You can see that the MyAPI project is listed as one of these modules.</p> |
| |
| <!-- =================================================================== --> |
| <!-- ++++++++++++++++++ Adding Class to MyAPI Module +++++++++++++++++++ --> |
| |
| <h2><a name="02"></a>Creating an API</h2> |
| <p>You created the <b>MyAPI</b> module when you created the module suite, but now you need to |
| create a class in the module and expose the class to other modules.</p> |
| |
| <div class="indent"> |
| <a name="02a"></a> |
| <h3>Creating a Class in the MyAPI Module</h3> |
| <p>In this exercise you will create a simple class named <tt>Event</tt>. |
| Each instance of <tt>Event</tt> will be unique because the field <tt>index</tt> |
| is incremented by 1 each time a new instance of <tt>Event</tt> is created.</p> |
| |
| <div class="indent"> |
| |
| <ol> |
| <li>In the <tt>com.mycompany.mavenselectionsuite</tt> package, |
| create a new Java class named <strong>Event</strong>. |
| </li> |
| <li>Modify the class to declare the following fields and getters: |
| <pre class="examplecode">package com.mycompany.mavenselectionsuite; |
| |
| import java.util.Date; |
| |
| public final class Event { |
| |
| private final Date date = new Date(); |
| private static int count = 0; |
| private final int index; |
| |
| public Event() { |
| index = count++; |
| } |
| |
| public Date getDate() { |
| return date; |
| } |
| |
| public int getIndex() { |
| return index; |
| } |
| |
| public String toString() { |
| return index + " - " + date; |
| } |
| |
| }</pre> |
| </li> |
| </ol> |
| </div> |
| <a name="02b"></a> |
| <h3>Exposing the Package</h3> |
| <p>In this tutorial you will create additional modules that will need to access |
| the <tt>Event</tt> class. |
| In this exercise, you will make the contents of the package |
| that contains the <tt>Event</tt> class public so |
| that other modules can access it. |
| To declare the <tt>com.mycompany.mavenselectionsuite</tt> package as public, you will |
| modify the <tt>configuration</tt> element of <tt>nbm-maven-plugin</tt> in |
| the POM to specify the packages that are exported as public. |
| You can make the changes to the POM in the editor or by selecting the |
| packages to make public in the project's Properties window.</p> |
| <div class="indent"> |
| |
| <ol> |
| <li>Right-click the MyAPI project node and choose Properties to open the Properties window.</li> |
| <li><p>Select the <strong>com.mycompany.mavenselectionsuite</strong> package |
| in the <strong>Public Packages</strong> category:</p> |
| <p><img src="../images/tutorials/maven-suite/72/pic5.png" alt="screenshot" title="screenshot" class="margin-around b-all" /></p> |
| <p>Click OK.</p> |
| <p>When you select a package to export, the IDE modifies the <tt>nbm-maven-plugin</tt> |
| element in the <b>MyAPI</b> module's POM to specify the package:</p> |
| <pre class="examplecode"><plugin> |
| <groupId>org.codehaus.mojo</groupId> |
| <artifactId>nbm-maven-plugin</artifactId> |
| <extensions>true</extensions> |
| <configuration> |
| <publicPackages> |
| <strong><publicPackage>com.mycompany.mavenselectionsuite</publicPackage></strong> |
| </publicPackages> |
| </configuration> |
| </plugin></pre></li> |
| <li><p>Right-click the project and choose Build. When you build the project, |
| the <tt>nbm-maven-plugin</tt> will generate a manifest header in |
| the <tt>MANIFEST.MF</tt> |
| of the JAR, to specify the public package:</p> |
| |
| <pre class="examplecode">Manifest-Version: 1.0 |
| Archiver-Version: Plexus Archiver |
| Created-By: Apache Maven |
| Built-By: geertjan |
| Build-Jdk: 1.7.0 |
| OpenIDE-Module-Localizing-Bundle: com/mycompany/mavenselectionsuite/Bu |
| ndle.properties |
| OpenIDE-Module-Specification-Version: 1.0 |
| OpenIDE-Module-Implementation-Version: 1.0-20111222 |
| OpenIDE-Module-Build-Version: 201112221054 |
| OpenIDE-Module: com.mycompany.MyAPI |
| <b>OpenIDE-Module-Public-Packages: com.mycompany.mavenselectionsuite.*</b> |
| OpenIDE-Module-Requires: org.openide.modules.ModuleFormat1 |
| OpenIDE-Module-Display-Category: com.mycompany |
| OpenIDE-Module-Name: MyAPI |
| OpenIDE-Module-Short-Description: <undefined> |
| OpenIDE-Module-Long-Description: <undefined> |
| OpenIDE-Module-Module-Dependencies: org.netbeans.api.annotations.commo |
| n/1 > 1.10.1</pre> |
| <p class="tips">For more information, see the <a href="http://mojo.codehaus.org/nbm-maven-plugin/manifest-mojo.html#publicPackages">nbm-maven-plugin manifest documentation</a>.</p> |
| |
| </li> |
| </ol> |
| |
| </div> |
| </div> |
| |
| <!-- =================================================================== --> |
| <!-- ++++++++++++++++++ Creating the MyViewer Module +++++++++++++++++++ --> |
| |
| <h2><a name="03"></a>Listening to the Selection</h2> |
| <p>In this section you will create a new module named MyViewer and add a window component and two text fields. |
| The component will implement <tt><a href="http://bits.netbeans.org/dev/javadoc/org-openide-util-lookup/org/openide/util/LookupListener.html">LookupListener</a></tt> |
| to listen for changes to the selection.</p> |
| |
| <div class="indent"> |
| <h3><a name="03a"></a>Creating the Module</h3> |
| <p>In this exercise you will create the MyViewer NetBeans module in the <tt>MavenSelectionSuite</tt> directory.</p> |
| <div class="indent"> |
| |
| <ol> |
| <li><p>Choose File > New Project from the main menu (Ctrl-Shift-N). |
| Select NetBeans Module from the Maven category:</p> |
| <p><img src="../images/tutorials/maven-suite/72/pic6.png" alt="screenshot" title="screenshot" class="margin-around b-all" /></p> |
| <p>Click Next.</p></li> |
| <li><p>Type <strong>MyViewer</strong> as the Project Name. |
| Make sure to set the Project Location to the <tt>MavenSelectionSuite</tt> directory:</p> |
| <p><img src="../images/tutorials/maven-suite/72/pic7.png" alt="screenshot" title="screenshot" class="margin-around b-all" /></p> |
| </li> |
| <li><p>Click Next. Select the NetBeans API version you'd like to use:</p> |
| <p><img src="../images/tutorials/maven-suite/72/pic8.png" alt="screenshot" title="screenshot" /></p> |
| <p>Click Finish.</p></li> |
| <li><p>The new module is created within the <b>parent</b> project, which is a Maven reactor. |
| Therefore, it becomes part of the reactor build. However, the new module is |
| not yet part of the <b>app</b> project. Right-click the Dependencies node in the |
| <b>app</b> project and choose Add Dependency:</p> |
| <p><img src="../images/tutorials/maven-suite/72/pic02.png" alt="screenshot" title="screenshot" /></p> |
| </li> |
| <li><p>Select the <b>MyViewer</b> module in the |
| Open Projects tab:</p> |
| <p><img src="../images/tutorials/maven-suite/72/pic03.png" alt="screenshot" title="screenshot" /></p> |
| </li> |
| <li><p>When you click Add above, the IDE adds the |
| <b>MyViewer</b> module to the list of dependencies of the <b>app</b> project. |
| You can see the new dependency in the POM of the |
| <b>app</b> project module and displayed as a new node |
| under the Dependencies node of the <b>app</b> project:</p> |
| <p><img src="../images/tutorials/maven-suite/72/pic04.png" alt="screenshot" title="screenshot" /></p> |
| </li> |
| <li><p>The module is going to use the API module, therefore |
| we need to set a dependency in the viewer module |
| on the API module. Right-click the Dependencies node in the |
| <b>MyViewer</b> project and choose Add Dependency:</p> |
| <p><img src="../images/tutorials/maven-suite/72/pic9.png" alt="screenshot" title="screenshot" /></p> |
| </li> |
| <li><p>Select the <b>MyAPI</b> module in the |
| Open Projects tab:</p> |
| <p><img src="../images/tutorials/maven-suite/72/pic10.png" alt="screenshot" title="screenshot" /></p> |
| </li> |
| |
| <li><p>When you click Add above, the IDE adds the |
| API module to the list of dependencies of the MyViewer module. |
| You can see the new dependency in the POM of the |
| MyViewer module and displayed as a new node |
| under the Dependencies node of the MyViewer module:</p> |
| <p><img src="../images/tutorials/maven-suite/72/pic01.png" alt="screenshot" title="screenshot" /></p> |
| </li> |
| </ol> |
| </div> |
| <p>You've now learned how to create a new module |
| in your application and you've also learned |
| how to set dependencies between your modules. Once |
| a dependency has been set, a module can use the publicly |
| exposed classes of the modules it depends on.</p> |
| |
| <a name="03b"></a> |
| <h3>Creating the Viewer Window</h3> |
| <p>In this exercise you will create a GUI component in your |
| viewer module. The data displayed in the GUI component |
| will be retrieved from the Lookup. That means you will learn |
| how to listen to the selection and how to update your GUI |
| component whenever an object of interest is published |
| into the Lookup.</p> |
| <div class="indent"> |
| |
| <ol> |
| <li><p>Right-click the MyViewer project and choose New > Window. |
| Select <strong>explorer</strong> |
| and select Open on Application Start:</p> |
| <p><img src="../images/tutorials/maven-suite/72/pic05.png" alt="screenshot" title="screenshot" /></p> |
| <p>Click Next.</p></li> |
| <li><p>Type <strong>MyViewer</strong> as the Class Name Prefix:</p> |
| <p><img src="../images/tutorials/maven-suite/72/pic06.png" alt="screenshot" title="screenshot" /></p> |
| <p>Click Finish. You should see you have a new NetBeans Platform window |
| component ready to be designed within the Matisse GUI Builder:</p> |
| <p><img src="../images/tutorials/maven-suite/72/pic07.png" alt="screenshot" title="screenshot" /></p> |
| </li> |
| <li><p>Drag two Labels from the Palette |
| into the window component:</p> |
| <p><img src="../images/tutorials/maven-suite/72/pic08.png" alt="screenshot" title="screenshot" /></p> |
| </li> |
| <li><p>You are now going to listen to the global context, provided by the <a href="http://wiki.netbeans.org/NetBeansDeveloperFAQ#Lookup">NetBeans Lookup</a>, |
| for Event objects. Right now, no Event objects will be present in the global context. |
| However, in the next section, we will create a new module that will publish |
| Event objects.</p> |
| <p>Click the Source tab and modify the class signature to implement <tt>LookupListener</tt>:</p> |
| <pre class="examplecode">public class MyViewerTopComponent extends TopComponent <strong>implements LookupListener</strong> {</pre> |
| <p>Add the following <tt>private</tt> field <tt>result</tt> and set the initial value to null.</p> |
| <pre class="examplecode">private Lookup.Result<Event> result = null;</pre> |
| |
| <p>Implement the LookupListener's "resultChanged" method as follows:</p> |
| <pre class="examplecode">@Override |
| public void resultChanged(LookupEvent le) { |
| if (!result.allInstances().isEmpty()) { |
| for (Event event : result.allInstances()) { |
| jLabel1.setText(Integer.toString(event.getIndex())); |
| jLabel2.setText(event.getDate().toString()); |
| } |
| } else { |
| jLabel1.setText("[no selection]"); |
| jLabel2.setText(""); |
| } |
| }</pre> |
| |
| <p>Make the following additions to the <tt>componentOpened()</tt> and |
| <tt>componentClosed()</tt> methods that have already been created |
| in the class by the New Window wizard:</p> |
| <pre class="examplecode">@Override |
| public void componentOpened() { |
| <strong>result = Utilities.actionsGlobalContext().lookupResult(Event.class); |
| result.addLookupListener(this);</strong> |
| } |
| |
| @Override |
| public void componentClosed() { |
| <strong>result.removeLookupListener (this);</strong> |
| }</pre> |
| <p class="notes"><b>Note.</b> By using <tt><a href="http://bits.netbeans.org/dev/javadoc/org-openide-util/org/openide/util/Utilities.html#actionsGlobalContext%28%29">Utilities.actionsGlobalContext()</a></tt>, |
| each time the window is opened, the window |
| listens to the global context for Event objects. Whenever a new |
| Event is published into the global context, the <tt>resultChanged</tt> |
| method is automatically triggered to handle the event.</p> |
| <p class="tips">Make sure to import the correct <tt>Event</tt> class, that is, <tt>com.mycompany.mavenselectionsuite.Event</tt>.</p> |
| </li> |
| </ol> |
| </div> |
| </div> |
| |
| |
| |
| <!-- =================================================================== --> |
| <!-- ++++++++++++++++++ Creating the MyEditor Module +++++++++++++++++++ --> |
| |
| <h2><a name="04"></a>Publishing a Selected Object</h2> |
| |
| <p>In this section you will create a new module called MyEditor. |
| The module will contain a |
| <tt><a href="http://bits.netbeans.org/dev/javadoc/org-openide-windows/org/openide/windows/TopComponent.html">TopComponent</a></tt> |
| that will publish instances of the <tt>Event</tt> object into the |
| Lookup of the TopComponent. When the user selects the TopComponent, |
| the objects in its Lookup will be available globally. Once published |
| globally, the viewer window created in the previous section, which |
| is listening for Events in the global Lookup, will |
| automatically update itself. |
| </p> |
| |
| <div class="indent"> |
| <a name="04a"></a> |
| <h3>Creating the Module</h3> |
| <p>In this exercise you will create a NetBeans module in the <tt>MavenSelectionSuite</tt> directory and add a dependency |
| on the MyAPI module.</p> |
| <div class="indent"> |
| |
| <ol> |
| <li> |
| <p> |
| As you did in the previous section, create a new module |
| in the <b>parent</b> folder. Type <strong>MyEditor</strong> as the Project Name. |
| </p> |
| </li> |
| <li> |
| <p> |
| As you did in the previous section, you need |
| to add the <b>MyEditor</b> module as a dependency of the <b>app</b> project, |
| so that it will be deployed when you run the application. |
| </p> |
| </li> |
| <li> |
| <p> |
| As you did in the previous section, you need |
| to add a dependency on the API module, so that you |
| can use its public packages. |
| </p> |
| </li> |
| <li> |
| <p> |
| As you did in the previous section, create a new window |
| in the <b>MyEditor</b> module. Set its position to "editor". |
| Type <strong>MyEditor</strong> as the Class Name Prefix. |
| </p> |
| </li> |
| <li> |
| <p> |
| Check that the result of the steps you have taken so far match the screenshot below: |
| </p> |
| <p><img src="../images/tutorials/maven-suite/72/pic09.png" alt="screenshot" title="screenshot" /></p> |
| </li> |
| <li><p>Use the Palette to drag and drop a Text Field onto the window:</p> |
| <p><img src="../images/tutorials/maven-suite/72/pic11.png" alt="screenshot" title="screenshot" /></p> |
| |
| </li> |
| <li><p>Switch to the Source tab. At the end of the constructor in the window, include the following code:</p> |
| |
| <pre class="examplecode">Event obj = new Event(); |
| associateLookup(Lookups.singleton(obj)); |
| |
| jTextField1.setText("Event #" + obj.getIndex() + " created at " + obj.getDate()); |
| |
| setDisplayName("MyEditor " + obj.getIndex());</pre> |
| |
| <p class="notes"><b>Note:</b> The <tt>associateLookup(Lookups.singleton(obj));</tt> line in the constructor will add |
| a new instance of <tt>Event</tt> to the <tt>Lookup</tt> of the <tt>TopComponent</tt>. When the |
| <tt>TopComponent</tt> is selected, its <tt>Lookup</tt> is passed into the global context. For |
| more details, see <a href="http://wiki.netbeans.org/NetBeansDeveloperFAQ#Lookup">NetBeans Lookup</a>.</p> |
| <p class="tips">Make sure to import the correct <tt>Event</tt> class, that is, <tt>com.mycompany.mavenselectionsuite.Event</tt>.</p> |
| </li> |
| <li><p>Change the <tt>@TopComponent.OpenActionRegistration</tt> so that no <tt>preferredId</tt> is |
| defined, as shown below, which means that a new Editor window will open whenever you |
| choose Window | Editor in the menubar:</p> |
| |
| <pre class="examplecode">@TopComponent.OpenActionRegistration(displayName = "#CTL_MyEditorAction")</pre> |
| |
| </li> |
| </ol> |
| |
| </div> |
| <p>The text field in the component only displays the index value and date |
| from the <tt>Event</tt>. |
| This will enable you to see that each MyEditor component is |
| unique and that MyViewer is displaying the |
| details of the MyEditor component that has the focus.</p> |
| |
| <h3><a name="05"></a>Building and Running the Application</h3> |
| <p>Now that the target installation of |
| the IDE is specified, you can use the Run command |
| on the <b>app</b> project.</p> |
| |
| <div class="indent"> |
| |
| <ol> |
| <li><p>Right-click <b>app</b> project and choose Run. |
| The application starts up, consisting of the NetBeans Platform, |
| together with the custom modules you created.</p> |
| </li> |
| <li> <p>The MyViewer window opens when the application starts and |
| displays the two labels. You can now choose MyEditor from the Window menu, multiple times, to |
| open multiple MyEditor components in the editor area. |
| The MyViewer window will display the details |
| of the currently selected MyEditor component.</p> |
| <p><img src="../images/tutorials/maven-suite/72/pic13.png" alt="screenshot" title="screenshot" /></p></li> |
| </ol> |
| |
| </div> |
| </div> |
| |
| |
| <p>This tutorial demonstrated how to create and run a NetBeans Platform application |
| that you create from a Maven archetype. |
| You saw how applications are structured and |
| how you configure a modules POM to specify public packages. Most important of all, |
| you learned how to publish objects into the selection and how to listen |
| for them and update other parts of the application accordingly. |
| For more examples on how to build NetBeans Platform applications, |
| see the tutorials listed in the <a href="https://netbeans.org/kb/trails/platform.html">NetBeans Platform Learning Trail</a>.</p> |
| |
| |
| <!-- ======================================================================================== --> |
| <div class="feedback-box"><a name="feedback"></a> |
| <a href="https://netbeans.org/about/contact_form.html?to=3&subject=Feedback:%20NetBeans%20Platform%20Selection%20Tutorial%20Using%20Maven%207.2"> |
| Send Us Your Feedback</a></div> |
| |
| <p> </p> |
| <!-- ======================================================================================== --> |
| |
| |
| <h2><a name="nextsteps"></a>See Also</h2> |
| |
| <p>For more information about creating and developing on the NetBeans Platform, see the following resources.</p> |
| <ul> |
| <li><a href="https://netbeans.org/kb/trails/platform.html">NetBeans Platform Learning Trail</a></li> |
| <li><a href="http://wiki.netbeans.org/NetBeansDeveloperFAQ">NetBeans Developer FAQ</a></li> |
| <li><a href="http://bits.netbeans.org/dev/javadoc/">NetBeans API Javadoc</a></li> |
| </ul> |
| <p>If you have any questions about the NetBeans Platform, feel free |
| to write to the mailing list, dev@platform.netbeans.org, or view the |
| <a href="https://netbeans.org/projects/platform/lists/dev/archive">NetBeans Platform mailing list archive</a>.</p> |
| |
| |
| <!-- ======================================================================================== --> |
| |
| |
| |
| </body> |
| |
| </html> |