[英]Eclipse 4.7.1a - open file in editor from code/programatically
我想向我的eclipse插件添加功能以在新的Eclipse编辑器中打开指定的文件。 我找到了基于org.eclipse.ui.ide.IDE
解决方案,并import org.eclipse.core.filesystem.EFS
:
import java.io.File;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
File fileToOpen = new File("externalfile.xml");
if (fileToOpen.exists() && fileToOpen.isFile()) {
IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileToOpen.toURI());
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try {
IDE.openEditorOnFileStore( page, fileStore );
} catch ( PartInitException e ) {
//Put your exception handler here if you wish to
}
} else {
//Do something if the file does not exist
}
不幸的是,该解决方案在Eclipse的第4版中不再受支持,仅适用于较旧的IDE。
是否有可能在Eclipse 4.xx中以编程方式打开指定文件上的编辑器,或者进行具有兼容性的解决方法/交易?
Eclipse 4仍然支持3.x样式代码(3.x兼容模式),因此,除非您正在编写纯的“ e4”样式应用程序,否则这应该仍然有效。
解决方案非常琐碎-当我想导入早期列出的类时,Eclipse无法识别这些导入,因此我第一次觉得它根本不兼容。 我进行了另一项研究,以在快速修复菜单中找到“ Fix project setup...
选项。 该选项只是将所需的依赖项添加到了我的要素项目中,因此现在它们可见,并且不再有错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.