Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » How to modify nodes index in a diagram?
How to modify nodes index in a diagram? [message #185014] Fri, 02 May 2008 06:41 Go to next message
Georges Bachelier is currently offline Georges BachelierFriend
Messages: 8
Registered: July 2009
Junior Member
Hello everyone,

I have built a very simple GMF-based flow editor. The user can place nodes
on the canvas with an auto-numbering operation through the Node 'nodeName'
attribute. Therefore, the first node name is N0, the second one N1, etc. I
want the nodes to be re-indexed if the user deletes one or more nodes so
that there is no missing index.
If I have nodes N0, N1 and N2 and if the user deletes the node N1, I want
the remaining nodes to be named N0 and N1 (N2 becomes N1).

How can I do this?

Thanks a lot in advance for your time!

Georges
Re: How to modify nodes index in a diagram? [message #185020 is a reply to message #185014] Fri, 02 May 2008 07:11 Go to previous messageGo to next message
Enrico Schnepel is currently offline Enrico SchnepelFriend
Messages: 121
Registered: July 2009
Senior Member
Hello Georges,

You could use a attribute which is marked as derived in EMF and implement
the getter to calculate the name on demand - based on the index in the
containing feature. GMF displays that attribute as usual. if one deletes a
node all text's of the other nodes should be updated to trigger the
reevaluation of that feature.

Regards,

Enrico

Georges wrote:

> Hello everyone,
>
> I have built a very simple GMF-based flow editor. The user can place nodes
> on the canvas with an auto-numbering operation through the Node 'nodeName'
> attribute. Therefore, the first node name is N0, the second one N1, etc. I
> want the nodes to be re-indexed if the user deletes one or more nodes so
> that there is no missing index.
> If I have nodes N0, N1 and N2 and if the user deletes the node N1, I want
> the remaining nodes to be named N0 and N1 (N2 becomes N1).
>
> How can I do this?
>
> Thanks a lot in advance for your time!
>
> Georges
Re: How to modify nodes index in a diagram? [message #185099 is a reply to message #185020] Sat, 03 May 2008 09:05 Go to previous messageGo to next message
Georges Bachelier is currently offline Georges BachelierFriend
Messages: 8
Registered: July 2009
Junior Member
Hello Enrico,

thanks a lot for the tip! I did not know this 'derived' feature. Where can
I find information about its purpose and benefits? With the node name
attribute marked as derived in the Ecore model, I could remove some GMF
code in which the node name was initialized.

One more question : if I delete a node in the GMF-based diagram editor,
the renaming of nodes is not done immediately. I have to save the diagram,
close it and re-open it to see nodes names changed. Is it possible to
force an immediate node names recalculation on node deletion?

Thanks a lot in advance for your time and help!

Georges
Re: How to modify nodes index in a diagram? [message #185169 is a reply to message #185099] Sun, 04 May 2008 11:52 Go to previous messageGo to next message
Enrico Schnepel is currently offline Enrico SchnepelFriend
Messages: 121
Registered: July 2009
Senior Member
Hello Georges

> Where can I find information about its purpose and benefits?
maybe someone from the emf team knows the answer...

> One more question : if I delete a node in the GMF-based diagram editor,
> the renaming of nodes is not done immediately. I have to save the diagram,
> close it and re-open it to see nodes names changed. Is it possible to
> force an immediate node names recalculation on node deletion?
Yes, you have to listen to notifications in your gmf and force an update of
your EditPart. I've attached a class and an aspect I am using for this
purpose. The Aspect could also be merged with the
[...]ItemSemanticEditPolicy by hand if you don't want to use AspectJ.
The RefreshNotificationListener does more than you want to be done - it
updates all of its direct children, itself thd the direct parent, so this
might be a subject to change.

Regards

Enrico

============

package customization.edit;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBr oker;
import org.eclipse.gmf.runtime.diagram.core.listener.NotificationLi stener;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditP art;

import [...]ItemSemanticEditPolicy;

public privileged aspect RefreshOnChange {

private NotificationListener
[...]ItemSemanticEditPolicy.notificationListener = null;

@Override
public void [...]ItemSemanticEditPolicy.activate() {
final IGraphicalEditPart igep = (IGraphicalEditPart) getHost();
TransactionalEditingDomain editingDomain = igep.getEditingDomain();
EObject element = igep.resolveSemanticElement();
notificationListener = new RefreshNotificationListener(igep);
DiagramEventBroker.getInstance(editingDomain).addNotificatio nListener(
element, notificationListener);
super.activate();
}

@Override
public void [...]ItemSemanticEditPolicy.deactivate() {
final IGraphicalEditPart igep = (IGraphicalEditPart) getHost();
TransactionalEditingDomain editingDomain = igep.getEditingDomain();
EObject element = igep.resolveSemanticElement();
DiagramEventBroker.getInstance(editingDomain)
.removeNotificationListener(element, notificationListener);
super.deactivate();
}
}


==================


package customization.edit;

import java.util.List;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.diagram.core.listener.NotificationLi stener;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditP art;

import de.bmiag.metamodel.base.dataflow.diagram.part.ValidateAction ;

public class RefreshNotificationListener implements NotificationListener {
private IGraphicalEditPart igep;

public RefreshNotificationListener(EditPart igep) {
this.igep = (IGraphicalEditPart) igep;
}

public void notifyChanged(Notification notification) {
@SuppressWarnings("unchecked")
List<EditPart> children = igep.getChildren();
for (EditPart editPart : children) {
editPart.refresh();
}
igep.refresh();
EditPart parent = igep.getParent();
if (null != parent) {
parent.refresh();
}
}
};
Re: How to modify nodes index in a diagram? [message #185233 is a reply to message #185169] Sun, 04 May 2008 15:55 Go to previous messageGo to next message
Georges Bachelier is currently offline Georges BachelierFriend
Messages: 8
Registered: July 2009
Junior Member
Hello Enrico,


thanks a lot for your reply; I did what you suggested, but nodes names are
not updated on node deletion. When I delete a node on my diagram, the
notifyChanged method of the RefreshNotificationListener class is executed,
but this has no visual effect on the diagram view; the nodes names remain
unchanged.
What do you think about this?

Thanks a lot in advance for your time!

Georges
Re: How to modify nodes index in a diagram? [message #212069 is a reply to message #185014] Tue, 25 November 2008 14:52 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse.tooling.gmail.com

Hi Georges

I am trying to build a simple GMF based flow editor, but am still very
new to all this.. is the code you developed publicly available? or would
you be able to point me to some code examples that will help me get
started quickly to build this..

many thanks
c. perera

On Fri, 02 May 2008 06:41:37 +0000, Georges wrote
> Hello everyone,
>
> I have built a very simple GMF-based flow editor. The user can place
> nodes on the canvas with an auto-numbering operation through the Node
> 'nodeName' attribute. Therefore, the first node name is N0, the second
> one N1, etc. I want the nodes to be re-indexed if the user deletes one
> or more nodes so that there is no missing index.
> If I have nodes N0, N1 and N2 and if the user deletes the node N1, I
> want the remaining nodes to be named N0 and N1 (N2 becomes N1).
>
> How can I do this?
>
> Thanks a lot in advance for your time!
>
> Georges
Previous Topic:Example to build a simple flow editor with GMF
Next Topic:Error on pasting Connections
Goto Forum:
  


Current Time: Sat Jul 13 18:38:45 GMT 2024

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

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

Back to the top