Sapphire Developer Guide > Services

ConnectionService

ConnectionService is responsible for listing and establishing connections in a diagram.

Typically, there is no need for the developer to implement this service as the provided StandardConnectionService uses the connection binding definitions in sdef to manage the connections. A custom implementation is only needed if sdef connection binding facilities are not sufficiently expressive or if the developer needs to customize user interaction when a connection is established. In the latter case, StandardConnectionService can be extended instead of implementing ConnectionService from scratch.

Example

In this example from the SQL Schema Editor sample, StandardConnectionService is extended to open a columns association wizard when user defines a foreign key.

public final class SqlSchemaConnectionService extends StandardConnectionService
{
    @Override
    public StandardDiagramConnectionPart connect( final DiagramNodePart node1, final DiagramNodePart node2, final String connectionType )
    {
        final StandardDiagramConnectionPart fkConnectionPart = super.connect( node1, node2, connectionType );
        final ForeignKey fk = (ForeignKey) fkConnectionPart.getLocalModelElement();

        ...
        
        final SapphireWizard wizard = new SapphireWizard( fk, DefinitionLoader.sdef( SqlSchemaEditor.class ).wizard( "DefineForeignKeyWizard" ) )
        {
            @Override
            public boolean performCancel()
            {
                fkConnectionPart.remove();
                return true;
            }
        };
        
        final WizardDialog dialog = new WizardDialog( Display.getDefault().getActiveShell(), wizard );
        
        dialog.open();
        
        return ( fk.disposed() ? null : fkConnectionPart );
    }
}