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);
}
Now start the editor and test the create connection feature: