NodeAction.performAction() deprecated, alternatives?
"bjarven" <[email protected]> Tue, 12 Sep 2017 07:59:22 +0000
| Newsgroups | gmane.comp.java.netbeans.modules.openide.devel |
|---|---|
| Message-ID | <[email protected]> |
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...
}
}