How to programmatically refresh an Eclipse view, or RSE file subsystem?

主宰稳场 提交于 2021-01-28 04:21:40

问题


How can I programmatically update an Eclipse view? (I suppose this might not need to be specific to RSE?).

Background: I use Remote System Explorer (RSE) for Eclipse, do some stuff by executing remote commands via SSH, which creates new files on the remote host. I realized that the SFTP file listing in the Remote systems view does not automatically get updated to show the newly created file.

I have managed so far to get the relevant view, like so:

IWorkbench workbench = PlatformUI.getWorkbench();
IViewRegistry viewReg = workbench.getViewRegistry();
IViewDescriptor[] views = viewReg.getViews();
for (IViewDescriptor view : views) {
  String viewID = view.getId();
    System.out.println("View ID: " + viewID);
    if (viewID.equals("org.eclipse.rse.ui.view.systemView")) {
      // Do something with the view here
    }
}

... and for possibly doing something RSE specific, I tried grabbing the RemoteFileSubSystem:

IRemoteFileSubSystem rfss = RemoteFileUtility.getFileSubSystem(HPCUtils.getApplication().getHPCHost());

... but neither in the ViewDescriptor object, nor the FileSubSystem, I have found any way to refresh the view, or the file subsystem. What have I missed?


回答1:


Are you looking to refresh a container that you constructed? IOW, a class that you wrote that extends org.eclipse.rse.core.subsystems.AbstractResource?

If so, try this code ...

ISystemRegistry registry = SystemStartHere.getSystemRegistry();

SystemResourceChangeEvent event = new SystemResourceChangeEvent(this, 
    ISystemResourceChangeEvents.EVENT_REFRESH, yoursubsystem);

registry.fireEvent(event);

If you're NOT inside your own resource container, but you know the resource container's object, replace this in the SystemResourceChangeEvent construction with the object.




回答2:


I'm not familar with RSE but AFAIK it uses a virtual filesystem. That means refreshing can be done via the normal Resource-API, something like:

IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(new Path("path/to/theparent/folder/on/remote/system"));
        folder.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());

The Filesystem manager of Eclipse will check your EFS-specific implementation of org.eclipse.core.filesystem.IFileInfo for a changed modification date. Make sure that your virtual filesystem will return correct File-Information



来源:https://stackoverflow.com/questions/7039349/how-to-programmatically-refresh-an-eclipse-view-or-rse-file-subsystem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!