我有一个 RCP 程序,有 3 个部分 - 2 个视图(左侧,2 个部分)和各种编辑器(右侧和另一部分)。在我看来,我有树,我可以打开编辑器(其他部分)。在编辑器上我可以打开另一个编辑器,但是当我调用编辑器时我需要过去一个对象,我让它:addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {....
我的按钮:
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
try {
handlerService.executeCommand("XPTO.command", null);
} catch (Exception ex) {
throw new RuntimeException(
"XPTO");
}
}
});
我的命令:
public class CallEditors extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
System.out.println("calledEditor");
// Get the view
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
Editor navEditor = (Editor) page.findEditor(Editor.IDI);
} }
谢谢
我有答案:
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
// Get the view
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
Object obj = btnNewButton.getData();
if (obj != null) {
xPTO input = new xPTO();
try {
page.openEditor(input, xptoEditor.ID, false);
} catch (PartInitException e1) {
throw new RuntimeException(e1);
}
}
}