M2M Transformation [message #417204] |
Fri, 29 February 2008 13:47 |
Eclipse User |
|
|
|
Originally posted by: invone2000.yahoo.de
Hmm cryptic:
I have two IEditingDomainProvider instances at hand. i opened the
corresponding editors and casted them to IEditingDomain.
IEditingDomainProvider src = ...
IEditingDomainProvider target = ...
Now I search one node in the target and one in the source.
Overview:
source:
-root
+-container
+-value
target:
-root
Now I travers through the source to get the container and then I traverse
through the target to get the root.
In my next step I want to "create" a new container as copy of the
container from the source in the target and I use the following:
EObject targetRoot = ...
EObject sourceContainer = ...
Command cmd =AddCommand.create(target.getEditingdomain(), targetRoot,
null, sourceContainer);
target.getEditingDomain().getCommandStack().execute(cmd);
Until now: Everything okay ;)
But then I check the opened editors. The target one is now like:
-root
+-container
+-value (superb)
But the source model does not have the container anymore it looks like
this:
-root
Seems that the container "went over"!
But now the curious thingy: I close the source editor and open it again
and the original content is there (with container and value)...
Any ideas why?
Cheers
harkon
|
|
|
|
Re: M2M Transformation [message #417233 is a reply to message #417205] |
Mon, 03 March 2008 09:27 |
Eclipse User |
|
|
|
Originally posted by: invone2000.yahoo.de
Thanx - I now manage this problem by the following:
I create a copy of the to be added alement and the source model won't be
altered anymore...
But now one other thing:
I use ResourceSet for XMI loading:
URI uri = URI.createFileURI(modelFileName);
Resource res = resourceSet.getResource(uri, true);
Then I fetch the complete content and store it in a List<EObject>
TreeIterator<EObject> iter = res.getAllContents();
List<EObject> ret = new ArrayList<EObject>();
while (iter.hasNext()) {
ret.add(iter.next());
}
Now: When I change the content of a model (AddCommand etc.) The model
contains more elements then before.
When I recall the load method (see above) the content is the same as
before.
Okay, I use the open editor's command stack for Commands and after
transformations I call the doSave() (now it works with syncExec()). The
editor contains the new info and the XMI file is updated as well. But when
I load the content again the old state is fetched.
Workflow:
1. Open editor with model
2. load resources via ResourceSet
3. Alter model via Commands
4. Save Editor
5. load resources via ResourceSet => Bang! Always the same content...
Any hint?
harkon
|
|
|
|
Re: M2M Transformation [message #417310 is a reply to message #417235] |
Wed, 05 March 2008 06:06 |
Eclipse User |
|
|
|
Originally posted by: invone2000.yahoo.de
Okay: just to be sure - here is the progress described
1. I open an ecore editor from a launch configuration and store the
IEditingDomainProvider instance with the appropriate URI with the
following statements (I use a dialog to select the model):
//Get resource for path name of model file
IResource selectedResource =
ResourcesPlugin.getWorkspace().getRoot().findMember(pathName );
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
//open editor and get
IEditingDomainProvider editor =
(IEditingDomainProvider)IDE.openEditor(page, (IFile) selectedResource,
true);
Now I store the editor AND the URI with:
URI fileUri = ((IFile) selectedResource).getLocationURI();
2. I start an RMI server which provides the corresponding file path name
of the currently opened editor. This delivers the URI in string
representation:
String fileName = fileUri.getPath();
3. I connect with an RMI client and get the file name and then I open the
file on the client side also, with:
ResourceSet resourceSet = new ResourceSetImpl();
// Enable loading of XMI files
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "*",
new XMIResourceFactoryImpl());
//register epackages...
URI uri = URI.createFileURI(fileName); //fetched from RMI server
Resource res = resourceSet.getResource(uri, true);
TreeIterator<EObject> iter = res.getAllContents();
List<EObject> ret = new ArrayList<EObject>();
while (iter.hasNext()) {
ret.add(iter.next());
}
4. I work myself with the client through the model and perform actions
which are delegated to the server (because EObjects and the rest is not
serializable). The server uses the real instance of the editor
(IEditingDomainProvider) and its command stack.
After each change I perform a doSave on the opened editor. Now the content
of the model must have been changed.
The URI of the target model file is the same but the content is new. When
I reload the content again (Step 4 from Resource res =
resourceSet.getResource() ...) the old content is loaded...
I don't see any change in the file I use and therefore I'm a bit confused.
By the way I formerly used the TreeIterator<EObject> (as you told me) but
I was afraid that the iterator remembers the position in the content.
Therefore I load the complete content just to be sure - but I didn't
help...
any hint or aid would be great - Thx
harkon
|
|
|
|
Re: M2M Transformation [message #417352 is a reply to message #417317] |
Thu, 06 March 2008 05:54 |
Eclipse User |
|
|
|
Originally posted by: invone2000.yahoo.de
Okay, I now want to use your mentioned changes:
- I get from the selected resource the org.eclipse.emf.common.util.URI
org.eclipse.emf.common.util.URI modelUri =
org.eclipse.emf.common.util.URI.createPlatformResourceURI(se lectedResource.getFullPath().toString(),
true);
[I previously used java.net.URI ...]
with the content during debug:
"platform:/resource/test/src/source.transformator"
- I deliver the file name to the RMI client:
String fileName = sourceModelUri.toPlatformString(true);
with the content during debug:
"/test/src/source.transformator"
- I use the ResourceSet on the client side to load and I use the file name
as follows:
URI uri = URI.createPlatformResourceURI(fileName, true);
with the content during debug:
"platform:/resource/test/src/source.transformator"
So far the both URI's seem to be identical. But I get the following
exception:
Exception in thread "main"
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1Diagnos ticWrappedException:
java.io.IOException: The path '/test/src/source.transformator' is unmapped
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDe mandLoadException(ResourceSetImpl.java:316)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:275)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:398)
at
de.fernunihagen.mda.transformator.concrete.model.impl.Defaul tModelLoader.getContent(DefaultModelLoader.java:45)
at
de.fernunihagen.mda.transformator.concrete.impl.DefaultTrans formator.getSourceObjects(DefaultTransformator.java:64)
at
de.fernunihagen.mda.transformator.concrete.impl.DefaultTrans formator.performTransformation(DefaultTransformator.java:82)
at main.Main.main(Main.java:44)
Caused by: java.io.IOException: The path '/test/src/source.transformator'
is unmapped
at
org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createP latformResourceInputStream(URIConverterImpl.java:648)
at
org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createI nputStream(URIConverterImpl.java:538)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1152)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:256)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:271)
... 5 more
ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code =
-2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):
[../../../src/share/back/util.c:820]
Hmm, now what?
Cheers
harkon
|
|
|
|
Re: M2M Transformation [message #417600 is a reply to message #417361] |
Mon, 17 March 2008 11:14 |
Eclipse User |
|
|
|
Originally posted by: invone2000.yahoo.de
Okay, solved ;)
But now something else:
I have the reference to the open editor which displays the previously
selected model.
The RMI client changes now the file physically (using dynamic EMF and then
I save the new content...).
What am I supposed to do in order to update the editors view?
I want to call some method on the server like updatedEditor().
But how do I update an already opened file viewd in an editor.
When I press F5 on the file the editor will be updated...
But programatically ???
Cheers
harkon
|
|
|
Re: M2M Transformation [message #417602 is a reply to message #417600] |
Mon, 17 March 2008 14:13 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Karkon,
Does it change the underlying file such that the file needs to be
reloaded? Or is it directly changing the model displayed by the
editor. I suspect the former, and in that case, it sound like you need
to do a refreshLocal on the IFile(s) being edited.
harkon wrote:
> Okay, solved ;)
> But now something else:
>
> I have the reference to the open editor which displays the previously
> selected model.
> The RMI client changes now the file physically (using dynamic EMF and
> then I save the new content...).
> What am I supposed to do in order to update the editors view?
> I want to call some method on the server like updatedEditor().
> But how do I update an already opened file viewd in an editor.
> When I press F5 on the file the editor will be updated...
>
> But programatically ???
>
> Cheers
> harkon
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03890 seconds