How to Rename a Diagram [message #195592] |
Thu, 03 July 2008 10:52 |
Eclipse User |
|
|
|
Originally posted by: youchy.gmail.com
Hi everybody,
I want to have an Action to Rename the diagram, so rename the files, and
all content inside the files that references to the old Nam.
How can I do this?? I think make my parser is a bad solution, and I'm sure
this is implemented, or not?
Thanks everyone!
|
|
|
|
|
|
Re: How to Rename a Diagram [message #196267 is a reply to message #196219] |
Wed, 09 July 2008 10:32 |
Eclipse User |
|
|
|
Originally posted by: youchy.gmail.com
yes, thats make me another Pair of Files .diagram and .model, but for
example:
if I have the diagram A (i've the Pair [.mode, .driagram]
now I want to Rename this diagram to B.
I must rename the files .mode .diagram , but I must rename the references
that are in the .diagram to the .model...
your code makes the first step, rename the files, but I can't fins how to
rename the refernces inside the file.
can you Understand Me??
Thanks
|
|
|
|
Re: How to Rename a Diagram [message #196299 is a reply to message #196282] |
Wed, 09 July 2008 11:15 |
Eclipse User |
|
|
|
Originally posted by: youchy.gmail.com
hi alex,
It's true sorry, the references are modified, but the name of the diagram
is not correct, i must set it' manually?? creating a transactional command
or with a SetValueCommand??
Thanks
|
|
|
|
|
Re: How to Rename a Diagram [message #506606 is a reply to message #506595] |
Fri, 08 January 2010 05:14 |
Sven Krause Messages: 119 Registered: July 2009 |
Senior Member |
|
|
Am 08.01.2010, 10:27 Uhr, schrieb Johannes Michler <orgler@gmail.com>:
> Hi,
>
> unfortunately, this didn't work for me. I'm having a .diagram and a
> .model file and I want to rename the .model (that is referenced by the=
> diagram for some graphic elements). So this is what I did:
>
>
> ResourceSet rs =3D new ResourceSetImpl();
> Resource diag_res =3D rs.getResource( diagramURI, true);
> Resource res =3D rs.getResource( modelURI, true);
> res.setURI(newModelURI);
> diag_res.save( ShmDiagramEditorUtil.getSaveOptions());
> res.save( ShmDiagramEditorUtil.getSaveOptions());
>
>
> Unfortunately, this creates me just a copy of the model file in
> newModelURI but doesn't adjust the references from my diagram-File to
> the new model file.
>
> Any ideas what I'm doing now? Maybe the problem is that we're using ou=
r
> own URI-Handler?
>
> For now, I'm working around this by doing a string-replace of
> href=3D"oldModel.shm#" to href=3D"newModel.shm#". But I consider this =
very
> ugly :-(
>
> Best regards,
>
> Johannes
>
> Alex Shatalin wrote:
>
>> Hello Carlos,
>>
>> Then you change URI for one of the resources and then save both you
>> should get all references updated in the second resource by EMF...
>>
>> -----------------
>> Alex Shatalin
>
>
>
-- =
Erstellt mit Operas revolution=E4rem E-Mail-Modul: http://www.opera.com/=
mail/
|
|
|
Re: How to Rename a Diagram [message #506609 is a reply to message #506595] |
Fri, 08 January 2010 10:23 |
Sven Krause Messages: 119 Registered: July 2009 |
Senior Member |
|
|
Hi Johannes,
you need to replace the references the diagram references items from old
model elements to the corresponding new one.
URI diagramUri = ...;
URI newModelUri = ...;
URI oldModelUri = ...;
ResourceSet rs = new ResourceSetImpl();
Resource diagRes = rs.getResource(diagramUri, true);
Resource newModelRes = rs.getResource(newModelUri, true);
Resource oldModelRes = rs.getResource(oldModelUri, true);
Diagram diagram = null;
EList<EObject> contents = diagRes.getContents();
for (Iterator<EObject> iterator = contents.iterator(); diagram == null
&& iterator.hasNext();) {
EObject eObject = iterator.next();
if (eObject instanceof Diagram) {
diagram = (Diagram) eObject;
}
}
for(TreeIterator<EObject> it = EcoreUtil.getAllContents(diagram, true);
it.hasNext();) {
EObject next = it.next();
if (next instanceof View) {
View view = (View) next;
EObject oldElement = view.getElement();
EObject newElement =
newModelRes.getEObject(oldModelRes.getURIFragment(oldElement ));
view.setElement(newElement);
}
}
Am 08.01.2010, 10:27 Uhr, schrieb Johannes Michler <orgler@gmail.com>:
> Hi,
>
> unfortunately, this didn't work for me. I'm having a .diagram and a
> .model file and I want to rename the .model (that is referenced by the
> diagram for some graphic elements). So this is what I did:
>
>
> ResourceSet rs = new ResourceSetImpl();
> Resource diag_res = rs.getResource( diagramURI, true);
> Resource res = rs.getResource( modelURI, true);
> res.setURI(newModelURI);
> diag_res.save( ShmDiagramEditorUtil.getSaveOptions());
> res.save( ShmDiagramEditorUtil.getSaveOptions());
>
>
> Unfortunately, this creates me just a copy of the model file in
> newModelURI but doesn't adjust the references from my diagram-File to
> the new model file.
>
> Any ideas what I'm doing now? Maybe the problem is that we're using our
> own URI-Handler?
>
> For now, I'm working around this by doing a string-replace of
> href="oldModel.shm#" to href="newModel.shm#". But I consider this very
> ugly :-(
>
> Best regards,
>
> Johannes
>
> Alex Shatalin wrote:
>
>> Hello Carlos,
>>
>> Then you change URI for one of the resources and then save both you
>> should get all references updated in the second resource by EMF...
>>
>> -----------------
>> Alex Shatalin
>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.33159 seconds