Commit 31c26dc6 authored by Alexander Diewald's avatar Alexander Diewald

JFX-GraphicalEditors: Restructuring & type check generalization

* Move fx-base classes dealing with controllers to a dedicated package
  to prepare adding more base classes.
* Place type checks in the constructors of AF3 base classes to avoid
  them in the large set of concrete classes.
* Transform several base classes to classes such that they can be
  directly instantiated by factories if no specialization is needed.

Issue-Ref: 3883
Issue-Url: https://af3-developer.fortiss.org/issues/3883Signed-off-by: Alexander Diewald's avatarAlexander Diewald <diewald@fortiss.org>
parent 07b98613
......@@ -25,6 +25,7 @@ Export-Package: org.fortiss.tooling.base.ui,
org.fortiss.tooling.base.ui.editor,
org.fortiss.tooling.base.ui.editor.annotations,
org.fortiss.tooling.base.ui.editor.fx,
org.fortiss.tooling.base.ui.editor.fx.controller,
org.fortiss.tooling.base.ui.editor.fx.visuals,
org.fortiss.tooling.base.ui.editpart,
org.fortiss.tooling.base.ui.editpart.allocation,
......
ContextMenuUtil.java 7be87ce47b775d90c533078e22d4d445d9864caf GREEN
EObjectBasedDiagramController.java bb2835572a07878dcbf33e3a727f931a33f54dbe YELLOW
EObjectBasedRectangularResizableContentControllerBase.java b7dd4ee94a8144229c807c8a441bcb99d8e71e18 YELLOW
EObjectModelChangeProvider.java f4b60cebb088a5c81ca92a41614e1a5d40030502 GREEN
KernelServiceBasedModelChangeProviderBase.java 18e48f17ea8dfba90de024a8959fc5a4b0d05d45 GREEN
LayoutModelElementModelChangeProvider.java dae8650dc5a8a63e18182521e0f59eb5452239b6 GREEN
LayoutedModelElementBasedContentAnchorageController.java 874a17f8ed7fa9510020f0c05a1eaf45b99a7216 YELLOW
LayoutedModelElementBasedDiagramAnchorageController.java 9e005b36b9f183cbbfcb4e08adc6b5056d0cf29a YELLOW
LayoutedModelElementBasedLinkBendPointController.java 2b6cca10a19e17a62e4820eea630d7bc7476b8b4 YELLOW
......@@ -13,7 +13,7 @@
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editor.fx;
package org.fortiss.tooling.base.ui.editor.fx.controller;
import static org.fortiss.tooling.base.utils.LayoutModelElementFactory.createPoint;
......
......@@ -11,12 +11,12 @@
* Florian Hoelzl (fortiss GmbH) - initial implementation
*
*******************************************************************************/
package org.fortiss.tooling.base.ui.editor.fx;
package org.fortiss.tooling.base.ui.editor.fx.controller;
import static java.lang.Math.max;
import static org.fortiss.tooling.base.ui.editor.fx.ContextMenuUtil.createDisplayMenu;
import static org.fortiss.tooling.base.ui.editor.fx.ContextMenuUtil.createElementCompositionContext;
import static org.fortiss.tooling.base.ui.editor.fx.ContextMenuUtil.createPrototypeMenu;
import static org.fortiss.tooling.base.ui.editor.fx.controller.ContextMenuUtil.createDisplayMenu;
import static org.fortiss.tooling.base.ui.editor.fx.controller.ContextMenuUtil.createElementCompositionContext;
import static org.fortiss.tooling.base.ui.editor.fx.controller.ContextMenuUtil.createPrototypeMenu;
import java.util.List;
......@@ -39,18 +39,23 @@ import javafx.scene.control.MenuItem;
*
* @author hoelzl
*/
public abstract class EObjectBasedDiagramControllerBase extends ControllerBase {
public class EObjectBasedDiagramController<T extends EObject> extends ControllerBase {
/** The model change provider. */
private final EObjectModelChangeProvider modelChangeProvider;
/** Constructor. */
public EObjectBasedDiagramControllerBase(IMVCBundle mvcb) {
public EObjectBasedDiagramController(IMVCBundle mvcb, Class<T> modelType) {
super(mvcb);
if(!(getModel() instanceof EObject)) {
throw new IllegalArgumentException("Model element must be an instance of an EObject.");
Object model = mvcb.getModel();
if(model == null) {
throw new IllegalArgumentException("The given model is null!");
}
this.modelChangeProvider = new EObjectModelChangeProvider(getEObject());
if(!modelType.isAssignableFrom(model.getClass())) {
throw new IllegalArgumentException("Expected model of type " +
modelType.getSimpleName() + ", but was " + model.getClass().getSimpleName());
}
this.modelChangeProvider = new EObjectModelChangeProvider(getModelElement());
}
/** {@inheritDoc} */
......@@ -60,9 +65,10 @@ public abstract class EObjectBasedDiagramControllerBase extends ControllerBase {
}
/** Returns the {@link EObject} model element. */
protected EObject getEObject() {
@SuppressWarnings("unchecked")
protected T getModelElement() {
// wild cast works: see constructor check with exception
return (EObject)getModel();
return (T)getModel();
}
/** {@inheritDoc} */
......@@ -74,7 +80,7 @@ public abstract class EObjectBasedDiagramControllerBase extends ControllerBase {
double y = max(features.getVerticalSpacing(), diagramLocation.getY());
// wild cast works: see constructor exception
EObject modelParent = getEObject();
T modelParent = getModelElement();
IElementCompositionContext edc = createElementCompositionContext(modelParent, x, y, true,
getViewer().getFeatures().getCurrentZoomFactor());
List<MenuItem> result = createPrototypeMenu(modelParent, edc);
......
......@@ -11,11 +11,11 @@
* Florian Hoelzl (fortiss GmbH) - initial implementation
*
*******************************************************************************/
package org.fortiss.tooling.base.ui.editor.fx;
package org.fortiss.tooling.base.ui.editor.fx.controller;
import static java.lang.Math.max;
import static org.fortiss.tooling.base.ui.editor.fx.ContextMenuUtil.createElementCompositionContext;
import static org.fortiss.tooling.base.ui.editor.fx.ContextMenuUtil.createPrototypeMenu;
import static org.fortiss.tooling.base.ui.editor.fx.controller.ContextMenuUtil.createElementCompositionContext;
import static org.fortiss.tooling.base.ui.editor.fx.controller.ContextMenuUtil.createPrototypeMenu;
import java.util.List;
......@@ -47,7 +47,7 @@ import javafx.scene.input.MouseEvent;
*
* @author hoelzl
*/
public abstract class EObjectBasedRectangularResizableContentControllerBase
public abstract class EObjectBasedRectangularResizableContentControllerBase<T extends ILayoutedModelElement>
extends RectangularResizableContentControllerBase {
/** {@link IModelChangeProvider} for this controller */
private final LayoutModelElementModelChangeProvider layoutModelChangeProvider;
......@@ -68,7 +68,7 @@ public abstract class EObjectBasedRectangularResizableContentControllerBase
@Override
public Change doubleClick(MouseEvent event, Node node, DiagramCoordinate diagramLocation) {
EObject eo = getLayoutedME();
EObject eo = getModelElement();
IModelElementHandler<EObject> handler =
IModelElementHandlerService.getInstance().getModelElementHandler(eo);
if(handler != null) {
......@@ -80,18 +80,25 @@ public abstract class EObjectBasedRectangularResizableContentControllerBase
};
/** Constructor. */
public EObjectBasedRectangularResizableContentControllerBase(IContentMVCBundle mvcb) {
public EObjectBasedRectangularResizableContentControllerBase(IContentMVCBundle mvcb,
Class<T> modelType) {
super(mvcb);
if(!(mvcb.getModel() instanceof ILayoutedModelElement)) {
throw new IllegalArgumentException(
"Model element must be an instance of an ILayoutedModelElement.");
Object model = mvcb.getModel();
if(model == null) {
throw new IllegalArgumentException("The given model is null!");
}
if(!modelType.isAssignableFrom(model.getClass())) {
throw new IllegalArgumentException("Expected model of type " +
modelType.getSimpleName() + ", but was " + model.getClass().getSimpleName());
}
ILayoutedModelElement lme = (ILayoutedModelElement)mvcb.getModel();
this.layoutModelChangeProvider = new LayoutModelElementModelChangeProvider(lme) {
/** {@inheritDoc} */
@Override
protected boolean acceptNotification(Notification notification) {
if(notification.getNotifier() != getLayoutedME()) {
if(notification.getNotifier() != getModelElement()) {
return false;
}
return isAnchorageFeature(notification.getFeature());
......@@ -99,10 +106,11 @@ public abstract class EObjectBasedRectangularResizableContentControllerBase
};
}
/** Returns the {@link ILayoutedModelElement} model element. */
protected ILayoutedModelElement getLayoutedME() {
/** Returns the correctly casted model element. */
@SuppressWarnings("unchecked")
protected T getModelElement() {
// wild cast works: see constructor check with exception
return (ILayoutedModelElement)getModel();
return (T)getModel();
}
/** {@inheritDoc} */
......@@ -129,7 +137,7 @@ public abstract class EObjectBasedRectangularResizableContentControllerBase
/** {@inheritDoc} */
@Override
public void delete() {
IElementCompositorService.getInstance().decompose(getLayoutedME());
IElementCompositorService.getInstance().decompose(getModelElement());
}
/** Checks whether the given feature corresponds to an anchorage model element. */
......
......@@ -13,7 +13,7 @@
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editor.fx;
package org.fortiss.tooling.base.ui.editor.fx.controller;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
......
......@@ -13,7 +13,7 @@
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editor.fx;
package org.fortiss.tooling.base.ui.editor.fx.controller;
import java.util.ArrayList;
import java.util.EventObject;
......
......@@ -13,7 +13,7 @@
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editor.fx;
package org.fortiss.tooling.base.ui.editor.fx.controller;
import static org.fortiss.tooling.base.model.layout.LayoutPackage.ILAYOUTED_MODEL_ELEMENT__LAYOUT_DATA;
......
......@@ -11,7 +11,7 @@
* Florian Hoelzl (fortiss GmbH) - initial implementation
*
*******************************************************************************/
package org.fortiss.tooling.base.ui.editor.fx;
package org.fortiss.tooling.base.ui.editor.fx.controller;
import static org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewerDefaultTags.LINK_TARGET_ALLOWED_TAG;
import static org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewerDefaultTags.LINK_TARGET_DENIED_TAG;
......@@ -34,18 +34,25 @@ import org.fortiss.tooling.kernel.service.IElementCompositorService;
*
* @author hoelzl
*/
public class LayoutedModelElementBasedContentAnchorageController
public class LayoutedModelElementBasedContentAnchorageController<T extends ILayoutedModelElement>
extends DelegatingContentAnchorageController {
/** {@link IModelChangeProvider} for this controller */
private final LayoutModelElementModelChangeProvider layoutModelChangeProvider;
/** Constructor. */
public LayoutedModelElementBasedContentAnchorageController(IContentAnchorageMVCBundle mvcb) {
public LayoutedModelElementBasedContentAnchorageController(IContentAnchorageMVCBundle mvcb,
Class<T> modelType) {
super(mvcb);
if(!(mvcb.getModel() instanceof ILayoutedModelElement)) {
throw new IllegalArgumentException(
"Model element must be an instance of an ILayoutedModelElement.");
Object model = mvcb.getModel();
if(model == null) {
throw new IllegalArgumentException("The given model is null!");
}
if(!modelType.isAssignableFrom(model.getClass())) {
throw new IllegalArgumentException("Expected model of type " +
modelType.getSimpleName() + ", but was " + model.getClass().getSimpleName());
}
ILayoutedModelElement lme = (ILayoutedModelElement)mvcb.getModel();
this.layoutModelChangeProvider = new LayoutModelElementModelChangeProvider(lme);
}
......
......@@ -11,7 +11,7 @@
* Florian Hoelzl (fortiss GmbH) - initial implementation
*
*******************************************************************************/
package org.fortiss.tooling.base.ui.editor.fx;
package org.fortiss.tooling.base.ui.editor.fx.controller;
import static org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewerDefaultTags.LINK_TARGET_ALLOWED_TAG;
import static org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewerDefaultTags.LINK_TARGET_DENIED_TAG;
......@@ -34,17 +34,25 @@ import org.fortiss.tooling.kernel.service.IElementCompositorService;
*
* @author hoelzl
*/
public class LayoutedModelElementBasedDiagramAnchorageController extends MoveControllerBase {
public class LayoutedModelElementBasedDiagramAnchorageController<T extends ILayoutedModelElement>
extends MoveControllerBase {
/** {@link IModelChangeProvider} for this controller */
private final LayoutModelElementModelChangeProvider layoutModelChangeProvider;
/** Constructor. */
public LayoutedModelElementBasedDiagramAnchorageController(IMVCBundle mvcb) {
public LayoutedModelElementBasedDiagramAnchorageController(IMVCBundle mvcb,
Class<T> modelType) {
super(mvcb);
if(!(mvcb.getModel() instanceof ILayoutedModelElement)) {
throw new IllegalArgumentException(
"Model element must be an instance of an ILayoutedModelElement.");
Object model = mvcb.getModel();
if(model == null) {
throw new IllegalArgumentException("The given model is null!");
}
if(!modelType.isAssignableFrom(model.getClass())) {
throw new IllegalArgumentException("Expected model of type " +
modelType.getSimpleName() + ", but was " + model.getClass().getSimpleName());
}
ILayoutedModelElement lme = (ILayoutedModelElement)mvcb.getModel();
this.layoutModelChangeProvider = new LayoutModelElementModelChangeProvider(lme);
}
......
......@@ -11,7 +11,7 @@
* Florian Hoelzl (fortiss GmbH) - initial implementation
*
*******************************************************************************/
package org.fortiss.tooling.base.ui.editor.fx;
package org.fortiss.tooling.base.ui.editor.fx.controller;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.addConnectionPoint;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.getConnectionPoints;
......@@ -37,24 +37,33 @@ import org.fortiss.tooling.kernel.service.IConnectionCompositorService;
*
* @author hoelzl
*/
public class LayoutedModelElementBasedLinkBendPointController extends LinkControllerBase {
public class LayoutedModelElementBasedLinkBendPointController<T extends ILayoutedModelElement>
extends LinkControllerBase {
/** {@link IModelChangeProvider} for this controller */
private final LayoutModelElementModelChangeProvider layoutModelChangeProvider;
/** Constructor. */
public LayoutedModelElementBasedLinkBendPointController(ILinkMVCBundle mvcb) {
public LayoutedModelElementBasedLinkBendPointController(ILinkMVCBundle mvcb,
Class<T> modelType) {
super(mvcb);
if(!(mvcb.getModel() instanceof ILayoutedModelElement)) {
throw new IllegalArgumentException(
"Model element must be an instance of an ILayoutedModelElement.");
Object model = mvcb.getModel();
if(model == null) {
throw new IllegalArgumentException("The given model is null!");
}
if(!modelType.isAssignableFrom(model.getClass())) {
throw new IllegalArgumentException("Expected model of type " +
modelType.getSimpleName() + ", but was " + model.getClass().getSimpleName());
}
ILayoutedModelElement lme = (ILayoutedModelElement)mvcb.getModel();
this.layoutModelChangeProvider = new LayoutModelElementModelChangeProvider(lme);
}
/** Returns the model element. */
public ILayoutedModelElement getLayoutedME() {
return (ILayoutedModelElement)getModel();
@SuppressWarnings("unchecked")
public T getModelElement() {
return (T)getModel();
}
/** {@inheritDoc} */
......@@ -66,7 +75,7 @@ public class LayoutedModelElementBasedLinkBendPointController extends LinkContro
/** {@inheritDoc} */
@Override
protected int getNumerOfBendPoints() {
return getBendPointList(getLayoutedME()).size();
return getBendPointList(getModelElement()).size();
}
/** Returns the list of bend-points. */
......@@ -79,13 +88,13 @@ public class LayoutedModelElementBasedLinkBendPointController extends LinkContro
protected void createBendPointAt(int bpIndex, DiagramCoordinate location) {
int x = (int)location.getX();
int y = (int)location.getY();
addConnectionPoint(getLayoutedME(), bpIndex, x, y);
addConnectionPoint(getModelElement(), bpIndex, x, y);
}
/** {@inheritDoc} */
@Override
protected void updateModelAfterBendPointMove(int bpIndex, double dx, double dy) {
List<Point> oldPoints = getBendPointList(getLayoutedME());
List<Point> oldPoints = getBendPointList(getModelElement());
Point point = oldPoints.get(bpIndex);
int oldX = point.getX();
int oldY = point.getY();
......@@ -98,7 +107,7 @@ public class LayoutedModelElementBasedLinkBendPointController extends LinkContro
/** {@inheritDoc} */
@Override
protected void deleteBendPoint(int bpIndex) {
removeConnectionPoint(getLayoutedME(), bpIndex);
removeConnectionPoint(getModelElement(), bpIndex);
}
/** {@inheritDoc} */
......@@ -111,7 +120,7 @@ public class LayoutedModelElementBasedLinkBendPointController extends LinkContro
/** {@inheritDoc} */
@Override
protected void deleteLink() {
IConnectionCompositorService.getInstance().disconnect(getLayoutedME());
IConnectionCompositorService.getInstance().disconnect(getModelElement());
}
/** {@inheritDoc} */
......
CoordinateCorrections.java f78a936ba49c5fc4daf29237ecb4e86a446316d4 GREEN
LayoutedCircularContentAnchorageVisualBase.java aa546c0c9d975972a33cf22682b5d6634e56d271 GREEN
LayoutedCircularDiagramAnchorageVisualBase.java c5cc5fb41777166bc169011324585e51acda04c3 GREEN
LayoutedLineLinkVisualBase.java 429483c1222a26345fbc3bf5c9b2dbe41c6ad5f1 GREEN
LayoutedRectangularContentVisualBase.java d4cd07a8056df99927b160f2d4ce1cf4778d1dfa GREEN
LayoutedCircularContentAnchorageVisualBase.java d1521fb71166a78e4e71bf3e2f3fa4b6c571fddb YELLOW
LayoutedCircularDiagramAnchorageVisualBase.java 215d74fb1bc979ee24fd0f31236a187c35f9b48b YELLOW
LayoutedLineLinkVisual.java 6491d2e22722e7cdf5672f0eb4c4a403dea15103 YELLOW
LayoutedRectangularContentVisualBase.java 3792d3cd78403c89a0ccbaff670f029b0fec1564 YELLOW
......@@ -46,26 +46,36 @@ import javafx.scene.paint.Paint;
*
* @author munaro
*/
public abstract class LayoutedCircularContentAnchorageVisualBase
public abstract class LayoutedCircularContentAnchorageVisualBase<T extends ILayoutedModelElement>
extends CircularContentAnchorageVisualBase implements ISideLayout, IOffsetLayout {
/** Constructor. */
public LayoutedCircularContentAnchorageVisualBase(IContentAnchorageMVCBundle mvcb) {
public LayoutedCircularContentAnchorageVisualBase(IContentAnchorageMVCBundle mvcb,
Class<T> modelType) {
super(mvcb);
// TODO(#3877): Move type checks to a common base class.
Object model = mvcb.getModel();
if(!(model instanceof ILayoutedModelElement)) {
throw new IllegalArgumentException(
"Expected model of type ILayoutedModelElement, but was " +
model.getClass().getSimpleName() + ".");
if(model == null) {
throw new IllegalArgumentException("The given model is null!");
}
if(!modelType.isAssignableFrom(model.getClass())) {
throw new IllegalArgumentException("Expected model of type " +
modelType.getSimpleName() + ", but was " + model.getClass().getSimpleName());
}
}
/** Returns the model element in the correct type. */
@SuppressWarnings("unchecked")
protected T getModelElement() {
return (T)getModel();
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <T extends ILayout> T getLayout(Class<T> type) {
return (T)this;
public <S extends ILayout> S getLayout(Class<S> type) {
return (S)this;
}
/** {@inheritDoc} */
......@@ -92,7 +102,7 @@ public abstract class LayoutedCircularContentAnchorageVisualBase
/** {@inheritDoc} */
@Override
public double getOffset() {
OffsetOrientation offsetOrientation = getConnectorOffsetOrientation(getLayoutedModelElement());
OffsetOrientation offsetOrientation = getConnectorOffsetOrientation(getModelElement());
double inset = getDimensions().getWidth() / 2;
return offsetOrientation.getOffset() - inset;
}
......@@ -101,7 +111,7 @@ public abstract class LayoutedCircularContentAnchorageVisualBase
@Override
public Side getSide() {
// TODO (#3868): Remove null check.
OffsetOrientation offsetOrientation = getConnectorOffsetOrientation(getLayoutedModelElement());
OffsetOrientation offsetOrientation = getConnectorOffsetOrientation(getModelElement());
EOrientation orientation = EOrientation.NORTH;
if(offsetOrientation != null) {
orientation = offsetOrientation.getOrientation();
......@@ -139,11 +149,4 @@ public abstract class LayoutedCircularContentAnchorageVisualBase
}
return super.getInteractionColor();
}
/** Return the {@link ILayoutedModelElement}. */
// TODO(#3877): Implement an equivalent, but generic method in a common base class.
private ILayoutedModelElement getLayoutedModelElement() {
// Safe wild cast due to type check in constructor
return (ILayoutedModelElement)getModel();
}
}
......@@ -39,26 +39,35 @@ import javafx.scene.paint.Paint;
*
* @author munaro
*/
public abstract class LayoutedCircularDiagramAnchorageVisualBase
public abstract class LayoutedCircularDiagramAnchorageVisualBase<T extends ILayoutedModelElement>
extends CircularDiagramAnchorageVisualBase {
/** Constructor. */
public LayoutedCircularDiagramAnchorageVisualBase(
IDiagramAnchorageMVCBundle mvcb) {
public LayoutedCircularDiagramAnchorageVisualBase(IDiagramAnchorageMVCBundle mvcb,
Class<T> modelType) {
super(mvcb);
// TODO(#3877): Move type checks to a common base class.
Object model = mvcb.getModel();
if(!(model instanceof ILayoutedModelElement)) {
throw new IllegalArgumentException(
"Expected model of type ILayoutedModelElement, but was " +
model.getClass().getSimpleName());
if(model == null) {
throw new IllegalArgumentException("The given model is null!");
}
if(!modelType.isAssignableFrom(model.getClass())) {
throw new IllegalArgumentException("Expected model of type " +
modelType.getSimpleName() + ", but was " + model.getClass().getSimpleName());
}
}
/** Returns the wrapped model as the expected type. */
@SuppressWarnings("unchecked")
protected T getModelElement() {
return (T)getModel();
}
/** {@inheritDoc} */
@Override
public Rectangle2D getModelBounds() {
Point p = getNodePosition(getLayoutedModelElement());
Point p = getNodePosition(getModelElement());
Dimension2D dim = getDimensions();
return new Rectangle2D(p.getX(), p.getY(), dim.getWidth(), dim.getHeight());
}
......@@ -105,11 +114,4 @@ public abstract class LayoutedCircularDiagramAnchorageVisualBase
}
return super.getInteractionColor();
}
/** Return the {@link ILayoutedModelElement}. */
// TODO(#3877): Move type checks to a common base class.
private ILayoutedModelElement getLayoutedModelElement() {
// Safe wild cast due to type check in constructor
return (ILayoutedModelElement)getModel();
}
}
......@@ -27,6 +27,7 @@ import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.rectangular
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.Point;
import org.fortiss.tooling.base.model.layout.Points;
import org.fortiss.tooling.kernel.model.INamedElement;
import javafx.geometry.Rectangle2D;
......@@ -36,20 +37,30 @@ import javafx.geometry.Rectangle2D;
*
* @author munaro
*/
public abstract class LayoutedLineLinkVisualBase extends LineLinkVisualBase {
public class LayoutedLineLinkVisual<T extends ILayoutedModelElement & INamedElement>
extends LineLinkVisualBase {
/** Constructor. */
public LayoutedLineLinkVisualBase(ILinkMVCBundle mvcb) {
public LayoutedLineLinkVisual(ILinkMVCBundle mvcb, Class<T> modelType) {
super(mvcb);
// TODO(#3877): Move type checks to a common base class.
Object model = mvcb.getModel();
if(!(model instanceof ILayoutedModelElement)) {
throw new IllegalArgumentException(
"Expected model of type ILayoutedModelElement, but was " +
model.getClass().getSimpleName());
if(model == null) {
throw new IllegalArgumentException("The given model is null!");
}
if(!modelType.isAssignableFrom(model.getClass())) {
throw new IllegalArgumentException("Expected model of type " +
modelType.getSimpleName() + ", but was " + model.getClass().getSimpleName());
}
}
/** Returns the model element with the expected type. */
@SuppressWarnings("unchecked")
protected T getModelElement() {
return (T)getModel();
}