"previousMode": Controling the Pin Action of a TopComponent

An excellent thing I learned today is that you, as a developer of a NetBeans module or NetBeans Platform application, can control the pin button. Up until today, whenever I had a TopComponent defined to appear in "rightSlidingSide" mode and then I clicked the "pin" button, as shown here...

...the TopComponent would then find itself pinned in the "explorer" mode. Would make more sense if it would be pinned in the "properties" mode, which is the docked mode closest to the "rightSlidingSide" mode. Not being able to control the "pin" button has been a recurring question (including in my own head) over several years.

But the NetBeans Team's window system guru Stan Aubrecht informed me today that a "previousMode" attribute exists in the "tc-ref" file of the TopComponent. Since a few releases, that file is generated via the annotations in the TopComponent. However, "previousMode" is currently not one of the attributes exposed by the @TopComponent.Registration annotation.

Therefore, what I did was this:

  1. Set "rightSlidingSide" in the "mode" attribute of the @TopComponent.Registration.

  2. Build the module.

  3. Find the "generated-layer.xml" (in the Files window) and move the layer registration of the TopComponent, including its action and menu item for opening the TopComponent, into my own manual layer within the module. Then remove all the TopComponent annotations from the TopComponent, though you can keep @ConvertAsProperties and @Messages.

  4. Then add the "previousMode" attribute, as highlighted below, into my own layer file, i.e., within the tags copied from the "generated-layer.xml":

    <folder name="Modes">
        <folder name="rightSlidingSide">
            <file name="ComparatorTopComponent.wstcref">
            <![CDATA[<?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE tc-ref PUBLIC "-//NetBeans//DTD Top Component in Mode Properties 2.0//EN" 
            <tc-ref version="2.0">
              <tc-id id="ComparatorTopComponent"/>
              <state opened="false"/>
              <previousMode name="properties" index="0" />

Now when you run the application and pin the specific TopComponent defined above, i.e., in the above case, named "ComparatorTopComponent", you will find it is pinned into the "properties" mode! That's pretty cool and if you agree, then you're a pretty cool NetBeans Platform developer, and I'd love to find out more about the application/s you're creating on the NetBeans Platform!

Meanwhile, I'm going to create an issue for exposing the "previousMode" attribute in the @TopComponent.Registration annotation.


Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« June 2016