Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Update diagram element after editing it with sub diagram editor
Update diagram element after editing it with sub diagram editor [message #226057] Wed, 15 April 2009 05:16 Go to next message
Thomas Spall is currently offline Thomas SpallFriend
Messages: 29
Registered: July 2009
Junior Member
Hi,

I have a diagram editor where I need to update the property of diagram
elements when changes have been done to a certain diagram nodes via
opening a sub diagram.

The steps I take in detail:
1. I open a diagram element in a subdiagram editor via creating and
installing an OpenDiagramEditPolicy. This works fine.

2. Then I edit the contents of this sub-diagram and press "Save".

3, Closing the sub diagram editor page and thus returning to the tab with
the main diagram I get informed that "The file has been changed on the
file system. Do yo want to load the changes?" which I answer with yes.

4. Now I would like to update a text property of the edited diagram
element so that it gives a brief textual representation of the "contents"
of this edited diagram element (i.e. the visual elements that I have just
before created/changed via the sub diagram). However, I can't find
anywhere where I could hook into the update process?

In the diagram element's EditPart I tried two solutions:
1. Writing a subclass of EditPartListener which overrides the
"selectedStateChanged" method: This is clearly not the right solution as
"selectedStateChanged" gets triggered at other times than i look for

2. Overriding the EditPart's "handleNotificationEvent" or "notifyChanged"
method: Both of them don't actually get triggered when I close my
subdiagram and click on "Yes" to load the changes from disk.


Any help would be appreciated a lot,
thanks,
Thomas
Re: Update diagram element after editing it with sub diagram editor [message #226154 is a reply to message #226057] Wed, 15 April 2009 09:52 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Thomas,

> 3, Closing the sub diagram editor page and thus returning to the tab
> with the main diagram I get informed that "The file has been changed
> on the file system. Do yo want to load the changes?" which I answer
> with yes.
If both editors were saved before modifying anything in sub-editor then this
dialog should not appear - diagram should be updated automatically instead.

In general everything in the model should be updated automatically in accordance
with actual file contents on a disk. You can try reopenning editor to see
if it will be updated properly or pressing F5 to update currently selected
diagram element.

-----------------
Alex Shatalin
Re: Update diagram element after editing it with sub diagram editor [message #226272 is a reply to message #226154] Thu, 16 April 2009 03:52 Go to previous messageGo to next message
Thomas Spall is currently offline Thomas SpallFriend
Messages: 29
Registered: July 2009
Junior Member
Hi Alex,

an automatic update can't work as I first have to actually set the text
property which is derived from the diagram that I draw in the sub editor.

Imagine a figure on the canvas that represents an IF-ELSE block. Square
across that figure I want to have a label that shows the content of the
IF-ELSE's condition as text, e.g. 'true==true'. Double clicking the
IF-ELSE results in a subdiagram editor opening up where I can click
together a boolean expression, e.g. by placing an AND figure on the
canvas, then linking various EQUAL figures to that AND.

When saving and closing the subeditor I want to analyse that new condition
(which up to that stage only exists as model element in the IF-ELSE!),
create a string representation for it as above and then put it into the
label that runs square across the IF-ELSE figure in the main diagram.

Thomas
Re: Update diagram element after editing it with sub diagram editor [message #226345 is a reply to message #226272] Thu, 16 April 2009 10:50 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Thomas,

I think you can do that by listening corresponding notifications from model
and firing appropriate one for derived attribute. Anyway, F5 for selected
IF-ELSE block should help you in this situation.

-----------------
Alex Shatalin
Re: Update diagram element after editing it with sub diagram editor [message #226465 is a reply to message #226057] Thu, 16 April 2009 22:55 Go to previous message
Thomas Spall is currently offline Thomas SpallFriend
Messages: 29
Registered: July 2009
Junior Member
Hi, thanks for the responses. I solved it meanwhile in a different way.
Instead of reacting on closing the dialog or updating of the main diagram
I rather incorporated some code into the "doSave" method of the
sub-diagram's document editor class:

public class SubDiagramEditor extends DiagramDocumentEditor {
...
public void doSave(IProgressMonitor progressMonitor) {
TransactionalEditingDomain domain = this.getEditingDomain();
EObject elem = this.getDiagram().getElement();

String propID =
PackageUtil.getID(MyPackage.eINSTANCE.getIfElse_CondExp());
String textAttribName = "condExp";
String condExp = "the value derived from the subdiagram content";

MySetPropertyCommand setCondExpCmd = new MySetPropertyCommand(
getEditingDomain(), new EObjectAdapter(elem),
propID, textAttribName, condExp);
domain.getCommandStack().execute(new GefCommandProxy(new
ICommandProxy(setCondExpCmd)));

super.doSave(progressMonitor);
}
}

Here "MySetPropertyCommand" is an extension of
" org.eclipse.gmf.runtime.diagram.core.commands.SetPropertyCom mand " and
"GefCommandProxy" is a rather stupid wrapper to convert from a GEF command
object to an EMF command object that can be understood by the
TransactionalEditingDomain.
Previous Topic:2 questions about GMF
Next Topic:Different EditParts for same model element
Goto Forum:
  


Current Time: Fri Apr 26 06:57:39 GMT 2024

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

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

Back to the top