The problem was the annotation on the TopComponent.
@ActionID(category = "Window", id = "org.netbeans.modules.plantumlnb.PUMLTopComponent")
@ActionReference(path = "Menu/Window" /*, position = 333 */)
I removed these annotations. I assume the annotation was instantiating a new TopComponent everytime and there was no way for me to tell the annotation to call the getInstance
method instead of instantiating it everytime.
Then I implemented a custom action and then wired the action to call open on the topcomponent as shown below. This is what seems to have fixed the problem.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.netbeans.modules.plantumlnb;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle.Messages;
@ActionID(
category = "Window",
id = "org.netbeans.modules.plantumlnb.PUMLViewAction")
@ActionRegistration(
iconBase = "org/netbeans/modules/plantumlnb/icon.png",
displayName = "#CTL_PUMLViewAction")
@ActionReferences({
@ActionReference(path = "Menu/Window/Other", position = 1050),
@ActionReference(path = "Shortcuts", name = "DS-P"),
@ActionReference(path = "Shortcuts", name = "DS-U")
})
@Messages("CTL_PUMLViewAction=Plant UML")
public final class PUMLViewAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
PUMLTopComponent pumlTopComponent = PUMLTopComponent.getInstance();
pumlTopComponent.open();
}
}
EDIT
Netbeans added support for singleton TopComponents in the first patch of Netbeans 7.3.
Support to Singleton TopComponents - @FactoryMethod