Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » synchronize file system and workspace
synchronize file system and workspace [message #211530] Wed, 19 November 2008 14:47 Go to next message
Vadim Chepegin is currently offline Vadim ChepeginFriend
Messages: 9
Registered: July 2009
Junior Member
Hello everybody,

I need an advice how to synchronize a workspace with a file system
programmatically.

I create a new project including directory structure using my wizard. I
also create a file with a new default diagram and write it into one of
those directories.

Then I open an editor for this file.

The problem is that sometimes (often) I get a popup with an error message:
"Modification could not be completed.
Reason
The following files are out of synchronization with the workspace:
<name_of_file>"

I tried several things:

1. Tried to listen changes in file system (may be needed something else?):

IResourceChangeListener rcl = FileChangeManager.getInstance();
ResourcesPlugin.getWorkspace().addResourceChangeListener(rcl );

2. Extract the code that writes a file into a separate thread, start it
and join the current thread to it. So writing a file must be finished
before opening an editor.

3. Re-opening a new resource and reveal it

IFile file = folder.getFile(schemaName + ".snf");
selectAndReveal(file);

4. force refreshing of a workspace

IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();

workspaceRoot.refreshLocal(IResource.DEPTH_INFINITE,
new NullProgressMonitor());

5. Check

file.isSynchronized(depth)

Even if it is true the message can appear.

6. Dummy Thread.wait(<some_seconds>)

Anyway, the problem occurs from time to time!


So, I need an advice how to force this synchronization when needed?
Re: synchronize file system and workspace [message #211564 is a reply to message #211530] Thu, 20 November 2008 00:08 Go to previous messageGo to next message
Zsolt Török is currently offline Zsolt TörökFriend
Messages: 22
Registered: July 2009
Junior Member
Hi Vadim,

Apparently you tried lots of different ways to fix this, but let me
recommend you another one: writing a WorkspaceJob implementation.
( http://help.eclipse.org/ganymede/topic/org.eclipse.platform. doc.isv/reference/api/org/eclipse/core/resources/WorkspaceJo b.html)
The javadoc is quite detailed, and it all boils down to putting your
workspace modification code into the runInWorkspace method and hooking up
a resource change listener.

HTH,
Zsolt
Re: synchronize file system and workspace [message #211641 is a reply to message #211564] Thu, 20 November 2008 14:01 Go to previous messageGo to next message
Vadim Chepegin is currently offline Vadim ChepeginFriend
Messages: 9
Registered: July 2009
Junior Member
Zsolt Török wrote:

> Hi Vadim,

> Apparently you tried lots of different ways to fix this, but let me
> recommend you another one: writing a WorkspaceJob implementation.
>
( http://help.eclipse.org/ganymede/topic/org.eclipse.platform. doc.isv/reference/api/org/eclipse/core/resources/WorkspaceJo b.html)
> The javadoc is quite detailed, and it all boils down to putting your
> workspace modification code into the runInWorkspace method and hooking up
> a resource change listener.

> HTH,
> Zsolt
Thank you, Zsolt! I will definetely give it a try.

If anybody has other options as wel, you are welcome :)
Re: synchronize file system and workspace [message #211817 is a reply to message #211641] Sun, 23 November 2008 13:45 Go to previous message
Martin Fluegge is currently offline Martin FlueggeFriend
Messages: 141
Registered: July 2009
Senior Member
Hi Vadim,

I had (maybe) a similar problem. After creating a file in a Wizard the
file did not appear in the workspace. There was no synchronisation with
the filesystem.
I played around hours with this problem, trying a lot of the things you
also tried, until I found a solution which worked for me.

I execute all file-creation-code into a WorkspaceModificationOperation
and execute I workspace refesh after creating the files.
Because I am quite new to Eclipse-development I do not know whether this
is the right way or whether it has some side-effects. Just try it, if
the idea with the WorkSpaceJob does not work.
Maybe this works for you, too.

See an example below.

Regards,

Martin

IRunnableWithProgress op = new WorkspaceModifyOperation(null)
{

protected void execute(IProgressMonitor monitor) throws
CoreException, InterruptedException
{

//....your file creation code

try
{
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
root.refreshLocal(IResource.DEPTH_INFINITE, monitor);

}
catch (CoreException e)
{

e.printStackTrace();
}
}
};

getContainer().run(false, true, op);


Vadim Chepegin schrieb:
> Zsolt Török wrote:
>
>> Hi Vadim,
>
>> Apparently you tried lots of different ways to fix this, but let me
>> recommend you another one: writing a WorkspaceJob implementation.
> ( http://help.eclipse.org/ganymede/topic/org.eclipse.platform. doc.isv/reference/api/org/eclipse/core/resources/WorkspaceJo b.html)
>
>> The javadoc is quite detailed, and it all boils down to putting your
>> workspace modification code into the runInWorkspace method and hooking
>> up a resource change listener.
>
>> HTH,
>> Zsolt
> Thank you, Zsolt! I will definetely give it a try.
>
> If anybody has other options as wel, you are welcome :)
>
Previous Topic:Using GMF with 64 bit Linux
Next Topic:create and display copy of existing EObject
Goto Forum:
  


Current Time: Fri Apr 26 07:46:44 GMT 2024

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

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

Back to the top