Skip to content
Snippets Groups Projects
Commit 12d93413 authored by Tiziano Munaro's avatar Tiziano Munaro
Browse files

Refactor bend point controllers

parent fcde16e2
No related branches found
No related tags found
1 merge request!88[3873] Ellipses and Bezier curves
...@@ -6,8 +6,9 @@ EObjectRectangularResizableContentControllerBase.java 787a540213f29e8daaecd9afe9 ...@@ -6,8 +6,9 @@ EObjectRectangularResizableContentControllerBase.java 787a540213f29e8daaecd9afe9
KernelServiceBasedModelChangeProviderBase.java 18e48f17ea8dfba90de024a8959fc5a4b0d05d45 GREEN KernelServiceBasedModelChangeProviderBase.java 18e48f17ea8dfba90de024a8959fc5a4b0d05d45 GREEN
LayoutModelChangeProvider.java b5449d02eaf39086909720c43e21bd061005fc9e GREEN LayoutModelChangeProvider.java b5449d02eaf39086909720c43e21bd061005fc9e GREEN
LayoutedContentAnchorageController.java 851a957839af8a22ea41d312e21b7a4a29b882e5 YELLOW LayoutedContentAnchorageController.java 851a957839af8a22ea41d312e21b7a4a29b882e5 YELLOW
LayoutedCurveLinkBendPointController.java 76e510cbaa39538ac3314cd909a62885b625486d RED LayoutedCurveLinkBendPointController.java 592c1e4f6dae466e38cc67b372a910b8a1f4b67e YELLOW
LayoutedDiagramAnchorageController.java 1e1ac7c5fa26c632736f5023e90f05d09bc0710d GREEN LayoutedDiagramAnchorageController.java 1e1ac7c5fa26c632736f5023e90f05d09bc0710d GREEN
LayoutedEllipticResizableContentController.java b2c9c48190b9ff69a175bbe5f89761c1b08621ab YELLOW LayoutedEllipticResizableContentController.java b2c9c48190b9ff69a175bbe5f89761c1b08621ab YELLOW
LayoutedLineLinkBendPointController.java e2dac36334191c39d54b4f95fa8482a6392ce82c RED LayoutedLineLinkBendPointController.java 6ea31e09f98b5e64890d4811e9c56b1abea39158 YELLOW
LayoutedLinkBendPointController.java e93683330e57725915e5040d9d2b23f6c7835e6c YELLOW
LayoutedRectangularResizableContentController.java 1e18af3ee10dd3754325ed389fed664da65a0b61 GREEN LayoutedRectangularResizableContentController.java 1e18af3ee10dd3754325ed389fed664da65a0b61 GREEN
...@@ -16,28 +16,18 @@ ...@@ -16,28 +16,18 @@
package org.fortiss.tooling.base.ui.editor.fx.controller; package org.fortiss.tooling.base.ui.editor.fx.controller;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static java.util.Objects.requireNonNull;
import static org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.FeedbackChange.locationFeedbackChange; import static org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.FeedbackChange.locationFeedbackChange;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.getConnectionPoints;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.removeConnectionPoint;
import static org.fortiss.tooling.base.utils.LayoutModelElementFactory.createPoint; import static org.fortiss.tooling.base.utils.LayoutModelElementFactory.createPoint;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramCoordinate; import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramCoordinate;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewer; import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewer;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewerFeatures; import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewerFeatures;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.FeedbackChange; 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.controller.IController;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.base.LinkControllerBase;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.model.IModelChangeProvider;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.ILinkMVCBundle; import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.ILinkMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.ILinkVisual; import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.ILinkVisual;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement; import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.Point; import org.fortiss.tooling.base.model.layout.Point;
import org.fortiss.tooling.kernel.service.IConnectionCompositorService;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
...@@ -48,59 +38,11 @@ import javafx.geometry.Point2D; ...@@ -48,59 +38,11 @@ import javafx.geometry.Point2D;
* @author munaro * @author munaro
*/ */
public class LayoutedCurveLinkBendPointController<T extends ILayoutedModelElement> public class LayoutedCurveLinkBendPointController<T extends ILayoutedModelElement>
extends LinkControllerBase { extends LayoutedLinkBendPointController<T> {
/** {@link IModelChangeProvider} for this controller */
private final LayoutModelChangeProvider layoutModelChangeProvider;
/** Constructor. */ /** Constructor. */
public LayoutedCurveLinkBendPointController(ILinkMVCBundle mvcb, Class<T> modelType) { public LayoutedCurveLinkBendPointController(ILinkMVCBundle mvcb, Class<T> modelType) {
super(mvcb); 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());
}
ILayoutedModelElement lme = (ILayoutedModelElement)mvcb.getModel();
this.layoutModelChangeProvider = new LayoutModelChangeProvider(lme);
}
/** Returns the model element. */
@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} */
@Override
public IModelChangeProvider getModelChangeProvider() {
return layoutModelChangeProvider;
}
/** {@inheritDoc} */
@Override
protected int getNumerOfBendPoints() {
return getBendPointList(getModelElement()).size();
}
/** Returns the list of bend-points. */
private EList<Point> getBendPointList(ILayoutedModelElement modelElement) {
return getConnectionPoints(modelElement).getPoints();
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
...@@ -166,42 +108,4 @@ public class LayoutedCurveLinkBendPointController<T extends ILayoutedModelElemen ...@@ -166,42 +108,4 @@ public class LayoutedCurveLinkBendPointController<T extends ILayoutedModelElemen
updateModelAfterBendPointMove(otherIndex, -chg.getDeltaX(), -chg.getDeltaY()); updateModelAfterBendPointMove(otherIndex, -chg.getDeltaX(), -chg.getDeltaY());
} }
} }
/** {@inheritDoc} */
@Override
protected void deleteBendPoint(int bpIndex) {
removeConnectionPoint(getModelElement(), bpIndex);
}
/** {@inheritDoc} */
@Override
protected void updateModelAfterLinkMove(ILinkMVCBundle linkBundle, IMVCBundle startBundle,
IMVCBundle endBundle) {
// ignored
}
/** {@inheritDoc} */
@Override
protected void deleteLink() {
IConnectionCompositorService.getInstance().disconnect(getModelElement());
}
/** {@inheritDoc} */
@Override
public void delete() {
deleteLink();
}
/** {@inheritDoc} */
@Override
protected void updateModelAfterBendPointMove(int bpIndex, double dx, double dy) {
List<Point> oldPoints = getBendPointList(getModelElement());
Point point = oldPoints.get(bpIndex);
int oldX = point.getX();
int oldY = point.getY();
int newX = oldX + (int)dx;
int newY = oldY + (int)dy;
point.setX(newX);
point.setY(newY);
}
} }
...@@ -13,85 +13,26 @@ ...@@ -13,85 +13,26 @@
*******************************************************************************/ *******************************************************************************/
package org.fortiss.tooling.base.ui.editor.fx.controller; 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.addConnectionPoint;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.getConnectionPoints;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.removeConnectionPoint;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramCoordinate; import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramCoordinate;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewer; import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewer;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.IController; import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.IController;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.base.LinkControllerBase;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.model.IModelChangeProvider;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.ILinkMVCBundle; import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.ILinkMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IMVCBundle;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement; import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.Point;
import org.fortiss.tooling.kernel.service.IConnectionCompositorService;
/** /**
* {@link IController} for {@link ILayoutedModelElement}s representing links and connections in a * {@link IController} for {@link ILayoutedModelElement}s representing straight links and
* {@link DiagramViewer}. * connections in a {@link DiagramViewer}.
* *
* @author hoelzl * @author hoelzl
*/ */
public class LayoutedLineLinkBendPointController<T extends ILayoutedModelElement> public class LayoutedLineLinkBendPointController<T extends ILayoutedModelElement>
extends LinkControllerBase { extends LayoutedLinkBendPointController<T> {
/** {@link IModelChangeProvider} for this controller */
private final LayoutModelChangeProvider layoutModelChangeProvider;
/** Constructor. */ /** Constructor. */
public LayoutedLineLinkBendPointController(ILinkMVCBundle mvcb, Class<T> modelType) { public LayoutedLineLinkBendPointController(ILinkMVCBundle mvcb, Class<T> modelType) {
super(mvcb); 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());
}
ILayoutedModelElement lme = (ILayoutedModelElement)mvcb.getModel();
this.layoutModelChangeProvider = new LayoutModelChangeProvider(lme);
}
/** Returns the model element. */
@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} */
@Override
public IModelChangeProvider getModelChangeProvider() {
return layoutModelChangeProvider;
}
/** {@inheritDoc} */
@Override
protected int getNumerOfBendPoints() {
return getBendPointList(getModelElement()).size();
}
/** Returns the list of bend-points. */
private EList<Point> getBendPointList(ILayoutedModelElement modelElement) {
return getConnectionPoints(modelElement).getPoints();
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
...@@ -101,42 +42,4 @@ public class LayoutedLineLinkBendPointController<T extends ILayoutedModelElement ...@@ -101,42 +42,4 @@ public class LayoutedLineLinkBendPointController<T extends ILayoutedModelElement
int y = (int)location.getY(); int y = (int)location.getY();
addConnectionPoint(getModelElement(), bpIndex, x, y); addConnectionPoint(getModelElement(), bpIndex, x, y);
} }
/** {@inheritDoc} */
@Override
protected void updateModelAfterBendPointMove(int bpIndex, double dx, double dy) {
List<Point> oldPoints = getBendPointList(getModelElement());
Point point = oldPoints.get(bpIndex);
int oldX = point.getX();
int oldY = point.getY();
int newX = oldX + (int)dx;
int newY = oldY + (int)dy;
point.setX(newX);
point.setY(newY);
}
/** {@inheritDoc} */
@Override
protected void deleteBendPoint(int bpIndex) {
removeConnectionPoint(getModelElement(), bpIndex);
}
/** {@inheritDoc} */
@Override
protected void updateModelAfterLinkMove(ILinkMVCBundle linkBundle, IMVCBundle startBundle,
IMVCBundle endBundle) {
// ignored
}
/** {@inheritDoc} */
@Override
protected void deleteLink() {
IConnectionCompositorService.getInstance().disconnect(getModelElement());
}
/** {@inheritDoc} */
@Override
public void delete() {
deleteLink();
}
} }
/*-------------------------------------------------------------------------+
| Copyright 2020 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.LayoutDataUIUtils.getConnectionPoints;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.removeConnectionPoint;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewer;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.IController;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.base.LinkControllerBase;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.model.IModelChangeProvider;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.ILinkMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IMVCBundle;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.Point;
import org.fortiss.tooling.kernel.service.IConnectionCompositorService;
/**
* Base class for {@link IController}s for {@link ILayoutedModelElement}s representing links and
* connections in a {@link DiagramViewer}.
*
* @author munaro
*/
public abstract class LayoutedLinkBendPointController<T extends ILayoutedModelElement>
extends LinkControllerBase {
/** {@link IModelChangeProvider} for this controller */
protected final LayoutModelChangeProvider layoutModelChangeProvider;
/** Returns the model element. */
@SuppressWarnings("unchecked")
public T getModelElement() {
return (T)getModel();
}
/** {@inheritDoc} */
@Override
public IModelChangeProvider getModelChangeProvider() {
return layoutModelChangeProvider;
}
/** Constructor. */
public LayoutedLinkBendPointController(ILinkMVCBundle mvcb, Class<T> modelType) {
super(mvcb);
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 LayoutModelChangeProvider(lme);
}
/** {@inheritDoc} */
@Override
public void delete() {
deleteLink();
}
/** {@inheritDoc} */
@Override
protected boolean clampAndSnapBendPointToGridCenter() {
// disable default mode
return false;
}
/** {@inheritDoc} */
@Override
protected boolean clampAndSnapBendPointToGrid() {
// enable clamping mode
return true;
}
/** {@inheritDoc} */
@Override
protected void deleteBendPoint(int bpIndex) {
removeConnectionPoint(getModelElement(), bpIndex);
}
/** {@inheritDoc} */
@Override
protected void updateModelAfterBendPointMove(int bpIndex, double dx, double dy) {
List<Point> oldPoints = getBendPointList(getModelElement());
Point point = oldPoints.get(bpIndex);
int oldX = point.getX();
int oldY = point.getY();
int newX = oldX + (int)dx;
int newY = oldY + (int)dy;
point.setX(newX);
point.setY(newY);
}
/** {@inheritDoc} */
@Override
protected void deleteLink() {
IConnectionCompositorService.getInstance().disconnect(getModelElement());
}
/** {@inheritDoc} */
@Override
protected void updateModelAfterLinkMove(ILinkMVCBundle linkBundle, IMVCBundle startBundle,
IMVCBundle endBundle) {
// ignored
}
/** Returns the list of bend-points. */
protected EList<Point> getBendPointList(ILayoutedModelElement modelElement) {
return getConnectionPoints(modelElement).getPoints();
}
/** {@inheritDoc} */
@Override
protected int getNumerOfBendPoints() {
return getBendPointList(getModelElement()).size();
}
}
CoordinateCorrections.java c5cc475b45de38c56fc2e888a2d3093cd2efb52a GREEN CoordinateCorrections.java c5cc475b45de38c56fc2e888a2d3093cd2efb52a GREEN
LayoutedCircularAnchorageContentVisualBase.java 2aa292444671bf644e37bc923b877c92de0235b1 GREEN LayoutedCircularAnchorageContentVisualBase.java 2aa292444671bf644e37bc923b877c92de0235b1 GREEN
LayoutedCircularAnchorageDiagramVisualBase.java f06e3b908020408e3cd268a3c63edcd75ef74f8b GREEN LayoutedCircularAnchorageDiagramVisualBase.java f06e3b908020408e3cd268a3c63edcd75ef74f8b GREEN
LayoutedCurveLinkVisual.java 7344139cd451f8d9d3b57e9cc32482753e8e53ed RED LayoutedCurveLinkVisual.java 7344139cd451f8d9d3b57e9cc32482753e8e53ed YELLOW
LayoutedEllipticContentVisualBase.java a06403f2c2245e017dc76e902a2b71ed124fedd1 YELLOW LayoutedEllipticContentVisualBase.java a06403f2c2245e017dc76e902a2b71ed124fedd1 YELLOW
LayoutedLineLinkVisual.java feea85e0bd288590fbe06c152a8a8b138ea85ca2 RED LayoutedLineLinkVisual.java 3f6fa536b3e767590e95faeaf07b72df16e5e718 YELLOW
LayoutedRectangularContentVisualBase.java c2a3937b99284713e0bbcd3ce458874567b25ac5 GREEN LayoutedRectangularContentVisualBase.java c2a3937b99284713e0bbcd3ce458874567b25ac5 GREEN
NamedLayoutedCircularAnchorageContentVisual.java c680002469ce897679fa5a3f4af51d1b19cb53d6 GREEN NamedLayoutedCircularAnchorageContentVisual.java c680002469ce897679fa5a3f4af51d1b19cb53d6 GREEN
NamedLayoutedCircularAnchorageDiagramVisual.java 714a176a0569a2049efb4009f710ca66bf3a57fb GREEN NamedLayoutedCircularAnchorageDiagramVisual.java 714a176a0569a2049efb4009f710ca66bf3a57fb GREEN
......
...@@ -36,9 +36,6 @@ import javafx.geometry.Rectangle2D; ...@@ -36,9 +36,6 @@ import javafx.geometry.Rectangle2D;
* *
* @author munaro * @author munaro
*/ */
// 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> public abstract class LayoutedLineLinkVisual<T extends ILayoutedModelElement>
extends LineLinkVisualBase { extends LineLinkVisualBase {
......
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