NodeAction.performAction() deprecated, alternatives?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

NodeAction.performAction() deprecated, alternatives?

bjarven
Hi, I'm wondering if there's any other way of doing this other than the deprecated method NodeAction.performAction().

I have a class that extends NodeAction, and it has a popup presenter. To get the data from the selected menu item i use performAction. But it's deprecated, so I guess there's another better way of doing this... Any recommendations?


Code:

public class MyAction extends NodeAction{

    @Override
    public JMenuItem getPopupPresenter() {
        JMenu menu = new JMenu();
        menu.setText("My menu");
        for (int i = 0; i < myItems.length; i++) {
            ExtendedMenuItem item = new ExtendedMenuItem(key);
            item.setText(key);
            item.addActionListener(this);
            menu.add(item);
        }
        return menu;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // need actionPerfomed to get information about the menu items!
        if (e.getSource() instanceof ExtendedMenuItem) {
            ExtendedMenuItem eItem = (ExtendedMenuItem) e.getSource();
            for (Node node : getActivatedNodes()) {
                // do something with the selected nodes depending on the menu choice
            }
        }
    }

    @Override
    protected void performAction(Node[] arg0) {
        // won't get any information about the menu here...

    }
}







Reply | Threaded
Open this post in threaded view
|

Re: NodeAction.performAction() deprecated, alternatives?

geertjan.wielenga@oracle.com

I would probably not use NodeAction, probably there’s a better way of doing the below — definitely get this book: https://leanpub.com/nbp4beginners

If you want to work with a menu item, probably you can add an AcrtionListener to it but, again, this approach below with NodeAction is probably in most cases not the right approach.

I recommend getting the book referenced above.



Geertjan Wielenga | Principal Product Manager
Phone: +31620320056 | 
Oracle Developer Tools

ORACLE Netherlands | Hertogswetering 163-167 | 3543 AS Utrecht | Netherlands


Oracle is committed to developing practices and products that help protect the environment

On 12 Sep 2017, at 09:59, bjarven <[hidden email]> wrote:

Hi, I'm wondering if there's any other way of doing this other than the deprecated method NodeAction.performAction(). 

I have a class that extends NodeAction, and it has a popup presenter. To get the data from the selected menu item i use performAction. But it's deprecated, so I guess there's another better way of doing this... Any recommendations? 


Code:

public class MyAction extends NodeAction{

   @Override
   public JMenuItem getPopupPresenter() {
       JMenu menu = new JMenu();
       menu.setText("My menu");
       for (int i = 0; i < myItems.length; i++) {
           ExtendedMenuItem item = new ExtendedMenuItem(key);
           item.setText(key);
           item.addActionListener(this);
           menu.add(item);
       }
       return menu;
   }

   @Override
   public void actionPerformed(ActionEvent e) {
       // need actionPerfomed to get information about the menu items!
       if (e.getSource() instanceof ExtendedMenuItem) {
           ExtendedMenuItem eItem = (ExtendedMenuItem) e.getSource();
           for (Node node : getActivatedNodes()) {
               // do something with the selected nodes depending on the menu choice
           }
       }
   }

   @Override
   protected void performAction(Node[] arg0) {
       // won't get any information about the menu here...

   }
}