Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
@ActionRegistration(displayName = "Compare Bands", lazy = false)
@NbBundle.Messages({"CTL_CompareBandActionName=Compare Bands"})
public class CompareBandAction extends AbstractAction implements ContextAwareAction, LookupListener {
    private final Lookup lkp;
    private final Lookup.Result<Band> result;
    
    public CompareBandAction() {
        this(Utilities.actionsGlobalContext());
    }

    public CompareBandAction(Lookup lkp) {
        super(Bundle.CTL_CompareBandActionName());
        this.lkp = lkp;
        result = lkp.lookupResult(Band.class);
        result.addLookupListener(WeakListeners.create(LookupListener.class, this, result));
        setEnabled(false);
    }
    
    @Override
    public Action createContextAwareInstance(Lookup lkp) {
        return new CompareBandAction(lkp);
    }
    
    @Override
    public void actionPerformed(ActionEvent e) {
	    // Do the action stuff
    }

    @Override
    public void resultChanged(LookupEvent le) {
        setEnabled(result.allInstances().size() >= 2);
    }
}
Note
titleNote

When using Bundle properties in an action with the The Annotation @NbBundle.Messages only works if the package where the action is implemented is not yet defined in an other module.

Having the package  org.esa.snap.rcp.actions in snap-rcp and using the same package in a second module the defined Bundle key will not be found by NetBeans. Because Probably because it first finds the bundle property file of snap-rcp but the key for the action is not specified there.

...