Commit abaf0e0f authored by Alexander Diewald's avatar Alexander Diewald
Browse files

Merge branch '3815-lwfxef-integration' into 'master'

3815 LWFXEditorFramework integration and FX Component Editor

See merge request af3/af3!260
parents b4926945 0db7cdba
......@@ -141,6 +141,11 @@
modelElementClass="org.fortiss.af3.component.model.behavior.code.CodeSpecification">
</modelElementClass>
</modelEditorBinding>
<modelEditorBinding
binding="org.fortiss.af3.component.ui.editor.fx.ComponentStructureFXEditorBinding">
<modelElementClass
modelElementClass="org.fortiss.af3.component.model.Component"></modelElementClass>
</modelEditorBinding>
</extension>
<extension
point="org.eclipse.ui.views.properties.tabbed.propertySections">
......
AF3ComponentUIActivator.java 99d0d05a3c61577b03724ff46eb6411d6ffbf110 GREEN
AF3ComponentUIActivator.java 235a4ae290abdc80966f4bb340a21cbc89260a70 YELLOW
DefaultStyle.java c3b60c89b4917e9d8514812ee1884010d142b616 GREEN
......@@ -15,6 +15,10 @@
+--------------------------------------------------------------------------*/
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;
......@@ -22,13 +26,15 @@ 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.
*
* @author hoelzl
*/
public class AF3ComponentUIActivator extends AbstractUIPlugin {
/** The plug-in ID. */
public static final String PLUGIN_ID = AF3ComponentUIActivator.class.getPackage().getName(); // $NON-NLS-1$
......@@ -64,4 +70,40 @@ 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
/*-------------------------------------------------------------------------+
| Copyright 2011 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 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;
import org.fortiss.tooling.kernel.ui.extension.base.LWFXEFEditorBase;
import javafx.geometry.Dimension2D;
/**
* Graphical editor for component structures based on JavaFX.
*
* @author hoelzl
*/
public class ComponentStructureFXEditor extends LWFXEFEditorBase<Component> {
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public Class<? extends EObject>[] getVisibleEObjectTypes() {
return new Class[] {Component.class, InputPort.class, OutputPort.class};
}
/** {@inheritDoc} */
@Override
protected void customizeViewer() {
DiagramViewerFeatures features = viewer.getFeatures();
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();
}
}
/*-------------------------------------------------------------------------+
| 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.ui.IEditorPart;
import org.fortiss.af3.component.model.Component;
import org.fortiss.tooling.kernel.ui.extension.base.ModelEditorBindingBase;
/**
* Editor binding for the JavaFX-based component structure editor.
*
* @author hoelzl
*/
public final class ComponentStructureFXEditorBinding extends ModelEditorBindingBase<Component> {
/** {@inheritDoc} */
@Override
public Class<? extends IEditorPart> getEditorClass() {
return ComponentStructureFXEditor.class;
}
/** {@inheritDoc} */
@Override
public String getLabel() {
return "Component Structure (FX)";
}
/** {@inheritDoc} */
@Override
public int getPriority() {
return -100;
}
}
/*-------------------------------------------------------------------------+
| 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.controller.IControllerFactory;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IContentAnchorageMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IContentMVCBundle;
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;
/**
* The implementation of the {@link IControllerFactory} for the component editor.
*
* @author hoelzl
*/
final class ControllerFactory implements IControllerFactory {
/** {@inheritDoc} */
@Override
public IController createContentController(IContentMVCBundle model) {
return new SubComponentController(model);
}
/** {@inheritDoc} */
@Override
public IController createDiagramAnchorageController(IDiagramAnchorageMVCBundle modelBundle) {
return new DiagramComponentPortController(modelBundle);
}
/** {@inheritDoc} */
@Override
public IController createContentAnchorageController(IContentAnchorageMVCBundle modelBundle) {
return new SubComponentPortController(modelBundle);
}
/** {@inheritDoc} */
@Override
public IController createLinkController(ILinkMVCBundle modelBundle) {
return new ChannelController(modelBundle);
}
/** {@inheritDoc} */
@Override
public IController createDiagramController(IDiagramMVCBundle diagramBundle) {
return new DiagramController(diagramBundle);
}
}
/*-------------------------------------------------------------------------+
| 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 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.af3.component.model.Channel;
import org.fortiss.af3.component.model.Component;
import org.fortiss.tooling.base.model.element.IConnection;
/**
* The implementation of the {@link IModelFactory} for the component editor.
*
* @author hoelzl
*/
final class ModelFactory implements IModelFactory {
/** The currently edited component. */
private final Component rootElement;
/** Constructor. */
public ModelFactory(Component root) {
this.rootElement = requireNonNull(root);
}
/** {@inheritDoc} */
@Override
public Object getRootModel() {
return rootElement;
}
/** {@inheritDoc} */
@Override
public List<?> getContentModels() {
return rootElement.getSubComponents();
}
/** {@inheritDoc} */
@Override
public List<?> getDiagramAnchorageModels() {
return rootElement.getConnectors();
}
/** {@inheritDoc} */
@Override
public List<?> getContentAnchorageModels(Object parent) {
if(parent instanceof Component) {
return ((Component)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 Channel) {
return ((Channel)link).getSource();
}
return null;
}
/** {@inheritDoc} */
@Override
public Object getLinkEnd(Object link) {
if(link instanceof Channel) {
return ((Channel)link).getTarget();
}
return null;
}
/** {@inheritDoc} */
@Override
public Object getParent(Object element) {
return null;
}
/** {@inheritDoc} */
@Override
public void update() {
// ignored
}
}
/*-------------------------------------------------------------------------+
| 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.mvc.IContentAnchorageMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IContentMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IDiagramAnchorageMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.ILinkMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.IContentAnchorageVisual;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.IContentVisual;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.IDiagramAnchorageVisual;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.ILinkVisual;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.IVisualFactory;
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.DiagramComponentPortVisual;
import org.fortiss.af3.component.ui.editor.fx.visual.SubComponentPortVisual;
import org.fortiss.af3.component.ui.editor.fx.visual.SubComponentVisual;
/**
* The implementation of the {@link IVisualFactory} for the component editor.
*
* @author hoelzl
*/
final class VisualFactory implements IVisualFactory {
/** {@inheritDoc} */
@Override
public IContentVisual createContentVisual(IContentMVCBundle modelBundle) {
Object modelObj = modelBundle.getModel();
if(modelObj instanceof Component) {
return new SubComponentVisual(modelBundle);
}
return null;
}
/** {@inheritDoc} */
@Override
public IDiagramAnchorageVisual
createDiagramAnchorageVisual(IDiagramAnchorageMVCBundle modelBundle) {
Object anchorageObj = modelBundle.getModel();
if(anchorageObj instanceof Port) {
return new DiagramComponentPortVisual(modelBundle);
}
return null;
}
/** {@inheritDoc} */
@Override
public IContentAnchorageVisual
createContentAnchorageVisual(IContentAnchorageMVCBundle modelBundle) {
Object anchorageObj = modelBundle.getModel();
if(anchorageObj instanceof Port) {
return new SubComponentPortVisual(modelBundle);
}
return null;
}
/** {@inheritDoc} */
@Override
public ILinkVisual createLinkVisual(ILinkMVCBundle modelBundle) {
Object linkObj = modelBundle.getModel();
if(linkObj instanceof Channel) {
return new ChannelVisual(modelBundle);
}
return null;
}
}
ChannelController.java fe3fd8b71f320e93fa8581298581af6a9d5f8aee YELLOW
DiagramComponentPortController.java c99d075a9bc6b9c4214dee19aa5fd634ca5be379 YELLOW
DiagramController.java 74e96ce04d715a8084eb5d20b74567bc0168910d YELLOW
SubComponentController.java 3fe6f80d4fec036983523b78a8a1892c7716cbda GREEN
SubComponentPortController.java ce6b20088baeb1ddd5c98111316f707f71cd133e 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.af3.component.ui.editor.fx.controller;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.IController;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.ILinkMVCBundle;
import org.fortiss.af3.component.model.Channel;
import org.fortiss.tooling.base.ui.editor.fx.LayoutedModelElementBasedLinkBendPointController;
/**
* {@link IController} for {@link Channel}s.
*
* @author hoelzl
*/
public final class ChannelController extends LayoutedModelElementBasedLinkBendPointController {
/** Constructor. */
public ChannelController(ILinkMVCBundle mvcb) {
super(mvcb);
Object model = mvcb.getModel();
if(!(model instanceof Channel)) {
throw new IllegalArgumentException(
"Expected model of type Channel, but was " + model.getClass().getSimpleName());
}
}
/** Returns the channel model element. */
public Channel getChannel() {
// wild cast works: see constructor
return (Channel)getModel();
}
/** {@inheritDoc} */
@Override
protected boolean clampAndSnapBendPointToGridCenter() {
// disable default mode
return false;
}
/** {@inheritDoc} */
@Override
protected boolean clampAndSnapBendPointToGrid() {
// enable clamping mode
return true;
}
}
/*-------------------------------------------------------------------------+
| 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 org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.IController;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IMVCBundle;
import org.fortiss.af3.component.model.Port;
import org.fortiss.tooling.base.ui.editor.fx.LayoutedModelElementBasedDiagramAnchorageController;
/**
* {@link IController} for the ports of the component displayed in the diagram (i.e. on the
* background).
*
* @author hoelzl
*/
public final class DiagramComponentPortController