Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Correct way to call delete programatically
Correct way to call delete programatically [message #735275] Tue, 11 October 2011 07:52 Go to next message
Adrian Mouat is currently offline Adrian Mouat
Messages: 16
Registered: September 2011
Junior Member
Hi,

From within a delete feature, I need to delete another object (both from the model and the diagram).

What's the correct (or idiomatic) way to do this?

I guess there are a few possibilities:

- manually delete from the model and then use an update feature to fix the diagram
- manually delete both from the model and the diagram (I think this might have a concurrent modification exception problem)
- directly call the delete feature with a new delete context. This sounds good, but how can you do it? Do you have to go via the FeatureProvider?

Sorry if this is obvious!

Regards,

Adrian.
Re: Correct way to call delete programatically [message #735289 is a reply to message #735275] Tue, 11 October 2011 08:57 Go to previous messageGo to next message
Christian B is currently offline Christian B
Messages: 68
Registered: August 2011
Member
I'd use the graphity way, sounds like the neatest way.

I have no example for a delete feature, but it works the same like a for example a move feature:
MMoveShapeContext moveContext = new MoveShapeContext(nodeContainerShape);
moveContext.setX(nodeRectangleX);
moveContext.setY(nodeRectangleY);
moveContext.setSourceContainer(nodeContainerShape.getContainer());
moveContext.setTargetContainer(nodeContainerShape.getContainer());
IMoveShapeFeature moveFeature = getFeatureProvider()
		.getMoveShapeFeature(moveContext);
if (moveFeature.canMoveShape(moveContext))
	moveFeature.moveShape(moveContext);

First create the delete-context and set its parameters, then aquire the correct delete feature via the feature provider, then, in case deleting is allowed, delete.
Re: Correct way to call delete programatically [message #735308 is a reply to message #735289] Tue, 11 October 2011 09:56 Go to previous message
Adrian Mouat is currently offline Adrian Mouat
Messages: 16
Registered: September 2011
Junior Member
I've got it now, you're quite right.

The problem I had before was that I was trying to iterate through a list at the same time as removing elements.

The only issue I had was that I needed to use MultiDeleteInfo to avoid the user being asked multiple times to confirm the delete, but it looks like this class is really meant to be internal only.

Thanks for your help,

Adrian.

[Updated on: Tue, 11 October 2011 09:56]

Report message to a moderator

Previous Topic:associate keyboard shortcut with custom feature
Next Topic:Text background color is ignored
Goto Forum:
  


Current Time: Sun Aug 31 04:29:04 EDT 2014

Powered by FUDForum. Page generated in 0.01893 seconds