我有一个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);
}
}
}
答案 0 :(得分:2)
使用IWorkbenchPage#openEditor(..)