aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRené Brandstetter2013-09-22 07:42:31 (EDT)
committerGerrit Code Review @ Eclipse.org2013-11-15 08:53:52 (EST)
commit4ba99c68eee2c4b938ae2d0057d041fd94d5e604 (patch)
tree73c382a88f2af2202dec4ff2cd2d70facbd92aed
parentf2d600f2ec1c79153a02a9d29f8d32fdace4f96b (diff)
downloadeclipse.platform.ui-4ba99c68eee2c4b938ae2d0057d041fd94d5e604.zip
eclipse.platform.ui-4ba99c68eee2c4b938ae2d0057d041fd94d5e604.tar.gz
eclipse.platform.ui-4ba99c68eee2c4b938ae2d0057d041fd94d5e604.tar.bz2
Bug 419888 - [Model] [API] Extend the EModelService#createModelElement(*) to read EMF extensionsrefs/changes/69/17769/3
Implemented a generic way to build EMF model elements, based on the Eclipse ExtensionRegistry. A map is build which maps the java classes, which extend the MApplicationElement, to EClasses. Change-Id: I616e6d93b0f09a063361c801831071d782a703ce Signed-off-by: René Brandstetter <Rene.Brandstetter@gmx.net>
-rw-r--r--bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/GenericMApplicationElementFactoryImpl.java373
-rw-r--r--bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java174
2 files changed, 399 insertions, 148 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/GenericMApplicationElementFactoryImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/GenericMApplicationElementFactoryImpl.java
new file mode 100644
index 0000000..f3358b3
--- /dev/null
+++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/GenericMApplicationElementFactoryImpl.java
@@ -0,0 +1,373 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.e4.ui.internal.workbench;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IRegistryEventListener;
+import org.eclipse.e4.ui.model.application.MApplicationElement;
+import org.eclipse.e4.ui.model.application.impl.ApplicationPackageImpl;
+import org.eclipse.e4.ui.workbench.modeling.EModelService;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.osgi.service.log.LogService;
+
+/**
+ * A factory which is able to build the EMF based EObjects for the given {@link MApplicationElement}
+ * class.
+ *
+ * <p>
+ * This factory checks the Eclipse ExtensionRegistry for all registered EMF-packages, via the
+ * {@code "org.eclipse.emf.ecore.generated_package"} ExtensionPoint generated by EMF. It uses the
+ * EPackage Namespace URI mentioned in this ExtensionPoint to build a mapping between normal java
+ * class and the corresponding {@link EClass}.
+ * </p>
+ *
+ * <p>
+ * <b>Important:</b> The mapping will only contain {@link EClass}es which extend the
+ * {@link MApplicationElement} and are neither abstract nor an interface.
+ * </p>
+ */
+final class GenericMApplicationElementFactoryImpl {
+
+ /**
+ * An ExtensionRegistryListener which will build the required {@link Class} to {@link EClass}
+ * mapping.
+ */
+ private final MApplicationElementClassToEClass emfGeneratedPackages;
+
+ /**
+ * Sole constructor.
+ *
+ * @param extensionRegistry
+ * the Eclipse ExtensionRegistry
+ * @throws NullPointerException
+ * if the given Eclipse ExtensionRegistry is {@code null}
+ */
+ GenericMApplicationElementFactoryImpl(IExtensionRegistry extensionRegistry) {
+ if (extensionRegistry == null)
+ throw new NullPointerException("No ExtensionRegistry given!"); //$NON-NLS-1$
+
+ emfGeneratedPackages = new MApplicationElementClassToEClass();
+
+ // A clean-up would be nice but the only using service is realized as a singleton-service
+ // which is used throughout the running application and so this instance will also life as
+ // long as the application is running.
+ extensionRegistry.addListener(emfGeneratedPackages,
+ MApplicationElementClassToEClass.EP_GENERATED_PACKAGE);
+ emfGeneratedPackages.initialize(extensionRegistry);
+ }
+
+ /**
+ * Takes the given class and creates the corresponding {@link EObject} implementation for it.
+ *
+ * @param clazz
+ * the class for which the corresponding {@link EObject} should be created
+ * @return the corresponding {@link EObject} or {@code null} if it wasn't able to create one
+ * (e.g.: no {@link EClass} maps to the given {@link Class})
+ */
+ public EObject createEObject(Class<? extends MApplicationElement> clazz) {
+ EClass eClass = emfGeneratedPackages.getEClass(clazz);
+ if (eClass != null) {
+ checkDeprecation(eClass);
+ return EcoreUtil.create(eClass);
+ }
+
+ return null;
+ }
+
+ /**
+ * Checks if the given {@link EClass} is marked as "deprecated".
+ *
+ * <p>
+ * The method will check if the {@link EClass} was annotated with
+ * {@code "http://www.eclipse.org/ui/2010/UIModel/application/deprecated"} and if so a warning
+ * will be logged via the {@link LogService}.
+ * </p>
+ *
+ * @param eClass
+ * the class to check
+ */
+ private static void checkDeprecation(EClass eClass) {
+ if (eClass == null)
+ return;
+
+ // TODO (if you want to keep it): find a good place for a constant variable and a valid
+ // "source" value
+ EAnnotation deprecated = eClass
+ .getEAnnotation("http://www.eclipse.org/ui/2010/UIModel/application/deprecated"); //$NON-NLS-1$
+ if (deprecated != null) {
+ StringBuilder sb = new StringBuilder("The element '").append(eClass.getInstanceTypeName()).append("' is already deprecated!"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ // TODO (if you want to keep it): adapted it the way you need it (or remove it,
+ // because it was just a show-case of what would be possible)
+ String since = deprecated.getDetails().get("since"); //$NON-NLS-1$
+ if (since != null) {
+ sb.append(" (since version: ").append(since).append(')'); //$NON-NLS-1$
+ }
+
+ Activator.log(LogService.LOG_WARNING, sb.toString());
+ }
+ }
+
+ /**
+ * An Eclipse ExtensionRegistry-Listener which will build the required map to find the
+ * {@link EClass} for the given {@link Class}.
+ *
+ * <p>
+ * This Listener must be registered on EMF's {@value #EP_GENERATED_PACKAGE} extension point to
+ * build the appropriate mapping between {@link Class} and {@link EClass}.
+ * </p>
+ *
+ * <p>
+ * <b>Info:</b> This map will only contain concrete {@link EClass} objects which extend the
+ * {@link MApplicationElement}.
+ * </p>
+ */
+ private static final class MApplicationElementClassToEClass implements IRegistryEventListener {
+
+ /** The extension point name which holds the required information. */
+ public static final String EP_GENERATED_PACKAGE = "org.eclipse.emf.ecore.generated_package"; //$NON-NLS-1$
+
+ /**
+ * The configuration element inside the extension point which holds the required
+ * information.
+ */
+ private static final String CONFIG_ELEMENT_NAME = "package"; //$NON-NLS-1$
+
+ /** Attribute name which holds the EMF EPackage Namespace URI. */
+ private static final String CONFIG_ATTR_EPACKAGE_URI = "uri"; //$NON-NLS-1$
+
+ /** Holds the mapping between {@link Class} and {@link EClass}. */
+ private final ConcurrentMap<Class<? extends MApplicationElement>, EClass> classToEClass = new ConcurrentHashMap<Class<? extends MApplicationElement>, EClass>();
+
+ /**
+ * Holds the required information per extension point which needs to be clean-up in the
+ * {@link #removed(IExtension[])} method.
+ */
+ private final ConcurrentMap<IExtension, List<Class<? extends MApplicationElement>>> registeredClasses = new ConcurrentHashMap<IExtension, List<Class<? extends MApplicationElement>>>();
+
+ /** A reference to the {@link MApplicationElement}-EClass. */
+ private final EClass mApplicationElementEClass = ApplicationPackageImpl.eINSTANCE
+ .getApplicationElement();
+
+ /**
+ * Method which will initialize the mapping with the information from the given Eclipse
+ * ExtensionRegistry.
+ *
+ * <p>
+ * The method will retrieve all {@link #EP_GENERATED_PACKAGE} extensions form the given
+ * Eclipse ExtensionRegistry and initializes the basic mapping.
+ * </p>
+ *
+ * @param extensionRegistry
+ * the Eclipse ExtensionRegistry on which the listener is already registered
+ */
+ void initialize(IExtensionRegistry extensionRegistry) {
+ if (extensionRegistry == null) { // just for safety's sake
+ throw new IllegalArgumentException("No ExtensionRegistry given!"); //$NON-NLS-1$
+ }
+
+ IExtensionPoint epGeneratedPackage = extensionRegistry
+ .getExtensionPoint(EP_GENERATED_PACKAGE);
+ if (epGeneratedPackage != null) {
+ added(epGeneratedPackage.getExtensions());
+ }
+ }
+
+ /**
+ * Lookup the {@link EClass} for the given {@link Class}.
+ *
+ * @param elementType
+ * the {@link Class} to which the {@link EClass} should be found
+ * @return the corresponding {@link EClass} or {@code null} if none was found
+ */
+ public EClass getEClass(Class<? extends MApplicationElement> elementType) {
+ return classToEClass.get(elementType);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.runtime.IRegistryEventListener#added(org.eclipse.core.runtime.IExtension
+ * [])
+ */
+ public void added(IExtension[] extensions) {
+ for (IExtension extension : extensions) {
+ List<Class<? extends MApplicationElement>> elementsToCleanup = addToMapping(extension
+ .getConfigurationElements());
+
+ if (elementsToCleanup != null) {
+ // keep the list of registered class per extension to remove them in the
+ // #remove(IExtension[]) method
+ registeredClasses.put(extension, elementsToCleanup);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.runtime.IRegistryEventListener#removed(org.eclipse.core.runtime.IExtension
+ * [])
+ */
+ public void removed(IExtension[] extensions) {
+ for (IExtension extension : extensions) {
+ List<Class<? extends MApplicationElement>> modelClassesToRemove = registeredClasses
+ .remove(extension);
+
+ if (modelClassesToRemove != null) {
+ // clean-up
+ for (Class<? extends MApplicationElement> modelClass : modelClassesToRemove) {
+ classToEClass.remove(modelClass);
+ }
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.IRegistryEventListener#added(org.eclipse.core.runtime.
+ * IExtensionPoint[])
+ */
+ public void added(IExtensionPoint[] extensionPoints) {
+ // not of interest
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.IRegistryEventListener#removed(org.eclipse.core.runtime.
+ * IExtensionPoint[])
+ */
+ public void removed(IExtensionPoint[] extensionPoints) {
+ // not of interest
+ }
+
+ /**
+ * Reads the information from the given {@link IConfigurationElement}s and updates the
+ * mapping.
+ *
+ * @param configurationElements
+ * the elements to read the information from
+ * @return the list of {@link Class}es which were put to the {@link #classToEClass} mapping
+ * or <code>null</code> if none were put into that list
+ */
+ private List<Class<? extends MApplicationElement>> addToMapping(
+ IConfigurationElement[] configurationElements) {
+ if (configurationElements == null) {
+ return null;
+ }
+
+ List<Class<? extends MApplicationElement>> allMappedEntried = new ArrayList<Class<? extends MApplicationElement>>();
+
+ for (IConfigurationElement configElement : configurationElements) {
+ if (configElement.getName().equals(CONFIG_ELEMENT_NAME)) {
+ String emfNsURI = configElement.getAttribute(CONFIG_ATTR_EPACKAGE_URI);
+
+ // find EPackage
+ EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(emfNsURI);
+
+ // build Class to EClass mapping from the classes in the EPackage
+ Map<Class<? extends MApplicationElement>, EClass> mapping = buildMapping(ePackage);
+
+ if (mapping != null) {
+ for (Map.Entry<Class<? extends MApplicationElement>, EClass> entry : mapping
+ .entrySet()) {
+
+ // if the current thread added the mapping we keep the key so it can be
+ // removed afterwards in the #remove(IExtension[]) method
+ if (classToEClass.putIfAbsent(entry.getKey(), entry.getValue()) == null) {
+ allMappedEntried.add(entry.getKey());
+ }
+ }
+ }
+ }
+ }
+
+ // null means nothing from the given configurationElementes was added to the Class to
+ // EClass map
+ return allMappedEntried.isEmpty() ? null : allMappedEntried;
+ }
+
+ /**
+ * Utility method which walks through all {@link EClass} of the given {@link EPackage} to
+ * build a Class-To-EClass map.
+ * <p>
+ * This method will only take {@link EClass}es into account which extend the
+ * {@link MApplicationElement} and are neither a abstract class nor an interface. Which
+ * means the mapping will only contain {@link EModelService#createModelElement(Class)}
+ * relevant classes.
+ * </p>
+ *
+ * @param ePackage
+ * the EPackage to scan
+ * @return a map containing all {@link Class}es and their corresponding {@link EClass} which
+ * are provided by the given {@link EPackage} and extend the
+ * {@link MApplicationElement}; {@code null} otherwise
+ */
+ private final Map<Class<? extends MApplicationElement>, EClass> buildMapping(
+ EPackage ePackage) {
+ if (ePackage == null)
+ return null;
+
+ List<EClassifier> eClassifiers = ePackage.getEClassifiers();
+ Map<Class<? extends MApplicationElement>, EClass> mapping = new HashMap<Class<? extends MApplicationElement>, EClass>();
+
+ for (EClassifier eClassifier : eClassifiers) {
+ if (eClassifier instanceof EClass) {
+ EClass eClass = (EClass) eClassifier;
+
+ if (mApplicationElementEClass.isSuperTypeOf(eClass) && !eClass.isAbstract()
+ && !eClass.isInterface()) {
+ @SuppressWarnings("unchecked")
+ Class<? extends MApplicationElement> instanceClass = (Class<? extends MApplicationElement>) eClass
+ .getInstanceClass();
+
+ // the Map.Entry check is just for safety, because of the EMF special for
+ // Key/Value pairs in HashMaps
+ // (see: UIElements.ecore/application/StringToStringMap)
+ if (!instanceClass.equals(Map.Entry.class)) {
+ // add the entry, but if there was already a mapping we should log it
+ EClass previousEntry = mapping.put(instanceClass, eClass);
+
+ if (previousEntry != null) {
+ Activator
+ .log(LogService.LOG_WARNING,
+ instanceClass
+ + " is mapped to multiple EClasses (" + eClass.getName() + ", " + previousEntry.getName() + ")!"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ }
+ }
+
+ }
+ }
+
+ return mapping.isEmpty() ? null : mapping;
+ }
+ }
+}
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java
index 9679db1..a22b920 100644
--- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java
+++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java
@@ -14,28 +14,16 @@ package org.eclipse.e4.ui.internal.workbench;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.events.IEventBroker;
-import org.eclipse.e4.ui.model.application.MAddon;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.MApplicationElement;
-import org.eclipse.e4.ui.model.application.MApplicationFactory;
-import org.eclipse.e4.ui.model.application.commands.MBindingContext;
-import org.eclipse.e4.ui.model.application.commands.MBindingTable;
-import org.eclipse.e4.ui.model.application.commands.MCategory;
-import org.eclipse.e4.ui.model.application.commands.MCommand;
-import org.eclipse.e4.ui.model.application.commands.MCommandParameter;
-import org.eclipse.e4.ui.model.application.commands.MCommandsFactory;
-import org.eclipse.e4.ui.model.application.commands.MHandler;
-import org.eclipse.e4.ui.model.application.commands.MKeyBinding;
-import org.eclipse.e4.ui.model.application.commands.MParameter;
import org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptor;
-import org.eclipse.e4.ui.model.application.ui.MCoreExpression;
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
import org.eclipse.e4.ui.model.application.ui.MGenericTile;
import org.eclipse.e4.ui.model.application.ui.MSnippetContainer;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
-import org.eclipse.e4.ui.model.application.ui.MUiFactory;
import org.eclipse.e4.ui.model.application.ui.SideValue;
import org.eclipse.e4.ui.model.application.ui.advanced.MAdvancedFactory;
import org.eclipse.e4.ui.model.application.ui.advanced.MArea;
@@ -43,8 +31,6 @@ import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack;
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
import org.eclipse.e4.ui.model.application.ui.basic.MBasicFactory;
-import org.eclipse.e4.ui.model.application.ui.basic.MCompositePart;
-import org.eclipse.e4.ui.model.application.ui.basic.MInputPart;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer;
import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainerElement;
@@ -54,21 +40,7 @@ import org.eclipse.e4.ui.model.application.ui.basic.MTrimmedWindow;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.model.application.ui.basic.MWindowElement;
import org.eclipse.e4.ui.model.application.ui.basic.impl.BasicFactoryImpl;
-import org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem;
-import org.eclipse.e4.ui.model.application.ui.menu.MDirectToolItem;
-import org.eclipse.e4.ui.model.application.ui.menu.MDynamicMenuContribution;
-import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
-import org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem;
-import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
-import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution;
-import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
-import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator;
-import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu;
-import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
-import org.eclipse.e4.ui.model.application.ui.menu.MToolBarContribution;
-import org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator;
import org.eclipse.e4.ui.model.application.ui.menu.MToolControl;
-import org.eclipse.e4.ui.model.application.ui.menu.MTrimContribution;
import org.eclipse.e4.ui.model.internal.ModelUtils;
import org.eclipse.e4.ui.workbench.IPresentationEngine;
import org.eclipse.e4.ui.workbench.UIEvents;
@@ -89,6 +61,9 @@ public class ModelServiceImpl implements EModelService {
private IEclipseContext appContext;
+ /** Factory which is able to create {@link MApplicationElement}s in a generic way. */
+ private GenericMApplicationElementFactoryImpl mApplicationElementFactory;
+
// Cleans up after a hosted element is disposed
private EventHandler hostedElementHandler = new EventHandler() {
@@ -114,15 +89,20 @@ public class ModelServiceImpl implements EModelService {
* This is a singleton service. One instance is used throughout the running application
*
* @param appContext
- * The applicationContext to get teh eventBroker from
+ * The applicationContext to get the eventBroker from
+ *
+ * @throws NullPointerException
+ * if the given appContext is <code>null</code>
*/
public ModelServiceImpl(IEclipseContext appContext) {
if (appContext == null)
- return;
+ throw new NullPointerException("No application context given!"); //$NON-NLS-1$
this.appContext = appContext;
IEventBroker eventBroker = appContext.get(IEventBroker.class);
eventBroker.subscribe(UIEvents.UIElement.TOPIC_WIDGET, hostedElementHandler);
+
+ mApplicationElementFactory = new GenericMApplicationElementFactoryImpl(appContext.get(IExtensionRegistry.class));
}
/**
@@ -131,125 +111,23 @@ public class ModelServiceImpl implements EModelService {
*/
@SuppressWarnings("unchecked")
public final <T extends MApplicationElement> T createModelElement(Class<T> elementType) {
- // WARNING: This method is automatically generated. Do not hand modify
if (elementType == null) {
throw new NullPointerException("Argument cannot be null."); //$NON-NLS-1$
}
- if (MAddon.class.equals(elementType)) {
- return (T) MApplicationFactory.INSTANCE.createAddon();
- }
- if (MApplication.class.equals(elementType)) {
- return (T) MApplicationFactory.INSTANCE.createApplication();
- }
- if (MArea.class.equals(elementType)) {
- return (T) MAdvancedFactory.INSTANCE.createArea();
- }
- if (MBindingContext.class.equals(elementType)) {
- return (T) MCommandsFactory.INSTANCE.createBindingContext();
- }
- if (MBindingTable.class.equals(elementType)) {
- return (T) MCommandsFactory.INSTANCE.createBindingTable();
- }
- if (MCategory.class.equals(elementType)) {
- return (T) MCommandsFactory.INSTANCE.createCategory();
- }
- if (MCommand.class.equals(elementType)) {
- return (T) MCommandsFactory.INSTANCE.createCommand();
- }
- if (MCommandParameter.class.equals(elementType)) {
- return (T) MCommandsFactory.INSTANCE.createCommandParameter();
- }
- if (MCompositePart.class.equals(elementType)) {
- return (T) MBasicFactory.INSTANCE.createCompositePart();
- }
- if (MCoreExpression.class.equals(elementType)) {
- return (T) MUiFactory.INSTANCE.createCoreExpression();
- }
- if (MDirectMenuItem.class.equals(elementType)) {
- return (T) MMenuFactory.INSTANCE.createDirectMenuItem();
- }
- if (MDirectToolItem.class.equals(elementType)) {
- return (T) MMenuFactory.INSTANCE.createDirectToolItem();
- }
- if (MDynamicMenuContribution.class.equals(elementType)) {
- return (T) MMenuFactory.INSTANCE.createDynamicMenuContribution();
- }
- if (MHandledMenuItem.class.equals(elementType)) {
- return (T) MMenuFactory.INSTANCE.createHandledMenuItem();
- }
- if (MHandledToolItem.class.equals(elementType)) {
- return (T) MMenuFactory.INSTANCE.createHandledToolItem();
- }
- if (MHandler.class.equals(elementType)) {
- return (T) MCommandsFactory.INSTANCE.createHandler();
- }
- if (MInputPart.class.equals(elementType)) {
- return (T) MBasicFactory.INSTANCE.createInputPart();
- }
- if (MKeyBinding.class.equals(elementType)) {
- return (T) MCommandsFactory.INSTANCE.createKeyBinding();
- }
- if (MMenu.class.equals(elementType)) {
- return (T) MMenuFactory.INSTANCE.createMenu();
- }
- if (MMenuContribution.class.equals(elementType)) {
- return (T) MMenuFactory.INSTANCE.createMenuContribution();
- }
- if (MMenuSeparator.class.equals(elementType)) {
- return (T) MMenuFactory.INSTANCE.createMenuSeparator();
- }
- if (MParameter.class.equals(elementType)) {
- return (T) MCommandsFactory.INSTANCE.createParameter();
- }
- if (MPart.class.equals(elementType)) {
- return (T) MBasicFactory.INSTANCE.createPart();
- }
- if (MPartDescriptor.class.equals(elementType)) {
- return (T) org.eclipse.e4.ui.model.application.descriptor.basic.MBasicFactory.INSTANCE
- .createPartDescriptor();
- }
- if (MPartSashContainer.class.equals(elementType)) {
- return (T) MBasicFactory.INSTANCE.createPartSashContainer();
- }
- if (MPartStack.class.equals(elementType)) {
- return (T) MBasicFactory.INSTANCE.createPartStack();
- }
- if (MPerspective.class.equals(elementType)) {
- return (T) MAdvancedFactory.INSTANCE.createPerspective();
- }
- if (MPerspectiveStack.class.equals(elementType)) {
- return (T) MAdvancedFactory.INSTANCE.createPerspectiveStack();
- }
- if (MPlaceholder.class.equals(elementType)) {
- return (T) MAdvancedFactory.INSTANCE.createPlaceholder();
- }
- if (MPopupMenu.class.equals(elementType)) {
- return (T) MMenuFactory.INSTANCE.createPopupMenu();
- }
- if (MToolBar.class.equals(elementType)) {
- return (T) MMenuFactory.INSTANCE.createToolBar();
- }
- if (MToolBarContribution.class.equals(elementType)) {
- return (T) MMenuFactory.INSTANCE.createToolBarContribution();
- }
- if (MToolBarSeparator.class.equals(elementType)) {
- return (T) MMenuFactory.INSTANCE.createToolBarSeparator();
- }
- if (MToolControl.class.equals(elementType)) {
- return (T) MMenuFactory.INSTANCE.createToolControl();
- }
- if (MTrimBar.class.equals(elementType)) {
- return (T) MBasicFactory.INSTANCE.createTrimBar();
- }
- if (MTrimContribution.class.equals(elementType)) {
- return (T) MMenuFactory.INSTANCE.createTrimContribution();
- }
- if (MTrimmedWindow.class.equals(elementType)) {
- return (T) MBasicFactory.INSTANCE.createTrimmedWindow();
- }
- if (MWindow.class.equals(elementType)) {
- return (T) MBasicFactory.INSTANCE.createWindow();
+
+ /*
+ * TODO: We can even tune the performance of this method if we add the previous generated
+ * if-else-if-else... block. The eObjectFactory#createEObject(Class) could afterwards be the
+ * fallback if a user specific model element should be created. But for this we need to
+ * adapt the generator of Paul Elder and to be honest I wasn't able to find it (either its
+ * call during the build nor its template) ;-( .
+ */
+
+ T back = (T) mApplicationElementFactory.createEObject(elementType);
+ if (back != null) {
+ return back;
}
+
throw new IllegalArgumentException(
"Unsupported model object type: " + elementType.getCanonicalName()); //$NON-NLS-1$
}
@@ -755,10 +633,10 @@ public class ModelServiceImpl implements EModelService {
} else {
MPartSashContainer newSash = BasicFactoryImpl.eINSTANCE.createPartSashContainer();
newSash.setHorizontal(horizontal);
-
+
// Maintain the existing weight in the new sash
newSash.setContainerData(relTo.getContainerData());
-
+
combine(toInsert, relTo, newSash, insertBefore, ratio);
}