Providing Reconnection Functionality

Creating a Reconnection Feature

The so called create connection feature manages only the creation of new connections. If you select an EReference with the selection tool you can drag and drop the endpoint to any other EClass as shown in the figure below. But this is accomplished with a reconnection feature, in our case the default implementation DefaultReconnectionFeature, which realizes the anchor handling.

 

Figure: Reconnection is allowed

 

The integration into the platform’s UI is done by the framework.

A reconnection feature has to implement the interface IReconnectionFeature. Instead of implementing it directly it should extend the standard implementation DefaultReconnectionFeature.

The most important methods here are:

In this example we simply do not want allow reconnecting existing EReferences at all.

 

Figure: Reconnection is not possible but reconnection is not completely disabled

 

You can see the complete implementation of the reconnection feature here:

 

package org.eclipse.graphiti.examples.tutorial.features;
 
public class TutorialReconnectionFeature extends DefaultReconnectionFeature {
 
      public TutorialReconnectionFeature(IFeatureProvider fp) {
          super(fp);
      }
 
      @Override
      public boolean canReconnect(IReconnectionContext context) {
          //do not allow to reconnect
          return false;
      }
 
}

 

Additionally the feature provider has to deliver our newly created feature (overwrite the method getReconnectionFeature).

This implementation can be seen here:

 

@Override
public IReconnectionFeature getReconnectionFeature(IReconnectionContext context) {
    return new TutorialReconnectionFeature(this);
}

 

Test: Try to reconnect an EReference

Now start the editor and test the create connection feature:

  1. create or open a diagram
  2. create two new EClasses (if you do not have them already) and create an EReference between them with the connection tool in the palette
  3. click on the “EReference” with the selection tool in the palette that it becomes selected
  4. drag the end point as it is shown in the figure above. You should notice the tiny prohibition symbol then. When you drop the endpoint, it snaps back to the original position.