Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • af3/kernel
  • diewald/kernel
2 results
Show changes
Commits on Source (45)
Showing
with 448 additions and 145 deletions
......@@ -25,7 +25,9 @@ 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.visuals,
org.fortiss.tooling.base.ui.editor.fx.controller,
org.fortiss.tooling.base.ui.editor.fx.model,
org.fortiss.tooling.base.ui.editor.fx.visual,
org.fortiss.tooling.base.ui.editpart,
org.fortiss.tooling.base.ui.editpart.allocation,
org.fortiss.tooling.base.ui.editpart.command,
......
ContextMenuUtil.java 7be87ce47b775d90c533078e22d4d445d9864caf GREEN
EObjectDiagramController.java 66b14c1c77953cad7caecae1e04f455958943f28 GREEN
EObjectModelChangeProvider.java f4b60cebb088a5c81ca92a41614e1a5d40030502 GREEN
EObjectRectangularResizableContentControllerBase.java 787a540213f29e8daaecd9afe98af8b3f4088db7 GREEN
KernelServiceBasedModelChangeProviderBase.java 18e48f17ea8dfba90de024a8959fc5a4b0d05d45 GREEN
LayoutModelChangeProvider.java b5449d02eaf39086909720c43e21bd061005fc9e GREEN
LayoutedContentAnchorageController.java 3794b41d76e9ce14ead0bd812cde5c1a6d348d5c GREEN
LayoutedDiagramAnchorageController.java 1e1ac7c5fa26c632736f5023e90f05d09bc0710d GREEN
LayoutedLinkBendPointController.java a8372485ae96f2abf773d1baeb1f8c7b2b25985f GREEN
LayoutedRectangularResizableContentController.java 1e18af3ee10dd3754325ed389fed664da65a0b61 GREEN
......@@ -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,13 @@
* 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 java.util.Objects.requireNonNull;
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 +40,20 @@ import javafx.scene.control.MenuItem;
*
* @author hoelzl
*/
public abstract class EObjectBasedDiagramControllerBase extends ControllerBase {
public class EObjectDiagramController<T extends EObject> extends ControllerBase {
/** The model change provider. */
private final EObjectModelChangeProvider modelChangeProvider;
/** Constructor. */
public EObjectBasedDiagramControllerBase(IMVCBundle mvcb) {
public EObjectDiagramController(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 = requireNonNull(mvcb.getModel(), "The given model is null!");
if(!modelType.isAssignableFrom(model.getClass())) {
throw new IllegalArgumentException("Expected model of type " +
modelType.getSimpleName() + ", but was " + model.getClass().getSimpleName());
}
this.modelChangeProvider = new EObjectModelChangeProvider(getEObject());
this.modelChangeProvider = new EObjectModelChangeProvider(getModelElement());
}
/** {@inheritDoc} */
......@@ -60,9 +63,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 +78,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);
......
......@@ -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;
......
......@@ -11,11 +11,14 @@
* 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 java.util.Objects.requireNonNull;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_SHAPE_MINIMUM_HEIGHT;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_SHAPE_MINIMUM_WIDTH;
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;
......@@ -25,9 +28,12 @@ import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramCoordinate;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewerFeatures;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.change.Change;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.IClickController;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.IDragController;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.base.ClickControllerBase;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.rectangular.RectangularContentAnchorageMoveController;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.rectangular.RectangularResizableContentControllerBase;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.model.IModelChangeProvider;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IContentAnchorageMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IContentMVCBundle;
import org.fortiss.tooling.base.model.element.ElementPackage;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
......@@ -37,6 +43,7 @@ import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler;
import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService;
import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
import javafx.geometry.Dimension2D;
import javafx.scene.Node;
import javafx.scene.control.MenuItem;
import javafx.scene.input.MouseEvent;
......@@ -47,28 +54,29 @@ import javafx.scene.input.MouseEvent;
*
* @author hoelzl
*/
public abstract class EObjectBasedRectangularResizableContentControllerBase
public abstract class EObjectRectangularResizableContentControllerBase<T extends EObject>
extends RectangularResizableContentControllerBase {
/** {@link IModelChangeProvider} for this controller */
private final LayoutModelElementModelChangeProvider layoutModelChangeProvider;
private final LayoutModelChangeProvider layoutModelChangeProvider;
/** The click controller handling double-click to open editor. */
private final IClickController openEditorDoubleClickController = new ClickControllerBase() {
@Override
public Change singleClick(MouseEvent event, Node node, DiagramCoordinate diagramLocation) {
return EObjectBasedRectangularResizableContentControllerBase.super.getClickController(
node, diagramLocation).singleClick(event, node, diagramLocation);
return EObjectRectangularResizableContentControllerBase.super.getClickController(node,
diagramLocation).singleClick(event, node, diagramLocation);
}
@Override
public Change secondaryClick(MouseEvent event, Node node,
DiagramCoordinate diagramLocation) {
return EObjectBasedRectangularResizableContentControllerBase.super.getClickController(
node, diagramLocation).secondaryClick(event, node, diagramLocation);
return EObjectRectangularResizableContentControllerBase.super.getClickController(node,
diagramLocation).secondaryClick(event, node, diagramLocation);
}
@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 +88,22 @@ public abstract class EObjectBasedRectangularResizableContentControllerBase
};
/** Constructor. */
public EObjectBasedRectangularResizableContentControllerBase(IContentMVCBundle mvcb) {
public EObjectRectangularResizableContentControllerBase(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 = requireNonNull(mvcb.getModel(), "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) {
this.layoutModelChangeProvider = new LayoutModelChangeProvider(lme) {
/** {@inheritDoc} */
@Override
protected boolean acceptNotification(Notification notification) {
if(notification.getNotifier() != getLayoutedME()) {
if(notification.getNotifier() != getModelElement()) {
return false;
}
return isAnchorageFeature(notification.getFeature());
......@@ -99,10 +111,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} */
......@@ -111,6 +124,28 @@ public abstract class EObjectBasedRectangularResizableContentControllerBase
return layoutModelChangeProvider;
}
/** {@inheritDoc} */
@Override
protected IDragController createAnchorageMoveController(IContentAnchorageMVCBundle anchorage) {
// we need an overridden port move controller due to the frameworks default snapping
// behavior, which snaps to anchorage size while AF3 ports snap to half their size
return new RectangularContentAnchorageMoveController(this, anchorage) {
/** {@inheritDoc} */
@Override
protected Dimension2D overrideBorderSnap(Dimension2D anchorageSize) {
// this override is required because ports can be moved by half their size
// while the default implementation would only allow for full size of the port
return new Dimension2D(anchorageSize.getWidth() / 2, anchorageSize.getHeight() / 2);
}
};
}
/** {@inheritDoc} */
@Override
protected Dimension2D getMinimumSize() {
return new Dimension2D(DEFAULT_SHAPE_MINIMUM_WIDTH, DEFAULT_SHAPE_MINIMUM_HEIGHT);
}
/** {@inheritDoc} */
@Override
public List<MenuItem> contextMenuContributions(Node node, DiagramCoordinate diagramLocation) {
......@@ -129,7 +164,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 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;
......@@ -26,11 +26,11 @@ import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.LayoutPackage;
/**
* An {@link KernelServiceBasedModelChangeProviderBase} for {@link ILayoutedModelElement}s.
* A {@link KernelServiceBasedModelChangeProviderBase} for {@link ILayoutedModelElement}s.
*
* @author hoelzl
*/
class LayoutModelElementModelChangeProvider
class LayoutModelChangeProvider
extends KernelServiceBasedModelChangeProviderBase<ILayoutedModelElement> {
/** The layouted model element. */
private final ILayoutedModelElement modelElement;
......@@ -38,7 +38,7 @@ class LayoutModelElementModelChangeProvider
private final LayoutModelElementAdapter notificationListener;
/** Constructor. */
public LayoutModelElementModelChangeProvider(ILayoutedModelElement modelElement) {
public LayoutModelChangeProvider(ILayoutedModelElement modelElement) {
this.modelElement = modelElement;
this.notificationListener = new LayoutModelElementAdapter();
}
......
......@@ -11,8 +11,9 @@
* 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.util.Objects.requireNonNull;
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,20 +35,23 @@ import org.fortiss.tooling.kernel.service.IElementCompositorService;
*
* @author hoelzl
*/
public class LayoutedModelElementBasedContentAnchorageController
public class LayoutedContentAnchorageController<T extends ILayoutedModelElement>
extends DelegatingContentAnchorageController {
/** {@link IModelChangeProvider} for this controller */
private final LayoutModelElementModelChangeProvider layoutModelChangeProvider;
private final LayoutModelChangeProvider layoutModelChangeProvider;
/** Constructor. */
public LayoutedModelElementBasedContentAnchorageController(IContentAnchorageMVCBundle mvcb) {
public LayoutedContentAnchorageController(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 = requireNonNull(mvcb.getModel(), "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);
this.layoutModelChangeProvider = new LayoutModelChangeProvider(lme);
}
/** Returns the model element. */
......
......@@ -11,8 +11,9 @@
* 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.util.Objects.requireNonNull;
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;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.moveNode;
......@@ -34,19 +35,23 @@ import org.fortiss.tooling.kernel.service.IElementCompositorService;
*
* @author hoelzl
*/
public class LayoutedModelElementBasedDiagramAnchorageController extends MoveControllerBase {
public class LayoutedDiagramAnchorageController<T extends ILayoutedModelElement>
extends MoveControllerBase {
/** {@link IModelChangeProvider} for this controller */
private final LayoutModelElementModelChangeProvider layoutModelChangeProvider;
private final LayoutModelChangeProvider layoutModelChangeProvider;
/** Constructor. */
public LayoutedModelElementBasedDiagramAnchorageController(IMVCBundle mvcb) {
public LayoutedDiagramAnchorageController(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 = requireNonNull(mvcb.getModel(), "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);
this.layoutModelChangeProvider = new LayoutModelChangeProvider(lme);
}
/** Returns the model element. */
......
......@@ -11,8 +11,9 @@
* 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.util.Objects.requireNonNull;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.addConnectionPoint;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.getConnectionPoints;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.removeConnectionPoint;
......@@ -37,24 +38,43 @@ import org.fortiss.tooling.kernel.service.IConnectionCompositorService;
*
* @author hoelzl
*/
public class LayoutedModelElementBasedLinkBendPointController extends LinkControllerBase {
public class LayoutedLinkBendPointController<T extends ILayoutedModelElement>
extends LinkControllerBase {
/** {@link IModelChangeProvider} for this controller */
private final LayoutModelElementModelChangeProvider layoutModelChangeProvider;
private final LayoutModelChangeProvider layoutModelChangeProvider;
/** Constructor. */
public LayoutedModelElementBasedLinkBendPointController(ILinkMVCBundle mvcb) {
public LayoutedLinkBendPointController(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 = requireNonNull(mvcb.getModel(), "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);
this.layoutModelChangeProvider = new LayoutModelChangeProvider(lme);
}
/** Returns the model element. */
public ILayoutedModelElement getLayoutedME() {
return (ILayoutedModelElement)getModel();
@SuppressWarnings("unchecked")
public T getModelElement() {
return (T)getModel();
}
/** {@inheritDoc} */
@Override
protected boolean clampAndSnapBendPointToGridCenter() {
// disable default mode
return false;
}
/** {@inheritDoc} */
@Override
protected boolean clampAndSnapBendPointToGrid() {
// enable clamping mode
return true;
}
/** {@inheritDoc} */
......@@ -66,7 +86,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 +99,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 +118,7 @@ public class LayoutedModelElementBasedLinkBendPointController extends LinkContro
/** {@inheritDoc} */
@Override
protected void deleteBendPoint(int bpIndex) {
removeConnectionPoint(getLayoutedME(), bpIndex);
removeConnectionPoint(getModelElement(), bpIndex);
}
/** {@inheritDoc} */
......@@ -111,7 +131,7 @@ public class LayoutedModelElementBasedLinkBendPointController extends LinkContro
/** {@inheritDoc} */
@Override
protected void deleteLink() {
IConnectionCompositorService.getInstance().disconnect(getLayoutedME());
IConnectionCompositorService.getInstance().disconnect(getModelElement());
}
/** {@inheritDoc} */
......
/*-------------------------------------------------------------------------+
| Copyright 2019 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.editor.fx.controller;
import static java.util.Objects.requireNonNull;
import static org.fortiss.tooling.base.ui.utils.LWFXEditorUtils.convertSideToEOrientation;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.getNodeSize;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.moveNode;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.setNodeSize;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.setStickyConnectorLayoutData;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.FeedbackChange;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.IController;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IContentAnchorageMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IContentMVCBundle;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.base.model.layout.Dimension;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import javafx.geometry.Dimension2D;
import javafx.geometry.Side;
/**
* {@link IController} for {@link ILayoutedModelElement}s that have a rectangular shape.
*
* @author diewald
*/
public class LayoutedRectangularResizableContentController<T extends ILayoutedModelElement>
extends EObjectRectangularResizableContentControllerBase<T> {
/** Constructor. */
public LayoutedRectangularResizableContentController(IContentMVCBundle mvcb,
Class<T> modelType) {
super(mvcb, modelType);
Object model = requireNonNull(mvcb.getModel(), "The given model is null!");
if(!modelType.isAssignableFrom(model.getClass())) {
throw new IllegalArgumentException("Expected model of type " +
modelType.getSimpleName() + ", but was " + model.getClass().getSimpleName());
}
}
/** {@inheritDoc} */
@Override
protected void moveAnchorageToSideOffset(IContentAnchorageMVCBundle anchorage, Side side,
double offset) {
Object connObj = anchorage.getModel();
if(connObj instanceof IConnector && connObj instanceof ILayoutedModelElement) {
ILayoutedModelElement conn = (ILayoutedModelElement)connObj;
Dimension2D portDim = anchorage.getVisual().getDimensions();
int correction;
if(side == Side.TOP || side == Side.BOTTOM) {
correction = (int)portDim.getWidth() / 2;
} else {
correction = (int)portDim.getHeight() / 2;
}
int corrected = (int)offset + correction;
setStickyConnectorLayoutData(conn, convertSideToEOrientation(side), corrected);
}
}
/** {@inheritDoc} */
@Override
protected void move(FeedbackChange deltaChange) {
moveNode(getModelElement(), (int)deltaChange.getDeltaX(), (int)deltaChange.getDeltaY());
}
/** {@inheritDoc} */
@Override
protected void resize(FeedbackChange delta) {
T element = getModelElement();
Dimension d = getNodeSize(element);
int w = d.getWidth() + (int)delta.getDeltaW();
int h = d.getHeight() + (int)delta.getDeltaH();
setNodeSize(element, w, h);
}
}
HierarchicElementModelFactoryBase.java 9996bfc1402c27424f0ae69e64560acce0ef81f4 GREEN
/*-------------------------------------------------------------------------+
| Copyright 2019 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.editor.fx.model;
import static java.util.Collections.emptyList;
import static java.util.Objects.requireNonNull;
import static org.fortiss.tooling.common.util.LambdaUtils.filterList;
import java.util.List;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.model.IModelFactory;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
/**
* {@link IModelFactory} for {@link IHierarchicElement}s of editors.
*
* @author diewald
*/
public abstract class HierarchicElementModelFactoryBase<T extends IHierarchicElement>
implements IModelFactory {
/** The currently edited element. */
private final T rootElement;
/** Constructor. */
public HierarchicElementModelFactoryBase(T root) {
this.rootElement = requireNonNull(root);
}
/** {@inheritDoc} */
@Override
public T getRootModel() {
return rootElement;
}
/** {@inheritDoc} */
@Override
public List<?> getDiagramAnchorageModels() {
return rootElement.getConnectors();
}
/** {@inheritDoc} */
@Override
public List<?> getContentAnchorageModels(Object parent) {
if(parent instanceof IHierarchicElement) {
return ((IHierarchicElement)parent).getConnectors();
}
return emptyList();
}
/** {@inheritDoc} */
@Override
public List<?> getLinkModels() {
return filterList(rootElement.getConnections(),
c -> filterPartiallyInitializedConnections(c));
}
/** Checks whether the given connection is only partially initialized. */
private boolean filterPartiallyInitializedConnections(IConnection c) {
return c.getSource() != null && c.getTarget() != null && c.eContainer() != null;
}
/** {@inheritDoc} */
@Override
public Object getLinkStart(Object link) {
if(link instanceof IConnection) {
return ((IConnection)link).getSource();
}
return null;
}
/** {@inheritDoc} */
@Override
public Object getLinkEnd(Object link) {
if(link instanceof IConnection) {
return ((IConnection)link).getTarget();
}
return null;
}
/** {@inheritDoc} */
@Override
public Object getParent(Object element) {
// Not used at the moment, so return null.
return null;
}
/** {@inheritDoc} */
@Override
public void update() {
// Not used at the moment.
}
}
CoordinateCorrections.java c5cc475b45de38c56fc2e888a2d3093cd2efb52a GREEN
LayoutedCircularAnchorageContentVisualBase.java 2aa292444671bf644e37bc923b877c92de0235b1 GREEN
LayoutedCircularAnchorageDiagramVisualBase.java f06e3b908020408e3cd268a3c63edcd75ef74f8b GREEN
LayoutedLineLinkVisual.java feea85e0bd288590fbe06c152a8a8b138ea85ca2 GREEN
LayoutedRectangularContentVisualBase.java c2a3937b99284713e0bbcd3ce458874567b25ac5 GREEN
NamedLayoutedCircularAnchorageContentVisual.java c680002469ce897679fa5a3f4af51d1b19cb53d6 GREEN
NamedLayoutedCircularAnchorageDiagramVisual.java 714a176a0569a2049efb4009f710ca66bf3a57fb GREEN
NamedLayoutedLineLinkVisual.java e66e5b2aaa40fe8b22a292e175bb8f3af4539b9d GREEN
NamedLayoutedRectangularContentVisual.java 122e193ac587857d1dad23b42583a0bcf465f0d0 GREEN
......@@ -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.visuals;
package org.fortiss.tooling.base.ui.editor.fx.visual;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_CONNECTOR_SIZE;
......@@ -27,14 +27,15 @@ import javafx.geometry.Dimension2D;
* This class contains corrections of {@link DefaultLayoutConstants}.
*
* @author hoelzl
* @author diewald
*/
class CoordinateCorrections {
public class CoordinateCorrections {
/** The insets of the {@link RectangularContentVisualBase}s. */
/* package */ static final Dimension2D RECTANGLE_INSETS =
public static final Dimension2D RECTANGLE_INSETS =
new Dimension2D(DEFAULT_CONNECTOR_SIZE / 2, DEFAULT_CONNECTOR_SIZE / 2);
/** The default size of {@link ContentAnchorageVisualBase}s. */
/* package */ static final Dimension2D ANCHOR_DIMENSION =
public static final Dimension2D ANCHOR_DIMENSION =
new Dimension2D(DEFAULT_CONNECTOR_SIZE, DEFAULT_CONNECTOR_SIZE);
/** The insets of the {@link ContentAnchorageVisualBase}s. */
/* package */ static final double ANCHOR_INSET = DEFAULT_CONNECTOR_SIZE / 4.5;
public static final double ANCHOR_INSET = DEFAULT_CONNECTOR_SIZE / 4.5;
}
......@@ -13,14 +13,14 @@
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editor.fx.visuals;
package org.fortiss.tooling.base.ui.editor.fx.visual;
import static javafx.scene.paint.Color.BLACK;
import static javafx.scene.paint.Color.rgb;
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;
import static org.fortiss.tooling.base.ui.editor.fx.visuals.CoordinateCorrections.ANCHOR_DIMENSION;
import static org.fortiss.tooling.base.ui.editor.fx.visuals.CoordinateCorrections.ANCHOR_INSET;
import static org.fortiss.tooling.base.ui.editor.fx.visual.CoordinateCorrections.ANCHOR_DIMENSION;
import static org.fortiss.tooling.base.ui.editor.fx.visual.CoordinateCorrections.ANCHOR_INSET;
import static org.fortiss.tooling.base.ui.utils.LWFXEditorUtils.convertEOrientationToSide;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.getConnectorOffsetOrientation;
......@@ -46,26 +46,36 @@ import javafx.scene.paint.Paint;
*
* @author munaro
*/
public abstract class LayoutedCircularContentAnchorageVisualBase
public abstract class LayoutedCircularAnchorageContentVisualBase<T extends ILayoutedModelElement>
extends CircularContentAnchorageVisualBase implements ISideLayout, IOffsetLayout {
/** Constructor. */
public LayoutedCircularContentAnchorageVisualBase(IContentAnchorageMVCBundle mvcb) {
public LayoutedCircularAnchorageContentVisualBase(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();
}
}
......@@ -13,14 +13,14 @@
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editor.fx.visuals;
package org.fortiss.tooling.base.ui.editor.fx.visual;
import static javafx.scene.paint.Color.BLACK;
import static javafx.scene.paint.Color.rgb;
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;
import static org.fortiss.tooling.base.ui.editor.fx.visuals.CoordinateCorrections.ANCHOR_DIMENSION;
import static org.fortiss.tooling.base.ui.editor.fx.visuals.CoordinateCorrections.ANCHOR_INSET;
import static org.fortiss.tooling.base.ui.editor.fx.visual.CoordinateCorrections.ANCHOR_DIMENSION;
import static org.fortiss.tooling.base.ui.editor.fx.visual.CoordinateCorrections.ANCHOR_INSET;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.getNodePosition;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IDiagramAnchorageMVCBundle;
......@@ -39,26 +39,35 @@ import javafx.scene.paint.Paint;
*
* @author munaro
*/
public abstract class LayoutedCircularDiagramAnchorageVisualBase
public abstract class LayoutedCircularAnchorageDiagramVisualBase<T extends ILayoutedModelElement>
extends CircularDiagramAnchorageVisualBase {
/** Constructor. */
public LayoutedCircularDiagramAnchorageVisualBase(
IDiagramAnchorageMVCBundle mvcb) {
public LayoutedCircularAnchorageDiagramVisualBase(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();
}
}
......@@ -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.visuals;
package org.fortiss.tooling.base.ui.editor.fx.visual;
import static java.util.Collections.emptyList;
import static org.fortiss.tooling.base.ui.utils.LWFXEditorUtils.computeLinkToCircleLocation;
......@@ -36,20 +36,33 @@ import javafx.geometry.Rectangle2D;
*
* @author munaro
*/
public abstract class LayoutedLineLinkVisualBase extends LineLinkVisualBase {
// TODO (TM): As this class already requires the generic type to implement INamedElement
// NamedLayoutedLineLinkVisual becomes useless. Remove INamedElement here and make class
// abstract (consistent with the other Layouted*VisualBase classes)
public abstract class LayoutedLineLinkVisual<T extends ILayoutedModelElement>
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();
}
/** {@inheritDoc} */
@Override
public DiagramCoordinate getBendPointLocation(int bpIndex) {
......@@ -85,7 +98,7 @@ public abstract class LayoutedLineLinkVisualBase extends LineLinkVisualBase {
/** Returns the list of bend-points. */
private List<Point> getBendPointList() {
Points connectionPoints = getConnectionPoints(getLayoutedModelElement());
Points connectionPoints = getConnectionPoints(getModelElement());
if(connectionPoints == null) {
return emptyList();
}
......@@ -107,11 +120,4 @@ public abstract class LayoutedLineLinkVisualBase extends LineLinkVisualBase {
protected double getInvisibleSelectionLineWidth() {
return 3;
}
/** 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();
}
}
......@@ -13,10 +13,10 @@
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editor.fx.visuals;
package org.fortiss.tooling.base.ui.editor.fx.visual;
import static java.lang.Math.min;
import static org.fortiss.tooling.base.ui.editor.fx.visuals.CoordinateCorrections.RECTANGLE_INSETS;
import static org.fortiss.tooling.base.ui.editor.fx.visual.CoordinateCorrections.RECTANGLE_INSETS;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.getNodeBounds;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramCoordinate;
......@@ -39,24 +39,36 @@ import javafx.geometry.Side;
*
* @author munaro
*/
public abstract class LayoutedRectangularContentVisualBase extends RectangularContentVisualBase {
public abstract class LayoutedRectangularContentVisualBase<T extends ILayoutedModelElement>
extends RectangularContentVisualBase {
/** Constructor. */
public LayoutedRectangularContentVisualBase(IContentMVCBundle mvcb) {
public LayoutedRectangularContentVisualBase(IContentMVCBundle 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 specified type. */
// TODO(#3877): Move type checks to a common base class.
@SuppressWarnings("unchecked")
protected T getModelElement() {
// Safe wild cast due to type check in constructor
return (T)getModel();
}
/** {@inheritDoc} */
@Override
public Rectangle2D getModelBounds() {
Rectangle rectangle = getNodeBounds(getLayoutedModelElement());
Rectangle rectangle = getNodeBounds(getModelElement());
double insetRadius = RECTANGLE_INSETS.getWidth();
double insetDiameter = insetRadius * 2;
return new Rectangle2D(rectangle.getX() + insetRadius, rectangle.getY() + insetRadius,
......@@ -102,11 +114,4 @@ public abstract class LayoutedRectangularContentVisualBase extends RectangularCo
protected boolean requireSelectionForResizeGesture() {
return false;
}
/** 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();
}
}