Re: Refresh GMF Editor [message #176631] |
Tue, 11 March 2008 11:51 |
Eclipse User |
|
|
|
Originally posted by: amsurana.in.ibm.com
This is a multipart message in MIME format.
--=_alternative 00412B4065257409_=
Content-Type: text/plain; charset="US-ASCII"
>It works if I open the generated EMF tree editor and add a new semantic
element, then save the resource. >However, if I programmatically add a new
semantic element
>
>Something s = MySemanticElementFactory.eINSTANCE.createSomething();
>someOtherElement.eContents().add(s);
>someOtherElement.eResource.save(EmptyMap);
>Then it doesn't work. If I close my editor and reopen it, then it
appears.
>cheers,
>ian
>
>
>Alex Shatalin wrote:
>Hello Ian,
>It sounds like:
> http://wiki.eclipse.org/index.php/GMF_New_and_Noteworthy#Aut omatic_dia
>gram_editor_refresh
>
>Yes, it is. Diagra, should be automatically updated if it is not in
"modified" state and you've saved >your changes onto file system
(Resource.save() was called for all the resources in your ResourceSet).
>
>-----------------
>Alex Shatalin
Hi,
I was going thru the above discussed problem.
I had similar problem but couldnt find any exact solution to this. So here
I am posting a solution that will help the other developers.
To refresh the editor when u create any model Element using dyanmic EMF,
all u need to do is
refresh the ???CanonicalEditPolicy of the Diagram/Container Element.
for Example in UML, I have PACKAGE as my Diagram/model Element. So I do
have a PackageCanonicalEditPolicy generated in diagram code.
I just call the refresh method of this EditPolicy. :)
One might have more than one canonical EditPolicy for a modelElement.
You can access this CanonicalEditPolicy using the following code snippet.
List editPolicies = CanonicalEditPolicy.getRegisteredEditPolicies
(rootPkg);
for (Iterator it = editPolicies.iterator();
it.hasNext();) {
CanonicalEditPolicy nextEditPolicy =
(CanonicalEditPolicy) it.next();
nextEditPolicy.refresh();
}
This code snippet is pasted here for clarity. You can refer to generated
???UpdateCommand for getting exact idea. ???UpdateCommand is called when
the GMF Editor is needed to be updated.
I Hope this helps. Please dont mind if there exist an already discussed
solution in the group
--=_alternative 00412B4065257409_=
Content-Type: text/html; charset="US-ASCII"
<br>
<br><tt><font size=3>>It works if I open the generated EMF tree editor
and add a new semantic element, then save the resource. >However, if
I programmatically add a new semantic element</font></tt><font size=3><br>
></font>
<br><tt><font size=3>>Something s = MySemanticElementFactory.eINSTANCE.createSomething();<br>
>someOtherElement.eContents().add(s);</font></tt>
<br>
<br><tt><font size=3>>someOtherElement.eResource.save(EmptyMap);</font ></tt>
<br>
<br><tt><font size=3>>Then it doesn't work. If I close my editor
and reopen it, then it appears.</font></tt>
<br>
<br><tt><font size=3>>cheers,<br>
>ian</font></tt>
<br><tt><font size=3>><br>
><br>
>Alex Shatalin wrote: </font></tt>
<br><tt><font size=3>>Hello Ian,</font></tt>
<br>
<br><tt><font size=3>>It sounds like:<br>
</font></tt><a href= http://wiki.eclipse.org/index.php/GMF_New_and_Noteworthy#Aut omatic_dia><tt><font size=3 color=blue><u>> http://wiki.eclipse.org/index.php/GMF_New_and_Noteworthy#Aut omatic_dia</u></font></tt></a><tt><font size=3><br>
>gram_editor_refresh<br>
></font></tt>
<br><tt><font size=3>>Yes, it is. Diagra, should be automatically updated
if it is not in "modified" state and you've saved >your changes
onto file system (Resource.save() was called for all the resources in your
ResourceSet).</font></tt><font size=3><br>
></font>
<br><tt><font size=3>>-----------------<br>
>Alex Shatalin</font></tt>
<br>
<br>
<br>
<br>
<br><tt><font size=3>Hi, </font></tt>
<br><tt><font size=3>I was going thru the above discussed problem. </font></tt>
<br><tt><font size=3>I had similar problem but couldnt find any exact solution
to this. So here I am posting a solution that will help the other developers.
</font></tt>
<br>
<br><tt><font size=3>To refresh the editor when u create any model Element
using dyanmic EMF, all u need to do is </font></tt>
<br><tt><font size=3>refresh the ???CanonicalEditPolicy of the Diagram/Container
Element.</font></tt>
<br>
<br><tt><font size=3>for Example in UML, I have PACKAGE as my Diagram/model
Element. So I do have a PackageCanonicalEditPolicy generated in diagram
code. </font></tt>
<br><tt><font size=3>I just call the refresh method of this EditPolicy.
:) </font></tt>
<br><tt><font size=3>One might have more than one canonical EditPolicy
for a modelElement.</font></tt>
<br>
<br>
<br><tt><font size=3>You can access this CanonicalEditPolicy using the
following code snippet.</font></tt>
<br>
<br><font size=2 color=#0021bf face="Courier New"> </font>
<br><font size=2 face="Courier New">List editPolicies = CanonicalEditPolicy.<i>getRegisteredEditPolicies</i>(rootPkg); </font>
<br><font size=2 face="Courier New">
</font><font size=2 color=#820040 face="Courier New"><b>for</b></font><font size=2 face="Courier New">
(Iterator it = editPolicies.iterator(); it.hasNext();) {</font>
<br><font size=2 face="Courier New">
CanonicalEditPolicy nextEditPolicy = (CanonicalEditPolicy)
it.next();</font>
<br><font size=2 face="Courier New">
nextEditPolicy.refresh();</font>
<br><font size=2 face="Courier New">
</font>
<br><font size=2 face="Courier New">
}</font>
<br>
<br><tt><font size=3>This code snippet is pasted here for clarity. You
can refer to generated ???UpdateCommand for getting exact idea. ???UpdateCommand
is called when the GMF Editor is needed to be updated.</font></tt>
<br>
<br><tt><font size=3>I Hope this helps. Please dont mind if there exist
an already discussed solution in the group</font></tt>
<br>
--=_alternative 00412B4065257409_=--
|
|
|
Powered by
FUDForum. Page generated in 0.01377 seconds