Re: Make action 'generic'

markiewb <[email protected]>
Newsgroups gmane.comp.java.netbeans.modules.openide.devel
Message-ID <[email protected]>
Hej Trevor,

1) Try CookieAction/AbstractAction
http://wiki.netbeans.org/CreateConditionallyEnabledActionFromScratch
https://benkiew.wordpress.com/2015/09/13/nb-how-to-create-a-context-aware-submenu/
https://benkiew.wordpress.com/2012/12/28/netbeans-how-to-create-a-context-aware-action-with-an-icon-for-the-context-menu/

In AbstactAction.isEnabled() you can decide, when the action is enabled

2) Or: Introduce an interface/common parent class for all your DataObjects. Then you can create an action, based on that interface/class. Yes, that works like instanceof.

3) Or: Create an action based the Node type. When executing the action get the data object from the lookup of the Node

BTW: A simple lookup viewer is useful for this task. https://blogs.oracle.com/geertjan/entry/lookup_viewer There are two plugins at the plugin  portal website 

Best regards, markiewb

----- Ursprungligt meddelande -----
Från: "Trevor Carpenter" <[email protected]>
Skickat: ‎06.‎02.‎2016 18:37
Till: "[email protected]" <[email protected]>
Ämne: [platform-dev] Make action 'generic'

Hi 
 
I have a set of classes that extend MultiDataObject that read bathymetry data in different formats via a set of readers that pass back a class implementing an interface so that they are all of a type that implements BathymetryAbstractProduct. At a project level I have an action that deletes other files in the project folders when the selected bathymetry file is deleted (since these become invalid). I added the action to the context menu of BathymetryDataNode. However, in the ActionListener the what is being passed to the constructor is the specific MultiDataObject type.
 
As a work around I guess I could enable the action when any DataObject is in the lookup, and rely upon the action only ever being added to BathymetryDataNode – (I have not tried this yet). 
 
Will the above work or is there a better alternative?
 
I would like to write one ActionListener that will work for BathymetryDataNode regardless of the specific MultiDataObject type.
 
Thanks for your help
 
Trevor
The Scottish Association for Marine Science (SAMS) is registered in Scotland as a Company Limited by Guarantee (SC009292) and is a registered charity (9206). SAMS has two actively trading wholly owned subsidiary companies: SAMS Research Services Ltd (SC224404) and SAMS Ltd (SC306912). All Companies in the group are registered in Scotland and share a registered office at Scottish Marine Institute, Oban Argyll PA37 1QA. The content of this message may contain personal views which are not the views of SAMS unless specifically stated. Please note that all email traffic is monitored for purposes of security and spam filtering. As such individual emails may be examined in more detail.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.