如何调用Eclipse F5在页面关闭后以编程方式刷新 [英] How to Call Eclipse F5 Refresh Programmatically after Page Closes

查看:595
本文介绍了如何调用Eclipse F5在页面关闭后以编程方式刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在eclipse中以编程方式调用refresh(F5)并获得NotHandledException,处理程序未找到错误。帮助将不胜感激。

I have been trying to call refresh (F5) programmatically in eclipse and get a NotHandledException, handler not found error. Help would be much appreciated.

在我的类中:NewPreferencePage extends PreferencePage实现IWorkbenchPreferencePage
我有以下代码:

In my class: NewPreferencePage extends PreferencePage implements IWorkbenchPreferencePage I have the following code:

@Override        
public void dispose() {

    super.dispose();

    final String COMMAND_ID = "org.eclipse.ui.file.refresh";
    IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);

    try {
        handlerService.executeCommand(COMMAND_ID,null);
    } catch (ExecutionException ex) {
        ex.printStackTrace();
    } catch (NotDefinedException ex) {
        ex.printStackTrace();
    } catch (NotEnabledException ex) {
        ex.printStackTrace();
    } catch (NotHandledException ex) {
        ex.printStackTrace();
    }
}


推荐答案

你可以使用具有(几乎)相同效果的 IResource#refreshLocal()。以下是单个文件的示例,但您可以以相同的方式执行项目:

You can use IResource#refreshLocal(), which has (almost) the same effect. The following is an example for a single file, but you can do a project in the same way:

IResource dfile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
dfile.create(blahblahblah, true, new NullProgressMonitor()); // obviously you don't need this, it's just an example
dfile.refreshLocal(IResource.DEPTH_ZERO, null);

请参阅常见问题什么时候应该使用refreshLocal?获取更多信息。

这篇关于如何调用Eclipse F5在页面关闭后以编程方式刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆