Commit 9a70f4f2 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

added abstract compositor base implementation

refs 737
parent f65fdc5a
......@@ -18,22 +18,14 @@ $Id$
package org.fortiss.af3.platform.ui.compose;
import static org.conqat.lib.commons.reflect.ReflectionUtils.isInstanceOfAny;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_CONNECTOR_SIZE;
import static org.fortiss.tooling.base.ui.utils.RectangleLayoutUtils.layoutConnectorInRectangle;
import static org.fortiss.tooling.base.ui.utils.RectangleLayoutUtils.layoutNodeInRoot;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.platform.model.IPlatformArchitectureElement;
import org.fortiss.af3.platform.model.PlatformConnectorUnit;
import org.fortiss.af3.platform.model.generic.GenericExecutionUnit;
import org.fortiss.af3.platform.model.generic.GenericReceiver;
import org.fortiss.af3.platform.model.generic.GenericTransceiver;
import org.fortiss.af3.platform.model.generic.GenericTransmitter;
import org.fortiss.tooling.base.decompose.HierarchicElementCompositorBase;
import org.fortiss.tooling.base.ui.dnd.gef.ElementDropContext;
import org.fortiss.tooling.kernel.extension.IElementCompositor;
import org.fortiss.tooling.kernel.extension.data.IElementCompositionContext;
import org.fortiss.tooling.kernel.extension.data.Prototype;
/**
* {@link IElementCompositor} for {@link GenericExecutionUnit}.
......@@ -42,58 +34,20 @@ import org.fortiss.tooling.kernel.extension.data.Prototype;
* @author wandinger
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: C3E142099DD17684A2BF81AE3F628CC8
* @ConQAT.Rating YELLOW Hash: 5AFDB4AC65F676AF7C85CCE447C76F1C
*/
public class GenericExecutionUnitCompositor extends HierarchicElementCompositorBase<IPlatformArchitectureElement> {
/** {@inheritDoc} */
@Override
public boolean canCompose(IPlatformArchitectureElement container, EObject contained,
IElementCompositionContext context) {
return isCorrectElementClass(container, contained);
}
/** {@inheritDoc} */
@Override
public boolean canComposePrototype(Prototype prototype) {
return isCorrectElementClass(null, prototype.getPrototype());
}
public final class GenericExecutionUnitCompositor extends
PlatformArchitectureElementCompositorBase<IPlatformArchitectureElement> {
/** {@inheritDoc} */
@Override
public boolean
compose(IPlatformArchitectureElement container, EObject contained, IElementCompositionContext context) {
if(contained instanceof PlatformConnectorUnit) {
PlatformConnectorUnit cunit = (PlatformConnectorUnit)contained;
if(context instanceof ElementDropContext) {
ElementDropContext ctx = (ElementDropContext)context;
if(ctx.isRoot()) {
int size = DEFAULT_CONNECTOR_SIZE / 2;
layoutNodeInRoot(cunit, ctx, size, true);
} else {
layoutConnectorInRectangle(cunit, container, ctx.getPosition());
}
}
container.getConnectorsList().add(cunit);
return true;
}
return false;
}
/** {@inheritDoc} */
@Override
public boolean canDecompose(EObject contained) {
return isCorrectElementClass(null, contained);
}
/** Returns whether the given element is of an acceptable class. */
private boolean isCorrectElementClass(IPlatformArchitectureElement container, EObject contained) {
protected boolean isCorrectElementClass(IPlatformArchitectureElement container,
EObject contained) {
if(container != null) {
return isInstanceOfAny(container, GenericExecutionUnit.class) &&
isInstanceOfAny(contained, GenericTransceiver.class, GenericTransmitter.class,
GenericReceiver.class);
}
return isInstanceOfAny(contained, GenericTransceiver.class, GenericTransmitter.class, GenericReceiver.class);
return isInstanceOfAny(contained, GenericTransceiver.class, GenericTransmitter.class,
GenericReceiver.class);
}
}
......@@ -33,19 +33,17 @@ import org.fortiss.tooling.kernel.extension.data.IConnectionCompositionContext;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 9082FC1A8101C91EFC93D222D4E78B10
* @ConQAT.Rating YELLOW Hash: 599BD737A7A5C78A45026E7370AED935
*/
public class GenericToBusConnectionCompositor
implements
public final class GenericToBusConnectionCompositor implements
IConnectionCompositor<IPlatformArchitectureElement, GenericTransceiver, GenericTransceiver> {
/** {@inheritDoc} */
@Override
public boolean canConnect(GenericTransceiver source,
GenericTransceiver target, IPlatformArchitectureElement parent,
IConnectionCompositionContext context) {
if (source.getOwner() instanceof GenericExecutionUnit
&& target.getOwner() instanceof GenericTransmissionUnit) {
public boolean canConnect(GenericTransceiver source, GenericTransceiver target,
IPlatformArchitectureElement parent, IConnectionCompositionContext context) {
if(source.getOwner() instanceof GenericExecutionUnit &&
target.getOwner() instanceof GenericTransmissionUnit) {
return source.getOutgoingList().isEmpty();
}
return false;
......@@ -53,11 +51,9 @@ public class GenericToBusConnectionCompositor
/** {@inheritDoc} */
@Override
public boolean connect(GenericTransceiver source,
GenericTransceiver target, IPlatformArchitectureElement parent,
IConnectionCompositionContext context) {
TransmissionConnection conn = PlatformModelElementFactory
.createTransmissionConnection();
public boolean connect(GenericTransceiver source, GenericTransceiver target,
IPlatformArchitectureElement parent, IConnectionCompositionContext context) {
TransmissionConnection conn = PlatformModelElementFactory.createTransmissionConnection();
parent.getPlatformArchitecture().getConnectionsList().add(conn);
conn.setSource(source);
conn.setTarget(target);
......@@ -85,10 +81,10 @@ public class GenericToBusConnectionCompositor
/** {@inheritDoc} */
@Override
public boolean canDisconnect(EObject connection) {
if (connection instanceof TransmissionConnection) {
TransmissionConnection c = (TransmissionConnection) connection;
return c.getSource() instanceof GenericTransceiver
&& c.getTarget() instanceof GenericTransceiver;
if(connection instanceof TransmissionConnection) {
TransmissionConnection c = (TransmissionConnection)connection;
return c.getSource() instanceof GenericTransceiver &&
c.getTarget() instanceof GenericTransceiver;
}
return false;
}
......@@ -96,8 +92,8 @@ public class GenericToBusConnectionCompositor
/** {@inheritDoc} */
@Override
public boolean disconnect(EObject connection) {
if (connection instanceof TransmissionConnection) {
TransmissionConnection tcon = ((TransmissionConnection) connection);
if(connection instanceof TransmissionConnection) {
TransmissionConnection tcon = ((TransmissionConnection)connection);
tcon.setOwner(null);
tcon.setSource(null);
tcon.setTarget(null);
......
......@@ -33,19 +33,17 @@ import org.fortiss.tooling.kernel.extension.data.IConnectionCompositionContext;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 7AA6857AA348B8D5A621B56107759406
* @ConQAT.Rating YELLOW Hash: FF1AD1B1C24D0446B5A7A8E5BCB408A7
*/
public class GenericToExecutionUnitConnectionCompositor
implements
public final class GenericToExecutionUnitConnectionCompositor implements
IConnectionCompositor<IPlatformArchitectureElement, GenericTransceiver, GenericTransceiver> {
/** {@inheritDoc} */
@Override
public boolean canConnect(GenericTransceiver source,
GenericTransceiver target, IPlatformArchitectureElement parent,
IConnectionCompositionContext context) {
if (source.getOwner() instanceof GenericTransmissionUnit
&& target.getOwner() instanceof GenericExecutionUnit) {
public boolean canConnect(GenericTransceiver source, GenericTransceiver target,
IPlatformArchitectureElement parent, IConnectionCompositionContext context) {
if(source.getOwner() instanceof GenericTransmissionUnit &&
target.getOwner() instanceof GenericExecutionUnit) {
return target.getOutgoingList().isEmpty();
}
return false;
......@@ -53,11 +51,9 @@ public class GenericToExecutionUnitConnectionCompositor
/** {@inheritDoc} */
@Override
public boolean connect(GenericTransceiver source,
GenericTransceiver target, IPlatformArchitectureElement parent,
IConnectionCompositionContext context) {
TransmissionConnection conn = PlatformModelElementFactory
.createTransmissionConnection();
public boolean connect(GenericTransceiver source, GenericTransceiver target,
IPlatformArchitectureElement parent, IConnectionCompositionContext context) {
TransmissionConnection conn = PlatformModelElementFactory.createTransmissionConnection();
parent.getPlatformArchitecture().getConnectionsList().add(conn);
// Swap connection target in model is always the bus.
conn.setSource(target);
......@@ -86,10 +82,10 @@ public class GenericToExecutionUnitConnectionCompositor
/** {@inheritDoc} */
@Override
public boolean canDisconnect(EObject connection) {
if (connection instanceof TransmissionConnection) {
TransmissionConnection c = (TransmissionConnection) connection;
return c.getSource() instanceof GenericTransceiver
&& c.getTarget() instanceof GenericTransceiver;
if(connection instanceof TransmissionConnection) {
TransmissionConnection c = (TransmissionConnection)connection;
return c.getSource() instanceof GenericTransceiver &&
c.getTarget() instanceof GenericTransceiver;
}
return false;
}
......@@ -97,8 +93,8 @@ public class GenericToExecutionUnitConnectionCompositor
/** {@inheritDoc} */
@Override
public boolean disconnect(EObject connection) {
if (connection instanceof TransmissionConnection) {
TransmissionConnection tcon = ((TransmissionConnection) connection);
if(connection instanceof TransmissionConnection) {
TransmissionConnection tcon = ((TransmissionConnection)connection);
tcon.setOwner(null);
tcon.setSource(null);
tcon.setTarget(null);
......
......@@ -18,19 +18,12 @@ $Id$
package org.fortiss.af3.platform.ui.compose;
import static org.conqat.lib.commons.reflect.ReflectionUtils.isInstanceOfAny;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_CONNECTOR_SIZE;
import static org.fortiss.tooling.base.ui.utils.RectangleLayoutUtils.layoutConnectorInRectangle;
import static org.fortiss.tooling.base.ui.utils.RectangleLayoutUtils.layoutNodeInRoot;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.platform.model.IPlatformArchitectureElement;
import org.fortiss.af3.platform.model.generic.GenericTransceiver;
import org.fortiss.af3.platform.model.generic.GenericTransmissionUnit;
import org.fortiss.tooling.base.decompose.HierarchicElementCompositorBase;
import org.fortiss.tooling.base.ui.dnd.gef.ElementDropContext;
import org.fortiss.tooling.kernel.extension.IElementCompositor;
import org.fortiss.tooling.kernel.extension.data.IElementCompositionContext;
import org.fortiss.tooling.kernel.extension.data.Prototype;
/**
* {@link IElementCompositor} for {@link GenericTransmissionUnit}.
......@@ -39,54 +32,14 @@ import org.fortiss.tooling.kernel.extension.data.Prototype;
* @author wandinger
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 89C09C335E421FE9105EB06298F5C895
* @ConQAT.Rating YELLOW Hash: 9886BD5913A1852457FF37E246E7526E
*/
public class GenericTransmissionUnitCompositor extends
HierarchicElementCompositorBase<IPlatformArchitectureElement> {
/** {@inheritDoc} */
@Override
public boolean canCompose(IPlatformArchitectureElement container, EObject contained,
IElementCompositionContext context) {
return isCorrectElementClass(container, contained);
}
/** {@inheritDoc} */
@Override
public boolean canComposePrototype(Prototype prototype) {
return isCorrectElementClass(null, prototype.getPrototype());
}
/** {@inheritDoc} */
@Override
public boolean compose(IPlatformArchitectureElement container, EObject contained,
IElementCompositionContext context) {
if(contained instanceof GenericTransceiver) {
GenericTransceiver trans = (GenericTransceiver)contained;
if(context instanceof ElementDropContext) {
ElementDropContext ctx = (ElementDropContext)context;
if(ctx.isRoot()) {
int size = DEFAULT_CONNECTOR_SIZE / 2;
layoutNodeInRoot(trans, ctx, size, true);
} else {
layoutConnectorInRectangle(trans, container, ctx.getPosition());
}
}
container.getConnectorsList().add(trans);
return true;
}
return false;
}
public final class GenericTransmissionUnitCompositor extends
PlatformArchitectureElementCompositorBase<IPlatformArchitectureElement> {
/** {@inheritDoc} */
@Override
public boolean canDecompose(EObject contained) {
return isCorrectElementClass(null, contained);
}
/** Returns whether the given element is of an acceptable class. */
private boolean
isCorrectElementClass(IPlatformArchitectureElement container, EObject contained) {
protected boolean isCorrectElementClass(IPlatformArchitectureElement container,
EObject contained) {
if(container != null) {
return isInstanceOfAny(container, GenericTransmissionUnit.class) &&
isInstanceOfAny(contained, GenericTransceiver.class);
......
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 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.af3.platform.ui.compose;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_CONNECTOR_SIZE;
import static org.fortiss.tooling.base.ui.utils.RectangleLayoutUtils.layoutConnectorInRectangle;
import static org.fortiss.tooling.base.ui.utils.RectangleLayoutUtils.layoutNodeInRoot;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.platform.model.IPlatformArchitectureElement;
import org.fortiss.af3.platform.model.PlatformConnectorUnit;
import org.fortiss.tooling.base.decompose.HierarchicElementCompositorBase;
import org.fortiss.tooling.base.ui.dnd.gef.ElementDropContext;
import org.fortiss.tooling.kernel.extension.data.IElementCompositionContext;
import org.fortiss.tooling.kernel.extension.data.Prototype;
/**
* Base class for compositors of {@link IPlatformArchitectureElement}s.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: C6CD3D338595FB85131D017E5E8EDE26
*/
public abstract class PlatformArchitectureElementCompositorBase<T extends IPlatformArchitectureElement>
extends HierarchicElementCompositorBase<T> {
/** {@inheritDoc} */
@Override
public boolean canCompose(T container, EObject contained, IElementCompositionContext context) {
return isCorrectElementClass(container, contained);
}
/** {@inheritDoc} */
@Override
public boolean canComposePrototype(Prototype prototype) {
return isCorrectElementClass(null, prototype.getPrototype());
}
/** {@inheritDoc} */
@Override
public boolean compose(T container, EObject contained, IElementCompositionContext context) {
if(contained instanceof PlatformConnectorUnit) {
PlatformConnectorUnit cunit = (PlatformConnectorUnit)contained;
if(context instanceof ElementDropContext) {
ElementDropContext ctx = (ElementDropContext)context;
if(ctx.isRoot()) {
int size = DEFAULT_CONNECTOR_SIZE / 2;
layoutNodeInRoot(cunit, ctx, size, true);
} else {
layoutConnectorInRectangle(cunit, container, ctx.getPosition());
}
}
container.getConnectorsList().add(cunit);
return true;
}
return false;
}
/** {@inheritDoc} */
@Override
public boolean canDecompose(EObject contained) {
return isCorrectElementClass(null, contained);
}
/** Returns whether the given contained element is of an acceptable class. */
protected abstract boolean isCorrectElementClass(T container, EObject contained);
}
......@@ -46,7 +46,7 @@ import org.fortiss.tooling.kernel.extension.base.PrototypeProviderBase;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: CAA05AA7DB2CCE5D9632C1DEE323BDF3
* @ConQAT.Rating YELLOW Hash: EE4AA66122F1431EA5F41012C2BCF5BC
*/
public final class PrototypeProvider extends PrototypeProviderBase {
......@@ -59,33 +59,32 @@ public final class PrototypeProvider extends PrototypeProviderBase {
/** Defines prototypes for {@link PlatformArchitecture}s. */
private void setupPlatformArchitecturePrototypes() {
registerPrimaryPrototype("Platform Architecture",
createPlatformArchitecture());
registerPrimaryPrototype("Platform Architecture", createPlatformArchitecture());
}
/** Defines prototypes of the generic platform. */
private void setupGenericPlatformPrototypes() {
GenericExecutionUnit geu = createGenericExecutionUnit("Generic ECU");
registerPrimaryPrototype("Generic ECU", geu);
GenericExecutionUnit geu = createGenericExecutionUnit("Generic_ECU");
registerPrimaryPrototype("Generic_ECU", geu);
GenericTransmissionUnit gtu = createGenericTransmissionUnit("Generic Bus");
GenericTransmissionUnit gtu = createGenericTransmissionUnit("Generic_Bus");
setNodeBounds(gtu, new Rectangle(0, 0, DEFAULT_SHAPE_MINIMUM_WIDTH,
DEFAULT_SHAPE_MINIMUM_HEIGHT));
registerPrimaryPrototype("Generic Bus", gtu);
registerPrimaryPrototype("Generic_Bus", gtu);
GenericTransmitter gt = createGenericTransmitter("Generic Actuator");
GenericTransmitter gt = createGenericTransmitter("Generic_Actuator");
setNodePosition(gt, 0, 0);
setConnectorPosition(gt, 0, 0);
registerPrototype("Generic Actuator", gt);
registerPrototype("Generic_Actuator", gt);
GenericTransceiver gtr = createGenericTransceiver("Generic BusController");
GenericTransceiver gtr = createGenericTransceiver("Generic_BusController");
setNodePosition(gtr, 0, 0);
setConnectorPosition(gtr, 0, 0);
registerPrototype("Generic BusController", gtr);
registerPrototype("Generic_BusController", gtr);
GenericReceiver gr = createGenericReceiver("Generic Sensor");
GenericReceiver gr = createGenericReceiver("Generic_Sensor");
setNodePosition(gr, 0, 0);
setConnectorPosition(gr, 0, 0);
registerPrototype("Generic Sensor", gr);
registerPrototype("Generic_Sensor", gr);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment