Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Repost : Reload-refresh resource supporting opened editor
Repost : Reload-refresh resource supporting opened editor [message #687416] Wed, 08 June 2011 15:17
Steven Derrien is currently offline Steven DerrienFriend
Messages: 50
Registered: July 2009
Member
Hi,

After claoing and reopenign my editor at lest 3000 time upon model file change, I realized that
I would need to make it refresh itself upon a model file change caused by an
external modification (editor, program, etc).

I searched the newsgroup and found the thread below, but since I am
not enough confortable with EMF editor/JFace stuff, I could not see how
to use Ed's answer to solve the problem.

> Carlos,
>
> Have a look in a generated editor how it handles a resource delta. Look
> for the code that calls Resource.unload...
>
>
> Carlos wrote:
>> Hello.
>>
>> I want to implement an utility for reloading a XMI resource into the
>> editor.
>> I have tried to close the editor and open it, but this is not very
>> smart. I would prefer loading the model without closing the editor.
>>
>> Is there any method in the EMF API to do this?
>> Have you got any suggestion?
>>
>> Thanks in advance.
>> Best regards.
>> Carlos.


Looking at the generated code I found the method below, but I don't know how to
customize is so as to make a proper use of resource.unload().

Any help would be greatly appreciated.


protected IResourceChangeListener resourceChangeListener =
new IResourceChangeListener() {
public void resourceChanged(IResourceChangeEvent event) {
IResourceDelta delta = event.getDelta();
try {
class ResourceDeltaVisitor implements IResourceDeltaVisitor {
protected ResourceSet resourceSet = editingDomain.getResourceSet();
protected Collection<Resource> changedResources = new ArrayList<Resource>();
protected Collection<Resource> removedResources = new ArrayList<Resource>();

public boolean visit(IResourceDelta delta) {
int type = delta.getResource().getType();
if (type == IResource.FILE) {
if (delta.getKind() == IResourceDelta.REMOVED ||
delta.getKind() == IResourceDelta.CHANGED && delta.getFlags() != IResourceDelta.MARKERS) {
URI createPlatformResourceURI = URI.createPlatformResourceURI(delta.getFullPath().toString(), true);
Resource resource = resourceSet.getResource(createPlatformResourceURI, false);

if (resource != null) {
if (delta.getKind() == IResourceDelta.REMOVED) {
removedResources.add(resource);
}
else if (!savedResources.remove(resource)) {
changedResources.add(resource);

/****

I understand I should reload the model somewhere in
here using resource.unload(); but always get an NPE exception


*****/




}
}
}
}

return true;
}

public Collection<Resource> getChangedResources() {
return changedResources;
}

public Collection<Resource> getRemovedResources() {
return removedResources;
}
}

thks,

Steven Derrien
Previous Topic:(no subject)
Next Topic:(no subject)
Goto Forum:
  


Current Time: Sun Sep 15 12:51:10 GMT 2019

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

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

Back to the top