From 2cd8f1a55e0284d9c5a7663b2b964a9778ad83d3 Mon Sep 17 00:00:00 2001 From: Florian Hoelzl <hoelzl@fortiss.org> Date: Mon, 25 Nov 2019 13:47:29 +0100 Subject: [PATCH] Kernel: JavaFX editor. Added base classes for extendable LWFXEF editor. Issue-Ref: 3870 Issue-Url: https://af3-developer.fortiss.org/issues/3815 Signed-off-by: Florian Hoelzl <hoelzl@fortiss.org> --- .../base/ui/editor/fx/delegating/.ratings | 4 + .../DelegatingControllerFactoryBase.java | 75 +++++++++++++++++++ .../fx/delegating/DelegatingFactoryBase.java | 44 +++++++++++ .../DelegatingModelFactoryBase.java | 62 +++++++++++++++ .../DelegatingVisualFactoryBase.java | 70 +++++++++++++++++ 5 files changed, 255 insertions(+) create mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/.ratings create mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/DelegatingControllerFactoryBase.java create mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/DelegatingFactoryBase.java create mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/DelegatingModelFactoryBase.java create mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/DelegatingVisualFactoryBase.java diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/.ratings new file mode 100644 index 000000000..56ae5dd34 --- /dev/null +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/.ratings @@ -0,0 +1,4 @@ +DelegatingControllerFactoryBase.java dea6b5dc56a157f0125bfe5c176e993d376b66b2 YELLOW +DelegatingFactoryBase.java 37955dec868a0cb0e12986997c0078e0348e9e16 YELLOW +DelegatingModelFactoryBase.java 413dcfad6542ffbc9a9504d08c17f6741ec3b01c YELLOW +DelegatingVisualFactoryBase.java 4ec6971399df993b4cbd6d6ced6e801d914e1ae4 YELLOW diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/DelegatingControllerFactoryBase.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/DelegatingControllerFactoryBase.java new file mode 100644 index 000000000..dea6b5dc5 --- /dev/null +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/DelegatingControllerFactoryBase.java @@ -0,0 +1,75 @@ +/*-------------------------------------------------------------------------+ +| 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.delegating; + +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.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IMVCBundle; +import org.fortiss.tooling.kernel.service.ITransformationService; + +/** + * Base class for {@link IControllerFactory controller factories} of extendable graphical LWFXEF + * editors. + * <P> + * This class uses the {@link ITransformationService} to find a delegate controller factory for the + * model elements in question. + * + * @author hoelzl + */ +public abstract class DelegatingControllerFactoryBase extends DelegatingFactoryBase + implements IControllerFactory { + /** Uses the {@link ITransformationService} to find a delegate {@link IControllerFactory}. */ + private IControllerFactory getDelegateControllerFactory(IMVCBundle modelBundle) { + return getDelegationResult(modelBundle.getModel(), IControllerFactory.class); + } + + /** {@inheritDoc} */ + @Override + public IController createContentController(IContentMVCBundle modelBundle) { + return getDelegateControllerFactory(modelBundle).createContentController(modelBundle); + } + + /** {@inheritDoc} */ + @Override + public IController createDiagramAnchorageController(IDiagramAnchorageMVCBundle modelBundle) { + return getDelegateControllerFactory(modelBundle) + .createDiagramAnchorageController(modelBundle); + } + + /** {@inheritDoc} */ + @Override + public IController createContentAnchorageController(IContentAnchorageMVCBundle modelBundle) { + return getDelegateControllerFactory(modelBundle) + .createContentAnchorageController(modelBundle); + } + + /** {@inheritDoc} */ + @Override + public IController createLinkController(ILinkMVCBundle modelBundle) { + return getDelegateControllerFactory(modelBundle).createLinkController(modelBundle); + } + + /** {@inheritDoc} */ + @Override + public IController createDiagramController(IDiagramMVCBundle diagramBundle) { + return getDelegateControllerFactory(diagramBundle).createDiagramController(diagramBundle); + } +} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/DelegatingFactoryBase.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/DelegatingFactoryBase.java new file mode 100644 index 000000000..37955dec8 --- /dev/null +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/DelegatingFactoryBase.java @@ -0,0 +1,44 @@ +/*-------------------------------------------------------------------------+ +| 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.delegating; + +import org.fortiss.tooling.kernel.extension.exception.TransformationFailedException; +import org.fortiss.tooling.kernel.service.ITransformationService; + +/** + * Base class for delegating request to the transformation service. + * + * @author hoelzl + */ +abstract class DelegatingFactoryBase { + /** The transformation service. */ + protected final static ITransformationService SERVICE = ITransformationService.getInstance(); + + /** Tries to transform the given object into the given target class. */ + @SuppressWarnings("unchecked") + protected <T> T getDelegationResult(Object model, Class<T> targetType) { + Exception ex = null; + try { + if(SERVICE.canTransform(model, targetType, null)) { + return (T)SERVICE.transform(model, targetType, null); + } + } catch(TransformationFailedException tfex) { + ex = tfex; + } + throw new IllegalArgumentException("Missing transformation from '" + + model.getClass().getName() + "' to '" + targetType.getName(), ex); + } +} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/DelegatingModelFactoryBase.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/DelegatingModelFactoryBase.java new file mode 100644 index 000000000..413dcfad6 --- /dev/null +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/DelegatingModelFactoryBase.java @@ -0,0 +1,62 @@ +/*-------------------------------------------------------------------------+ +| 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.delegating; + +import java.util.List; + +import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.model.IModelFactory; +import org.fortiss.tooling.kernel.service.ITransformationService; + +/** + * Base class for {@link IModelFactory model factories} of extendable graphical LWFXEF + * editors. + * <P> + * This class uses the {@link ITransformationService} to find a delegate model factory for the + * model elements in question. + * + * @author hoelzl + */ +public abstract class DelegatingModelFactoryBase extends DelegatingFactoryBase + implements IModelFactory { + /** Uses the {@link ITransformationService} to find a delegate {@link IModelFactory}. */ + private IModelFactory getDelegateModelFactory(Object model) { + return getDelegationResult(model, IModelFactory.class); + } + + /** {@inheritDoc} */ + @Override + public List<?> getContentAnchorageModels(Object parent) { + return getDelegateModelFactory(parent).getContentAnchorageModels(parent); + } + + /** {@inheritDoc} */ + @Override + public Object getLinkStart(Object link) { + return getDelegateModelFactory(link).getLinkStart(link); + } + + /** {@inheritDoc} */ + @Override + public Object getLinkEnd(Object link) { + return getDelegateModelFactory(link).getLinkEnd(link); + } + + /** {@inheritDoc} */ + @Override + public Object getParent(Object element) { + return getDelegateModelFactory(element).getParent(element); + } +} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/DelegatingVisualFactoryBase.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/DelegatingVisualFactoryBase.java new file mode 100644 index 000000000..4ec697139 --- /dev/null +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/delegating/DelegatingVisualFactoryBase.java @@ -0,0 +1,70 @@ +/*-------------------------------------------------------------------------+ +| 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.delegating; + +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.mvc.IMVCBundle; +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.tooling.kernel.service.ITransformationService; + +/** + * Base class for {@link IVisualFactory visual factories} of extendable graphical LWFXEF editors. + * <P> + * This class uses the {@link ITransformationService} to find a delegate visual factory for the + * model elements in question. + * + * @author hoelzl + */ +public abstract class DelegatingVisualFactoryBase extends DelegatingFactoryBase + implements IVisualFactory { + /** Uses the {@link ITransformationService} to find a delegate {@link IVisualFactory}. */ + private IVisualFactory getDelegateVisualFactory(IMVCBundle modelBundle) { + return getDelegationResult(modelBundle.getModel(), IVisualFactory.class); + } + + /** {@inheritDoc} */ + @Override + public IContentVisual createContentVisual(IContentMVCBundle modelBundle) { + return getDelegateVisualFactory(modelBundle).createContentVisual(modelBundle); + } + + /** {@inheritDoc} */ + @Override + public IDiagramAnchorageVisual + createDiagramAnchorageVisual(IDiagramAnchorageMVCBundle modelBundle) { + return getDelegateVisualFactory(modelBundle).createDiagramAnchorageVisual(modelBundle); + } + + /** {@inheritDoc} */ + @Override + public IContentAnchorageVisual + createContentAnchorageVisual(IContentAnchorageMVCBundle modelBundle) { + return getDelegateVisualFactory(modelBundle).createContentAnchorageVisual(modelBundle); + } + + /** {@inheritDoc} */ + @Override + public ILinkVisual createLinkVisual(ILinkMVCBundle modelBundle) { + return getDelegateVisualFactory(modelBundle).createLinkVisual(modelBundle); + } +} -- GitLab