Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Re: Refresh GMF Editor
Re: Refresh GMF Editor [message #176631] Tue, 11 March 2008 11:51
Eclipse UserFriend
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>&gt;It works if I open the generated EMF tree editor
and add a new semantic element, then save the resource. &gt;However, if
I programmatically add a new semantic element</font></tt><font size=3><br>
&gt;</font>
<br><tt><font size=3>&gt;Something s = MySemanticElementFactory.eINSTANCE.createSomething();<br>
&gt;someOtherElement.eContents().add(s);</font></tt>
<br>
<br><tt><font size=3>&gt;someOtherElement.eResource.save(EmptyMap);</font ></tt>
<br>
<br><tt><font size=3>&gt;Then it doesn't work. &nbsp;If I close my editor
and reopen it, then it appears.</font></tt>
<br>
<br><tt><font size=3>&gt;cheers,<br>
&gt;ian</font></tt>
<br><tt><font size=3>&gt;<br>
&gt;<br>
&gt;Alex Shatalin wrote: </font></tt>
<br><tt><font size=3>&gt;Hello Ian,</font></tt>
<br>
<br><tt><font size=3>&gt;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>&gt; http://wiki.eclipse.org/index.php/GMF_New_and_Noteworthy#Aut omatic_dia</u></font></tt></a><tt><font size=3><br>
&gt;gram_editor_refresh<br>
&gt;</font></tt>
<br><tt><font size=3>&gt;Yes, it is. Diagra, should be automatically updated
if it is not in &quot;modified&quot; state and you've saved &gt;your changes
onto file system (Resource.save() was called for all the resources in your
ResourceSet).</font></tt><font size=3><br>
&gt;</font>
<br><tt><font size=3>&gt;-----------------<br>
&gt;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">&nbsp; &nbsp;</font>
<br><font size=2 face="Courier New">List editPolicies = CanonicalEditPolicy.<i>getRegisteredEditPolicies</i>(rootPkg); </font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </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">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; CanonicalEditPolicy nextEditPolicy = (CanonicalEditPolicy)
it.next();</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nextEditPolicy.refresh();</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</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_=--
Previous Topic:DestroyElementRequest problem
Next Topic:Refresh Layout of a View
Goto Forum:
  


Current Time: Fri Apr 19 05:45:18 GMT 2024

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

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

Back to the top