NetBeans 模块中的操作 - 上下文菜单、主菜单
我正在开发 NetBeans 模块,并且已经声明了一个与我的自定义项目类型(EsperProject 类)配合使用的操作(使用注释,它们被转换为 layer.xml 记录):
@ActionID(category = "Run", id = "my.package.RunEsperAction")
@ActionRegistration(displayName = "My Action", asynchronous=true)
@ActionReferences({
@ActionReference(path = "Menu/BuildProject", position = 0)
})
public final class RunEsperAction implements ActionListener {
private final EsperProject project;
public RunEsperAction(EsperProject project) {
this.project = project;
}
@Override
public void actionPerformed(ActionEvent ev) {
// do sth with project
}
}
我可以从 BuildProject 菜单运行该操作(实际上是 Run菜单),但我无法使其在我需要的两种情况下工作(都按照注释中声明的方式异步调用):
- 我想从项目上下文菜单运行该操作。
- 我需要在运行 EsperProject 时触发操作 从主菜单项“运行主项目”。
感谢您的任何建议。
I am developing NetBeans module and I have declared an action (using annotations, they are translated to layer.xml record) which works with my custom project type (EsperProject class):
@ActionID(category = "Run", id = "my.package.RunEsperAction")
@ActionRegistration(displayName = "My Action", asynchronous=true)
@ActionReferences({
@ActionReference(path = "Menu/BuildProject", position = 0)
})
public final class RunEsperAction implements ActionListener {
private final EsperProject project;
public RunEsperAction(EsperProject project) {
this.project = project;
}
@Override
public void actionPerformed(ActionEvent ev) {
// do sth with project
}
}
I can run the action from the BuildProject Menu (which is actualy Run menu), but i CANNOT make it work in two cases I need (both called asynchronously as declared in the annotation):
- I'd like to run the action from the project context menu.
- I need to have the action triggered when my EsperProject is run
from the main menu item "Run Main Project".
Thanks for any suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需将 @ActionReference(path = "Project/Actions",position = 0) 添加到 @ActionReferences 即可
It will be possible just by adding @ActionReference(path = "Project/Actions", position = 0) to @ActionReferences
我已经弄清楚了第一点:要从上下文菜单运行操作,我们必须将其添加到项目根节点的 getActions() 方法中,如下所示:
操作出现在项目的上下文菜单中并运行异步地。但是,覆盖“运行主项目”对我来说仍然是不可能的。我尝试了类似的方法,但这失败了
:
I have figured out the first point: To run the action from the context menu, we must add it to the getActions() method of the project root node, something like this:
The action appears in the context menu of the project and is run asynchronously. However, overriding "Run main project" is still imposible for me. I try the simmilar aproach but this fails:
with