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

added connection compositor base implementation

parent c97a40c1
No related branches found
No related tags found
No related merge requests found
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.compose;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.RootEditPart;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.base.ui.dnd.DragContext;
import org.fortiss.tooling.base.ui.dnd.DropContext;
import org.fortiss.tooling.base.ui.editpart.RootEditPartBase;
import org.fortiss.tooling.kernel.interfaces.IConnectionContext;
import org.fortiss.tooling.kernel.services.ICompositorService;
/**
* Base implementation for supporting direct connection of two
* {@link IHierarchicElement}s.
*
* <p>
* Sub-classes must implement:
* <UL>
* <LI>
* {@link #createConnection(IHierarchicElement, IHierarchicElement, IConnectionContext)}
* <LI>
* {@link #createSourceConnector(IHierarchicElement, IHierarchicElement, IConnectionContext)}
* <LI>
* {@link #createTargetConnector(IHierarchicElement, IHierarchicElement, IConnectionContext)}
* <LI>
* {@link #getParent(IHierarchicElement, IHierarchicElement, IConnectionContext)}
* </UL>
* These methods are called in order to create specific model elements.
*
* <p>
* Sub-classes may implement {@link #canConnectInterally()} to support internal
* connections. By default connectors of the parent element cannot be connected
* in internal view of the element.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public abstract class HierarchicElementConnectionCompositorBase<HE extends IHierarchicElement, S extends IHierarchicElement, T extends IHierarchicElement>
implements org.fortiss.tooling.kernel.interfaces.IConnector<S, T> {
/**
* Determines whether connectors of the component may be connected
* internally. The default value is <code>false</code>.
*/
protected boolean canConnectInterally() {
return false;
}
/** Creates the application specific {@link IConnection} model element. */
protected abstract IConnection createConnection(S source, T target,
IConnectionContext context);
/**
* Creates the application specific source {@link IConnector} model element.
*/
protected abstract IConnector createSourceConnector(S source, T target,
IConnectionContext context);
/**
* Creates the application specific target {@link IConnector} model element.
*/
protected abstract IConnector createTargetConnector(S source, T target,
IConnectionContext context);
/** Returns the parent model element used to compose the connection. */
protected abstract HE getParent(S source, T target,
IConnectionContext context);
/** {@inheritDoc} */
@Override
public boolean canConnect(S source, T target, EObject connection,
IConnectionContext context) {
if (context instanceof DragContext) {
DragContext dc = (DragContext) context;
// Is an internal feedback connection allowed?
if (dc.getSource() instanceof RootEditPartBase
&& dc.getTarget() instanceof RootEditPart) {
return canConnectInterally();
}
}
// all other connections are allowed by default
return true;
}
/** {@inheritDoc} */
@Override
public void connect(S source, T target, EObject conn,
IConnectionContext context) {
// create application specific connection
IConnection connection = createConnection(source, target, context);
// TODO (FH): use ID fixing here
getParent(source, target, context).getConnectionsList().add(connection);
// create application specific connectors
IConnector sourceConnector = createSourceConnector(source, target,
context);
IConnector targetConnector = createTargetConnector(source, target,
context);
// TODO (FH): use ID fixing here
// drop source connector
DropContext sourceDrop = context instanceof DragContext ? ((DragContext) context)
.getSourceDropContext() : null;
ICompositorService.INSTANCE
.compose(source, sourceConnector, sourceDrop);
// drop target target connector
DropContext targetDrop = context instanceof DragContext ? ((DragContext) context)
.getTargetDropContext() : null;
ICompositorService.INSTANCE
.compose(target, targetConnector, targetDrop);
// link connection to connectors
connection.setSource(sourceConnector);
connection.setTarget(targetConnector);
}
}
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