3

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?

Samuel Lampa
  • 4,336
  • 5
  • 42
  • 63

2 Answers2

3

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.

David G
  • 3,940
  • 1
  • 22
  • 30
  • Indeed, this does the trick, if i send in my "rfss" object above, as the "yoursubsystem" parameter, and switch ISystemResourceChangeEvents.EVENT_REFRESH to ISystemResourceChangeEvents.EVENT_REFRESH_SELECTED_PARENT (only little problem is that this event (EVENT_REFRESH_SELECTED_PARENT) is deprecatted :/ ... any hints on how to get around it? – Samuel Lampa Aug 12 '11 at 13:40
  • The [javadoc's](http://help.eclipse.org/indigo/topic/org.eclipse.rse.doc.isv/reference/api/org/eclipse/rse/core/events/ISystemResourceChangeEvents.html#EVENT_REFRESH_SELECTED_PARENT) indicate 'obtain the selection yourself and do EVENT_REFRESH or EVENT_REFRESH_REMOTE'. My code uses the EVENT_REFRESH event without a problem. – David G Aug 12 '11 at 13:57
  • Right, thanks. Well, I guess the problem is that I typically has a file in the current directory selected, while I need to refresh it's parent folder in order to see new files. Using EVENT_REFRESH_SELECTED_PARENT had been convenient, since I'd not need to grab the currently selected file, which I need to do now, in order to then get it's parent folder... – Samuel Lampa Aug 12 '11 at 14:04
1

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

Tom Seidel
  • 9,525
  • 1
  • 26
  • 38
  • Strange ... I don't seem to have any ResourcesPlugin (there's nothing to import, with that name :-o). – Samuel Lampa Aug 12 '11 at 13:41
  • You have to add a dependecy to org.eclipse.core.resources. This bundle holds the abstraction-layer for resources. But this works only if you use the EFS integration, see this blog-posting -> http://tmober.blogspot.com/2007/04/target-management-m6-efs-and-webinar.html – Tom Seidel Aug 12 '11 at 14:11