Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » How to use IFeature(Modify existing business object)
How to use IFeature [message #1446442] Thu, 16 October 2014 21:26 Go to next message
Simon Delisle is currently offline Simon DelisleFriend
Messages: 3
Registered: July 2014
Junior Member
Hi,

I want to know how I can modify an existing business Object when I create a ConnectionFeature. More precisely, I'm trying to make a state machine and I want to be able to add some information in the source state when I create a transition.

Exemple, I create two states (S0 and S1) and I make a transition from S0 to S1. When the method create(ICreateConnectionContext context) from the class TransitionCreateConnectionFeature is called I want to modify the source state (S0) to add the information of the transition, so the state know how many transition it have.

I don't know what to use, because I use the IFeature thing in graphiti for the property, but I don't know how to use it in this situation.

Thanks
Re: How to use IFeature [message #1449564 is a reply to message #1446442] Tue, 21 October 2014 14:33 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Simon,

the usual way to do this would be to get the source/target pictogram
elements from the create connection context and use the
getBusinessObjectForPictogramElement methods of the feature provider to find
the associated business object. Then you can start to modify it.

Michael
Re: How to use IFeature [message #1450516 is a reply to message #1449564] Wed, 22 October 2014 14:21 Go to previous messageGo to next message
Simon Delisle is currently offline Simon DelisleFriend
Messages: 3
Registered: July 2014
Junior Member
Thanks for your answer

I already tried that, but maybe I use it wrong. Here is my code for createFeature of my transition. The modification that I make in create methode will not be saved and I don't know why.

@Override
public boolean canCreate(ICreateConnectionContext context) {
		PictogramElement sourcePictogramElement = context.getSourcePictogramElement();
		PictogramElement targetPictogramElement = context.getTargetPictogramElement();

		if (getBusinessObjectForPictogramElement(sourcePictogramElement) instanceof AbstractState && getBusinessObjectForPictogramElement(targetPictogramElement) instanceof AbstractState) {
			targetState = (AbstractState) getBusinessObjectForPictogramElement(targetPictogramElement);
			sourceState = (AbstractState) getBusinessObjectForPictogramElement(sourcePictogramElement);
			return true;
		}
		
		return sourceState != null && targetState != null && sourcePictogramElement != null && targetPictogramElement != null;
	}

	@Override
	public Connection create(ICreateConnectionContext context) {
		Connection newConnection = null;
		
		final Transition transition = StatemachineFactory.eINSTANCE.createTransition();
		transition.setName("Transition");
		if (targetState != null) {
			transition.setState(targetState);
		}
		
		if(sourceState != null) {
                       // If I put any modification here, they will not be saved
		}
		
		AddConnectionContext addContext = new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor());
		addContext.setNewObject(transition);
		newConnection = (Connection) getFeatureProvider().addIfPossible(addContext);
		
		getDiagram().eResource().getContents().add(transition);

		return newConnection;
	}


Thanks
Re: How to use IFeature [message #1457425 is a reply to message #1450516] Fri, 31 October 2014 10:02 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Simon,

not sure, but maybe you forgot to add the newly created Connection to a
resource? That should happen inside the add feature's add method.

Michael
Previous Topic:delete confirmation dialog
Next Topic:Create PictogramLink for Diagram object itself.
Goto Forum:
  


Current Time: Tue Apr 23 06:27:16 GMT 2024

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

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

Back to the top