如何在RCP中使用ResourceNavigator双击项目以打开包含内容的默认编辑器?

时间:2014-05-05 03:26:00

标签: eclipse rcp

这是我的导航器视图。

public class myNavigatorView extends ResourceNavigator {

private NavigatorActionGroup navigatorActionGroup;
private CollapseAllHandler collapseAllHandler;
public myNavigatorView() {
    // TODO Auto-generated constructor stub
}
protected void makeActions() {

    navigatorActionGroup = new NavigatorActionGroup( this );
    setActionGroup(navigatorActionGroup);

    IHandlerService service = (IHandlerService) getSite().getService(IHandlerService.class);
    service.activateHandler(IWorkbenchCommandConstants.NAVIGATE_TOGGLE_LINK_WITH_EDITOR,
            new ActionHandler(navigatorActionGroup.toggleLinkingAction));
    collapseAllHandler = new CollapseAllHandler(this.getViewer());
    service.activateHandler(CollapseAllHandler.COMMAND_ID,
            collapseAllHandler);
}
}

当我双击我选择的项目时,内容没有显示在编辑器中。

layout.setEditorAreaVisible(true);
leftFolder.addView("BIT_DEC.myNavigator");

1 个答案:

答案 0 :(得分:1)

资源导航器执行此操作以进行打开:

protected void handleOpen(ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        getActionGroup().runDefaultAction((IStructuredSelection)selection);
    }
}

因此,您的操作组runDefaultAction方法需要打开。资源导航器代码执行此操作:

public void runDefaultAction(IStructuredSelection selection) {
    Object element = selection.getFirstElement();
    if (element instanceof IFile) {
        openFileAction.selectionChanged(selection);
        openFileAction.run();
    }
}

其中openFileActionorg.eclipse.ui.actions.OpenFileAction的实例。

注意:ResourceNavigator已被弃用了很长时间!