diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/compose/ConnectorConnectionCompositorBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/compose/ConnectorConnectionCompositorBase.java index b499336820ef29dad24c5f1ccb659b5423645566..b41066f5ef542ffea69dbe872dc577acdccd1d8b 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/compose/ConnectorConnectionCompositorBase.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/compose/ConnectorConnectionCompositorBase.java @@ -41,7 +41,7 @@ import org.fortiss.tooling.kernel.services.IPersistencyService; * @ConQAT.Rating RED Hash: */ public abstract class ConnectorConnectionCompositorBase<HE extends IHierarchicElement, S extends IConnector, T extends IConnector> - implements IConnectionCompositor<S, T> { + implements IConnectionCompositor<HE, S, T> { /** {@inheritDoc} */ @Override @@ -155,7 +155,7 @@ public abstract class ConnectorConnectionCompositorBase<HE extends IHierarchicEl * {@inheritDoc} */ @Override - public void connect(S source, T target, EObject connection, + public boolean connect(S source, T target, EObject connection, IConnectionCompositionContext context) { ConnectionSegmentBase conn; @@ -217,6 +217,7 @@ public abstract class ConnectorConnectionCompositorBase<HE extends IHierarchicEl conn.setSource(source); conn.setTarget(target); } + return true; } /** @@ -249,4 +250,12 @@ public abstract class ConnectorConnectionCompositorBase<HE extends IHierarchicEl protected boolean allowInternalFeedback() { return false; } + + /** {@inheritDoc} */ + @Override + public HE getConnectionParent(S source, T target, EObject connection, + IConnectionCompositionContext context) { + throw new UnsupportedOperationException( + "Connection parent is determined by connect."); + } } diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/compose/HierarchicElementConnectionCompositorBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/compose/HierarchicElementConnectionCompositorBase.java index c29d0efe9fd250eb41e8b57d58baa1ccced8b936..86a1b83922e9d5e029e9d08cca373237ad95f14c 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/compose/HierarchicElementConnectionCompositorBase.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/compose/HierarchicElementConnectionCompositorBase.java @@ -43,7 +43,7 @@ import org.fortiss.tooling.kernel.services.IElementCompositorService; * <LI> * {@link #createTargetConnector(IHierarchicElement, IHierarchicElement, IConnectionCompositionContext)} * <LI> - * {@link #getParent(IHierarchicElement, IHierarchicElement, IConnectionCompositionContext)} + * {@link #getConnectionParent(EObject, EObject, EObject, IConnectionCompositionContext)} * </UL> * These methods are called in order to create specific model elements. * @@ -58,7 +58,7 @@ import org.fortiss.tooling.kernel.services.IElementCompositorService; * @ConQAT.Rating RED Hash: */ public abstract class HierarchicElementConnectionCompositorBase<HE extends IHierarchicElement, S extends IHierarchicElement, T extends IHierarchicElement> - implements IConnectionCompositor<S, T> { + implements IConnectionCompositor<HE, S, T> { /** * Determines whether connectors of the component may be connected @@ -84,10 +84,6 @@ public abstract class HierarchicElementConnectionCompositorBase<HE extends IHier protected abstract IConnector createTargetConnector(S source, T target, IConnectionCompositionContext context); - /** Returns the parent model element used to compose the connection. */ - protected abstract HE getParent(S source, T target, - IConnectionCompositionContext context); - /** {@inheritDoc} */ @Override public boolean canConnect(S source, T target, EObject connection, @@ -106,13 +102,14 @@ public abstract class HierarchicElementConnectionCompositorBase<HE extends IHier /** {@inheritDoc} */ @Override - public void connect(S source, T target, EObject conn, + public boolean connect(S source, T target, EObject conn, IConnectionCompositionContext context) { // create application specific connection IConnection connection = createConnection(source, target, context); // TODO (FH): use ID fixing here - getParent(source, target, context).getConnectionsList().add(connection); + getConnectionParent(source, target, connection, context) + .getConnectionsList().add(connection); // create application specific connectors IConnector sourceConnector = createSourceConnector(source, target, @@ -124,17 +121,19 @@ public abstract class HierarchicElementConnectionCompositorBase<HE extends IHier // drop source connector DropContext sourceDrop = context instanceof DragContext ? ((DragContext) context) .getSourceDropContext() : null; - IElementCompositorService.INSTANCE - .compose(source, sourceConnector, sourceDrop); + IElementCompositorService.INSTANCE.compose(source, sourceConnector, + sourceDrop); // drop target target connector DropContext targetDrop = context instanceof DragContext ? ((DragContext) context) .getTargetDropContext() : null; - IElementCompositorService.INSTANCE - .compose(target, targetConnector, targetDrop); + IElementCompositorService.INSTANCE.compose(target, targetConnector, + targetDrop); // link connection to connectors connection.setSource(sourceConnector); connection.setTarget(targetConnector); + + return true; } } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IConnectionCompositionContext.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IConnectionCompositionContext.java index 11b4cc91f60d509f9b502d503dcabab564a8bfc5..eb89859eb042dcf0fe4befef2e881b6beba658ad 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IConnectionCompositionContext.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IConnectionCompositionContext.java @@ -19,10 +19,12 @@ $Id$ package org.fortiss.tooling.kernel.interfaces; /** - * An {@link IConnectionCompositionContext} provides additional information like drag point - * positions to an {@link IConnectionCompositor}. + * This class is a marker interface to provide additional information to an + * {@link IConnectionCompositor}. * - * @FloH: what is a "drag point position"? + * A typical example of such information is the source and target location + * obtained from the user's mouse drag gesture in some graphical editor, which + * should be used when computing the composed connection's layout information. * * @author hoelzl * @author $Author$ diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IConnectionCompositor.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IConnectionCompositor.java index 4861cc423397fc8c5e6e7bd86b447f488bb728fe..68d61fc2d8bf725b382a5576eab90cd83c76f283 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IConnectionCompositor.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IConnectionCompositor.java @@ -23,34 +23,32 @@ import org.eclipse.emf.ecore.EObject; * Interface for connectors, i.e. classes which connect model elements. This may * either be a direct connection or by using an additional connection element. * - * @TODO: rename to "ConnectionCompositor" + make the parent explicit - * * @author hoelzl * @author $Author$ * @version $Rev$ * @ConQAT.Rating YELLOW Hash: 3AF8EF4B6F61B768A17A63A6FF51CB2B */ -public interface IConnectionCompositor<S extends EObject, T extends EObject> extends - IEObjectAware2<S, T> { +public interface IConnectionCompositor<P extends EObject, S extends EObject, T extends EObject> + extends IEObjectAware2<S, T> { /** - * Returns whether a connection between the source and the destination is + * Returns whether a connection between the source and the target is * possible. Additional information can be included in the context, which * also may be null. The connection parameter holds an existing connection * in case of a reconnect. */ - boolean canConnect(S source, T destination, EObject connection, + boolean canConnect(S source, T target, EObject connection, IConnectionCompositionContext context); /** - * Actually connects the given source and destination. This will only be - * called if + * Actually connects the given source and target. This will only be called + * if * {@link #canConnect(EObject, EObject, EObject, IConnectionCompositionContext)} * returned true. * * @param source * the source of the connection. - * @param destination - * the destination of the connection. + * @param target + * the target of the connection. * @param connection * the (existing) connection object. This may be null to indicate * that no connection object exists yet, or none is needed @@ -59,6 +57,38 @@ public interface IConnectionCompositor<S extends EObject, T extends EObject> ext * @param context * context information for the connection. May be null. */ - void connect(S source, T destination, EObject connection, + boolean connect(S source, T target, EObject connection, + IConnectionCompositionContext context); + + /** + * Returns the parent element of the connection to be used during connecting + * the given elements. + */ + P getConnectionParent(S source, T target, EObject connection, + IConnectionCompositionContext context); + + /** + * Returns whether a connection between the source and the target can be + * removed. + */ + boolean canDisconnect(S source, T target, EObject connection, + IConnectionCompositionContext context); + + /** + * Actually disconnects the given source and destination. This will only be + * called if + * {@link #canDisconnect(EObject, EObject, EObject, IConnectionCompositionContext)} + * returned true. + * + * @param source + * the source of the connection. + * @param target + * the target of the connection. + * @param connection + * the existing connection object. + * @param context + * context information for the connection. May be null. + */ + boolean disconnect(S source, T target, EObject connection, IConnectionCompositionContext context); } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IElementCompositionContext.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IElementCompositionContext.java index ae63f5ba2c22dace78f0964134ca4104c852558a..83f3b23d56df95e6595cbfd4bd862e40cab02661 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IElementCompositionContext.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IElementCompositionContext.java @@ -19,10 +19,12 @@ $Id$ package org.fortiss.tooling.kernel.interfaces; /** - * An {@link IElementCompositionContext} provides additional information like drop - * point positions to an {@link IElementCompositor}. + * This class is a marker interface to provide additional information to an + * {@link IElementCompositor}. * - * @FloH: what is a "drop point" position? + * A typical example of such information is the target location obtained from + * the user's mouse drag-and-drop gesture in some graphical editor, which should + * be considered when computing the composed model element's layout information. * * @author hoelzl * @author $Author$ diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ConnectionCompositorService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ConnectionCompositorService.java index 9234ce3fd181310963d5e578d70caf58493679ef..4c60ce03a34a77e05cf0eabd9575797a310fe272 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ConnectionCompositorService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ConnectionCompositorService.java @@ -33,8 +33,9 @@ import org.fortiss.tooling.kernel.services.IConnectionCompositorService; * @version $Rev$ * @ConQAT.Rating YELLOW Hash: E4E7A3B42928271F17D36BABCB6BEF58 */ -public class ConnectionCompositorService extends - EObjectAware2ServiceBase<IConnectionCompositor<EObject, EObject>> +public class ConnectionCompositorService + extends + EObjectAware2ServiceBase<IConnectionCompositor<EObject, EObject, EObject>> implements IConnectionCompositorService { /** The connector extension point ID. */ @@ -65,15 +66,15 @@ public class ConnectionCompositorService extends * Returns the first {@link IConnectionCompositor} which can connect the * given elements (or <code>null</code>n if no such connector exists). */ - private IConnectionCompositor<EObject, EObject> findWorkingConnector( + private IConnectionCompositor<EObject, EObject, EObject> findWorkingConnector( EObject source, EObject target, EObject connection, IConnectionCompositionContext context) { - List<IConnectionCompositor<EObject, EObject>> list = getRegisteredHandlers( + List<IConnectionCompositor<EObject, EObject, EObject>> list = getRegisteredHandlers( source.getClass(), target.getClass()); if (list == null) { return null; } - for (IConnectionCompositor<EObject, EObject> connector : list) { + for (IConnectionCompositor<EObject, EObject, EObject> connector : list) { if (connector.canConnect(source, target, connection, context)) { return connector; }