Skip to content
Snippets Groups Projects
Commit b847e58b authored by Florian Hölzl's avatar Florian Hölzl
Browse files

added disconnect feature to IConnectionCompositor

parent aab105f5
No related branches found
No related tags found
No related merge requests found
......@@ -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.");
}
}
......@@ -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;
}
}
......@@ -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$
......
......@@ -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);
}
......@@ -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$
......
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment