Commit 231eecac authored by Alexander Diewald's avatar Alexander Diewald

IVisuals: Add more base classes

* For Connectors & Links.
* Add a controller for HierarchicElements.

Issue-Ref: 3883
Issue-Url: https://af3-developer.fortiss.org/issues/3883Signed-off-by: Alexander Diewald's avatarAlexander Diewald <diewald@fortiss.org>
parent 0a80ea3d
......@@ -26,6 +26,7 @@ Export-Package: org.fortiss.tooling.base.ui,
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.factory,
org.fortiss.tooling.base.ui.editor.fx.visuals,
org.fortiss.tooling.base.ui.editpart,
org.fortiss.tooling.base.ui.editpart.allocation,
......
......@@ -2,6 +2,7 @@ ContextMenuUtil.java 7be87ce47b775d90c533078e22d4d445d9864caf GREEN
EObjectBasedDiagramController.java bb2835572a07878dcbf33e3a727f931a33f54dbe YELLOW
EObjectBasedRectangularResizableContentControllerBase.java b7dd4ee94a8144229c807c8a441bcb99d8e71e18 YELLOW
EObjectModelChangeProvider.java f4b60cebb088a5c81ca92a41614e1a5d40030502 GREEN
HierarchicElementController.java f7fc3b919736f782955b89b8f6fcbe24b935dd5a RED
KernelServiceBasedModelChangeProviderBase.java 18e48f17ea8dfba90de024a8959fc5a4b0d05d45 GREEN
LayoutModelElementModelChangeProvider.java dae8650dc5a8a63e18182521e0f59eb5452239b6 GREEN
LayoutedModelElementBasedContentAnchorageController.java 874a17f8ed7fa9510020f0c05a1eaf45b99a7216 YELLOW
......
/*-------------------------------------------------------------------------+
| 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 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.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.controller.IDragController;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.rectangular.RectangularContentAnchorageMoveController;
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.element.IHierarchicElement;
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 IHierarchicElement}s that are also {@link ILayoutedModelElement}s.
*
* @author diewald
*/
// TODO(AD): I guess it would make sense to swap inheritance between the Hierarchic and the
// RectengularController.
public class HierarchicElementController<T extends IHierarchicElement & ILayoutedModelElement>
extends EObjectBasedRectangularResizableContentControllerBase<T> {
/** Constructor. */
public HierarchicElementController(IContentMVCBundle mvcb, Class<T> modelType) {
super(mvcb, modelType);
}
/** {@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 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);
}
/** {@inheritDoc} */
@Override
protected Dimension2D getMinimumSize() {
return new Dimension2D(DEFAULT_SHAPE_MINIMUM_WIDTH, DEFAULT_SHAPE_MINIMUM_HEIGHT);
}
}
HierarchicElementModelFactoryBase.java 21c18441961971ca89802e4047b27a31db8499a9 YELLOW
/*-------------------------------------------------------------------------+
| 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.factory;
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.
}
}
......@@ -3,3 +3,6 @@ LayoutedCircularContentAnchorageVisualBase.java d1521fb71166a78e4e71bf3e2f3fa4b6
LayoutedCircularDiagramAnchorageVisualBase.java 215d74fb1bc979ee24fd0f31236a187c35f9b48b YELLOW
LayoutedLineLinkVisual.java 6491d2e22722e7cdf5672f0eb4c4a403dea15103 YELLOW
LayoutedRectangularContentVisualBase.java 3792d3cd78403c89a0ccbaff670f029b0fec1564 YELLOW
NamedLayoutedConnectorContentVisual.java 439396abe75d951af8139c94786273b0afa8ce81 YELLOW
NamedLayoutedConnectorDiagramVisual.java 49f92af16948da62ef672675c6445cac4cec5039 YELLOW
NamedLayoutedLinkVisual.java 0088164d71e79f2345685d003f6777b03ca343d6 YELLOW
/*-------------------------------------------------------------------------+
| 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.visuals;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IContentAnchorageMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.IVisual;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.kernel.model.INamedElement;
/**
* {@link IVisual} for layouted and named {@link IConnector}s of some content element within a
* diagram (sticky connectors).
*
* @author diewald
*/
public class NamedLayoutedConnectorContentVisual<T extends ILayoutedModelElement & INamedElement>
extends LayoutedCircularContentAnchorageVisualBase<T> {
/** Constructor. */
public NamedLayoutedConnectorContentVisual(IContentAnchorageMVCBundle mvcb, Class<T> modelType) {
super(mvcb, modelType);
}
/** {@inheritDoc} */
@Override
protected String getHoverText() {
return getModelElement().getName();
}
}
/*-------------------------------------------------------------------------+
| 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.visuals;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IDiagramAnchorageMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.IVisual;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.kernel.model.INamedElement;
/**
* {@link IVisual} for layouted and named {@link IConnector}s within a diagram (free connectors).
*
* @author diewald
*/
public class NamedLayoutedConnectorDiagramVisual<T extends ILayoutedModelElement & INamedElement>
extends LayoutedCircularDiagramAnchorageVisualBase<T> {
/** Constructor. */
public NamedLayoutedConnectorDiagramVisual(IDiagramAnchorageMVCBundle mvcb, Class<T> modelType) {
super(mvcb, modelType);
}
/** {@inheritDoc} */
@Override
protected String getHoverText() {
return getModelElement().getName();
}
}
/*-------------------------------------------------------------------------+
| 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.visuals;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.ILinkMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.IVisual;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.kernel.model.INamedElement;
/**
* {@link IVisual} for layouted and named links within a diagram. Typically, those are
* {@link IConnection}s.
*
* @author diewald
*/
public class NamedLayoutedLinkVisual<T extends INamedElement & ILayoutedModelElement>
extends LayoutedLineLinkVisual<T> {
/** Constructor. */
public NamedLayoutedLinkVisual(ILinkMVCBundle mvcb, Class<T> modelType) {
super(mvcb, modelType);
}
/** {@inheritDoc} */
@Override
protected String getLabelText(int currentSegment, int lastSegment) {
if(currentSegment == 0) {
return getModelElement().getName();
}
return null;
}
}
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