Commit be9ca546 authored by Johannes Eder's avatar Johannes Eder
Browse files

Merge remote-tracking branch 'origin/master' into 3891

parents 7beca13a 9c20e188
AF3ComponentUIActivator.java 235a4ae290abdc80966f4bb340a21cbc89260a70 YELLOW
AF3ComponentUIActivator.java 64ae4377ecc4975ff42fc3dbe70754dd1775dc07 YELLOW
DefaultStyle.java c3b60c89b4917e9d8514812ee1884010d142b616 GREEN
......@@ -15,10 +15,6 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.component.ui;
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.fortiss.af3.component.ui.simulator.SimulationManager;
......@@ -26,9 +22,6 @@ import org.fortiss.af3.component.ui.simulator.menu.ISimulationContextMenuService
import org.fortiss.af3.component.ui.simulator.menu.SimulationContextMenuService;
import org.osgi.framework.BundleContext;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
/**
* The activator class controls the plug-in life cycle.
*
......@@ -70,40 +63,4 @@ public class AF3ComponentUIActivator extends AbstractUIPlugin {
public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
/** Returns the plugin-local URI string for the given resource. */
public static String getURIString(String localPath) {
return "platform:/plugin/" + PLUGIN_ID + localPath;
}
/** The image cache of loaded images. */
private static final HashMap<String, Image> imageCache = new HashMap<>();
/** Returns the Java FX Image load from the local path. */
public static Image getFXImage(String localPath) {
String uri = getURIString(localPath);
if(uri == null) {
return null;
}
Image cacheImage = imageCache.get(uri);
if(cacheImage == null) {
InputStream in = null;
try {
in = new URL(uri).openStream();
} catch(Exception e) {
e.printStackTrace();
}
if(in != null) {
cacheImage = new Image(in);
}
imageCache.put(uri, cacheImage);
}
return cacheImage;
}
/** Converts the given SWT color to Java FX color. */
public static Color convertColor(org.eclipse.swt.graphics.Color swtColor) {
return Color.rgb(swtColor.getRed(), swtColor.getGreen(), swtColor.getBlue(),
swtColor.getAlpha() / 255.0);
}
}
ComponentStructureFXEditor.java d097c17a4ebc5bc2a87659544d3dd15f2afde254 GREEN
ComponentStructureFXEditorBinding.java 230337d9526109ee2a9df599c370b0b3f2ec0b40 GREEN
ControllerFactory.java 0adaa2e7ab2e3bc73bae21aec736842a5abeb9a1 GREEN
ModelFactory.java d97242e6b8c69ccaad9fbb6adf80ffdb40520f80 GREEN
VisualFactory.java c3f9acf01cb627f07dca673631a4c8f632d2c4a9 GREEN
ComponentControllerFactory.java debf3bb80cb56197d4dd0c84f38e466f99da9a34 GREEN
ComponentModelFactory.java 7e58831949f50a9887bcbf31959f887a87f703cb GREEN
ComponentStructureFXEditor.java d662863a84c9e3f24e46de19dad1d750a1462cd3 GREEN
ComponentStructureFXEditorBinding.java 370fe5c458f15bd8299364f858250d5c2bda6729 GREEN
ComponentVisualFactory.java 4b5f4e36726d65422719d628765d176aa077b673 GREEN
SubComponentController.java e7361eb33367c160f9a7502721bca13f1ee85128 GREEN
......@@ -22,18 +22,21 @@ import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IContentMVCBun
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IDiagramAnchorageMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IDiagramMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.ILinkMVCBundle;
import org.fortiss.af3.component.ui.editor.fx.controller.ChannelController;
import org.fortiss.af3.component.ui.editor.fx.controller.DiagramComponentPortController;
import org.fortiss.af3.component.ui.editor.fx.controller.DiagramController;
import org.fortiss.af3.component.ui.editor.fx.controller.SubComponentController;
import org.fortiss.af3.component.ui.editor.fx.controller.SubComponentPortController;
import org.fortiss.af3.component.model.Channel;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.Port;
import org.fortiss.tooling.base.ui.editor.fx.controller.EObjectDiagramController;
import org.fortiss.tooling.base.ui.editor.fx.controller.LayoutedContentAnchorageController;
import org.fortiss.tooling.base.ui.editor.fx.controller.LayoutedDiagramAnchorageController;
import org.fortiss.tooling.base.ui.editor.fx.controller.LayoutedLinkBendPointController;
/**
* The implementation of the {@link IControllerFactory} for the component editor.
*
* @author hoelzl
* @author diewald
*/
final class ControllerFactory implements IControllerFactory {
public final class ComponentControllerFactory implements IControllerFactory {
/** {@inheritDoc} */
@Override
public IController createContentController(IContentMVCBundle model) {
......@@ -43,24 +46,24 @@ final class ControllerFactory implements IControllerFactory {
/** {@inheritDoc} */
@Override
public IController createDiagramAnchorageController(IDiagramAnchorageMVCBundle modelBundle) {
return new DiagramComponentPortController(modelBundle);
return new LayoutedDiagramAnchorageController<>(modelBundle, Port.class);
}
/** {@inheritDoc} */
@Override
public IController createContentAnchorageController(IContentAnchorageMVCBundle modelBundle) {
return new SubComponentPortController(modelBundle);
return new LayoutedContentAnchorageController<>(modelBundle, Port.class);
}
/** {@inheritDoc} */
@Override
public IController createLinkController(ILinkMVCBundle modelBundle) {
return new ChannelController(modelBundle);
return new LayoutedLinkBendPointController<>(modelBundle, Channel.class);
}
/** {@inheritDoc} */
@Override
public IController createDiagramController(IDiagramMVCBundle diagramBundle) {
return new DiagramController(diagramBundle);
return new EObjectDiagramController<>(diagramBundle, Component.class);
}
}
......@@ -31,12 +31,12 @@ import org.fortiss.tooling.base.model.element.IConnection;
*
* @author hoelzl
*/
final class ModelFactory implements IModelFactory {
public final class ComponentModelFactory implements IModelFactory {
/** The currently edited component. */
private final Component rootElement;
/** Constructor. */
public ModelFactory(Component root) {
public ComponentModelFactory(Component root) {
this.rootElement = requireNonNull(root);
}
......
......@@ -19,9 +19,6 @@ import static javafx.scene.paint.Color.LIGHTGRAY;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewerFeatures;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.IControllerFactory;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.model.IModelFactory;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.IVisualFactory;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.component.model.OutputPort;
......@@ -49,22 +46,4 @@ public class ComponentStructureFXEditor extends LWFXEFEditorBase<Component> {
features.setIndicatorSpacing(new Dimension2D(12, 12));
features.setBackgroundColor(LIGHTGRAY);
}
/** {@inheritDoc} */
@Override
protected IModelFactory createModelFactory() {
return new ModelFactory(editedObject);
}
/** {@inheritDoc} */
@Override
protected IVisualFactory createVisualFactory() {
return new VisualFactory();
}
/** {@inheritDoc} */
@Override
protected IControllerFactory createControllerFactory() {
return new ControllerFactory();
}
}
......@@ -15,6 +15,9 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.component.ui.editor.fx;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.IControllerFactory;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.model.IModelFactory;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.IVisualFactory;
import org.eclipse.ui.IEditorPart;
import org.fortiss.af3.component.model.Component;
import org.fortiss.tooling.kernel.ui.extension.base.ModelEditorBindingBase;
......@@ -31,6 +34,24 @@ public final class ComponentStructureFXEditorBinding extends ModelEditorBindingB
return ComponentStructureFXEditor.class;
}
/** {@inheritDoc} */
@Override
public Class<? extends IModelFactory> getModelFactory() {
return ComponentModelFactory.class;
}
/** {@inheritDoc} */
@Override
public Class<? extends IVisualFactory> getVisualFactory() {
return ComponentVisualFactory.class;
}
/** {@inheritDoc} */
@Override
public Class<? extends IControllerFactory> getControllerFactory() {
return ComponentControllerFactory.class;
}
/** {@inheritDoc} */
@Override
public String getLabel() {
......
......@@ -27,23 +27,24 @@ import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.IVisualFact
import org.fortiss.af3.component.model.Channel;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.Port;
import org.fortiss.af3.component.ui.editor.fx.visual.ChannelVisual;
import org.fortiss.af3.component.ui.editor.fx.visual.ContentComponentPortVisual;
import org.fortiss.af3.component.ui.editor.fx.visual.ContentComponentVisual;
import org.fortiss.af3.component.ui.editor.fx.visual.DiagramComponentPortVisual;
import org.fortiss.af3.component.ui.editor.fx.visual.SubComponentPortVisual;
import org.fortiss.af3.component.ui.editor.fx.visual.SubComponentVisual;
import org.fortiss.tooling.base.ui.editor.fx.visual.NamedLayoutedLineLinkVisual;
/**
* The implementation of the {@link IVisualFactory} for the component editor.
*
* @author hoelzl
* @author diewald
*/
final class VisualFactory implements IVisualFactory {
public final class ComponentVisualFactory implements IVisualFactory {
/** {@inheritDoc} */
@Override
public IContentVisual createContentVisual(IContentMVCBundle modelBundle) {
Object modelObj = modelBundle.getModel();
if(modelObj instanceof Component) {
return new SubComponentVisual(modelBundle);
return new ContentComponentVisual(modelBundle);
}
return null;
}
......@@ -65,7 +66,7 @@ final class VisualFactory implements IVisualFactory {
createContentAnchorageVisual(IContentAnchorageMVCBundle modelBundle) {
Object anchorageObj = modelBundle.getModel();
if(anchorageObj instanceof Port) {
return new SubComponentPortVisual(modelBundle);
return new ContentComponentPortVisual(modelBundle);
}
return null;
}
......@@ -75,7 +76,7 @@ final class VisualFactory implements IVisualFactory {
public ILinkVisual createLinkVisual(ILinkMVCBundle modelBundle) {
Object linkObj = modelBundle.getModel();
if(linkObj instanceof Channel) {
return new ChannelVisual(modelBundle);
return new NamedLayoutedLineLinkVisual<>(modelBundle, Channel.class);
}
return null;
}
......
/*-------------------------------------------------------------------------+
| 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.af3.component.ui.editor.fx;
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.af3.component.model.Component;
import org.fortiss.af3.component.model.Port;
import org.fortiss.tooling.base.ui.editor.fx.controller.LayoutedRectangularResizableContentController;
import javafx.geometry.Side;
/**
* {@link IController} for sub-components of the component displayed in the diagram.
*
* @author hoelzl
* @author diewald
*/
public final class SubComponentController
extends LayoutedRectangularResizableContentController<Component> {
/** Constructor. */
public SubComponentController(IContentMVCBundle mvcb) {
super(mvcb, Component.class);
}
/** {@inheritDoc} */
@Override
protected void moveAnchorageToSideOffset(IContentAnchorageMVCBundle anchorage, Side side,
double offset) {
Object portObj = anchorage.getModel();
if(portObj instanceof Port) {
super.moveAnchorageToSideOffset(anchorage, side, offset);
}
}
}
ChannelController.java fe3fd8b71f320e93fa8581298581af6a9d5f8aee GREEN
DiagramComponentPortController.java c99d075a9bc6b9c4214dee19aa5fd634ca5be379 GREEN
DiagramController.java 74e96ce04d715a8084eb5d20b74567bc0168910d GREEN
SubComponentController.java 3fe6f80d4fec036983523b78a8a1892c7716cbda GREEN
SubComponentPortController.java ce6b20088baeb1ddd5c98111316f707f71cd133e 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.af3.component.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.af3.component.model.Component;
import org.fortiss.af3.component.model.Port;
import org.fortiss.tooling.base.model.layout.Dimension;
import org.fortiss.tooling.base.ui.editor.fx.EObjectBasedRectangularResizableContentControllerBase;
import javafx.geometry.Dimension2D;
import javafx.geometry.Side;
/**
* {@link IController} for sub-components of the component displayed in the diagram.
*
* @author hoelzl
*/
public final class SubComponentController
extends EObjectBasedRectangularResizableContentControllerBase {
/** Constructor. */
public SubComponentController(IContentMVCBundle mvcb) {
super(mvcb);
Object model = mvcb.getModel();
if(!(model instanceof Component)) {
throw new IllegalArgumentException("Expected model of type Component, but was " +
model.getClass().getSimpleName());
}
}
/** Returns the component. */
private Component getComponent() {
// wild cast works: see constructor
return (Component)getModel();
}
/** {@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 portObj = anchorage.getModel();
if(portObj instanceof Port) {
Port port = (Port)portObj;
// the following correction compensates for SubComponentPortVisual.getOffset()
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(port, convertSideToEOrientation(side), corrected);
}
}
/** {@inheritDoc} */
@Override
protected void move(FeedbackChange deltaChange) {
moveNode(getComponent(), (int)deltaChange.getDeltaX(), (int)deltaChange.getDeltaY());
}
/** {@inheritDoc} */
@Override
protected void resize(FeedbackChange delta) {
Component component = getComponent();
Dimension d = getNodeSize(component);
int w = d.getWidth() + (int)delta.getDeltaW();
int h = d.getHeight() + (int)delta.getDeltaH();
setNodeSize(component, w, h);
}
/** {@inheritDoc} */
@Override
protected Dimension2D getMinimumSize() {
return new Dimension2D(DEFAULT_SHAPE_MINIMUM_WIDTH, DEFAULT_SHAPE_MINIMUM_HEIGHT);
}
}
<!-- (c) 2019 fortiss GmbH -->
<body>
Package for controllers of the JavaFX-based editors of the AF3 component language.
</body>
ChannelVisual.java b381c8ff8d3c807b0efc0408f873a96d5db865a6 GREEN
DiagramComponentPortVisual.java 604db6f8979fdb307247fdce9aa1ca28837b55a4 GREEN
SubComponentPortVisual.java 5ccd54942b0306bc1354611856e9103fb174b0a8 GREEN
SubComponentVisual.java 974bb721aa15d16c16efd8c00bb67817d66f1065 GREEN
ContentComponentPortVisual.java 8c4b9e27d3bd314c9e11fd544dd2ff9ecd7b70d6 GREEN
ContentComponentVisual.java 9e3e2dbc823722a34c5b1e5fe1268e26ec5f8c38 GREEN
DiagramComponentPortVisual.java bbee9f118b4f6c6077f58d144643ac974c8526fe GREEN
......@@ -22,7 +22,7 @@ import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IContentAnchor
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.IContentVisual;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.component.model.Port;
import org.fortiss.tooling.base.ui.editor.fx.visuals.LayoutedCircularContentAnchorageVisualBase;
import org.fortiss.tooling.base.ui.editor.fx.visual.NamedLayoutedCircularAnchorageContentVisual;
import javafx.scene.paint.Paint;
......@@ -32,36 +32,20 @@ import javafx.scene.paint.Paint;
*
* @author hoelzl
* @author munaro
* @author diewald
*/
public final class SubComponentPortVisual
extends LayoutedCircularContentAnchorageVisualBase {
public final class ContentComponentPortVisual
extends NamedLayoutedCircularAnchorageContentVisual<Port> {
/** Constructor. */
public SubComponentPortVisual(IContentAnchorageMVCBundle mvcb) {
super(mvcb);
Object model = mvcb.getModel();
if(!(model instanceof Port)) {
throw new IllegalArgumentException(
"Expected model of type Port, but was " + model.getClass().getSimpleName());
}
}
/** Returns the port model element. */
private Port getPort() {
// wild cast works: see constructor.
return (Port)super.getModel();
}
/** {@inheritDoc} */
@Override
protected String getHoverText() {
return getPort().getName();
public ContentComponentPortVisual(IContentAnchorageMVCBundle mvcb) {
super(mvcb, Port.class);
}
/** {@inheritDoc} */
@Override
protected Paint getFillColor() {
Port p = getPort();
Port p = getModelElement();
if(p instanceof InputPort) {
return WHITE;
}
......
......@@ -15,16 +15,17 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.component.ui.editor.fx.visual;
import static org.fortiss.af3.component.ui.AF3ComponentUIActivator.convertColor;
import static org.fortiss.af3.component.ui.AF3ComponentUIActivator.getFXImage;
import static org.fortiss.af3.component.ui.DefaultStyle.STRONGLY_CAUSAL_COMPONENT_BACKGROUND;
import static org.fortiss.af3.component.ui.DefaultStyle.SUBSTRUCTURE_COMPONENT_BACKGROUND;
import static org.fortiss.af3.component.ui.DefaultStyle.WEAKLY_CAUSAL_COMPONENT_BACKGROUND;
import static org.fortiss.tooling.common.ui.javafx.util.GraphicUtils.convertColor;
import static org.fortiss.tooling.common.ui.javafx.util.GraphicUtils.getFXImage;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IContentMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.IContentVisual;
import org.fortiss.af3.component.model.Component;
import org.fortiss.tooling.base.ui.editor.fx.visuals.LayoutedRectangularContentVisualBase;
import org.fortiss.af3.component.ui.AF3ComponentUIActivator;
import org.fortiss.tooling.base.ui.editor.fx.visual.NamedLayoutedRectangularContentVisual;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
......@@ -35,9 +36,14 @@ import javafx.scene.paint.Paint;
*
* @author hoelzl
* @author munaro
* @author diewald
*/
public final class SubComponentVisual
extends LayoutedRectangularContentVisualBase {
public final class ContentComponentVisual extends NamedLayoutedRectangularContentVisual<Component> {
/** The plug-in ID. */
public static final String PLUGIN_ID = AF3ComponentUIActivator.class.getPackage().getName();
/** The icon image. */
private static final Image ICON = getFXImage(PLUGIN_ID, "/icons/component.gif");
/** The fill color used by composite components. */
private static final Color COMPOSITE_COLOR = convertColor(SUBSTRUCTURE_COMPONENT_BACKGROUND);
/** The fill color used by strongly causal components. */
......@@ -46,29 +52,16 @@ public final class SubComponentVisual
/** The fill color used by weakly causal components. */
private static final Color WEAKLY_CAUSAL_COLOR =
convertColor(WEAKLY_CAUSAL_COMPONENT_BACKGROUND);
/** The icon image. */
private static final Image ICON = getFXImage("/icons/component.gif");
/** Constructor. */
public SubComponentVisual(IContentMVCBundle mvcb) {