Commit e3901471 authored by Alexander Diewald's avatar Alexander Diewald

JFX diagram editors: Delegation factories for extensibility

* Only use delegate factories in the FX editor base. By that all editors
  are extensible.
* Move the definition of the factories of one editor from the editor to
  its bindings.
* Create the concrete factories by reflection when a FX editor is
  constructed.

Issue-Ref: 3883
Issue-Url: https://af3-developer.fortiss.org/issues/3883Signed-off-by: Alexander Diewald's avatarAlexander Diewald <diewald@fortiss.org>
parent 962da433
......@@ -26,7 +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.model,
org.fortiss.tooling.base.ui.editor.fx.visual,
org.fortiss.tooling.base.ui.editpart,
org.fortiss.tooling.base.ui.editpart.allocation,
......
DelegatingControllerFactoryBase.java dea6b5dc56a157f0125bfe5c176e993d376b66b2 YELLOW
DelegatingFactoryBase.java 37955dec868a0cb0e12986997c0078e0348e9e16 YELLOW
DelegatingModelFactoryBase.java 413dcfad6542ffbc9a9504d08c17f6741ec3b01c YELLOW
DelegatingVisualFactoryBase.java 4ec6971399df993b4cbd6d6ced6e801d914e1ae4 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.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);
}
}
HierarchicElementModelFactoryBase.java 21c18441961971ca89802e4047b27a31db8499a9 YELLOW
DelegatingControllerFactoryBase.java dea6b5dc56a157f0125bfe5c176e993d376b66b2 YELLOW
DelegatingFactoryBase.java 37955dec868a0cb0e12986997c0078e0348e9e16 YELLOW
DelegatingModelFactoryBase.java 413dcfad6542ffbc9a9504d08c17f6741ec3b01c YELLOW
DelegatingVisualFactoryBase.java 4ec6971399df993b4cbd6d6ced6e801d914e1ae4 YELLOW
HierarchicElementModelFactoryBase.java 9996bfc1402c27424f0ae69e64560acce0ef81f4 YELLOW
......@@ -13,7 +13,7 @@
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editor.fx.factory;
package org.fortiss.tooling.base.ui.editor.fx.model;
import static java.util.Collections.emptyList;
import static java.util.Objects.requireNonNull;
......
......@@ -4,11 +4,12 @@ Bundle-Name: Tooling Kernel UI
Bundle-SymbolicName: org.fortiss.tooling.kernel.ui;singleton:=true
Bundle-Version: 2.16.0.qualifier
Bundle-Activator: org.fortiss.tooling.kernel.ui.ToolingKernelUIActivator
Require-Bundle: org.fortiss.tooling.common.ui;bundle-version="2.16.0";visibility:=reexport,
org.fortiss.tooling.kernel;bundle-version="2.16.0";visibility:=reexport,
Require-Bundle: org.fortiss.tooling.common.ui;visibility:=reexport,
org.fortiss.tooling.kernel;visibility:=reexport,
org.eclipse.core.resources;visibility:=reexport,
org.eclipse.emf.databinding;visibility:=reexport,
org.eclipse.core.databinding.property;visibility:=reexport
org.eclipse.core.databinding.property;visibility:=reexport,
com.google.guava;visibility:=reexport
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-11
Bundle-Vendor: fortiss GmbH
......
......@@ -4,7 +4,7 @@ IContextMenuContributor.java 0f09c76662c154cf52ddab61b417e82a42854162 GREEN
IContextMenuMultiSelectionContributor.java 125b31dd38009bc2095b7e6bc860e946e39f58c4 GREEN
IEditPartFactory.java 5729715847f553d95a5bad4a9211c7e6f458badd GREEN
IModelEditor.java 962d7f7758abc88bbc6064c8b4eb32da00abf8e8 GREEN
IModelEditorBinding.java a3d5c344f61fa6f12ab944a4e933a557d6e7011b GREEN
IModelEditorBinding.java 809c43872305441495f0ece63ea1004cb37f22b4 YELLOW
IModelElementHandler.java 21b4a96251e0267f156b4b8f2b95a97f6e81e646 GREEN
ITutorialStepUI.java b8aee2b95857484ab6ad9ecd55b5de9f0ea158e5 GREEN
ITutorialUIProvider.java aa0ff5db4d7ba0953e34edeb99f3e8279567e18f GREEN
......
......@@ -16,6 +16,9 @@
package org.fortiss.tooling.kernel.ui.extension;
import org.eclipse.emf.ecore.EObject;
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.tooling.kernel.service.base.IEObjectAware;
import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService;
......@@ -24,8 +27,10 @@ import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService;
* Interface for editor bindings. An editor binding a defines a model element
* editor. Usually, an editor (in the Eclipse interpretation) is a view (in the
* model-based development interpretation) on the underlying model.
*
* <P>
* <p>
* This interface also specifies bindings to those MVC factories that are responsible for the
* interaction of the editor with the model, its presentation, and behavior.
* <p>
* Each editor provided by some binding becomes part of an Eclipse multi-page editor. Its page
* carries the name delivered by {@link #getLabel}. The {@link IModelEditorBindingService} sorts the
* provided editors according to their priority returned by {@link #getPriority} with higher values
......@@ -40,6 +45,15 @@ public interface IModelEditorBinding<T extends EObject> extends IEObjectAware<EO
/** Returns the class of the editor registered by this binding. */
Class<? extends IEditorPart> getEditorClass(T object);
/** Returns the {@link IModelFactory} to instantiate for the {@link IEditorPart}. */
Class<? extends IModelFactory> getModelFactory();
/** Returns the {@link IVisualFactory} to instantiate for the {@link IEditorPart}. */
Class<? extends IVisualFactory> getVisualFactory();
/** Returns the {@link IControllerFactory} to instantiate for the {@link IEditorPart}. */
Class<? extends IControllerFactory> getControllerFactory();
/** Returns the label of the editor. */
String getLabel(T object);
......
......@@ -7,8 +7,8 @@ EReferencePropertySectionBase.java 0548da6778516003257f59d0b4c2b60d458be3b6 GREE
EditorBase.java 9c09fff92945256bb8680992ae7bb2c78f47b150 GREEN
FXEditorBase.java 2e520be0bbae7d0aebdff70218a124dbe0896ce2 GREEN
IListPropertySection.java 8bb00fe7959583e794ff9437b7a77404c9a9e70f GREEN
LWFXEFEditorBase.java 0b8e6af85d83d0542dcd908974e52c618bc22a08 GREEN
ModelEditorBindingBase.java 4c5ac569c0b6e7678fc8191096b26dfd09fdcb98 GREEN
LWFXEFEditorBase.java 121fd466f47bbfe0236834db1ad30efae6db219a YELLOW
ModelEditorBindingBase.java c258cb0ea28d74440856cd2abf367408fbbc1279 YELLOW
ModelElementHandlerBase.java 384727748f125c9d43f19d9c0eba4ba1be5a7a26 GREEN
MultiEObjectActionBase.java 9e237d8ea640c4194e4877af4a9cfce88698e543 GREEN
NamedCommentedModelElementHandlerBase.java 681b98b50b362f01abb7a36f108f4f11b9e51829 GREEN
......
......@@ -15,8 +15,11 @@
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.extension.base;
import static java.util.stream.Collectors.toList;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ISelection;
......@@ -32,14 +35,21 @@ import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.IContro
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.model.IModelFactory;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.IVisualFactory;
import org.eclipse.ui.IEditorPart;
import org.fortiss.tooling.kernel.service.ICommandStackService;
import org.fortiss.tooling.kernel.ui.extension.IModelEditorBinding;
import org.fortiss.tooling.kernel.ui.extension.base.factory.DelegatingControllerFactory;
import org.fortiss.tooling.kernel.ui.extension.base.factory.DelegatingModelFactory;
import org.fortiss.tooling.kernel.ui.extension.base.factory.DelegatingVisualFactory;
import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService;
import javafx.scene.Parent;
/**
* Base implementation of model element editors which are using LWFXEF DiaViewer.
* Base class for JavaFX-based {@link IEditorPart}s that display diagrams of {@link EObject}s.
*
* @author hoelzlf
* @author hoelzl
* @author diewald
*/
public abstract class LWFXEFEditorBase<T extends EObject> extends FXEditorBase<T>
implements ISelectionProvider {
......@@ -48,30 +58,54 @@ public abstract class LWFXEFEditorBase<T extends EObject> extends FXEditorBase<T
/** The list of {@link ISelectionChangedListener}s. */
private final List<ISelectionChangedListener> selectionListeners = new ArrayList<>();
/** References the delegating {@link IModelFactory} of this JavaFX {@link IEditorPart}. */
private IModelFactory delegatingModelFactory;
/** References the delegating {@link IModelFactory} of this JavaFX {@link IEditorPart}. */
private IVisualFactory delegatingVisualFactory;
/** References the delegating {@link IModelFactory} of this JavaFX {@link IEditorPart}. */
private IControllerFactory delegatingControllerFactory;
/** {@inheritDoc} */
@Override
protected final Parent createSceneRoot() {
viewer = new DiagramViewer(createModelFactory(), createVisualFactory(),
createControllerFactory(), cb -> modelSelected(), chg -> applyModelChange(chg));
constructMVCFactories();
viewer = new DiagramViewer(delegatingModelFactory, delegatingVisualFactory,
delegatingControllerFactory, cb -> modelSelected(), chg -> applyModelChange(chg));
customizeViewer();
getSite().setSelectionProvider(this);
return viewer.getVisualNode();
}
/**
* Constructs delegating factories that wrap all factories registered by
* {@link IModelEditorBinding}s for the edited type. Delegating factories are used for extending
* editors of the same type.
*/
protected void constructMVCFactories() {
List<IModelEditorBinding<EObject>> bindings =
IModelEditorBindingService.getInstance().getBindings(editedObject);
bindings.removeIf(b -> !LWFXEFEditorBase.class.isAssignableFrom(b.getEditorClass(null)));
List<Class<? extends IModelFactory>> modelFactories = bindings.stream()
.map(b -> b.getModelFactory()).filter(Objects::nonNull).collect(toList());
List<Class<? extends IVisualFactory>> visualFactories = bindings.stream()
.map(b -> b.getVisualFactory()).filter(Objects::nonNull).collect(toList());
List<Class<? extends IControllerFactory>> controllerFactories = bindings.stream()
.map(b -> b.getControllerFactory()).filter(Objects::nonNull).collect(toList());
delegatingModelFactory = new DelegatingModelFactory(modelFactories, editedObject);
delegatingVisualFactory = new DelegatingVisualFactory(visualFactories);
delegatingControllerFactory = new DelegatingControllerFactory(controllerFactories);
}
/** Customize the viewer after it is created. The default implementation changes nothing. */
protected void customizeViewer() {
// the default does nothing
}
/** Create the {@link IModelFactory}. */
protected abstract IModelFactory createModelFactory();
/** Create the {@link IVisualFactory}. */
protected abstract IVisualFactory createVisualFactory();
/** Create the {@link IControllerFactory}. */
protected abstract IControllerFactory createControllerFactory();
/** Called when a model element is selected in the diagram viewer. */
protected void modelSelected() {
getSite().getSelectionProvider().setSelection(createSelection());
......
......@@ -16,6 +16,9 @@
package org.fortiss.tooling.kernel.ui.extension.base;
import org.eclipse.emf.ecore.EObject;
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.tooling.kernel.service.base.IEObjectAware;
import org.fortiss.tooling.kernel.ui.extension.IModelEditorBinding;
import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService;
......@@ -34,6 +37,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService;
* @see IModelEditorBindingService
*
* @author hoelzl
* @author diewald
*/
public abstract class ModelEditorBindingBase<T extends EObject>
implements IEObjectAware<EObject>, IModelEditorBinding<T> {
......@@ -48,6 +52,30 @@ public abstract class ModelEditorBindingBase<T extends EObject>
return getEditorClass(null);
}
/** {@inheritDoc} */
@Override
public Class<? extends IModelFactory> getModelFactory() {
throw new UnsupportedOperationException("This method shall only be called from FX" +
" editors. Ensure to define the model factory in the editor binding. Remove" +
" this method when the ediors are migrated to JavaFX.");
}
/** {@inheritDoc} */
@Override
public Class<? extends IVisualFactory> getVisualFactory() {
throw new UnsupportedOperationException("This method shall only be called from FX" +
" editors. Ensure to define the visual factory in the editor binding. Remove" +
" this method when the ediors are migrated to JavaFX.");
}
/** {@inheritDoc} */
@Override
public Class<? extends IControllerFactory> getControllerFactory() {
throw new UnsupportedOperationException("This method shall only be called from FX" +
" editors. Ensure to define the controller factory in the editor binding. Remove" +
" this method when the ediors are migrated to JavaFX.");
}
/** Returns the label of editor */
@Override
public String getLabel(T object) {
......
DelegatingControllerFactory.java ad214d83b5821b39862b7c382c91a13c3dfddbd0 YELLOW
DelegatingFactoryBase.java f421742267610f41bb6196346026d2f239d90ed0 YELLOW
DelegatingModelFactory.java ea7c3e1c612101bb3ba71d7dc97893783c0319a3 YELLOW
DelegatingVisualFactory.java 7e834acd12ae4d1c2b2b32a5456dc9f2b6d4e466 YELLOW
......@@ -13,7 +13,10 @@
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editor.fx.delegating;
package org.fortiss.tooling.kernel.ui.extension.base.factory;
import java.util.List;
import java.util.Optional;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.IController;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.IControllerFactory;
......@@ -23,53 +26,86 @@ import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IDiagramAnchor
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.
* Delegates the creational calls to concrete {@link IControllerFactory}s. The first non-null
* element returned by the factories of the initially given list is returned. If no element is
* created (all delegates returned null), this factory throws a {@link RuntimeException}.
*
* @author hoelzl
* @author diewald
*/
public abstract class DelegatingControllerFactoryBase extends DelegatingFactoryBase
public class DelegatingControllerFactory extends DelegatingFactoryBase<IControllerFactory>
implements IControllerFactory {
/** Uses the {@link ITransformationService} to find a delegate {@link IControllerFactory}. */
private IControllerFactory getDelegateControllerFactory(IMVCBundle modelBundle) {
return getDelegationResult(modelBundle.getModel(), IControllerFactory.class);
/** Constructor. */
public DelegatingControllerFactory(List<Class<? extends IControllerFactory>> factories) {
super(factories, null);
}
/** {@inheritDoc} */
@Override
public IController createContentController(IContentMVCBundle modelBundle) {
return getDelegateControllerFactory(modelBundle).createContentController(modelBundle);
Optional<IController> controller =
getDelegateFactories().stream().map(f -> f.createContentController(modelBundle))
.filter(cc -> cc != null).findFirst();
if(controller.isPresent()) {
return controller.get();
}
throw createNoControllerException(modelBundle);
}
/** {@inheritDoc} */
@Override
public IController createDiagramAnchorageController(IDiagramAnchorageMVCBundle modelBundle) {
return getDelegateControllerFactory(modelBundle)
.createDiagramAnchorageController(modelBundle);
Optional<IController> controller = getDelegateFactories().stream()
.map(f -> f.createDiagramAnchorageController(modelBundle)).filter(cc -> cc != null)
.findFirst();
if(controller.isPresent()) {
return controller.get();
}
throw createNoControllerException(modelBundle);
}
/** {@inheritDoc} */
@Override
public IController createContentAnchorageController(IContentAnchorageMVCBundle modelBundle) {
return getDelegateControllerFactory(modelBundle)
.createContentAnchorageController(modelBundle);
Optional<IController> controller = getDelegateFactories().stream()
.map(f -> f.createContentAnchorageController(modelBundle)).filter(cc -> cc != null)
.findFirst();
if(controller.isPresent()) {
return controller.get();
}
throw createNoControllerException(modelBundle);
}
/** {@inheritDoc} */
@Override
public IController createLinkController(ILinkMVCBundle modelBundle) {
return getDelegateControllerFactory(modelBundle).createLinkController(modelBundle);
Optional<IController> controller = getDelegateFactories().stream()
.map(f -> f.createLinkController(modelBundle)).filter(cc -> cc != null).findFirst();
if(controller.isPresent()) {
return controller.get();
}
throw createNoControllerException(modelBundle);
}
/** {@inheritDoc} */
@Override
public IController createDiagramController(IDiagramMVCBundle diagramBundle) {
return getDelegateControllerFactory(diagramBundle).createDiagramController(diagramBundle);
Optional<IController> controller = getDelegateFactories().stream().map(f -> {
return f.createDiagramController(diagramBundle);
}).filter(cc -> cc != null).findFirst();
if(controller.isPresent()) {
return controller.get();
}
throw createNoControllerException(diagramBundle);
}
/** Throws a runtime exception indicating a missing controller. */
private RuntimeException createNoControllerException(IMVCBundle modelBundle) {
return new RuntimeException("No controller has been specified for model elements of the" +
" type " + modelBundle.getModel().getClass().getSimpleName() + ". Please check" +
" the editor bindings and the delegate controllers.");
}
}
......@@ -13,50 +13,67 @@
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editor.fx.delegating;
package org.fortiss.tooling.kernel.ui.extension.base.factory;
import static java.util.stream.Collectors.toList;
import static org.apache.commons.lang3.reflect.ConstructorUtils.getMatchingAccessibleConstructor;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.fortiss.tooling.kernel.ui.ToolingKernelUIActivator;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.model.IModelFactory;
import org.fortiss.tooling.kernel.service.ITransformationService;
import com.google.common.collect.ImmutableList;
/**
* 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.
* Base class for delegating MVC factories that wrap 1..n factories for editors of a defined type.
*
* @author hoelzl
* @author diewald
*/
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);
}
/* package */ abstract class DelegatingFactoryBase<T> {
/** {@inheritDoc} */
@Override
public List<?> getContentAnchorageModels(Object parent) {
return getDelegateModelFactory(parent).getContentAnchorageModels(parent);
}
/** References the edited Object in case it is needed by some factory. May be {@code null}. */
protected final Object editedObject;
/** References the */
private List<T> delegateFactories = new ArrayList<>();
/** Constructor. */
protected DelegatingFactoryBase(List<Class<? extends T>> factories, Object editedObject) {
this.editedObject = editedObject;
/** {@inheritDoc} */
@Override
public Object getLinkStart(Object link) {
return getDelegateModelFactory(link).getLinkStart(link);
delegateFactories = factories.stream().map(fCls -> constructFactory(fCls))
.flatMap(Optional::stream).collect(toList());
}
/** {@inheritDoc} */
@Override
public Object getLinkEnd(Object link) {
return getDelegateModelFactory(link).getLinkEnd(link);
/** Creates an instance of the given {@code delegateFactory}. */
protected Optional<? extends T> constructFactory(Class<? extends T> delegateFactory) {
Constructor<? extends T> ctor = null;
try {
ctor = getMatchingAccessibleConstructor(delegateFactory);
try {
return Optional.of(ctor.newInstance());
} catch(InstantiationException | IllegalAccessException | IllegalArgumentException |
InvocationTargetException e) {
error(ToolingKernelUIActivator.getDefault(), "Failed to instantiate the factory " +
delegateFactory.getSimpleName() + ".");
return Optional.empty();
}
} catch(NullPointerException | SecurityException e1) {
error(ToolingKernelUIActivator.getDefault(), "The factory " +
delegateFactory.getSimpleName() +
" is missing a no-arg Constructor. Only such constructors are allowed for" +
" these factories.");
return Optional.empty();
}
}
/** {@inheritDoc} */
@Override
public Object getParent(Object element) {
return getDelegateModelFactory(element).getParent(element);
/** Returns the list of delegate factory instances whose types are given during construction. */
protected ImmutableList<T> getDelegateFactories() {
return ImmutableList.copyOf(delegateFactories);
}
}
/*-------------------------------------------------------------------------+
| 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.kernel.ui.extension.base.factory;
import static java.util.stream.Collectors.toList;
import static org.apache.commons.lang3.reflect.ConstructorUtils.getMatchingAccessibleConstructor;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getInterfaceType;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.model.IModelFactory;
import org.fortiss.tooling.kernel.ui.ToolingKernelUIActivator;
/**
* Delegates the creational and getter calls to concrete {@link IModelFactory}s. The first non-null
* element returned by the factories of the initially given list is returned. If no element is
* created (all delegates returned null), this factory also returns null.
* <p>
* Only the root model must be identical for all delegate factories. Hence, the root element of the
* first delegate is returned.
*
* @author hoelzl
*/
public class DelegatingModelFactory extends DelegatingFactoryBase<IModelFactory>
implements IModelFactory {
/** Constructor. */
public DelegatingModelFactory(List<Class<? extends IModelFactory>> factories,
Object editedObject) {
super(factories, editedObject);