Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » How to delete / remove a connection ?
How to delete / remove a connection ? [message #1415360] Tue, 02 September 2014 15:49 Go to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi all,

Graphiti provides support for creating a connection like AbstractCreateConnectionFeature.
But I found no AbstractDelete/RemoveConnectionFeature. Is there a reason ?
Am I supposed to use DefaultDeleteFeature or DefaultRemoveFeature instead ?

Kind regards,

Laurent
Re: How to delete / remove a connection ? [message #1416189 is a reply to message #1415360] Thu, 04 September 2014 14:24 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hi Laurent,

yes, DefaultDeleteFeature and DefaultRemoveFeature should be used for
connections as well. This is different to create/add simply because on
create or add you need additional information like start and end anchors in
order to be able to draw the connection. On delete / remove you already have
the connection that holds already all the information you will need.

Michael
Re: How to delete / remove a connection ? [message #1434599 is a reply to message #1416189] Tue, 30 September 2014 10:08 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi Michael,

Sorry for my late answer. I implemented an InvokesDeleteFeature and an UsesDeleteFeature to delete 'invokes' and 'uses' connections between 'Agent', 'Application' and 'Operation' elements in my diagram.

I then added the following code to my feature provider but I can not get my deletion features executed.

	public IDeleteFeature getDeleteFeature(IDeleteContext context) {
		PictogramElement pictogramElement = context.getPictogramElement();
		if (pictogramElement instanceof ContainerShape) {
			Object bo = getBusinessObjectForPictogramElement(pictogramElement);
			if ((bo instanceof Application) || (bo instanceof Operation) || (bo instanceof User))
				return new CantDeleteFeature(this);
		}
		if (pictogramElement instanceof Connection) {
			Connection connection = (Connection) pictogramElement;
			Object sourceElement = getBusinessObjectForPictogramElement(connection.getStart().getParent());
			Object targetElement = getBusinessObjectForPictogramElement(connection.getEnd().getParent());
			if ((sourceElement instanceof Application) && (targetElement instanceof Operation))
				return new InvokesDeleteFeature(this);
			if ((sourceElement instanceof User) && (targetElement instanceof Application))
				return new UsesDeleteFeature(this);
		}
		return super.getDeleteFeature(context);
	}


Apparently my pictogram element is never considered as a connection instance...
As a result, when I first select the connection between two elements in the diagram and then, make a right click, the 'delete' action is not active in the context menu.

Could you please precise me how to get my features executed ?

Regards,

Laurent
Re: How to delete / remove a connection ? [message #1434672 is a reply to message #1434599] Tue, 30 September 2014 12:34 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hi Laurent,

hard to tell without debugging. I would assume that the problem is hidden
somewhere in the lines

Object sourceElement =
getBusinessObjectForPictogramElement(connection.getStart().getParent());
Object targetElement =
getBusinessObjectForPictogramElement(connection.getEnd().getParent());

Are you sure the anchor parents are linked to the domain objects you
require? Maybe there is some other hierarchy in between.

Michael
Re: How to delete / remove a connection ? [message #1434711 is a reply to message #1434672] Tue, 30 September 2014 13:23 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Sorry Michael. I actually did not correctly identified and described my problem...

When hovering the mouse over a diagram element, getDeleteFeature as well as other methods of my feature provider get normally executed.
As a result, remove, delete and update actions are displayed normally next to the element.

Whereas, when hovering the mouse over a connection between two elements, nothing happens.
getDeleteFeature doesn't even get called. It looks as if the feature provider is not involved for connections. And no action at all is displayed...

So I don't see how to "associate" my delete features to the connections...
Re: How to delete / remove a connection ? [message #1436895 is a reply to message #1434711] Fri, 03 October 2014 15:22 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Apparently, when hovering the mouse over an element, GFRoundedRectangle calls a ContextButtonManagerForPad that has registered an internal MouseMotionListener.
This one, in turn, builds the delete, remove and update context buttons by relying on the feature provider.

In case of a connection, it seems that no "GFConnection" is registered to react on mouse events like GFRoundedRectangle does.
Only a FreeFormConnectionEditPart reacts on selection.
Re: How to delete / remove a connection ? [message #1438815 is a reply to message #1436895] Mon, 06 October 2014 14:38 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Speed buttons do not show up for connections, they only appear on shapes.
When opening the contecxt menu for a connection, the feature provider should
be queried.

Michael
Re: How to delete / remove a connection ? [message #1439793 is a reply to message #1438815] Tue, 07 October 2014 14:15 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Except for the custom features, the feature provider is not queried when I select and right-click on a connection.
As a result, I get a context menu with inactive update, remove and delete actions.

Moreover, if I select nothing in the menu and click on my editor background, the context menu normally disappears and, only then, my feature provider is queried.
And only for the update feature (with a free form connection as picture element in the update context).

In debug mode, DiagramEditorContextMenuProvider.addDefaultMenuGroupRest calls addActionToMenuIfAvailable for update, remove and delete actions.
For the update action, isEnabled() calls UpdateAction.calculateEnabled() which surprisingly returns false because no selected pictogram element is found...
Therefore, the feature provider is not queried...

To sum up, it looks as if the free form connection selection is taken into account only after the context menu has been built, displayed and has disappeared...

And, even then, the remove and delete features are still not called.
Re: How to delete / remove a connection ? [message #1441182 is a reply to message #1439793] Thu, 09 October 2014 11:11 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hm, that sounds strange. Can you compare your behavior to the one in the
tutorial? There the feature provider method getDeleteFeature is called from
DeleteAction.calculateEnabled() on connection selection.

Not sure where the difference in your scenario is...

Michael
Re: How to delete / remove a connection ? [message #1443918 is a reply to message #1441182] Mon, 13 October 2014 11:55 Go to previous message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi Michael,

I finally found the cause... It is due to the workaround I set up, in relation with bug 428227, to filter out "selection changed" event to avoid NPE when closing editor.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=428227

As side effect, there was no picture element selected when calling isAvailable or calculatedEnabled methods in the delete, remove or any other action...

So I changed the initial workaround based on adding a part listener and simply adapted DiagramBehavior.selectPictogramElements to catch the NPE.

...
if (editParts.size() > 0) {
	final EditPart editpart = editParts.get(0);
	// if the editPart is newly created it is possible that his
	// figure has not a valid bounds. Hence we have to wait for
	// the UI update (for the validation of the figure tree).
	// Otherwise the reveal method can't work correctly.
	Display.getDefault().asyncExec(new Runnable() {
		public void run() {
			try {
				getDiagramContainer().getGraphicalViewer().reveal(editpart);
			} catch (NullPointerException e) {
				// Simply catch NPE as workaround for bug 428227
			}
		}
	});
}
...


I'll update the bug details with a link to this topic...

Regards,

Laurent
Previous Topic:Text alignment issue in Text inside a Rectangle
Next Topic:Drawing polygons and lines
Goto Forum:
  


Current Time: Fri Sep 20 12:28:20 GMT 2024

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

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

Back to the top