Skip to content
Snippets Groups Projects
Commit 0d8b643e authored by Simon Barner's avatar Simon Barner
Browse files

Add ConnectorCompositorBase, a compositor base class for IConnectors

parent a4b90d05
No related branches found
No related tags found
1 merge request!593735: MemoryAreas
ConnectionCompositorBase.java 692689b535d7136acab2ab67a015f70809e64b6b GREEN ConnectionCompositorBase.java 692689b535d7136acab2ab67a015f70809e64b6b GREEN
ConnectorCompositorBase.java 0264edd4034da7187d1dbdf35a674c7067adf3cd YELLOW
ConnectorConnectionCompositorBase.java eed310a4710492b7ce3bc302c3db4e5c40f4d817 GREEN ConnectorConnectionCompositorBase.java eed310a4710492b7ce3bc302c3db4e5c40f4d817 GREEN
ConnectorHierarchicElementConnectionCompositorBase.java 7a8e4acf235d5eb006c859056cce89fbb0aac05d GREEN ConnectorHierarchicElementConnectionCompositorBase.java 7a8e4acf235d5eb006c859056cce89fbb0aac05d GREEN
ConstraintInstanceContainerCompositor.java 9cb23f13c6cddba18ac7f9dcfd1afd9e7bce4d77 GREEN ConstraintInstanceContainerCompositor.java 9cb23f13c6cddba18ac7f9dcfd1afd9e7bce4d77 GREEN
......
/*-------------------------------------------------------------------------+
| Copyright 2017 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.compose;
import static org.fortiss.tooling.base.utils.RectangleLayoutUtils.layoutConnectorInRectangle;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.base.dnd.ElementDropContext;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.Point;
import org.fortiss.tooling.kernel.extension.data.IElementCompositionContext;
import org.fortiss.tooling.kernel.extension.data.Prototype;
/**
* Compositor base class for {@link IConnector}s.
*
* @author zverlov
* @author barner
*/
public abstract class ConnectorCompositorBase<T extends IHierarchicElement & ILayoutedModelElement>
extends HierarchicElementCompositorBase<T> {
/** {@inheritDoc} */
@Override
public boolean canCompose(T container, EObject contained, IElementCompositionContext context) {
return isCorrectElementClass(contained);
}
/** {@inheritDoc} */
@Override
public boolean canComposePrototype(Prototype prototype) {
return isCorrectElementClass(prototype.getPrototype());
}
/** {@inheritDoc} */
@Override
public boolean compose(T container, EObject contained, IElementCompositionContext context) {
super.compose(container, contained, context);
if(isCorrectElementClass(contained)) {
IConnector connector = (IConnector)contained;
if(context instanceof ElementDropContext) {
final ElementDropContext ctx = (ElementDropContext)context;
Point ctxPosition = ctx.getPosition();
if(((ElementDropContext)context).isRootFigureCanvas()) {
ctxPosition.translate(ctx.getViewLocationZoomed());
}
layoutConnectorInRectangle((ILayoutedModelElement)connector, container,
ctxPosition);
}
container.getConnectors().add(connector);
return true;
}
return false;
}
/** {@inheritDoc} */
@Override
public boolean canDecompose(EObject contained) {
return isCorrectElementClass(contained);
}
/** Returns whether the given element is of an acceptable class. */
protected abstract boolean isCorrectElementClass(EObject element);
}
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