[Eclipse]在程序里隐藏但利用Resource Navigator

有些时候需要在应用程序里隐藏Resource Navigator,用程序控制而非双击鼠标打开编辑器。一个方法是让程序在目标workspace里创建一个project和需要的文件,用户不知道它们的存在:

IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(".my");
if (!project.exists()) {
    try {
        project.create(null);
    } catch (CoreException e1) {
        e1.printStackTrace();
    }
}
if(!project.isOpen()){
    try {
        project.open(null);
    } catch (CoreException e1) {
        e1.printStackTrace();
    }
}
IFile file = project.getFile("default.my");
if (!file.exists()) {
    InputStream is = this.getClass().getResourceAsStream("/data/blank.my");
    try {
        file.create(is, false, null);
    } catch (CoreException e1) {
        e1.printStackTrace();
    }
}
FileEditorInput input = new FileEditorInput(file);
openEditor(input, MyEditor.EDITOR_ID);//IWorkbenchPage#openEditor()

搬家前链接:https://www.cnblogs.com/bjzhanghao/archive/2007/01/11/617260.html