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

Kernel: JavaFX editor. Added LayoutedModelElement base controllers.

Issue-Ref: 3815
Issue-Url: https://af3-developer.fortiss.org/issues/3815

Signed-off-by: Florian Hölzl's avatarFlorian Hoelzl <hoelzl@fortiss.org>
parent 2f882866
......@@ -2,3 +2,4 @@ EObjectBasedDiagramControllerBase.java 1d57b1b031d57ffb5123773c752e3415bacd8f7e
EObjectBasedRectangularResizableContentControllerBase.java 6cdf3d430353b79ec8c2ccf1bc20736db2ed102c RED
LayoutedModelElementBasedContentAnchorageController.java abbf310db98983a6e80c4cd339cb34a23c795101 RED
LayoutedModelElementBasedDiagramAnchorageController.java bb4a942f9cca35f032dfe3adee26443654315774 RED
LayoutedModelElementBasedLinkBendPointController.java 7363f371c416d26540c679036aa27c74d5a32b5a RED
/*******************************************************************************
* Copyright (c) 2017, 2018 fortiss GmbH.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v2.0 which is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Florian Hoelzl (fortiss GmbH) - initial implementation
*
*******************************************************************************/
package org.fortiss.tooling.base.ui.editor.fx;
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.LinkedList;
import java.util.List;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
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.controller.IController;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.base.LinkControllerBase;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.model.IModelChangeListener;
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.base.utils.LayoutModelElementAdapter;
/**
* {@link IController} for {@link ILayoutedModelElement}s representing links and connections in a
* {@link DiagramViewer}.
*/
public class LayoutedModelElementBasedLinkBendPointController extends LinkControllerBase
implements IModelChangeProvider {
/** Layout adapter used for listening to EMF model changes. */
private final LayoutModelElementAdapter layoutAdapter;
/** Constructor. */
public LayoutedModelElementBasedLinkBendPointController(ILinkMVCBundle mvcb) {
super(mvcb);
if(!(mvcb.getModel() instanceof ILayoutedModelElement)) {
throw new IllegalArgumentException(
"Model element must be an instance of an ILayoutedModelElement.");
}
ILayoutedModelElement lme = (ILayoutedModelElement)mvcb.getModel();
layoutAdapter = new LayoutModelElementAdapter(lme) {
@Override
public void layoutChanged(Notification notification) {
fireUpdateComplete();
}
};
}
/** Returns the model element. */
public ILayoutedModelElement getLayoutedME() {
return (ILayoutedModelElement)getModel();
}
/** {@inheritDoc} */
@Override
protected int getNumerOfBendPoints() {
return getBendPointList(getLayoutedME()).size();
}
/** Returns the list of bend-points. */
private EList<Point> getBendPointList(ILayoutedModelElement modelElement) {
return getConnectionPoints(modelElement).getPoints();
}
/** {@inheritDoc} */
@Override
protected void createBendPointAt(int bpIndex, DiagramCoordinate location) {
int x = (int)location.getX();
int y = (int)location.getY();
addConnectionPoint(getLayoutedME(), bpIndex, x, y);
}
/** {@inheritDoc} */
@Override
protected void updateModelAfterBendPointMove(int bpIndex, double dx, double dy) {
List<Point> oldPoints = getBendPointList(getLayoutedME());
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(getLayoutedME(), bpIndex);
}
/** {@inheritDoc} */
@Override
protected void updateModelAfterLinkMove(ILinkMVCBundle linkBundle, IMVCBundle startBundle,
IMVCBundle endBundle) {
// TODO
}
/** {@inheritDoc} */
@Override
protected void deleteLink() {
// deleteByService(getLayoutedME(), context);
}
/** The model change listener list. */
private final List<IModelChangeListener> changeListeners =
new LinkedList<IModelChangeListener>();
/** {@inheritDoc} */
@Override
public void addListener(IModelChangeListener l) {
if(changeListeners.isEmpty()) {
connectToModel();
}
if(!changeListeners.contains(l)) {
changeListeners.add(l);
}
}
/** Called when sub-class should register with the underlying {@link EObject}. */
protected void connectToModel() {
getLayoutedME().eAdapters().add(layoutAdapter);
}
/** {@inheritDoc} */
@Override
public void removeListener(IModelChangeListener l) {
changeListeners.remove(l);
if(changeListeners.isEmpty()) {
disconnectFromModel();
}
}
/** Called when sub-class should unregister from the underlying {@link EObject}. */
protected void disconnectFromModel() {
getLayoutedME().eAdapters().remove(layoutAdapter);
}
/** {@inheritDoc} */
@Override
public void fireUpdateComplete() {
EObject eo = getLayoutedME();
for(IModelChangeListener mcl : changeListeners) {
mcl.changed(eo);
}
}
/** {@inheritDoc} */
@Override
public void delete() {
deleteLink();
}
}
Markdown is supported
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