Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » How to Rename a Diagram
How to Rename a Diagram [message #195592] Thu, 03 July 2008 10:52 Go to next message
Eclipse UserFriend
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 #195639 is a reply to message #195592] Thu, 03 July 2008 12:14 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Carlos,

Eacy way is: load all "cross-referenced" EMF resources into the single ResourceSet,
change name for the Resource you'd like to rename and save all the resoruces.

-----------------
Alex Shatalin
Re: How to Rename a Diagram [message #196174 is a reply to message #195639] Wed, 09 July 2008 07:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: youchy.gmail.com

Hi Alex,

I don't understand what is a Cross Reference. Can you show me a little bit
of code, doing what you say??

Thanks
Re: How to Rename a Diagram [message #196219 is a reply to message #196174] Wed, 09 July 2008 09:26 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Carlos,

ResourceSet rs = new ResourceSetImpl();
Resource resource1 = rs.getResource(model1URI, true);
Resource resource2 = rs.getResource(model2URI, true);
.... <all the resources with possible references>

resource1.serURI(newModel1URI);

resource1.save(..);
resource2.save(..);
....

By "cross references" i meant references between EObjects stored in different
resources. For example, elements of .diagram file are keeping references
to the elements of .domain file (resource).

-----------------
Alex Shatalin
Re: How to Rename a Diagram [message #196267 is a reply to message #196219] Wed, 09 July 2008 10:32 Go to previous messageGo to next message
Eclipse UserFriend
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 #196282 is a reply to message #196267] Wed, 09 July 2008 10:53 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
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
Re: How to Rename a Diagram [message #196299 is a reply to message #196282] Wed, 09 July 2008 11:15 Go to previous messageGo to next message
Eclipse UserFriend
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 #196305 is a reply to message #196299] Wed, 09 July 2008 11:29 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Carlos,

> 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??
Yes. In case of loading all the resources into ResourceSetImpl (without any
EditingDomain associated) you can just call .setName() for the diagram instance
before saving models.

-----------------
Alex Shatalin
Re: How to Rename a Diagram [message #506595 is a reply to message #196282] Fri, 08 January 2010 09:27 Go to previous messageGo to next message
Johannes Michler is currently offline Johannes MichlerFriend
Messages: 21
Registered: July 2009
Junior Member
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



--
Re: How to Rename a Diagram [message #506606 is a reply to message #506595] Fri, 08 January 2010 05:14 Go to previous messageGo to next message
Sven Krause is currently offline Sven KrauseFriend
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 Go to previous message
Sven Krause is currently offline Sven KrauseFriend
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
>
>
>
Previous Topic:Avoid obstructions only works for toplevel elements
Next Topic:Refresh command on diagram modification
Goto Forum:
  


Current Time: Tue Apr 13 20:56:16 GMT 2021

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

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

Back to the top