[英]RCP: How to call a class from a command handler
我有一個菜單,其中有一個綁定到命令的標簽。
可以說:
plugin.xml
<menu label="Settings">
<command
commandId="prototype.standalone.MainDirectory"
label="Main">
</command>
</menu>
public class MainDirectory extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// How can I call from here all my business methods from my main View.
// Do I have to use DI? If yes, can you give me an easy example related to this snippet?
return null;
}
}
如評論中所問。 如何調用我的方法? 因為如果我從不實例化MainDirectory
那么我也不能僅從createControls
傳遞對象-我認為我必須使用依賴注入,但我不知道如何。 有人可以給我一個例子或其他解決方案嗎
編輯:或者是否有可能將偵聽器添加到菜單項? 將使一切變得容易。 沒有找到任何東西
似乎是不使用org.eclipse.ui.menu
創建菜單的最簡單方法,而是僅使用基本的SWT Menu
並將其添加到框架中-我仍然有一個獨立的應用程序,因此eclipse菜單將是一個過大的殺傷力
您還應該在plugin.xml
包含以下內容
<extension point="org.eclipse.ui.commands">
<command
defaultHandler="your MainDirectory class path"
id="prototype.standalone.MainDirectory"
name="My Label">
</command>
</extension>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.