Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Refresh resource after external alteration to file
Refresh resource after external alteration to file [message #328487] Mon, 26 May 2008 14:11 Go to next message
Eclipse UserFriend
Hi,

I have code that has to save via a path (String). So, I create my own
FileOutputStream that writes the file to the workspace (not via IFile),
and close the stream. The workspace is obviously not aware of this, and
I need to hit refresh before using the file (I use a CommonNavigator).
Is there some way I can locate the file in the workspace by name or
external (non-workspace) path, so I can get a handle to the IFile and
call "refresh" programmatically? Or could someone recommend another
strategy so that the resource is refreshed automatically on external
modification?

Cheers,

.../Ola
Re: Refresh resource after external alteration to file [message #328498 is a reply to message #328487] Mon, 26 May 2008 16:55 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.Friend
Messages: 621
Registered: July 2009
Senior Member
Use IWorkspaceRoot.getFileForLocation() to get the IFile and do a
refreshLocal() on that.

--

- Prakash

Eclipse Tips: http://blog.cypal-solutions.com
Eclipse Search: http://www.cypal.in/eclipsesearch


Ola Spjuth wrote:
> Hi,
>
> I have code that has to save via a path (String). So, I create my own
> FileOutputStream that writes the file to the workspace (not via IFile),
> and close the stream. The workspace is obviously not aware of this, and
> I need to hit refresh before using the file (I use a CommonNavigator).
> Is there some way I can locate the file in the workspace by name or
> external (non-workspace) path, so I can get a handle to the IFile and
> call "refresh" programmatically? Or could someone recommend another
> strategy so that the resource is refreshed automatically on external
> modification?
>
> Cheers,
>
> .../Ola
Re: Refresh resource after external alteration to file [message #328636 is a reply to message #328487] Thu, 29 May 2008 08:14 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Ola Spjuth wrote:
> Hi,
>
> I have code that has to save via a path (String). So, I create my own
> FileOutputStream that writes the file to the workspace (not via
> IFile), and close the stream. The workspace is obviously not aware of
> this, and I need to hit refresh before using the file (I use a
> CommonNavigator). Is there some way I can locate the file in the
> workspace by name or external (non-workspace) path, so I can get a
> handle to the IFile and call "refresh" programmatically? Or could
> someone recommend another strategy so that the resource is refreshed
> automatically on external modification?
The simplest for you would be to use file buffers. You can get it by
path and it will even handle the load and save operations for you.

Dani
>
> Cheers,
>
> .../Ola
Re: Refresh resource after external alteration to file [message #328642 is a reply to message #328498] Thu, 29 May 2008 14:03 Go to previous message
Eclipse UserFriend
Originally posted by: kosta.bea.com

Here is a conversion routine that I had to write a while back for
getting IFile given File:

public static IFile getWorkspaceFile( final File f )
{
final IWorkspace ws = ResourcesPlugin.getWorkspace();
final IWorkspaceRoot wsroot = ws.getRoot();
final IPath path = new Path( f.getAbsolutePath() );

final IFile[] wsFiles = wsroot.findFilesForLocation( path );

if( wsFiles.length > 0 )
{
return wsFiles[ 0 ];
}

return null;
}

- Konstantin
Previous Topic:How to find the updated buffer in Compare Editor?
Next Topic:Working sets loosing projects
Goto Forum:
  


Current Time: Thu Jul 18 01:12:19 GMT 2024

Powered by FUDForum. Page generated in 0.04050 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top