Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Call add feature from within a custom feature(How to call add many times afer altering the model in a custom feature)
Call add feature from within a custom feature [message #1720183] Thu, 14 January 2016 23:56 Go to next message
David G. is currently offline David G.Friend
Messages: 4
Registered: April 2015
Location: Madrid, Spain
Junior Member
Hi all!

I'm quite a newbie at graphiti and taking my first steps.

I'm creating a small editor for creating graphs and applying algorithms to them and I've come across an issue.

I've made a custom feature that applies an algorithm that alters the domain objects from my model (creates some new edges in my graph).

After the algortithm is applied (in my custom feature) I'd like to check the model and add the graphics algorithms for my newly created domain objects. I guess the best way would be to use the already-implemented add feature, calling it several times, one for each newly created domaing object that has not a linked GA, right?

Which would be the best way to do this? I've searched across the tutorial but have not seen any example of calling a feature from within another feature. Should I first create and populate a context and then just instantiate and call the feature?

Re: Call add feature from within a custom feature [message #1720252 is a reply to message #1720183] Fri, 15 January 2016 15:01 Go to previous messageGo to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 526
Registered: November 2009
Senior Member
You can certainly do as you described by calling feature from another feature, for example

for(IColumnType column : selectedColumns){
   AddContext addContext = new AddContext();
   IAddFeature addFeature = getFeatureProvider().getAddFeature(addContext);

You can also use shortcut for the add feature - the addGraphicalRepresentation(...) method

[Updated on: Fri, 15 January 2016 15:39]

Report message to a moderator

Re: Call add feature from within a custom feature [message #1720281 is a reply to message #1720252] Fri, 15 January 2016 21:06 Go to previous message
David G. is currently offline David G.Friend
Messages: 4
Registered: April 2015
Location: Madrid, Spain
Junior Member
Thanks for the tip!

On with this, I'm adding 'Edge's (my domain object) wich are represented as connections, so I need to provide an ICreateConnectionConext.
For this, I need to provide the anchors, and it has been tricky, but finally got it working.

I'll post the code here, so maybe it helps someone else. Any improvements or corrections are more than welcome!

	public void execute(ICustomContext context) {

		// Access the graph
		Graph theGraph = ExampleUtil.getRootGraph(getDiagram());

		// Instance the related algorithm
		ConvexHullAlgorithm gda = new ConvexHullAlgorithm();

		// Initialize the algorithm with the graph

		// Run the algorithm to the end

		// Model is modified now, with new edges

		// Get linkservice to ask for relations between DOs and PEs
		ILinkService linkserv = Graphiti.getLinkService();

		// Check the edges in the domain model
		for (Edge edge : theGraph.getEdges()) {
			// If an edge without graphical representation is found...
			if (linkserv.getPictogramElements(getDiagram(), edge).isEmpty()) {
				// Call add feature to add the edge

				// We need the source anchor (from the first connected node)
				Anchor sourceAnchor = null;

				for (PictogramElement aPe : linkserv.getPictogramElements(getDiagram(),
						edge.getConnectedNodes().get(0))) {
					if (aPe instanceof ContainerShape) {
						sourceAnchor = ((ContainerShape) aPe).getAnchors().get(0);

				// And the target anchor (from the second connected node)
				Anchor targetAnchor = null;

				for (PictogramElement aPe : linkserv.getPictogramElements(getDiagram(),
						edge.getConnectedNodes().get(1))) {
					if (aPe instanceof ContainerShape) {
						targetAnchor = ((ContainerShape) aPe).getAnchors().get(0);

				// Now we can create the add connection context with both anchors
				AddConnectionContext acc = new AddConnectionContext(sourceAnchor, targetAnchor);
				// ... and the new edge
				// ... to be created into the diagram

				// Instantiate the add feature
				AddEdgeConnectionFeature addCF = new AddEdgeConnectionFeature(getFeatureProvider());

				// And, if it can be added
				if (addCF.canAdd(acc)) {
					// Add and update
					PictogramElement pe = addCF.add(acc);



Previous Topic:Disable moving an end connection
Next Topic:Cannot move ContainerShape
Goto Forum:

Current Time: Wed Mar 21 07:29:53 GMT 2018

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

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