【发布时间】:2021-04-16 12:09:52
【问题描述】:
我有一个插件。在这个插件中,我有一个创建一些标记的视图,以便我可以打开文件并自动导航到选定的行。但是,这种方法以前对我有用。它现在停止了吗?它只返回 null 作为我的 IFile。
这是我创建标记的方法 注意:此方法不在 FXML 文件的控制类中。它位于另一个外部文件中。
public static String openAbsoluteFileInEclipseEditor(String absoluteLocationP, int lineNumberP) {
File absolute = new File(absoluteLocationP);
if(absolute.isFile() && absolute.exists()) {
if(Globals.testing) {
try {
Desktop.getDesktop().open(absolute);
return null;
} catch (IOException e) {
ErrorHandling.reportErrors(e);
return "";
}
}else {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
if(lineNumberP != 0) {
IPath location = Path.fromOSString(absolute.getAbsolutePath());
System.out.println("location " + location);
IFile iFile = workspace.getRoot().getFileForLocation(location);
System.out.println("iFile " + iFile);
IMarker marker = iFile.createMarker(IMarker.TEXT);
marker.setAttribute(IMarker.LINE_NUMBER, lineNumberP);
IDE.openEditor(page, marker);
marker.delete();
}else {
IFileStore fileStore = EFS.getLocalFileSystem().getStore(absolute.toURI());
IDE.openEditorOnFileStore( page, fileStore );
}
return null;
} catch (PartInitException e) {
ErrorHandling.reportErrors(e);
return "";
} catch (CoreException e) {
ErrorHandling.reportErrors(e);
return "";
}
}
}else {
return "File not found";
}
}
这是您可以在方法中间看到的两个打印值。
位置 C:/SoftwareAG_Workspaces/workspace105/HOSPITAL/Natural-Libraries/HOSPITAL/Programs/XX021P01.NSP iFile 为空
谁能向我指出为什么它可能不再起作用以及为什么它只返回空值?如果可能的话,您能否建议一种可行的替代方法?该文件确实存在于我确定的那个位置。
提前致谢。
【问题讨论】:
-
这和fx有什么关系?确保文件确实在您期望的位置
标签: java eclipse javafx plugins markers