当我尝试在eclipse中打开编辑器时,为什么IWorkbenchPage页面为空?

时间:2016-07-08 16:51:29

标签: java eclipse-plugin

我找到了这个示例代码:

<div id="popover"> content </div>

#popover{
    position: absolute;
//    left: <x>px;
//    top: <y>px;
    display: inline-block;
    height: 100px;
    width: 100px;
}

当我运行我的插件时,eclipse报告IWorkbenchPage页面为空。

我以这种方式实现我的代码:

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
}

方法openFile是从同一个类中的另一个方法调用的。

这是我的SampleHandlers(我自己不写):

public void openFile(Path filepath) throws Exception
{
    File fileToOpen = new File(filepath.toString());

    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
    }               
}

0 个答案:

没有答案