0

Netbeans 项目 TopComponent 的正确首选 ID 是什么?我创建了一个小模块来帮助项目,但是我需要模块中的一个按钮来触发某个子节点在项目窗格中突出显示。使用 Utilities.actionsGlobalContext() 将无济于事,因为按钮位于另一个模块中,并且简单地重新声明一个值以保留最近选择的子节点并不理想。有没有人有什么建议?

4

1 回答 1

2

如果我理解正确,您希望能够执行另一个模块中存在的(按钮的)操作?

一种方法是在模块的层文件中注册您的(按钮的)操作:

...
<folder name="SomeFolder">
    <folder name="MyActions">
        <file name="com-my-Action.instance">
            <attr name="delegate" newvalue="com.my.Action"/>
            <attr name="displayName" bundlevalue="com.my.Bundle#MYACTION_DIPLAYNAME"/>
            ...
        </file>
    </folder>
</folder>

然后使用Utilities.actionsForPath(string)查找此操作:

List<? extends Action> actions = Utilities.actionsForPath("SomeFolder/MyActions");
Action myAction = null;
for (Action action : a) {
    if (action.getValue(Action.NAME).equals("My Action Display Name")) {
        myAction = action;
        break;
    }
}
// use the action
myAction.actionPerformed(null);

也可以看看

Utilities.actionsForPath(string)的 javadoc

于 2011-11-26T23:28:16.540 回答