Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2016-02-11 02:48:20 +0000
committerGerrit Code Review @ Eclipse.org2016-02-12 15:31:41 +0000
commitecd4928b327f5561364c5068c9ff5f1668e92d13 (patch)
tree7c34f46cf82a1d65ac753fa92c2a5d55371b8dba /plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus
parent751a204d74e15eb2db6b41c937691fc56dcc1252 (diff)
downloadorg.eclipse.papyrus-ecd4928b327f5561364c5068c9ff5f1668e92d13.tar.gz
org.eclipse.papyrus-ecd4928b327f5561364c5068c9ff5f1668e92d13.tar.xz
org.eclipse.papyrus-ecd4928b327f5561364c5068c9ff5f1668e92d13.zip
Bug 485220: [Architecture] Provide a more modular architecture
https://bugs.eclipse.org/bugs/show_bug.cgi?id=485220 Factor UI dependencies out of the UML Element Types bundle. This includes moving some advices that interact with the user into a new org.eclipse.papyrus.uml.service.types.ui bundle. Pull up the PasteCommandService and IPasteCommandProvider API into the Infra Diagram layer where the extension point is defined. Deprecate the old API in the UML layer. Introduce a service for participation of languages in CSS styling: * styling reset actions in the Reset Style command * access to semantic model classes and properties to make available to CSS Factor PapyrusObservableValue and cohorts out of the UML Tools bundle into the Infra Layer for more general reuse and to relieve the Diagram Infrastructure layer of UML dependencies. The old API remains as deprecated. Remove the Infra Diagram Layer dependency on UML Layer for property testers governing deletion in the diagram. Includes introduction of a new IGraphicalDeletionHelper OSGi service for delegation of the determination of whether an element can be deleted from the diagram and replacement of the XML expression properties * org.eclipse.papyrus.uml.diagram.common.isSemanticDeletion * org.eclipse.papyrus.uml.diagram.common.isReadOnly by * org.eclipse.papyrus.infra.gmfdiag.common.isSemanticDeletion * org.eclipse.papyrus.infra.gmfdiag.common.canDelete (where the latter is the negation of the property that it supersedes) Extract UML dependencies from the Diagram Outline and CSS Editor bundles. Remove unused MDTUtil APIs that referenced a UML-specific annotation. Move the Diagram Infrastructure CSS Palette bundle into the UML layer because it serves to provide extensions on the Palette Service, which is an overtly UML-specific capability. All client APIs for the Properties View are moved from org.eclipse.papyrus.views.properties bundle to a new org.eclipse.papyrus.infra.properties.ui bundle. This includes renaming of: * extension points * label-provider contexts * XWT namespaces Add an "all UI tests" suite. Define a componentized hierarchical build layout of the main plug-ins Change-Id: I43f8f3644857a18b69715f5a2f1da9b1cf286d67
Diffstat (limited to 'plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus')
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/AbstractConfigurableElementTypeFactory.java120
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/Activator.java64
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/AspectConfigurationFactoryRegistry.java273
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/AspectSemanticTypeFactory.java106
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ComposedContainerDescriptor.java95
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ComposedEditHelperAdvice.java178
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ComposedElementCreationValidator.java59
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ComposedElementMatcher.java50
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ConfigurableElementMatcherFactoryRegistry.java132
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ElementTypeSetUtils.java117
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ExtendedElementTypeSetRegistry.java471
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ExtendedTypeRegistryService.java52
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IActionConfigurationModelCreation.java22
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IActionContainerDescriptor.java30
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IActionCreationElementValidator.java26
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IActionEditHelperAdvice.java24
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IAspectTypeExtensionPoint.java41
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IConfigurableElementMatcher.java30
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IConfigurableElementMatcherFactory.java32
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ICreationElementValidator.java28
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IEditHelperAdviceConstants.java22
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IElementMatcherConfigurationModelCreation.java22
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IElementMatcherExtensionPoint.java33
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IExtendedElementTypeFactory.java42
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IExtendedElementTypeSetExtensionPoint.java40
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IExtendedTypeConfigurationExtensionPoint.java39
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/UserExtendedTypesRegistry.java107
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/advices/ExtendedTypesOwnerAdvice.java240
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/internal/spi/IUserExtendedTypesProvider.java39
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantcontainerconfiguration/InvariantContainerConfigurationContainerDescriptor.java155
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantcontainerconfiguration/InvariantContainerConfigurationModelCreation.java29
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantcontainerconfiguration/InvariantContainerEditHelperAdvice.java141
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantcontainerconfiguration/InvariantContainerMatcher.java127
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/AndRuleCreationElementValidator.java52
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/AndRuleEditHelperAdvice.java56
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/AndRuleElementMatcher.java65
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantConfigurationModelCreation.java22
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantContainerDescriptor.java27
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantCreationElementValidator.java24
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantEditHelperAdvice.java29
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantElementMatcher.java30
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantRuleExtensionPoint.java38
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/InvariantElementTypeFactory.java80
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/InvariantSemanticTypeContainerDescriptor.java47
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/InvariantSemanticTypeEditHelperAdvice.java30
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/OrRuleCreationElementValidator.java52
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/OrRuleEditHelperAdvice.java61
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/OrRuleElementMatcher.java65
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/RuleConfigurationFactoryRegistry.java348
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/semantic/ISemanticTypeFactory.java23
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/types/ExtendedHintedElementType.java72
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/types/IExtendedHintedElementType.java27
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/util/ElementTypeUtils.java183
-rw-r--r--plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/util/InternalUtils.java157
54 files changed, 4474 insertions, 0 deletions
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/AbstractConfigurableElementTypeFactory.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/AbstractConfigurableElementTypeFactory.java
new file mode 100644
index 00000000000..eaeb61bb7b0
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/AbstractConfigurableElementTypeFactory.java
@@ -0,0 +1,120 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.IContainerDescriptor;
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.papyrus.infra.extendedtypes.types.ExtendedHintedElementType;
+import org.eclipse.papyrus.infra.extendedtypes.types.IExtendedHintedElementType;
+import org.osgi.framework.Bundle;
+
+/**
+ * Factory to create element type from its {@link ElementTypeConfiguration}
+ */
+public abstract class AbstractConfigurableElementTypeFactory<T extends ElementTypeConfiguration> implements IExtendedElementTypeFactory<T> {
+
+ /**
+ * {@inheritDoc}
+ */
+ public IExtendedHintedElementType createElementType(T configuration) {
+ String id = configuration.getIdentifier();
+ // display name of the element Type (used mainly in GUIs)
+ String displayName = configuration.getName();
+ // Specialized element types
+ List<IElementType> specializedTypes = new ArrayList<IElementType>(configuration.getSpecializedTypesID().size());
+ for (String specializedTypeId : configuration.getSpecializedTypesID()) {
+ IElementType specializedType = ElementTypeRegistry.getInstance().getType(specializedTypeId);
+ specializedTypes.add(specializedType);
+ }
+ IElementType[] elementTypes = specializedTypes.toArray(new IElementType[] {});
+ // icon associated to the element Type (GUI)
+ IconEntry entry = configuration.getIconEntry();
+ URL iconURL = null;
+ if (entry != null) {
+ iconURL = getURLFromEntry(entry);
+ }
+ IExtendedHintedElementType type = new ExtendedHintedElementType(id, iconURL, displayName, elementTypes, createElementMatcher(configuration), createContainerDescriptor(configuration), createEditHelperAdvice(configuration),
+ getSemanticHint(configuration), createElementCreationValidator(configuration));
+ return type;
+ }
+
+ /**
+ * Returns the semantic hint for the element type from the given configuration
+ */
+ protected String getSemanticHint(T configuration) {
+ return configuration.getHint();
+ }
+
+ /**
+ * @param configuration
+ * @return
+ */
+ protected abstract IEditHelperAdvice createEditHelperAdvice(T configuration);
+
+ /**
+ * @param configuration
+ * @return
+ */
+ protected abstract IContainerDescriptor createContainerDescriptor(T configuration);
+
+ /**
+ * Creates the element matcher for the given configuration
+ *
+ * @param configuration
+ * the configuration from which element matcher should be created
+ * @return the new element matcher for the created element type
+ */
+ protected IElementMatcher createElementMatcher(T configuration) {
+ MatcherConfiguration matcherConfiguration = configuration.getMatcherConfiguration();
+ if (matcherConfiguration == null) {
+ return null;
+ }
+ // create matcher from the configuration
+ IElementMatcher matcher = ConfigurableElementMatcherFactoryRegistry.getInstance().createElementMatcher(matcherConfiguration);
+ return matcher;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public abstract ICreationElementValidator createElementCreationValidator(T configuration);
+
+ /**
+ * @param entry
+ * @return
+ */
+ protected URL getURLFromEntry(IconEntry entry) {
+ Bundle bundle = Platform.getBundle(entry.getBundleId());
+ if (bundle == null) {
+ return null;
+ }
+ URL result = bundle.getEntry(entry.getIconPath());
+ if (result == null) {
+ try {
+ result = new URL(entry.getIconPath());
+ } catch (MalformedURLException e) {
+ result = null;
+ }
+ }
+ return result;
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/Activator.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/Activator.java
new file mode 100644
index 00000000000..ba4815c1708
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/Activator.java
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ * Copyright (c) 2014, 2016 CEA LIST, Christian W. Damus, 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:
+ * Patrick Tessier (CEA LIST) - Initial API and implementation
+ * Christian W. Damus - bug 485220
+ *
+ /*****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends Plugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.extendedtypes"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /** Logging helper */
+ public static LogHelper log;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ log = new LogHelper(this);
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ log = null;
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/AspectConfigurationFactoryRegistry.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/AspectConfigurationFactoryRegistry.java
new file mode 100644
index 00000000000..c8561cccb9b
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/AspectConfigurationFactoryRegistry.java
@@ -0,0 +1,273 @@
+/*****************************************************************************
+ * Copyright (c) 2013, 2016 CEA LIST, Christian W. Damus, 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ * Christian W. Damus - bug 485220
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+import static org.eclipse.papyrus.infra.extendedtypes.util.InternalUtils.loadClass;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.gmf.runtime.emf.type.core.IContainerDescriptor;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+
+/**
+ * Registry that manages all possible pre/post action configurations
+ */
+public class AspectConfigurationFactoryRegistry {
+
+ /** private singleton instance */
+ private static AspectConfigurationFactoryRegistry registry;
+
+ /** map configuration type to matcher descriptor */
+ protected Map<String, ConfigurableClassDescriptor> configurationTypeToClassDescriptor = null;
+
+ /**
+ * returns the singleton instance of this registry
+ *
+ * @return the singleton instance of this registry
+ */
+ public static synchronized AspectConfigurationFactoryRegistry getInstance() {
+ if (registry == null) {
+ registry = new AspectConfigurationFactoryRegistry();
+ registry.init();
+ }
+ return registry;
+ }
+
+ /**
+ * Inits the registry.
+ */
+ protected void init() {
+ configurationTypeToClassDescriptor = new HashMap<String, AspectConfigurationFactoryRegistry.ConfigurableClassDescriptor>();
+ // read invariant rule configuration etension point
+ IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(IAspectTypeExtensionPoint.EXTENSION_POINT_ID);
+ // for each element, parses and retrieve the model file. then loads it and returns the root element
+ for (IConfigurationElement configurationElement : elements) {
+ // contributor will always be the same, but implementation could be different.
+ String contributorName = configurationElement.getContributor().getName();
+
+ String configurationClass = configurationElement.getAttribute(IAspectTypeExtensionPoint.CONFIGURATION_CLASS);
+
+ String editHelperAdviceClassName = configurationElement.getAttribute(IAspectTypeExtensionPoint.EDIT_HELPER_ADVICE_CLASS);
+ String containerDescriptorClassName = configurationElement.getAttribute(IAspectTypeExtensionPoint.CONTAINER_DESCRIPTOR_CLASS);
+ String creationElementValidatorClassName = configurationElement.getAttribute(IAspectTypeExtensionPoint.CREATION_ELEMENT_VALIDATOR_CLASS);
+
+ ConfigurableClassDescriptor configurableClassDescriptor = new ConfigurableClassDescriptor(contributorName, editHelperAdviceClassName, contributorName, containerDescriptorClassName, contributorName, creationElementValidatorClassName);
+ configurationTypeToClassDescriptor.put(configurationClass, configurableClassDescriptor);
+ }
+
+ }
+
+ /**
+ * @param ruleConfiguration
+ * @return
+ */
+ public IContainerDescriptor createContainerDescriptor(ActionConfiguration ruleConfiguration) {
+ Class<IActionContainerDescriptor<ActionConfiguration>> containerDescriptorClass = getContainerDescriptorClass(ruleConfiguration);
+ if (containerDescriptorClass == null) {
+ return null;
+ }
+ try {
+ IActionContainerDescriptor<ActionConfiguration> containerDescriptor = containerDescriptorClass.newInstance();
+ if (containerDescriptor != null) {
+ containerDescriptor.init(ruleConfiguration);
+ }
+ return containerDescriptor;
+ } catch (InstantiationException e) {
+ Activator.log.error(e);
+ } catch (IllegalAccessException e) {
+ Activator.log.error(e);
+ }
+ return null;
+ }
+
+ /**
+ * @param actionConfiguration
+ * @return
+ */
+ public IEditHelperAdvice createEditHelperAdvice(ActionConfiguration actionConfiguration) {
+ Class<IActionEditHelperAdvice<ActionConfiguration>> editHelperAdviceClass = getEditHelperAdviceClass(actionConfiguration);
+ if (editHelperAdviceClass == null) {
+ Activator.log.error("impossible to find the edit helper advice implementation for configuration type : " + ((actionConfiguration != null) ? actionConfiguration.eClass().getName() : "null"), null);
+ return null;
+ }
+ try {
+ IActionEditHelperAdvice<ActionConfiguration> editHelperAdvice = editHelperAdviceClass.newInstance();
+ if (editHelperAdvice != null) {
+ editHelperAdvice.init(actionConfiguration);
+ }
+ return editHelperAdvice;
+ } catch (InstantiationException e) {
+ Activator.log.error(e);
+ } catch (IllegalAccessException e) {
+ Activator.log.error(e);
+ }
+ return null;
+ }
+
+ /**
+ * @param ruleConfiguration
+ * @return
+ */
+ public ICreationElementValidator createCreationElementValidator(ActionConfiguration actionConfiguration) {
+ Class<IActionCreationElementValidator<ActionConfiguration>> creationElementValidatorClass = getCreationElementValidatorClass(actionConfiguration);
+ if (creationElementValidatorClass == null) {
+ Activator.log.error("impossible to find the Creation Element Validator for configuration type : " + ((actionConfiguration != null) ? actionConfiguration.eClass().getName() : "null"), null);
+ return null;
+ }
+ try {
+ IActionCreationElementValidator<ActionConfiguration> creationElementValidator = creationElementValidatorClass.newInstance();
+ if (creationElementValidator != null) {
+ creationElementValidator.init(actionConfiguration);
+ }
+ return creationElementValidator;
+ } catch (InstantiationException e) {
+ Activator.log.error(e);
+ } catch (IllegalAccessException e) {
+ Activator.log.error(e);
+ }
+ return null;
+ }
+
+
+ /**
+ * @param ruleConfiguration
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ protected Class<IActionCreationElementValidator<ActionConfiguration>> getCreationElementValidatorClass(ActionConfiguration configuration) {
+ String configurationType = configuration.eClass().getInstanceClassName();
+ String className = configurationTypeToClassDescriptor.get(configurationType).getCreationElementValidatorClassName();
+ String contributorName = configurationTypeToClassDescriptor.get(configurationType).getCreationElementValidatorContributorName();
+ // look in the list of registered matcher for the right one
+ if (className == null) {
+ Activator.log.error("There should be an implementation class for the configuration " + configurationType + " from contributor " + contributorName, null);
+ } else if (contributorName != null) {
+ return (Class<IActionCreationElementValidator<ActionConfiguration>>) loadClass(className, contributorName);
+ }
+ return null;
+ }
+
+ /**
+ * @param configurationType
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ protected Class<IActionEditHelperAdvice<ActionConfiguration>> getEditHelperAdviceClass(ActionConfiguration configuration) {
+ String configurationType = configuration.eClass().getInstanceClassName();
+ String className = configurationTypeToClassDescriptor.get(configurationType).getEditHelperAdviceClassName();
+ String contributorName = configurationTypeToClassDescriptor.get(configurationType).getEditHelperAdviceContributorName();
+
+ // look in the list of registered edit helper advices for the right one
+ return (Class<IActionEditHelperAdvice<ActionConfiguration>>) loadClass(className, contributorName);
+ }
+
+ /**
+ * @param configurationType
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ protected Class<IActionContainerDescriptor<ActionConfiguration>> getContainerDescriptorClass(ActionConfiguration configuration) {
+ String configurationType = configuration.eClass().getInstanceClassName();
+ String className = configurationTypeToClassDescriptor.get(configurationType).getContainerDescriptorClassName();
+ String contributorName = configurationTypeToClassDescriptor.get(configurationType).getContainerDescriptorContributorName();
+
+
+ // look in the list of registered edit helper advices for the right one
+ if (className != null && contributorName != null) {
+ return (Class<IActionContainerDescriptor<ActionConfiguration>>) loadClass(className, contributorName);
+ }
+ return null;
+ }
+
+ protected static class ConfigurableClassDescriptor {
+
+ /**
+ * @param editHelperAdviceContributorName
+ * @param editHelperAdviceClassName
+ * @param containerDescriptorContributorName
+ * @param containerDescriptorClassName
+ */
+ public ConfigurableClassDescriptor(String editHelperAdviceContributorName, String editHelperAdviceClassName, String containerDescriptorContributorName, String containerDescriptorClassName, String creationElementValidatorContributorName,
+ String creationElementValidatorClassName) {
+ this.editHelperAdviceContributorName = editHelperAdviceContributorName;
+ this.editHelperAdviceClassName = editHelperAdviceClassName;
+ this.containerDescriptorContributorName = containerDescriptorContributorName;
+ this.containerDescriptorClassName = containerDescriptorClassName;
+ this.creationElementValidatorContributorName = creationElementValidatorContributorName;
+ this.creationElementValidatorClassName = creationElementValidatorClassName;
+ }
+
+ private final String editHelperAdviceContributorName;
+
+ private final String editHelperAdviceClassName;
+
+ private final String containerDescriptorContributorName;
+
+ private final String containerDescriptorClassName;
+
+ private final String creationElementValidatorContributorName;
+
+ private final String creationElementValidatorClassName;
+
+ /**
+ * @return
+ */
+ public String getCreationElementValidatorContributorName() {
+ return creationElementValidatorContributorName;
+ }
+
+ /**
+ * @return
+ */
+ public String getCreationElementValidatorClassName() {
+ return creationElementValidatorClassName;
+ }
+
+ /**
+ * @return the editHelperAdviceContributorName
+ */
+ public String getEditHelperAdviceContributorName() {
+ return editHelperAdviceContributorName;
+ }
+
+
+ /**
+ * @return the editHelperAdviceClassName
+ */
+ public String getEditHelperAdviceClassName() {
+ return editHelperAdviceClassName;
+ }
+
+
+ /**
+ * @return the containerDescriptorContributorName
+ */
+ public String getContainerDescriptorContributorName() {
+ return containerDescriptorContributorName;
+ }
+
+
+ /**
+ * @return the containerDescriptorClassName
+ */
+ public String getContainerDescriptorClassName() {
+ return containerDescriptorClassName;
+ }
+
+ }
+
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/AspectSemanticTypeFactory.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/AspectSemanticTypeFactory.java
new file mode 100644
index 00000000000..242ea071b23
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/AspectSemanticTypeFactory.java
@@ -0,0 +1,106 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.gmf.runtime.emf.type.core.IContainerDescriptor;
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+import org.eclipse.gmf.runtime.emf.type.core.NullElementMatcher;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+
+
+/**
+ * Factory to create Aspect Semantic Element Types from their {@link AspectSemanticTypeConfiguration}
+ */
+public class AspectSemanticTypeFactory extends AbstractConfigurableElementTypeFactory<AspectSemanticTypeConfiguration> {
+
+ /**
+ * Default Constructor
+ */
+ public AspectSemanticTypeFactory() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected IEditHelperAdvice createEditHelperAdvice(AspectSemanticTypeConfiguration configuration) {
+ List<SemanticActionConfiguration> semanticActionConfigurations = configuration.getActionConfiguration();
+ List<IEditHelperAdvice> actionAdvices = new ArrayList<IEditHelperAdvice>(semanticActionConfigurations.size());
+ for (SemanticActionConfiguration actionConfiguration : semanticActionConfigurations) {
+ IEditHelperAdvice advice = AspectConfigurationFactoryRegistry.getInstance().createEditHelperAdvice(actionConfiguration);
+ if (advice != null) {
+ actionAdvices.add(advice);
+ // } else {
+ // Activator.log.error("Impossible to create an advice for :" + actionConfiguration, null);
+ }
+ }
+ if (actionAdvices != null && actionAdvices.size() > 0) {
+ return new ComposedEditHelperAdvice(actionAdvices);
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected IContainerDescriptor createContainerDescriptor(AspectSemanticTypeConfiguration configuration) {
+ List<SemanticActionConfiguration> semanticActionConfigurations = configuration.getActionConfiguration();
+ List<IContainerDescriptor> containerDescriptors = new ArrayList<IContainerDescriptor>(semanticActionConfigurations.size());
+ for (SemanticActionConfiguration actionConfiguration : semanticActionConfigurations) {
+ IContainerDescriptor containerDescriptor = AspectConfigurationFactoryRegistry.getInstance().createContainerDescriptor(actionConfiguration);
+ if (containerDescriptor != null) {
+ containerDescriptors.add(containerDescriptor);
+ // } else {
+ // Activator.log.error("Impossible to create a container descriptor for :" + actionConfiguration, null);
+ }
+ }
+ if (containerDescriptors != null && containerDescriptors.size() > 0) {
+ return new ComposedContainerDescriptor(containerDescriptors);
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public ICreationElementValidator createElementCreationValidator(AspectSemanticTypeConfiguration configuration) {
+ List<SemanticActionConfiguration> semanticActionConfigurations = configuration.getActionConfiguration();
+ List<ICreationElementValidator> actionValidators = new ArrayList<ICreationElementValidator>(semanticActionConfigurations.size());
+ for (SemanticActionConfiguration actionConfiguration : semanticActionConfigurations) {
+ ICreationElementValidator validator = AspectConfigurationFactoryRegistry.getInstance().createCreationElementValidator(actionConfiguration);
+ if (validator != null) {
+ actionValidators.add(validator);
+ // } else {
+ // Activator.log.error("Impossible to create a creation element validator for :" + actionConfiguration, null);
+ }
+ }
+ if (actionValidators != null && actionValidators.size() > 0) {
+ return new ComposedElementCreationValidator(actionValidators);
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected IElementMatcher createElementMatcher(AspectSemanticTypeConfiguration configuration) {
+ // these element types are there only for creation => it can not be match at any time
+ return new NullElementMatcher();
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ComposedContainerDescriptor.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ComposedContainerDescriptor.java
new file mode 100644
index 00000000000..eee67c4fedc
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ComposedContainerDescriptor.java
@@ -0,0 +1,95 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.gmf.runtime.emf.type.core.IContainerDescriptor;
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+
+/**
+ * @author RS211865
+ */
+public class ComposedContainerDescriptor implements IContainerDescriptor {
+
+ private final List<IContainerDescriptor> containerDescriptors;
+
+ /**
+ * @param containerDescriptors
+ */
+ public ComposedContainerDescriptor(List<IContainerDescriptor> containerDescriptors) {
+ this.containerDescriptors = containerDescriptors;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IElementMatcher getMatcher() {
+ List<IElementMatcher> matchers = new ArrayList<IElementMatcher>();
+ // creates a composed matcher from all container descriptors
+ for (IContainerDescriptor containerDescriptor : getContainerDescriptors()) {
+ // each composed advice should approve the request
+ IElementMatcher composedMatcher = containerDescriptor.getMatcher();
+ if (composedMatcher != null) {
+ matchers.add(composedMatcher);
+ }
+ }
+ if (matchers != null && !matchers.isEmpty()) {
+ return new ComposedElementMatcher(matchers);
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public EReference[] getContainmentFeatures() {
+ // retrieve all references in the intersection of all composed container descriptors
+ List<EReference> joinReferences = null;
+ // creates a composed matcher from all container descriptors
+ for (IContainerDescriptor containerDescriptor : getContainerDescriptors()) {
+ // each composed advice should approve the request
+ EReference[] eReferencesArray = containerDescriptor.getContainmentFeatures();
+ if (eReferencesArray != null) {
+ List<EReference> eReferences = Arrays.asList(eReferencesArray);
+ // if join references has not been set yet, set the list of possible containment features
+ // if not, make the intersection of both list
+ if (joinReferences == null) {
+ joinReferences = eReferences;
+ } else {
+ List<EReference> newReferences = new ArrayList<EReference>();
+ for (EReference eReference : joinReferences) {
+ if (eReferences.contains(eReference)) {
+ newReferences.add(eReference);
+ }
+ }
+ joinReferences = newReferences;
+ }
+ }
+ }
+ if (joinReferences != null) {
+ return joinReferences.toArray(new EReference[] {});
+ }
+ return null;
+ }
+
+ /**
+ * @return the containerDescriptors
+ */
+ protected List<IContainerDescriptor> getContainerDescriptors() {
+ return containerDescriptors;
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ComposedEditHelperAdvice.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ComposedEditHelperAdvice.java
new file mode 100644
index 00000000000..ae5fba0c6e6
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ComposedEditHelperAdvice.java
@@ -0,0 +1,178 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+import java.util.List;
+
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+/**
+ * Generic class for Aspect Element types
+ */
+public class ComposedEditHelperAdvice extends AbstractEditHelperAdvice {
+
+ /**
+ * List of composed advices
+ */
+ private final List<IEditHelperAdvice> composedAdvices;
+
+ /**
+ * Creates a composed edit helper advice from an ordered list of advices
+ */
+ public ComposedEditHelperAdvice(List<IEditHelperAdvice> composedAdvices) {
+ this.composedAdvices = composedAdvices;
+ }
+
+ /**
+ * Returns the list of composed advices for this edit helper advice.
+ *
+ * @return the list of composed advices
+ */
+ protected List<IEditHelperAdvice> getComposedAdvices() {
+ return composedAdvices;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean approveRequest(IEditCommandRequest request) {
+ for (IEditHelperAdvice advice : getComposedAdvices()) {
+ // each composed advice should approve the request
+ if (!advice.approveRequest(request)) {
+ return false;
+ }
+ }
+ return super.approveRequest(request);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ICommand getBeforeConfigureCommand(ConfigureRequest request) {
+ ICommand resultCommand = null;
+ for (IEditHelperAdvice advice : getComposedAdvices()) {
+ ICommand command = advice.getBeforeEditCommand(request);
+ if (command != null) {
+ if (resultCommand != null) {
+ resultCommand = resultCommand.compose(command);
+ } else {
+ resultCommand = command;
+ }
+ }
+ }
+ return resultCommand;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ICommand getAfterConfigureCommand(ConfigureRequest request) {
+ ICommand resultCommand = null;
+ for (IEditHelperAdvice advice : getComposedAdvices()) {
+ ICommand command = advice.getAfterEditCommand(request);
+ if (command != null) {
+ if (resultCommand != null) {
+ resultCommand = resultCommand.compose(command);
+ } else {
+ resultCommand = command;
+ }
+ }
+ }
+ return resultCommand;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ICommand getBeforeCreateCommand(CreateElementRequest request) {
+ ICommand resultCommand = null;
+ for (IEditHelperAdvice advice : getComposedAdvices()) {
+ ICommand command = advice.getBeforeEditCommand(request);
+ if (command != null) {
+ if (resultCommand != null) {
+ resultCommand = resultCommand.compose(command);
+ } else {
+ resultCommand = command;
+ }
+ }
+ }
+ return resultCommand;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ICommand getAfterCreateCommand(CreateElementRequest request) {
+ ICommand resultCommand = null;
+ for (IEditHelperAdvice advice : getComposedAdvices()) {
+ ICommand command = advice.getAfterEditCommand(request);
+ if (command != null) {
+ if (resultCommand != null) {
+ resultCommand = resultCommand.compose(command);
+ } else {
+ resultCommand = command;
+ }
+ }
+ }
+ return resultCommand;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ICommand getBeforeCreateRelationshipCommand(CreateRelationshipRequest request) {
+ ICommand resultCommand = null;
+ for (IEditHelperAdvice advice : getComposedAdvices()) {
+ ICommand command = advice.getBeforeEditCommand(request);
+ if (command != null) {
+ if (resultCommand != null) {
+ resultCommand = resultCommand.compose(command);
+ } else {
+ resultCommand = command;
+ }
+ }
+ }
+ return resultCommand;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ICommand getAfterCreateRelationshipCommand(CreateRelationshipRequest request) {
+ ICommand resultCommand = null;
+ for (IEditHelperAdvice advice : getComposedAdvices()) {
+ ICommand command = advice.getAfterEditCommand(request);
+ if (command != null) {
+ if (resultCommand != null) {
+ resultCommand = resultCommand.compose(command);
+ } else {
+ resultCommand = command;
+ }
+ }
+ }
+ return resultCommand;
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ComposedElementCreationValidator.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ComposedElementCreationValidator.java
new file mode 100644
index 00000000000..cbe283a8f64
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ComposedElementCreationValidator.java
@@ -0,0 +1,59 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+import java.util.List;
+
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+
+
+/**
+ * {@link ICreationElementValidator} composed by several validators
+ */
+public class ComposedElementCreationValidator implements ICreationElementValidator {
+
+
+ private final List<ICreationElementValidator> composedValidators;
+
+ /**
+ * Default Constructor
+ *
+ * @param composedValidators
+ * the list of composed validators
+ */
+ public ComposedElementCreationValidator(List<ICreationElementValidator> composedValidators) {
+ this.composedValidators = composedValidators;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canCreate(CreateElementRequest request) {
+ for (ICreationElementValidator validator : getComposedValidators()) {
+ if (!validator.canCreate(request)) {
+ return false;
+ }
+ }
+ // all validators were OK => element can be created
+ return true;
+ }
+
+ /**
+ * Returns the list of composed validators
+ *
+ * @return the list of composed validators
+ */
+ protected List<ICreationElementValidator> getComposedValidators() {
+ return composedValidators;
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ComposedElementMatcher.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ComposedElementMatcher.java
new file mode 100644
index 00000000000..de437cdd300
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ComposedElementMatcher.java
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+
+
+/**
+ * @author RS211865
+ */
+public class ComposedElementMatcher implements IElementMatcher {
+
+ private final List<IElementMatcher> matchers;
+
+ public ComposedElementMatcher(List<IElementMatcher> matchers) {
+ this.matchers = matchers;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean matches(EObject eObject) {
+ for (IElementMatcher matcher : getMatchers()) {
+ if (!matcher.matches(eObject)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * @return the matchers
+ */
+ protected List<IElementMatcher> getMatchers() {
+ return matchers;
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ConfigurableElementMatcherFactoryRegistry.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ConfigurableElementMatcherFactoryRegistry.java
new file mode 100644
index 00000000000..22fec1b1ebe
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ConfigurableElementMatcherFactoryRegistry.java
@@ -0,0 +1,132 @@
+/*****************************************************************************
+ * Copyright (c) 2013, 2016 CEA LIST, Christian W. Damus, 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ * Christian W. Damus - bug 485220
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+import static org.eclipse.papyrus.infra.extendedtypes.util.InternalUtils.loadClass;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+
+/**
+ * Registry for all element matcher factories for element matcher based on {@link MatcherConfiguration}.
+ */
+public class ConfigurableElementMatcherFactoryRegistry {
+
+ /** private singleton instance */
+ private static ConfigurableElementMatcherFactoryRegistry registry;
+
+ protected Map<String, IConfigurableElementMatcherFactory<MatcherConfiguration>> configurationTypeToMatcherFactory = null;
+
+ protected List<String> configurationTypeFactoryExceptions = null;
+
+ /**
+ * returns the singleton instance of this registry
+ *
+ * @return the singleton instance of this registry
+ */
+ public static synchronized ConfigurableElementMatcherFactoryRegistry getInstance() {
+ if (registry == null) {
+ registry = new ConfigurableElementMatcherFactoryRegistry();
+ registry.init();
+ }
+ return registry;
+ }
+
+ /**
+ * Inits the registry.
+ */
+ protected void init() {
+ configurationTypeToMatcherFactory = new HashMap<String, IConfigurableElementMatcherFactory<MatcherConfiguration>>();
+
+ }
+
+ /**
+ * Creates the {@link IElementMatcher} specific to the given rule configuration
+ *
+ * @param ruleConfiguration
+ * the rule configuration that will configure the created matcher
+ * @return the {@link IElementMatcher} created or <code>null</code> if none could be created
+ */
+ public IConfigurableElementMatcher<MatcherConfiguration> createElementMatcher(MatcherConfiguration matcherConfiguration) {
+ String configurationType = matcherConfiguration.eClass().getInstanceTypeName();
+ IConfigurableElementMatcherFactory<MatcherConfiguration> factory = configurationTypeToMatcherFactory.get(configurationType);
+ // check factory is not on the exception table
+ if (factory == null && isNotInFactoryExceptionList(configurationType)) {
+ Class<IConfigurableElementMatcherFactory<MatcherConfiguration>> factoryClass = retrieveFactoryClassFromExtensionPoint(configurationType);
+ if (factoryClass != null) {
+ try {
+ factory = factoryClass.newInstance();
+ } catch (InstantiationException e) {
+ if (configurationTypeFactoryExceptions == null) {
+ configurationTypeFactoryExceptions = new ArrayList<String>();
+ }
+ configurationTypeFactoryExceptions.add(configurationType);
+ } catch (IllegalAccessException e) {
+ if (configurationTypeFactoryExceptions == null) {
+ configurationTypeFactoryExceptions = new ArrayList<String>();
+ }
+ configurationTypeFactoryExceptions.add(configurationType);
+ }
+ configurationTypeToMatcherFactory.put(configurationType, factory);
+ }
+ }
+ if (factory != null) {
+ IConfigurableElementMatcher<MatcherConfiguration> elementMatcher = factory.createElementMatcher(matcherConfiguration);
+ if (elementMatcher != null) {
+ // elementMatcher.init(matcherConfiguration);
+ return elementMatcher;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * check this configuration type has not already caused issues du
+ *
+ * @param configurationType
+ * @return
+ */
+ protected boolean isNotInFactoryExceptionList(String configurationType) {
+ if (configurationTypeFactoryExceptions == null) {
+ return true;
+ }
+ // this is not null, check the configuration type is not in the list
+ return !configurationTypeFactoryExceptions.contains(configurationType);
+ }
+
+ /**
+ * Returns the {@link IExtendedElementTypeFactory} class used to instantiate element type for the given configuration
+ *
+ * @return the {@link IExtendedElementTypeFactory} found or <code>null</code> if none was found
+ */
+ @SuppressWarnings("unchecked")
+ protected Class<IConfigurableElementMatcherFactory<MatcherConfiguration>> retrieveFactoryClassFromExtensionPoint(String configurationType) {
+ IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(IElementMatcherExtensionPoint.EXTENSION_POINT_ID);
+ for (IConfigurationElement configurationElement : elements) {
+ String eCoreClassName = configurationElement.getAttribute(IElementMatcherExtensionPoint.MATCHER_CONFIGURATION_CLASS);
+ if (configurationType.equals(eCoreClassName)) {
+ // retrieve factory to load
+ String factoryClassName = configurationElement.getAttribute(IElementMatcherExtensionPoint.MATCHER_FACTORY_CLASS);
+ return (Class<IConfigurableElementMatcherFactory<MatcherConfiguration>>) loadClass(factoryClassName, configurationElement.getContributor().getName());
+ }
+ }
+ return null;
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ElementTypeSetUtils.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ElementTypeSetUtils.java
new file mode 100644
index 00000000000..e143ee86007
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ElementTypeSetUtils.java
@@ -0,0 +1,117 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+
+/**
+ * Utility class to manipulate {@link ExtendedElementTypeSet}.
+ */
+public class ElementTypeSetUtils {
+
+ /**
+ * Loads
+ *
+ * @param extendedElementTypeSet
+ */
+ public static void load(ExtendedElementTypeSet extendedElementTypeSet) {
+
+ }
+
+
+ // public static void unload(String identifier) {
+ // // retrieve the extended type set with given identifier and unloads it
+ // ExtendedElementTypeSet set = ExtendedElementTypeSetRegistry.getInstance().getExtendedTypeSets().get(identifier);
+ // if(set!=null) {
+ // unload(set);
+ // }
+ // }
+
+ // /**
+ // * Unloads a given {@link ExtendedElementTypeSet}
+ // * @param elementTypeSet the element type set to unload
+ // */
+ // public static void unload(ExtendedElementTypeSet elementTypeSet) {
+ // // retrieve the specializationTypeRegistry to remove all contribution from the given element type set
+ // Field declaredField = null;
+ // try {
+ // declaredField = ElementTypeRegistry.class.getDeclaredField("specializationTypeRegistry");
+ // } catch (SecurityException e1) {
+ // Activator.log.error(e1);
+ // return;
+ // } catch (NoSuchFieldException e1) {
+ // Activator.log.error(e1);
+ // return;
+ // }
+ // if(declaredField==null) {
+ // Activator.log.error("impossible to find specializationTypeRegistry", null);
+ // return;
+ // }
+ // declaredField.setAccessible(true);
+ // SpecializationTypeRegistry registry = null;
+ // try {
+ // registry = (SpecializationTypeRegistry)declaredField.get(ElementTypeRegistry.getInstance());
+ // } catch (IllegalArgumentException e) {
+ // Activator.log.error(e);
+ // } catch (IllegalAccessException e) {
+ // Activator.log.error(e);
+ // }
+ //
+ // if(registry == null) {
+ // return;
+ // }
+ //
+ // for(ElementTypeConfiguration configuration : elementTypeSet.getElementType()) {
+ // if(configuration!=null && configuration.getIdentifier()!=null) {
+ // String identifier = configuration.getIdentifier();
+ // // retrieve descriptor
+ // SpecializationTypeDescriptor descriptor = registry.getSpecializationTypeDescriptor(identifier);
+ // if(descriptor!=null) {
+ // registry.removeSpecializationType(descriptor);
+ // }
+ // }
+ // }
+ //
+ // elementTypeSet.eResource().unload();
+ // elementTypeSet.eResource().getResourceSet().getResources().remove(elementTypeSet.eResource());
+ // }
+
+ // public static void resetRegistry() {
+ // // FIXME save the current listeners, to add them back to the registry
+ // IClientContext context;
+ // try {
+ // context = TypeContext.getContext();
+ // } catch (ServiceException e1) {
+ // Activator.log.error(e1);
+ // return;
+ // }
+ // // impossibe to unregister element types...
+ // // => destroy the singleton instance of the registry...
+ // try {
+ // Field declaredField = ElementTypeRegistry.class.getDeclaredField("INSTANCE");
+ // declaredField.setAccessible(true);
+ // declaredField.set(null, null);
+ // } catch (SecurityException e1) {
+ // e1.printStackTrace();
+ // } catch (NoSuchFieldException e1) {
+ // e1.printStackTrace();
+ // } catch (IllegalArgumentException e) {
+ // e.printStackTrace();
+ // } catch (IllegalAccessException e) {
+ // e.printStackTrace();
+ // }
+ //
+ // // create the registry
+ // ElementTypeRegistry.getInstance();
+ // }
+
+} \ No newline at end of file
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ExtendedElementTypeSetRegistry.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ExtendedElementTypeSetRegistry.java
new file mode 100644
index 00000000000..0c2aa4964ec
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ExtendedElementTypeSetRegistry.java
@@ -0,0 +1,471 @@
+/*****************************************************************************
+ * Copyright (c) 2013, 2016 CEA LIST, Christian W. Damus, 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ * Christian W. Damus - bugs 459174, 459825, 485220
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+import static org.eclipse.papyrus.infra.extendedtypes.util.InternalUtils.loadClass;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeUtil;
+import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.internal.descriptors.IEditHelperAdviceDescriptor;
+import org.eclipse.gmf.runtime.emf.type.core.internal.impl.SpecializationTypeRegistry;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.elementtypesconfigurations.registries.ElementTypeSetConfigurationRegistry;
+import org.eclipse.papyrus.infra.extendedtypes.types.IExtendedHintedElementType;
+import org.eclipse.papyrus.infra.services.edit.internal.context.TypeContext;
+import org.osgi.framework.Bundle;
+
+/**
+ * Registry to manage load/unloaded {@link ExtendedElementTypeSet}.
+ */
+public class ExtendedElementTypeSetRegistry {
+
+ public static final String LOCAL_CONTRIBUTOR_ID = "local contribution";
+
+ /** private singleton instance */
+ private static ExtendedElementTypeSetRegistry registry;
+
+ /** Map of retrieved extended type sets, key is their identifier */
+ protected Map<String, ExtendedElementTypeSet> extendedTypeSets = null;
+
+ /** unique resource set to load all extended types models */
+ protected ResourceSet extendedTypesResourceSet = null;
+
+ protected List<ExtendedElementTypeSet> loadedExtendedElementTypeSets = null;
+
+ protected Map<String, IExtendedElementTypeFactory<ElementTypeConfiguration>> configurationTypeToElementTypeFactory = null;
+
+ protected List<String> configurationTypeFactoryExceptions = null;
+
+ /**
+ * returns the singleton instance of this registry
+ *
+ * @return the singleton instance of this registry
+ */
+ public static synchronized ExtendedElementTypeSetRegistry getInstance() {
+ if (registry == null) {
+ // Ensure the existence of element types modeled by the Element Types Configurations
+ ElementTypeSetConfigurationRegistry.getInstance();
+
+ registry = new ExtendedElementTypeSetRegistry();
+ registry.init();
+ }
+ return registry;
+ }
+
+ /**
+ * Inits the registry.
+ */
+ protected void init() {
+ // 0. Resets values
+ extendedTypesResourceSet = null;
+ extendedTypeSets = null;
+ configurationTypeToElementTypeFactory = new HashMap<String, IExtendedElementTypeFactory<ElementTypeConfiguration>>();
+ // 1. creates the resource set
+ extendedTypesResourceSet = createResourceSet();
+ // 2. creates the list only when registry is acceded for the first time, (or on reload?)
+ extendedTypeSets = loadExtendedTypeSets();
+ }
+
+ /**
+ * Dispose this registry, i.e. remove all contribution on the element type registry
+ */
+ public void dispose() {
+ if (extendedTypeSets == null) {
+ return;
+ }
+ // copy set of entries to iterate and unload them one by one
+ List<Entry<String, ExtendedElementTypeSet>> entriesToDispose = new ArrayList<Entry<String, ExtendedElementTypeSet>>(extendedTypeSets.entrySet());
+
+ for (Entry<String, ExtendedElementTypeSet> entry : entriesToDispose) {
+ unload(entry.getKey());
+ }
+ extendedTypesResourceSet = null;
+ extendedTypeSets = null;
+ configurationTypeToElementTypeFactory = new HashMap<String, IExtendedElementTypeFactory<ElementTypeConfiguration>>();
+ // 1. creates the resource set
+ extendedTypesResourceSet = null;
+ registry = null;
+ }
+
+
+ /**
+ * Loads a given extended type set from a given identifier
+ */
+ public void loadExtendedElementTypeSet(String identifier) {
+ if (getExtendedTypeSets() == null) {
+ return;
+ }
+
+ // retrieve the path from the identifier
+ String path = UserExtendedTypesRegistry.getInstance().getLocalExtendedTypesDefinitions().get(identifier);
+ if (path == null) {
+ return;
+ }
+
+ URI localURI = URI.createPlatformResourceURI(path, true);
+ Resource resource = extendedTypesResourceSet.createResource(localURI);
+ try {
+ resource.load(null);
+ EObject content = resource.getContents().get(0);
+ if (content instanceof ExtendedElementTypeSet) {
+ getExtendedTypeSets().put(identifier, (ExtendedElementTypeSet) content);
+ loadExtendedElementTypeSet((ExtendedElementTypeSet) content);
+ }
+ } catch (IOException e) {
+ Activator.log.error(e);
+ }
+ }
+
+ /**
+ * Loads the specified extended element type set.
+ * This does not take care to unload a similar set (a set with the same id) before loading. This should be handled before calling this method.
+ *
+ * @param extendedElementTypeSet
+ * {@link ExtendedElementTypeSet} to load.
+ */
+ public void loadExtendedElementTypeSet(ExtendedElementTypeSet extendedElementTypeSet) {
+ IClientContext context;
+ try {
+ context = TypeContext.getContext();
+ } catch (ServiceException e1) {
+ Activator.log.error(e1);
+ return;
+ }
+ List<ElementTypeConfiguration> elementTypeConfigurations = extendedElementTypeSet.getElementType();
+ for (ElementTypeConfiguration configuration : elementTypeConfigurations) {
+ // load class associated to the configuration model => read extension point that defines this kind of configuration.
+ String configurationType = configuration.eClass().getInstanceTypeName();
+ // retrieve the factory for a given kind of configuration
+ IExtendedElementTypeFactory<ElementTypeConfiguration> factory = configurationTypeToElementTypeFactory.get(configurationType);
+ // check factory is not on the exception table
+ if (factory == null && isNotInFactoryExceptionList(configurationType)) {
+ Class<IExtendedElementTypeFactory<ElementTypeConfiguration>> factoryClass = retrieveFactoryClassFromExtensionPoint(configurationType);
+ if (factoryClass != null) {
+ try {
+ factory = factoryClass.newInstance();
+ } catch (InstantiationException e) {
+ if (configurationTypeFactoryExceptions == null) {
+ configurationTypeFactoryExceptions = new ArrayList<String>();
+ }
+ configurationTypeFactoryExceptions.add(configurationType);
+ } catch (IllegalAccessException e) {
+ if (configurationTypeFactoryExceptions == null) {
+ configurationTypeFactoryExceptions = new ArrayList<String>();
+ }
+ configurationTypeFactoryExceptions.add(configurationType);
+ }
+ configurationTypeToElementTypeFactory.put(configurationType, factory);
+ }
+ }
+ if (factory != null) {
+ IExtendedHintedElementType type = factory.createElementType(configuration);
+ // register element Type
+ ElementTypeRegistry.getInstance().register(type);
+ context.bindId(type.getId());
+ }
+ }
+ }
+
+ /**
+ * Unloads a given {@link ExtendedElementTypeSet}
+ *
+ * @param elementTypeSet
+ * the element type set to unload
+ */
+ public void unload(String identifier) {
+ if (extendedTypeSets == null) {
+ return;
+ }
+ ExtendedElementTypeSet elementTypeSet = extendedTypeSets.get(identifier);
+ if (elementTypeSet == null) {
+ // there is an entry in the map for this extended type set, it should be removed...
+ extendedTypeSets.remove(identifier);
+ return;
+ }
+
+ // Retrieve the element types to remove them from the registry
+ ElementTypeRegistry registry = ElementTypeRegistry.getInstance();
+ List<IElementType> elementTypes = new ArrayList<IElementType>(elementTypeSet.getElementType().size());
+ for (ElementTypeConfiguration configuration : elementTypeSet.getElementType()) {
+ if (configuration != null && configuration.getIdentifier() != null) {
+ String configIdentifier = configuration.getIdentifier();
+ // retrieve element type
+ IElementType elementType = registry.getType(configIdentifier);
+ if (elementType != null) {
+ elementTypes.add(elementType);
+ }
+ }
+ }
+
+ // And remove them
+ ElementTypeUtil.deregisterElementTypes(elementTypes, ElementTypeUtil.ALL_DEPENDENTS);
+
+ // Then unload the configuration model
+ Resource resource = elementTypeSet.eResource();
+ if (resource != null) {
+ resource.unload();
+ if (extendedTypesResourceSet != null) {
+ extendedTypesResourceSet.getResources().remove(resource);
+ }
+ }
+ extendedTypeSets.remove(identifier);
+ }
+
+ protected void removeAdviceFromBindings(SpecializationTypeRegistry registry, String adviceDescriptorId, IEditHelperAdviceDescriptor adviceDescriptor) {
+ ElementTypeRegistry.getInstance().deregisterAdvice(adviceDescriptor);
+ }
+
+
+
+
+ /**
+ * check this configuration type has not already caused issues du
+ *
+ * @param configurationType
+ * @return
+ */
+ protected boolean isNotInFactoryExceptionList(String configurationType) {
+ if (configurationTypeFactoryExceptions == null) {
+ return true;
+ }
+ // this is not null, check the configuration type is not in the list
+ return !configurationTypeFactoryExceptions.contains(configurationType);
+ }
+
+ /**
+ * Returns the {@link IExtendedElementTypeFactory} class used to instantiate element type for the given configuration
+ *
+ * @return the {@link IExtendedElementTypeFactory} found or <code>null</code> if none was found
+ */
+ @SuppressWarnings("unchecked")
+ protected Class<IExtendedElementTypeFactory<ElementTypeConfiguration>> retrieveFactoryClassFromExtensionPoint(String configurationType) {
+ IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(IExtendedTypeConfigurationExtensionPoint.EXTENSION_POINT_ID);
+ for (IConfigurationElement configurationElement : elements) {
+ String eCoreClassName = configurationElement.getAttribute(IExtendedTypeConfigurationExtensionPoint.CONFIGURATION_CLASS);
+ if (configurationType.equals(eCoreClassName)) {
+ // retrieve factory to load
+ String factoryClassName = configurationElement.getAttribute(IExtendedTypeConfigurationExtensionPoint.FACTORY_CLASS);
+ return (Class<IExtendedElementTypeFactory<ElementTypeConfiguration>>) loadClass(factoryClassName, configurationElement.getContributor().getName());
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Retrieves and loads extended type sets registered in the platform. It should also load configuration sets from the workspace.
+ */
+ protected Map<String, ExtendedElementTypeSet> loadExtendedTypeSets() {
+ Map<String, ExtendedElementTypeSet> extendedElementTypeSets = new HashMap<String, ExtendedElementTypeSet>();
+ // 1. retrieve from the workspace
+ Map<String, ExtendedElementTypeSet> localSets = loadExtendedTypeSetsFromWorkspace();
+ if (localSets != null && !localSets.isEmpty()) {
+ extendedElementTypeSets.putAll(localSets);
+ }
+
+ // 2. retrieve from the platform. If already in workspace (id), do not load the platform ones
+ Map<String, ExtendedElementTypeSet> registeredSets = loadExtendedTypeSetsFromPlatform(localSets.keySet());
+ if (registeredSets != null && !registeredSets.isEmpty()) {
+ extendedElementTypeSets.putAll(registeredSets);
+ }
+ // load each extended element type set
+ for (Entry<String, ExtendedElementTypeSet> entry : extendedElementTypeSets.entrySet()) {
+ loadExtendedElementTypeSet(entry.getValue());
+ }
+ return extendedElementTypeSets;
+ }
+
+ /**
+ * @return
+ */
+ protected Map<String, ExtendedElementTypeSet> loadExtendedTypeSetsFromWorkspace() {
+ Map<String, String> localFilesPath = UserExtendedTypesRegistry.getInstance().getLocalExtendedTypesDefinitions();
+ Map<String, ExtendedElementTypeSet> workspaceElementTypeSets = new HashMap<String, ExtendedElementTypeSet>();
+ if (localFilesPath != null && !localFilesPath.isEmpty()) {
+ for (Entry<String, String> idToPath : localFilesPath.entrySet()) {
+ String filePath = idToPath.getValue();
+ String id = idToPath.getKey();
+
+ URI localURI = URI.createPlatformResourceURI(filePath, true);
+ Resource resource = extendedTypesResourceSet.createResource(localURI);
+ try {
+ resource.load(null);
+ EObject content = resource.getContents().get(0);
+ if (content instanceof ExtendedElementTypeSet) {
+ workspaceElementTypeSets.put(id, (ExtendedElementTypeSet) content);
+ }
+ } catch (IOException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+ return workspaceElementTypeSets;
+ }
+
+ /**
+ * Loads the extensions in the platform
+ *
+ * @return the list of extension registered in the platform
+ */
+ protected Map<String, ExtendedElementTypeSet> loadExtendedTypeSetsFromPlatform(Set<String> workspaceDefinitions) {
+ Map<String, ExtendedElementTypeSet> platformElementTypeSets = new HashMap<String, ExtendedElementTypeSet>();
+ IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(IExtendedElementTypeSetExtensionPoint.EXTENSION_POINT_ID);
+ // for each element, parses and retrieve the model file. then loads it and returns the root element
+ for (IConfigurationElement element : elements) {
+ String modelPath = element.getAttribute(IExtendedElementTypeSetExtensionPoint.PATH);
+ String extendedTypeSetId = element.getAttribute(IExtendedElementTypeSetExtensionPoint.ID);
+ String contributorID = element.getContributor().getName();
+ if (Platform.inDebugMode()) {
+ Activator.log.debug("[Reading extension point]");
+ Activator.log.debug("- Path to the model: " + modelPath);
+ Activator.log.debug("- id of the container bundle: " + contributorID);
+ Activator.log.debug("- id of the extended type set: " + extendedTypeSetId);
+ }
+ ExtendedElementTypeSet set = getExtendedElementTypeSet(extendedTypeSetId, modelPath, contributorID);
+ if (set != null && !workspaceDefinitions.contains(extendedTypeSetId)) { // do not add if it is locally redefined
+ platformElementTypeSets.put(extendedTypeSetId, set);
+ }
+ }
+ return platformElementTypeSets;
+ }
+
+ /**
+ * <p>
+ * Loads the resource containing the extended element type set model.
+ * </p>
+ * <p>
+ * It looks the model file in the fragments first, then in the plugin itself.<BR>
+ * If this is already a fragment, it should look in the fragment only
+ * </p>
+ *
+ * @param extendedTypesID
+ * id of the extended type set to load
+ * @param modelPath
+ * path of the model in the bundle
+ * @param bundleId
+ * id of the bundle containing the model file
+ * @return the loaded file or <code>null</code> if some problem occured during loading
+ */
+ protected ExtendedElementTypeSet getExtendedElementTypeSet(String extendedTypesID, String modelPath, String bundleId) {
+ // 1. look in preferences.
+ String filePath = UserExtendedTypesRegistry.getInstance().getExtendedTypesRedefinition(extendedTypesID);
+ if (filePath != null) {
+ getExtendedElementTypeSetInPluginStateArea(extendedTypesID);
+ }
+ // 2. no local redefinition. Load extended type set from plugin definition
+ Bundle bundle = Platform.getBundle(bundleId);
+ if (Platform.isFragment(bundle)) {
+ return getExtendedElementTypeSetInBundle(modelPath, bundleId);
+ } else { // this is a plugin. Search in sub fragments, then in the plugin
+ Bundle[] fragments = Platform.getFragments(bundle);
+ // no fragment, so the file should be in the plugin itself
+ if (fragments == null) {
+ return getExtendedElementTypeSetInBundle(modelPath, bundleId);
+ } else {
+ for (Bundle fragment : fragments) {
+ ExtendedElementTypeSet extendedElementTypeSet = getExtendedElementTypeSetInBundle(modelPath, fragment.getSymbolicName());
+ if (extendedElementTypeSet != null) {
+ return extendedElementTypeSet;
+ }
+ }
+ // not found in fragments. Look in the plugin itself
+ return getExtendedElementTypeSetInBundle(modelPath, bundleId);
+ }
+ }
+ }
+
+ /**
+ * Retrieves the contribution in the plugin area
+ *
+ * @param path
+ * the path of the element type set to load in the plugin area
+ */
+ protected ExtendedElementTypeSet getExtendedElementTypeSetInPluginStateArea(String path) {
+ // read in preferences area
+ IPath resourcePath = Activator.getDefault().getStateLocation().append(path);
+ URI uri = URI.createFileURI(resourcePath.toOSString());
+ if (uri != null && uri.isFile()) {
+ Resource resource = extendedTypesResourceSet.createResource(uri);
+ try {
+ resource.load(null);
+ } catch (IOException e) {
+ return null;
+ }
+ EObject content = resource.getContents().get(0);
+ if (content instanceof ExtendedElementTypeSet) {
+ return (ExtendedElementTypeSet) content;
+ }
+ Activator.log.error("Impossible to cast the object into an ExtendedElementTypeSet: " + content, null);
+ return null;
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param modelPath
+ * path of the model in the bundle
+ * @param bundleId
+ * id of the bundle containing the model file
+ * @return the loaded file or <code>null</code> if some problem occured during loading
+ */
+ protected ExtendedElementTypeSet getExtendedElementTypeSetInBundle(String modelPath, String bundleID) {
+ Resource resource = extendedTypesResourceSet.createResource(URI.createPlatformPluginURI(bundleID + IPath.SEPARATOR + modelPath, true));
+ try {
+ resource.load(null);
+ } catch (IOException e) {
+ return null;
+ }
+ EObject content = resource.getContents().get(0);
+ if (content instanceof ExtendedElementTypeSet) {
+ return (ExtendedElementTypeSet) content;
+ }
+ Activator.log.error("Impossible to cast the object into an ExtendedElementTypeSet: " + content, null);
+ return null;
+ }
+
+ /**
+ * Creates the resource set that contains all models for extended types
+ *
+ * @return the resource set newly created.
+ */
+ protected ResourceSet createResourceSet() {
+ ResourceSet set = new ResourceSetImpl();
+ return set;
+ }
+
+ /**
+ * @return the extendedTypeSets
+ */
+ public Map<String, ExtendedElementTypeSet> getExtendedTypeSets() {
+ return extendedTypeSets;
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ExtendedTypeRegistryService.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ExtendedTypeRegistryService.java
new file mode 100644
index 00000000000..f08da3a43fc
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ExtendedTypeRegistryService.java
@@ -0,0 +1,52 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+import org.eclipse.papyrus.infra.core.services.IService;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+
+
+/**
+ * Service to register extended element types
+ */
+public class ExtendedTypeRegistryService implements IService {
+
+ /**
+ * {@inheritDoc}
+ */
+ public void init(ServicesRegistry servicesRegistry) throws ServiceException {
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void startService() throws ServiceException {
+ // register elements in element type registry
+ ExtendedElementTypeSetRegistry.getInstance();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void disposeService() throws ServiceException {
+ // extended element type set registry should unregister all added element types in the gmf registry
+ ExtendedElementTypeSetRegistry.getInstance().dispose();
+ }
+
+ public ExtendedElementTypeSetRegistry getExtendedElementTypeSetRegistry() {
+ return ExtendedElementTypeSetRegistry.getInstance();
+ }
+
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IActionConfigurationModelCreation.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IActionConfigurationModelCreation.java
new file mode 100644
index 00000000000..1364c39d18d
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IActionConfigurationModelCreation.java
@@ -0,0 +1,22 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+
+/**
+ * Interface used to create new aspect action model element in the configuration model
+ */
+public interface IActionConfigurationModelCreation<T extends ActionConfiguration> {
+
+ public T createConfigurationModel();
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IActionContainerDescriptor.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IActionContainerDescriptor.java
new file mode 100644
index 00000000000..1b71bf52bbf
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IActionContainerDescriptor.java
@@ -0,0 +1,30 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+import org.eclipse.gmf.runtime.emf.type.core.IContainerDescriptor;
+
+
+/**
+ * Descriptor for the configurable container descriptor
+ */
+public interface IActionContainerDescriptor<T extends ActionConfiguration> extends IContainerDescriptor {
+
+ /**
+ * Initializes the container descriptor using the given configuration
+ *
+ * @param actionConfiguration
+ * the confiugration for this container descriptor
+ */
+ void init(T actionConfiguration);
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IActionCreationElementValidator.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IActionCreationElementValidator.java
new file mode 100644
index 00000000000..037a56994e7
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IActionCreationElementValidator.java
@@ -0,0 +1,26 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+
+/**
+ * Interface implemented by all {@link ICreationElementValidator} configured by {@link ActionConfiguration}
+ */
+public interface IActionCreationElementValidator<T extends ActionConfiguration> extends ICreationElementValidator {
+
+
+ /**
+ * Initialize the validator with the given action configuration
+ */
+ void init(T configuration);
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IActionEditHelperAdvice.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IActionEditHelperAdvice.java
new file mode 100644
index 00000000000..7d6bd8e78b4
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IActionEditHelperAdvice.java
@@ -0,0 +1,24 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+
+
+/**
+ *
+ */
+public interface IActionEditHelperAdvice<T extends ActionConfiguration> extends IEditHelperAdvice {
+
+ public void init(T configuration);
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IAspectTypeExtensionPoint.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IAspectTypeExtensionPoint.java
new file mode 100644
index 00000000000..7c69ddaa2b3
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IAspectTypeExtensionPoint.java
@@ -0,0 +1,41 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+
+/**
+ * Constants for the extension point aspectActionConfiguration (registering models containing definition of {@link ActionConfiguration}).
+ */
+public interface IAspectTypeExtensionPoint {
+
+ /** ID of the extension point */
+ public final static String EXTENSION_POINT_ID = Activator.PLUGIN_ID + ".aspectActionConfiguration";
+
+ /** attribute: name of the configuration */
+ public static final String NAME = "name";
+
+ /** attribute: icon of the configuration */
+ public static final String ICON = "icon";
+
+ /** attribute: description of the configuration */
+ public static final String DESCRIPTION = "description";
+
+ public static final String CONTAINER_DESCRIPTOR_CLASS = "semanticTypeDescriptor";
+
+ public static final String EDIT_HELPER_ADVICE_CLASS = "editHelperAdvice";
+
+ public static final String CONFIGURATION_CLASS = "configurationClass";
+
+ public static final String CONFIGURATION_MODEL_CREATION = "configurationModelCreation";
+
+ public static final String CREATION_ELEMENT_VALIDATOR_CLASS = "creationElementValidator";
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IConfigurableElementMatcher.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IConfigurableElementMatcher.java
new file mode 100644
index 00000000000..e2b02bdd02e
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IConfigurableElementMatcher.java
@@ -0,0 +1,30 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+
+
+/**
+ * Interface implemented by all element matchers configured by a {@link MatcherConfiguration}
+ */
+public interface IConfigurableElementMatcher<T extends MatcherConfiguration> extends IElementMatcher {
+
+ /**
+ * Inits the element matcher with the given contribution. Should be called once, after element matcher instantiation
+ *
+ * @param configuration
+ * the configuration of this {@link IElementMatcher}
+ */
+ // public void init(T configuration);
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IConfigurableElementMatcherFactory.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IConfigurableElementMatcherFactory.java
new file mode 100644
index 00000000000..a7e2cd495b2
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IConfigurableElementMatcherFactory.java
@@ -0,0 +1,32 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+import org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration.IInvariantElementMatcher;
+
+
+/**
+ * interface for factories that instantiate {@link IInvariantElementMatcher} with their given configuration
+ */
+public interface IConfigurableElementMatcherFactory<T extends MatcherConfiguration> {
+
+ /**
+ * Creates an element matcher with the specified configuration
+ *
+ * @param configuration
+ * the configuration of the {@link IElementMatcher}
+ * @return the created element matcher or <code>null</code> if none was created
+ */
+ public IConfigurableElementMatcher<T> createElementMatcher(T configuration);
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ICreationElementValidator.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ICreationElementValidator.java
new file mode 100644
index 00000000000..ffc53f9935a
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ICreationElementValidator.java
@@ -0,0 +1,28 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+
+
+/**
+ * Validator used to check if element can be created for a given {@link CreateElementRequest}
+ */
+public interface ICreationElementValidator {
+
+ /**
+ * @param request
+ * @return
+ */
+ public boolean canCreate(CreateElementRequest request);
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IEditHelperAdviceConstants.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IEditHelperAdviceConstants.java
new file mode 100644
index 00000000000..155a5189141
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IEditHelperAdviceConstants.java
@@ -0,0 +1,22 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+
+/**
+ * Constants used by Papyrus edit helper advices
+ */
+public interface IEditHelperAdviceConstants {
+
+ public String NO_UI_KEY = "no_ui";
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IElementMatcherConfigurationModelCreation.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IElementMatcherConfigurationModelCreation.java
new file mode 100644
index 00000000000..0e831b6b4d1
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IElementMatcherConfigurationModelCreation.java
@@ -0,0 +1,22 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+
+/**
+ * Interface that all extension point for element matcher should provide
+ */
+public interface IElementMatcherConfigurationModelCreation<T extends MatcherConfiguration> {
+
+ public T createConfigurationModel();
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IElementMatcherExtensionPoint.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IElementMatcherExtensionPoint.java
new file mode 100644
index 00000000000..81a1157c10c
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IElementMatcherExtensionPoint.java
@@ -0,0 +1,33 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+
+
+/**
+ * Extension point interface for {@link MatcherConfiguration} runtime implementations
+ */
+public interface IElementMatcherExtensionPoint {
+
+ /** ID of the extension point */
+ public final static String EXTENSION_POINT_ID = Activator.PLUGIN_ID + ".elementMatcherConfiguration";
+
+ public static final String CONFIGURATION_NAME = "name";
+
+ public static final String MATCHER_CONFIGURATION_CLASS = "configurationClass";
+
+ public static final String MATCHER_FACTORY_CLASS = "factoryClass";
+
+ public static final String CONFIGURATION_MODEL_CREATION = "configurationModelCreation";
+
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IExtendedElementTypeFactory.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IExtendedElementTypeFactory.java
new file mode 100644
index 00000000000..f15147da7be
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IExtendedElementTypeFactory.java
@@ -0,0 +1,42 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+import org.eclipse.papyrus.infra.extendedtypes.types.IExtendedHintedElementType;
+
+
+/**
+ * Interface for all factories that will create element types from a given configuration
+ */
+public interface IExtendedElementTypeFactory<T extends ElementTypeConfiguration> /* extends IElementTypeFactory */{
+
+ /**
+ * Creates an element type for the given configuration
+ *
+ * @param configuration
+ * configuration of the element type to create
+ * @return the newly created element type or <code>null</code> if no element type could be created
+ */
+ IExtendedHintedElementType createElementType(T configuration);
+
+
+ /**
+ * Creates the element creation validator which will be used to know if the element can be created or not
+ *
+ * @param configuration
+ * the configuration of the new element type
+ * @return the element creation Validator or <code>null</code> if none could be created
+ */
+ ICreationElementValidator createElementCreationValidator(T configuration);
+
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IExtendedElementTypeSetExtensionPoint.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IExtendedElementTypeSetExtensionPoint.java
new file mode 100644
index 00000000000..6ab8e147751
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IExtendedElementTypeSetExtensionPoint.java
@@ -0,0 +1,40 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+
+/**
+ * Constants for the extension point ExtendedTypesSet (registering models containing definition of {@link ExtendedElementTypeSet}).
+ */
+public interface IExtendedElementTypeSetExtensionPoint {
+
+ /** ID of the extension point */
+ public final static String EXTENSION_POINT_ID = Activator.PLUGIN_ID + ".extendedElementTypeSet";
+
+ /** attribute: path to the model file in the bundle */
+ public static final String PATH = "path";
+
+ /** attribute: identifier of the contribution */
+ public static final String ID = "id";
+
+ /** attribute: name of the configuration */
+ public static final String NAME = "name";
+
+ /** attribute: icon of the configuration */
+ public static final String ICON = "icon";
+
+ /** attribute: description of the configuration */
+ public static final String DESCRIPTION = "description";
+
+ /** element: element for the configuration element */
+ public static final String CONFIGURATION = "configuration";
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IExtendedTypeConfigurationExtensionPoint.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IExtendedTypeConfigurationExtensionPoint.java
new file mode 100644
index 00000000000..b129474889c
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/IExtendedTypeConfigurationExtensionPoint.java
@@ -0,0 +1,39 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes;
+
+/**
+ * Constants for the extension point ExtendedTypesSet (registering models containing definition of {@link ExtendedElementTypeSet}).
+ */
+public interface IExtendedTypeConfigurationExtensionPoint {
+
+ /** ID of the extension point */
+ public final static String EXTENSION_POINT_ID = Activator.PLUGIN_ID + ".extendedTypeConfiguration";
+
+ /** attribute: name of the configuration */
+ public static final String NAME = "name";
+
+ /** attribute: icon of the configuration */
+ public static final String ICON = "icon";
+
+ /** attribute: description of the configuration */
+ public static final String DESCRIPTION = "description";
+
+ /** attribute factoryClass */
+ public static final String FACTORY_CLASS = "factoryClass";
+
+ /** attribute configurationClass */
+ public static final String CONFIGURATION_CLASS = "configurationClass";
+
+ /** attribute itemProvider */
+ public static final String ITEM_PROVIDER = "itemProvider";
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/UserExtendedTypesRegistry.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/UserExtendedTypesRegistry.java
new file mode 100644
index 00000000000..e94d7291781
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/UserExtendedTypesRegistry.java
@@ -0,0 +1,107 @@
+/*****************************************************************************
+ * Copyright (c) 2016 Christian W. Damus 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:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.extendedtypes;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Predicate;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.papyrus.infra.elementtypesconfigurations.Activator;
+import org.eclipse.papyrus.infra.extendedtypes.internal.spi.IUserExtendedTypesProvider;
+
+/**
+ * Registry of {@link IUserExtendedTypesProvider}s.
+ */
+class UserExtendedTypesRegistry implements IUserExtendedTypesProvider {
+
+ private static final UserExtendedTypesRegistry INSTANCE = new UserExtendedTypesRegistry();
+
+ // Only should have the one in the UI bundle
+ private final List<IUserExtendedTypesProvider> providers = new ArrayList<>(1);
+
+ private UserExtendedTypesRegistry() {
+ super();
+
+ IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(Activator.PLUGIN_ID, "userExtendedTypes"); //$NON-NLS-1$
+ for (IConfigurationElement next : elements) {
+ switch (next.getName()) {
+ case "provider": //$NON-NLS-1$
+ try {
+ providers.add(createProvider(next));
+ } catch (ClassCastException e) {
+ Activator.log.error(e);
+ } catch (CoreException e) {
+ Activator.log.log(e.getStatus());
+ }
+ break;
+ }
+ }
+ }
+
+ public static UserExtendedTypesRegistry getInstance() {
+ return INSTANCE;
+ }
+
+ private IUserExtendedTypesProvider createProvider(IConfigurationElement config) throws CoreException {
+ Object result = config.createExecutableExtension("class"); //$NON-NLS-1$
+
+ if (!(result instanceof IUserExtendedTypesProvider)) {
+ throw new ClassCastException("Extension does not implement IUserExtendedTypesProvider interface in contributor " + config.getContributor().getName()); //$NON-NLS-1$
+ }
+
+ return (IUserExtendedTypesProvider) result;
+ }
+
+ @Override
+ public String getExtendedTypesRedefinition(String extendedTypesID) {
+ switch (providers.size()) {
+ case 0:
+ return null;
+ case 1:
+ return providers.get(0).getExtendedTypesRedefinition(extendedTypesID);
+ default:
+ return providers.stream()
+ .map(p -> p.getExtendedTypesRedefinition(extendedTypesID))
+ .filter(Objects::nonNull)
+ .findFirst()
+ .orElse(null);
+ }
+ }
+
+ @Override
+ public Map<String, String> getLocalExtendedTypesDefinitions() {
+ switch (providers.size()) {
+ case 0:
+ return Collections.emptyMap();
+ case 1:
+ return providers.get(0).getLocalExtendedTypesDefinitions();
+ default:
+ return providers.stream()
+ .map(IUserExtendedTypesProvider::getLocalExtendedTypesDefinitions)
+ .filter(Objects::nonNull)
+ .filter(((Predicate<? super Map<String, String>>) Map::isEmpty).negate())
+ .reduce(new HashMap<>(), (acc, elem) -> {
+ acc.putAll(elem);
+ return acc;
+ });
+ }
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/advices/ExtendedTypesOwnerAdvice.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/advices/ExtendedTypesOwnerAdvice.java
new file mode 100644
index 00000000000..76c7c0d7dd1
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/advices/ExtendedTypesOwnerAdvice.java
@@ -0,0 +1,240 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.advices;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.IContainerDescriptor;
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.papyrus.infra.extendedtypes.ICreationElementValidator;
+import org.eclipse.papyrus.infra.extendedtypes.types.IExtendedHintedElementType;
+
+/**
+ * Advice for potential owners of Extended Element Types. This advice will help to the pre/post validation for the creation of child element which is
+ * describe by the extended type
+ */
+public class ExtendedTypesOwnerAdvice extends AbstractEditHelperAdvice {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean approveRequest(IEditCommandRequest request) {
+ if (request instanceof CreateElementRequest) {
+ // approve the request for this element and all super types
+ IElementType typeToCreate = ((CreateElementRequest) request).getElementType();
+ if (typeToCreate instanceof IExtendedHintedElementType) {
+ if (!approveCreationRequest(((IExtendedHintedElementType) typeToCreate), (CreateElementRequest) request)) {
+ return false;
+ }
+ // ask for extended super types
+ List<IExtendedHintedElementType> superExtendedTypes = getAllSuperExtendedTypes((IExtendedHintedElementType) typeToCreate);
+ if (superExtendedTypes == null || superExtendedTypes.size() == 0) {
+ return super.approveRequest(request);
+ } else {
+ for (IExtendedHintedElementType superType : superExtendedTypes) {
+ // only refuse if one element refuses the request
+ if (!approveCreationRequest(superType, (CreateElementRequest) request)) {
+ return false;
+ }
+ }
+ }
+ }
+ } else if (request instanceof SetRequest) {
+ // check the feature to set is a containment feature and element to move is an extended element type
+ EStructuralFeature feature = ((SetRequest) request).getFeature();
+ if (feature instanceof EReference) {
+ if (!((EReference) feature).isContainment()) {
+ return super.approveRequest(request);
+ } else {
+ // containment. Check the kind of element to edit
+ Object value = ((SetRequest) request).getValue();
+ // value = single object or list ?
+ if (value instanceof EObject) {
+ IElementType type = ElementTypeRegistry.getInstance().getElementType((EObject) value, request.getClientContext());
+ if (type instanceof IExtendedHintedElementType) {
+ return approveMoveRequest((IExtendedHintedElementType) type, (SetRequest) request);
+ }
+ } else if (value instanceof List<?>) {
+ for (Object object : (List<Object>) value) {
+ if (object instanceof EObject) {
+ IElementType[] types = ElementTypeRegistry.getInstance().getAllTypesMatching((EObject) object, request.getClientContext());
+ for (IElementType type : types) {
+ if (type instanceof IExtendedHintedElementType) {
+ if (!approveMoveRequest((IExtendedHintedElementType) type, (SetRequest) request)) {
+ return false;
+ }
+ List<IExtendedHintedElementType> superExtendedTypes = getAllSuperExtendedTypes((IExtendedHintedElementType) type);
+ if (superExtendedTypes == null || superExtendedTypes.size() == 0) {
+ // nothing here
+ } else {
+ for (IExtendedHintedElementType superType : superExtendedTypes) {
+ // only refuse if one element refuses the request
+ if (!approveMoveRequest(superType, (SetRequest) request)) {
+ return false;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ } else if (request instanceof MoveRequest) {
+ // check the feature to set is a containment feature and element to move is an extended element type
+ Map<EObject, EReference> objectsToMove = ((MoveRequest) request).getElementsToMove();
+ if (objectsToMove == null || objectsToMove.isEmpty()) {
+ return super.approveRequest(request);
+ }
+ for (Entry<EObject, EReference> movedElement : objectsToMove.entrySet()) {
+ // do not compute with reference, this can be null. This could be interesting to check...
+ IElementType[] types = ElementTypeRegistry.getInstance().getAllTypesMatching(movedElement.getKey(), request.getClientContext());
+ for (IElementType type : types) {
+ if (type instanceof IExtendedHintedElementType) {
+ if (!approveMoveRequest((IExtendedHintedElementType) type, movedElement.getKey(), (MoveRequest) request)) {
+ return false;
+ }
+ List<IExtendedHintedElementType> superExtendedTypes = getAllSuperExtendedTypes((IExtendedHintedElementType) type);
+ if (superExtendedTypes == null || superExtendedTypes.size() == 0) {
+ // nothing here
+ } else {
+ for (IExtendedHintedElementType superType : superExtendedTypes) {
+ // only refuse if one element refuses the request
+ if (!approveMoveRequest(superType, movedElement.getKey(), (MoveRequest) request)) {
+ return false;
+ }
+ }
+ }
+ }
+ }
+ }
+ return super.approveRequest(request);
+ }
+ return super.approveRequest(request);
+ }
+
+ /**
+ * @param iExtendedHintedElementType
+ * @param request
+ * @return
+ */
+ protected boolean approveCreationRequest(IExtendedHintedElementType typeToCreate, CreateElementRequest request) {
+ IContainerDescriptor containerDescriptor = typeToCreate.getEContainerDescriptor();
+ EObject newContainer = request.getContainer();
+ // check it matches the container descriptor for the element type
+ if (containerDescriptor != null && newContainer != null) {
+ if (containerDescriptor.getContainmentFeatures() != null && containerDescriptor.getContainmentFeatures().length > 0) {
+ // check containment feature
+ List<EReference> references = Arrays.asList(containerDescriptor.getContainmentFeatures());
+ if (!(references.contains(request.getContainmentFeature()))) {
+ return false;
+ }
+ }
+ IElementMatcher containerMatcher = containerDescriptor.getMatcher();
+ if (containerMatcher != null) {
+ if (!containerMatcher.matches(newContainer)) {
+ return false;
+ }
+ }
+ }
+
+ // check that the element can be created. Delegates to the created element type if it can be created or not (rather than being based on the container, as usual on GMF element type framework).
+ ICreationElementValidator creationValidator = typeToCreate.getCreationElementValidator();
+ if (creationValidator != null) {
+ return creationValidator.canCreate(request);
+ }
+
+ return true;
+ }
+
+ protected boolean approveMoveRequest(IExtendedHintedElementType typeToMove, SetRequest request) {
+ IContainerDescriptor containerDescriptor = typeToMove.getEContainerDescriptor();
+ EObject newContainer = request.getElementToEdit();
+ // check it matches the container descriptor for the element type
+ if (containerDescriptor == null || newContainer == null) {
+ return true;
+ }
+ if (containerDescriptor.getContainmentFeatures() != null && containerDescriptor.getContainmentFeatures().length > 0) {
+ // check containment feature
+ List<EReference> references = Arrays.asList(containerDescriptor.getContainmentFeatures());
+ if (!(references.contains(request.getFeature()))) {
+ return false;
+ }
+ }
+ IElementMatcher containerMatcher = containerDescriptor.getMatcher();
+ if (containerMatcher != null) {
+ return containerMatcher.matches(newContainer);
+ }
+ // check container is matching the matcher of the container descriptor for the new type
+ return true;
+ }
+
+ protected boolean approveMoveRequest(IExtendedHintedElementType typeToMove, EObject objectToMove, MoveRequest request) {
+ IContainerDescriptor containerDescriptor = typeToMove.getEContainerDescriptor();
+ EObject newContainer = request.getTargetContainer();
+ // check it matches the container descriptor for the element type
+ if (containerDescriptor == null || newContainer == null) {
+ return true;
+ }
+ if (containerDescriptor.getContainmentFeatures() != null && containerDescriptor.getContainmentFeatures().length > 0) {
+ // check containment feature
+ List<EReference> references = Arrays.asList(containerDescriptor.getContainmentFeatures());
+ if (!(references.contains(request.getTargetFeature(objectToMove)))) {
+ return false;
+ }
+ }
+ IElementMatcher containerMatcher = containerDescriptor.getMatcher();
+ if (containerMatcher != null) {
+ return containerMatcher.matches(newContainer);
+ }
+ // check container is matching the matcher of the container descriptor for the new type
+ return true;
+ }
+
+ public List<IExtendedHintedElementType> getAllSuperExtendedTypes(IExtendedHintedElementType type) {
+ IElementType[] superTypes = type.getAllSuperTypes();
+ if (superTypes.length == 0) {
+ return Collections.emptyList();
+ }
+ List<IExtendedHintedElementType> superExtendedTypes = new ArrayList<IExtendedHintedElementType>();
+ // get the reverse order (the extended element types are the closest types
+ for (int i = superTypes.length - 1; i >= 0; i--) {
+ if (superTypes[i] instanceof IExtendedHintedElementType) {
+ superExtendedTypes.add((IExtendedHintedElementType) superTypes[i]);
+ } /*
+ * else { // optimization: once we are in the hierarchy of "standard" types, we should not go into this hierarchy
+ * return superExtendedTypes;
+ * }
+ */
+ }
+ return superExtendedTypes;
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/internal/spi/IUserExtendedTypesProvider.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/internal/spi/IUserExtendedTypesProvider.java
new file mode 100644
index 00000000000..ca558417d00
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/internal/spi/IUserExtendedTypesProvider.java
@@ -0,0 +1,39 @@
+/*****************************************************************************
+ * Copyright (c) 2014, 2016 CEA LIST, Christian W. Damus, 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:
+ * CEA LIST - Initial API and implementation
+ * Christian W. Damus - bug 485220
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.extendedtypes.internal.spi;
+
+import java.util.Map;
+
+/**
+ * An extension protocol for providers of user-defined extended types models.
+ */
+public interface IUserExtendedTypesProvider {
+ /**
+ * Returns the path for a given extended type local redefinition
+ *
+ * @param extendedTypesID
+ * the unique identifier of the extended type to retrieve
+ * @return the path to the configuration of the extended types or <code>null</code> if no customization exists for this extended type
+ * configuration
+ */
+ String getExtendedTypesRedefinition(String extendedTypesID);
+
+ /**
+ * Returns all the paths in the workspace that should be an extended type set to load, with the id as a key
+ *
+ * @return
+ */
+ Map<String, String> getLocalExtendedTypesDefinitions();
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantcontainerconfiguration/InvariantContainerConfigurationContainerDescriptor.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantcontainerconfiguration/InvariantContainerConfigurationContainerDescriptor.java
new file mode 100644
index 00000000000..8e85a2ca13c
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantcontainerconfiguration/InvariantContainerConfigurationContainerDescriptor.java
@@ -0,0 +1,155 @@
+/*****************************************************************************
+ * Copyright (c) 2013, 2014 CEA LIST 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ * Sebastien Gabel (Esterel Technologies) - Change implementation to consider denied permissions
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantcontainerconfiguration;
+
+import java.util.Arrays;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.IMetamodelType;
+import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.extendedtypes.Activator;
+import org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration.IInvariantContainerDescriptor;
+import org.eclipse.papyrus.infra.services.edit.internal.context.TypeContext;
+
+/**
+ * @author RS211865
+ */
+public class InvariantContainerConfigurationContainerDescriptor implements IInvariantContainerDescriptor<InvariantContainerConfiguration> {
+
+ protected EList<HierarchyPermission> permissions;
+
+ private IClientContext sharedContext;
+
+ private IElementMatcher matcher;
+
+ /**
+ * {@inheritDoc}
+ */
+ public IElementMatcher getMatcher() {
+ if (matcher == null) {
+ matcher = createMatcher();
+ }
+ return matcher;
+ }
+
+ /**
+ * @return
+ */
+ protected IElementMatcher createMatcher() {
+ return new IElementMatcher() {
+
+ public boolean matches(EObject eObject) {
+ if (eObject == null) {
+ return false;
+ }
+
+ IElementType objectMetamodelType = ElementTypeRegistry.getInstance().getElementType(eObject, sharedContext);
+
+ boolean isValid = false;
+ for (HierarchyPermission permission : permissions) { // for each permission, get the matcher and matches directly
+ boolean isPermitted = permission.isIsPermitted();
+ String childType = permission.getChildType();
+ boolean isStrict = permission.isIsStrict();
+ IElementType type = ElementTypeRegistry.getInstance().getType(childType);
+
+ // check is the permission type is a specialization type or a metamodel type, to enhance performances
+ // if this is a metamodel type and strict, a simple equals can match or not if it is permitted or not
+ // if this is a metamodel type and not strict, we only compare the list of supertypes of the eobject type with the permission Type
+ if (type instanceof IMetamodelType) {
+ if (isStrict) {
+ isValid = type.equals(objectMetamodelType) ? isPermitted : !isPermitted;
+ } else {
+ // this is not strict
+ // so any super metamodeltype of permission type that matches objectMetamodelType is OK
+ isValid = Arrays.asList(objectMetamodelType.getAllSuperTypes()).contains(type) ? isPermitted : !isPermitted;
+ }
+ } else if (type instanceof ISpecializationType) {
+ IElementMatcher matcher = ((ISpecializationType) type).getMatcher();
+ if (matcher != null) {
+ boolean matchesSpecialization = matcher.matches(eObject) && objectMetamodelType.equals(((ISpecializationType) type).getMetamodelType()); // the eObject matches the speciailization type that is permitted. Should then check the
+ if (matchesSpecialization) {
+ // test the isStrict now... It will be false if it matches one of the sub-specialization type
+ if (isStrict) {
+ ISpecializationType[] subtypes = ElementTypeRegistry.getInstance().getSpecializationsOf(childType);
+ if (subtypes != null && subtypes.length > 0) {
+ for (ISpecializationType subType : subtypes) {
+ isValid = subType.getMatcher().matches(eObject) ? isPermitted : !isPermitted; // the isStrict is not verified (one of the subtypes is matched whereas it shoud not)
+ }
+ } else { // there are no further sub specialization types.
+ isValid = isPermitted;
+ }
+ } else {
+ // not strict
+ isValid = isPermitted;
+ }
+ } else { // eObject type does not match the permission type
+ isValid = !isPermitted;
+
+ }
+ }
+ }
+ }
+
+ // IElementType[] types = ElementTypeRegistry.getInstance().getAllTypesMatching(eObject, sharedContext);
+ // if (types == null || types.length == 0) {
+ // return false;
+ // }
+ //
+ // for (HierarchyPermission permission : permissions) {
+ // boolean isPermitted = permission.isIsPermitted();
+ // String childType = permission.getChildType();
+ // boolean isStrict = permission.isIsStrict();
+ // IElementType type = ElementTypeRegistry.getInstance().getType(childType);
+ // if (type != null) {
+ // if (isStrict) {
+ // isValid = types[0].equals(type) ? isPermitted : !isPermitted;
+ // } else {
+ // // not strict. The super types of typeToCreate should contain the permission type if permitted, or not contain the permission type if not permitted
+ // List<IElementType> allTypes = Arrays.asList(types);
+ // isValid = allTypes.contains(type) ? isPermitted : !isPermitted;
+ // }
+ // }
+ // }
+ return isValid;
+ }
+ };
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public EReference[] getContainmentFeatures() {
+ // TODO should implement in permissions...
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void init(InvariantContainerConfiguration ruleConfiguration) {
+ this.permissions = ruleConfiguration.getPermissions();
+ try {
+ sharedContext = TypeContext.getContext();
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantcontainerconfiguration/InvariantContainerConfigurationModelCreation.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantcontainerconfiguration/InvariantContainerConfigurationModelCreation.java
new file mode 100644
index 00000000000..4d294cd94a9
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantcontainerconfiguration/InvariantContainerConfigurationModelCreation.java
@@ -0,0 +1,29 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantcontainerconfiguration;
+
+import org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration.IInvariantConfigurationModelCreation;
+
+
+/**
+ * @author RS211865
+ */
+public class InvariantContainerConfigurationModelCreation implements IInvariantConfigurationModelCreation<InvariantContainerConfiguration> {
+
+ /**
+ * {@inheritDoc}
+ */
+ public InvariantContainerConfiguration createConfigurationModel() {
+ return InvariantContainerConfigurationFactory.eINSTANCE.createInvariantContainerConfiguration();
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantcontainerconfiguration/InvariantContainerEditHelperAdvice.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantcontainerconfiguration/InvariantContainerEditHelperAdvice.java
new file mode 100644
index 00000000000..5dace245400
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantcontainerconfiguration/InvariantContainerEditHelperAdvice.java
@@ -0,0 +1,141 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantcontainerconfiguration;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.extendedtypes.Activator;
+import org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration.IInvariantEditHelperAdvice;
+import org.eclipse.papyrus.infra.services.edit.internal.context.TypeContext;
+
+/**
+ * Edit Helper advice configured by the {@link InvariantHierarchyConfiguration}
+ */
+public class InvariantContainerEditHelperAdvice extends AbstractEditHelperAdvice implements IInvariantEditHelperAdvice<InvariantContainerConfiguration> {
+
+ protected List<HierarchyPermission> permissions;
+
+ protected IClientContext sharedContext;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean approveRequest(IEditCommandRequest request) {
+ if (request instanceof SetRequest) {
+ SetRequest setRequest = ((SetRequest) request);
+ EStructuralFeature structuralFeature = setRequest.getFeature();
+ if (structuralFeature instanceof EReference) {
+ EReference reference = ((EReference) structuralFeature);
+ if (reference.isContainment() && setRequest.getValue() != null) {
+ // check new value
+ return canContain(setRequest);
+ }
+ }
+ } else if (request instanceof CreateElementRequest) {
+ CreateElementRequest createElementRequest = ((CreateElementRequest) request);
+ IElementType typeToCreate = createElementRequest.getElementType();
+ boolean approvedRequest = isValid(typeToCreate, false);
+ return approvedRequest;
+ }
+ return super.approveRequest(request);
+ }
+
+ protected boolean isValid(IElementType typeToAdd, boolean baseIsValid) {
+ boolean isValid = baseIsValid;
+ for (HierarchyPermission permission : permissions) {
+ boolean isPermitted = permission.isIsPermitted();
+ String childType = permission.getChildType();
+ boolean isStrict = permission.isIsStrict();
+ IElementType type = ElementTypeRegistry.getInstance().getType(childType);
+ if (type != null) {
+ if (isStrict) {
+ if (typeToAdd.equals(type)) {
+ if (isPermitted) {
+ isValid = true;
+ }
+ } else if (!isPermitted) {
+ isValid = false;
+ }
+ } else {
+ // not strict. The super types of typeToCreate should contain the permission type if permitted, or not contain the permission type if not permitted
+ List<IElementType> allTypes = Arrays.asList(typeToAdd.getAllSuperTypes());
+ allTypes.add(typeToAdd);
+ if (allTypes.contains(type)) {
+ if (isPermitted) {
+ isValid = true;
+ }
+ } else if (!isPermitted) {
+ isValid = false;
+ }
+ }
+ }
+ }
+ return isValid;
+ }
+
+
+ protected boolean canContain(SetRequest request) {
+ // multivalue or simple value ?
+ if (request.getValue() instanceof List<?>) {
+ List<Object> values = (List<Object>) request.getValue();
+ for (Object value : values) {
+ if (value instanceof EObject) {
+ IElementType type = ElementTypeRegistry.getInstance().getElementType((EObject) value, request.getClientContext());
+ if (type != null) {
+ if (!isValid(type, false)) {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+ }
+ } else {
+ if (request.getValue() instanceof EObject) {
+ IElementType type = ElementTypeRegistry.getInstance().getElementType((EObject) request.getValue(), request.getClientContext());
+ if (type != null) {
+ return isValid(type, false);
+ } else {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void init(InvariantContainerConfiguration configuration) {
+ try {
+ sharedContext = TypeContext.getContext();
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ permissions = configuration.getPermissions();
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantcontainerconfiguration/InvariantContainerMatcher.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantcontainerconfiguration/InvariantContainerMatcher.java
new file mode 100644
index 00000000000..1998d627068
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantcontainerconfiguration/InvariantContainerMatcher.java
@@ -0,0 +1,127 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantcontainerconfiguration;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.IMetamodelType;
+import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.extendedtypes.Activator;
+import org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration.IInvariantElementMatcher;
+import org.eclipse.papyrus.infra.services.edit.internal.context.TypeContext;
+
+/**
+ * Matcher of the hierarchy matcher
+ */
+public class InvariantContainerMatcher implements IInvariantElementMatcher<InvariantContainerConfiguration> {
+
+ protected List<HierarchyPermission> permissions;
+
+ protected IClientContext sharedContext;
+
+ /**
+ *
+ */
+ public InvariantContainerMatcher() {
+ // nothing here. Trying not to create list to avoid unnecessary created objects
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean matches(EObject eObject) {
+ EObject container = eObject.eContainer();
+
+ if (container == null) {
+ return false;
+ }
+
+ IElementType objectMetamodelType = ElementTypeRegistry.getInstance().getElementType(container, sharedContext);
+
+ boolean isValid = false;
+ for (HierarchyPermission permission : permissions) { // for each permission, get the matcher and matches directly
+ boolean isPermitted = permission.isIsPermitted();
+ String childType = permission.getChildType();
+ boolean isStrict = permission.isIsStrict();
+ IElementType type = ElementTypeRegistry.getInstance().getType(childType);
+
+ // check is the permission type is a specialization type or a metamodel type, to enhance performances
+ // if this is a metamodel type and strict, a simple equals can match or not if it is permitted or not
+ // if this is a metamodel type and not strict, we only compare the list of supertypes of the eobject type with the permission Type
+ if (type instanceof IMetamodelType) {
+ if (isStrict) {
+ isValid = type.equals(objectMetamodelType) ? isPermitted : !isPermitted;
+ } else {
+ // this is not strict
+ // so any super metamodeltype of permission type that matches objectMetamodelType is OK
+ isValid = Arrays.asList(objectMetamodelType.getAllSuperTypes()).contains(type) ? isPermitted : !isPermitted;
+ }
+ } else if (type instanceof ISpecializationType) {
+ IElementMatcher matcher = ((ISpecializationType) type).getMatcher();
+ if (matcher != null) {
+ boolean matchesSpecialization = matcher.matches(container) && objectMetamodelType.equals(((ISpecializationType) type).getMetamodelType()); // the eObject matches the speciailization type that is permitted. Should then check the
+ if (matchesSpecialization) {
+ // test the isStrict now... It will be false if it matches one of the sub-specialization type
+ if (isStrict) {
+ ISpecializationType[] subtypes = ElementTypeRegistry.getInstance().getSpecializationsOf(childType);
+ if (subtypes != null && subtypes.length > 0) {
+ for (ISpecializationType subType : subtypes) {
+ isValid = subType.getMatcher().matches(container) ? isPermitted : !isPermitted; // the isStrict is not verified (one of the subtypes is matched whereas it shoud not)
+ }
+ } else { // there are no further sub specialization types.
+ isValid = isPermitted;
+ }
+ } else {
+ // not strict
+ isValid = isPermitted;
+ }
+ } else { // eObject type does not match the permission type
+ isValid = !isPermitted;
+
+ }
+ }
+ }
+ }
+
+ return isValid;
+
+//
+//
+// // retrieve element type
+// IElementType[] containerTypes = ElementTypeRegistry.getInstance().getAllTypesMatching(container, sharedContext);
+// if(containerTypes != null && containerTypes.length >0) {
+// return InvariantContainerUtils.isContainerValid(containerTypes, matches, permissions);
+// }
+// return false;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void init(InvariantContainerConfiguration configuration) {
+ try {
+ sharedContext = TypeContext.getContext();
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ this.permissions = configuration.getPermissions();
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/AndRuleCreationElementValidator.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/AndRuleCreationElementValidator.java
new file mode 100644
index 00000000000..20d119ccd7b
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/AndRuleCreationElementValidator.java
@@ -0,0 +1,52 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+
+
+/**
+ *
+ */
+public class AndRuleCreationElementValidator implements IInvariantCreationElementValidator<AndRule> {
+
+ protected List<IInvariantCreationElementValidator<InvariantRuleConfiguration>> composedValidators;
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canCreate(CreateElementRequest request) {
+ for (IInvariantCreationElementValidator<InvariantRuleConfiguration> creationElementValidator : composedValidators) {
+ if (!creationElementValidator.canCreate(request)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void init(AndRule configuration) {
+ composedValidators = new ArrayList<IInvariantCreationElementValidator<InvariantRuleConfiguration>>();
+ for (InvariantRuleConfiguration composedRule : configuration.getComposedRules()) {
+ IInvariantCreationElementValidator<InvariantRuleConfiguration> creationElementValidator = RuleConfigurationFactoryRegistry.getInstance().createCreationElementValidator(composedRule);
+ if (creationElementValidator != null) {
+ composedValidators.add(creationElementValidator);
+ }
+ }
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/AndRuleEditHelperAdvice.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/AndRuleEditHelperAdvice.java
new file mode 100644
index 00000000000..c58c5842a5d
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/AndRuleEditHelperAdvice.java
@@ -0,0 +1,56 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public class AndRuleEditHelperAdvice extends AbstractEditHelperAdvice implements IInvariantEditHelperAdvice<AndRule> {
+
+ protected List<IInvariantEditHelperAdvice<InvariantRuleConfiguration>> composedEditHelperAdvices;
+
+ public AndRuleEditHelperAdvice() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void init(AndRule ruleConfiguration) {
+ // configuration should be a AndRule as declared in the extension point
+ composedEditHelperAdvices = new ArrayList<IInvariantEditHelperAdvice<InvariantRuleConfiguration>>();
+ for (InvariantRuleConfiguration composedRule : ruleConfiguration.getComposedRules()) {
+ IInvariantEditHelperAdvice<InvariantRuleConfiguration> editHelperAdvice = RuleConfigurationFactoryRegistry.getInstance().createEditHelperAdvice(composedRule);
+ if (editHelperAdvice != null) {
+ composedEditHelperAdvices.add(editHelperAdvice);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean approveRequest(IEditCommandRequest request) {
+ // to approve the request, all the composed edit helper advices should approve it
+ for (IEditHelperAdvice advice : composedEditHelperAdvices) {
+ if (!advice.approveRequest(request)) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/AndRuleElementMatcher.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/AndRuleElementMatcher.java
new file mode 100644
index 00000000000..233ca8c7707
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/AndRuleElementMatcher.java
@@ -0,0 +1,65 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+
+/**
+ * {@link IElementMatcher} for the {@link AndRule}
+ */
+public class AndRuleElementMatcher implements IInvariantElementMatcher<AndRule> {
+
+ protected List<IElementMatcher> composedMatchers;
+
+ /**
+ *
+ */
+ public AndRuleElementMatcher() {
+ // Nothing here
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean matches(EObject eObject) {
+ // deactivate if list of rules is empty
+ if (composedMatchers == null || composedMatchers.isEmpty()) {
+ return false;
+ }
+ for (IElementMatcher matcher : composedMatchers) {
+ if (!matcher.matches(eObject)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void init(AndRule configuration) {
+ // for each children configuraton, generates the matcher class and then, the 'matches' method of this matcher will delegate to the matches of the sub rules, and will add all results together
+ // configuration should be a AndRule as declared in the extension point
+ composedMatchers = new ArrayList<IElementMatcher>();
+ for (InvariantRuleConfiguration composedRule : configuration.getComposedRules()) {
+ IElementMatcher matcher = RuleConfigurationFactoryRegistry.getInstance().createMatcher(composedRule);
+ if (matcher != null) {
+ composedMatchers.add(matcher);
+ }
+ }
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantConfigurationModelCreation.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantConfigurationModelCreation.java
new file mode 100644
index 00000000000..c089f4d28cc
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantConfigurationModelCreation.java
@@ -0,0 +1,22 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration;
+
+
+/**
+ * Interface used to create new invariant rule model element in the configuration model
+ */
+public interface IInvariantConfigurationModelCreation<T extends InvariantRuleConfiguration> {
+
+ public T createConfigurationModel();
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantContainerDescriptor.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantContainerDescriptor.java
new file mode 100644
index 00000000000..75da81c8f4d
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantContainerDescriptor.java
@@ -0,0 +1,27 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration;
+
+import org.eclipse.gmf.runtime.emf.type.core.IContainerDescriptor;
+
+
+/**
+ * Descriptor for the configurable container descriptor
+ */
+public interface IInvariantContainerDescriptor<T extends InvariantRuleConfiguration> extends IContainerDescriptor {
+
+ /**
+ * @param ruleConfiguration
+ */
+ void init(T ruleConfiguration);
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantCreationElementValidator.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantCreationElementValidator.java
new file mode 100644
index 00000000000..abeb9cafa6a
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantCreationElementValidator.java
@@ -0,0 +1,24 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration;
+
+import org.eclipse.papyrus.infra.extendedtypes.ICreationElementValidator;
+
+
+/**
+ *
+ */
+public interface IInvariantCreationElementValidator<T extends InvariantRuleConfiguration> extends ICreationElementValidator {
+
+ void init(T configuration);
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantEditHelperAdvice.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantEditHelperAdvice.java
new file mode 100644
index 00000000000..d50cf3ddd43
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantEditHelperAdvice.java
@@ -0,0 +1,29 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+
+/**
+ * Interface for all {@link IEditHelperAdvice} that are configured by an {@link InvariantRuleConfiguration}.
+ */
+public interface IInvariantEditHelperAdvice<T extends InvariantRuleConfiguration> extends IEditHelperAdvice {
+
+ /**
+ * Inits the edit helper advice with its given configuration
+ *
+ * @param ruleConfiguration
+ * the configuration of the edit helper advice
+ */
+ void init(T ruleConfiguration);
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantElementMatcher.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantElementMatcher.java
new file mode 100644
index 00000000000..361021e0d74
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantElementMatcher.java
@@ -0,0 +1,30 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration;
+
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+
+
+/**
+ * Interface that all {@link IElementMatcher} that can be configured at runtime using a model should implement
+ */
+public interface IInvariantElementMatcher<T extends InvariantRuleConfiguration> extends IElementMatcher {
+
+ /**
+ * Initialize the element matcher with the given configuration
+ *
+ * @param configuration
+ * the runtime configuration of the matcher
+ */
+ void init(T configuration);
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantRuleExtensionPoint.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantRuleExtensionPoint.java
new file mode 100644
index 00000000000..17551f2b2ae
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/IInvariantRuleExtensionPoint.java
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration;
+
+import org.eclipse.papyrus.infra.extendedtypes.Activator;
+
+
+/**
+ * @author RS211865
+ */
+public interface IInvariantRuleExtensionPoint {
+
+ /** ID of the extension point */
+ public final static String EXTENSION_POINT_ID = Activator.PLUGIN_ID + ".invariantRule";
+
+ public static final String ELEMENT_MATCHER_CLASS = "elementMatcher";
+
+ public static final String CONTAINER_DESCRIPTOR_CLASS = "semanticTypeDescriptor";
+
+ public static final String EDIT_HELPER_ADVICE_CLASS = "editHelperAdvice";
+
+ public static final String RULE_CONFIGURATION_CLASS = "configurationClass";
+
+ public static final String CONFIGURATION_MODEL_CREATION = "configurationModelCreation";
+
+ public static final String CREATION_ELEMENT_VALIDATOR_CLASS = "creationElementValidator";
+
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/InvariantElementTypeFactory.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/InvariantElementTypeFactory.java
new file mode 100644
index 00000000000..882fe8ab63f
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/InvariantElementTypeFactory.java
@@ -0,0 +1,80 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration;
+
+import java.util.Arrays;
+
+import org.eclipse.gmf.runtime.emf.type.core.IContainerDescriptor;
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.papyrus.infra.extendedtypes.AbstractConfigurableElementTypeFactory;
+import org.eclipse.papyrus.infra.extendedtypes.ComposedElementMatcher;
+import org.eclipse.papyrus.infra.extendedtypes.ICreationElementValidator;
+
+/**
+ * Factory used to create ElementType from a {@link InvariantSemanticTypeConfiguration}.
+ */
+public class InvariantElementTypeFactory extends AbstractConfigurableElementTypeFactory<InvariantSemanticTypeConfiguration> {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public ICreationElementValidator createElementCreationValidator(InvariantSemanticTypeConfiguration configuration) {
+ return RuleConfigurationFactoryRegistry.getInstance().createCreationElementValidator(configuration.getInvariantRuleConfiguration());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected String getSemanticHint(InvariantSemanticTypeConfiguration configuration) {
+ return configuration.getHint();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected IEditHelperAdvice createEditHelperAdvice(InvariantSemanticTypeConfiguration configuration) {
+ return RuleConfigurationFactoryRegistry.getInstance().createEditHelperAdvice(configuration.getInvariantRuleConfiguration());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected IContainerDescriptor createContainerDescriptor(InvariantSemanticTypeConfiguration configuration) {
+ return RuleConfigurationFactoryRegistry.getInstance().createContainerDescriptor(configuration.getInvariantRuleConfiguration());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected IElementMatcher createElementMatcher(InvariantSemanticTypeConfiguration configuration) {
+ IElementMatcher superMatcher = super.createElementMatcher(configuration);
+ if (superMatcher != null) {
+ // create a composed matcher to have the matcher described by the model configuration element type and the one for the specific invariants
+ IElementMatcher invariantMatcher = RuleConfigurationFactoryRegistry.getInstance().createMatcher(configuration.getInvariantRuleConfiguration());
+ if (invariantMatcher != null) {
+ ComposedElementMatcher composedMatcher = new ComposedElementMatcher(Arrays.asList(superMatcher, invariantMatcher));
+ return composedMatcher;
+ }
+ return superMatcher;
+ }
+ // no configured matcher. Return the invariant one
+ return RuleConfigurationFactoryRegistry.getInstance().createMatcher(configuration.getInvariantRuleConfiguration());
+ }
+
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/InvariantSemanticTypeContainerDescriptor.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/InvariantSemanticTypeContainerDescriptor.java
new file mode 100644
index 00000000000..3d5e695d937
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/InvariantSemanticTypeContainerDescriptor.java
@@ -0,0 +1,47 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration;
+
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.gmf.runtime.emf.type.core.IContainerDescriptor;
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+
+
+/**
+ * @author RS211865
+ */
+public class InvariantSemanticTypeContainerDescriptor implements IContainerDescriptor {
+
+ /**
+ * @param configuration
+ */
+ public InvariantSemanticTypeContainerDescriptor(InvariantSemanticTypeConfiguration configuration) {
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IElementMatcher getMatcher() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public EReference[] getContainmentFeatures() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/InvariantSemanticTypeEditHelperAdvice.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/InvariantSemanticTypeEditHelperAdvice.java
new file mode 100644
index 00000000000..401b8330c88
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/InvariantSemanticTypeEditHelperAdvice.java
@@ -0,0 +1,30 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
+
+
+/**
+ * Advice based on invariants
+ */
+public class InvariantSemanticTypeEditHelperAdvice extends AbstractEditHelperAdvice {
+
+ /**
+ * @param configuration
+ */
+ public InvariantSemanticTypeEditHelperAdvice(InvariantSemanticTypeConfiguration configuration) {
+ // TODO Auto-generated constructor stub
+ }
+
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/OrRuleCreationElementValidator.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/OrRuleCreationElementValidator.java
new file mode 100644
index 00000000000..815538de96d
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/OrRuleCreationElementValidator.java
@@ -0,0 +1,52 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+
+
+/**
+ * @author RS211865
+ */
+public class OrRuleCreationElementValidator implements IInvariantCreationElementValidator<OrRule> {
+
+ protected List<IInvariantCreationElementValidator<InvariantRuleConfiguration>> composedValidators;
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canCreate(CreateElementRequest request) {
+ for (IInvariantCreationElementValidator<InvariantRuleConfiguration> creationElementValidator : composedValidators) {
+ if (creationElementValidator.canCreate(request)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void init(OrRule configuration) {
+ composedValidators = new ArrayList<IInvariantCreationElementValidator<InvariantRuleConfiguration>>();
+ for (InvariantRuleConfiguration composedRule : configuration.getComposedRules()) {
+ IInvariantCreationElementValidator<InvariantRuleConfiguration> creationElementValidator = RuleConfigurationFactoryRegistry.getInstance().createCreationElementValidator(composedRule);
+ if (creationElementValidator != null) {
+ composedValidators.add(creationElementValidator);
+ }
+ }
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/OrRuleEditHelperAdvice.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/OrRuleEditHelperAdvice.java
new file mode 100644
index 00000000000..b3bbcb1deeb
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/OrRuleEditHelperAdvice.java
@@ -0,0 +1,61 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+
+/**
+ * @author RS211865
+ */
+public class OrRuleEditHelperAdvice extends AbstractEditHelperAdvice implements IInvariantEditHelperAdvice<OrRule> {
+
+ protected List<IInvariantEditHelperAdvice<InvariantRuleConfiguration>> composedEditHelperAdvices;
+
+ public OrRuleEditHelperAdvice() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void init(OrRule ruleConfiguration) {
+ // configuration should be a AndRule as declared in the extension point
+ composedEditHelperAdvices = new ArrayList<IInvariantEditHelperAdvice<InvariantRuleConfiguration>>();
+ for (InvariantRuleConfiguration composedRule : ruleConfiguration.getComposedRules()) {
+ IInvariantEditHelperAdvice<InvariantRuleConfiguration> editHelperAdvice = RuleConfigurationFactoryRegistry.getInstance().createEditHelperAdvice(composedRule);
+ if (editHelperAdvice != null) {
+ composedEditHelperAdvices.add(editHelperAdvice);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean approveRequest(IEditCommandRequest request) {
+ // to approve the request, all the composed edit helper advices should approve it
+ for (IEditHelperAdvice advice : composedEditHelperAdvices) {
+ if (advice.approveRequest(request)) {
+ return true;
+ }
+ }
+ // return no only if no advice approves the request. As soon as one approves, return true
+ return false;
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/OrRuleElementMatcher.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/OrRuleElementMatcher.java
new file mode 100644
index 00000000000..dfd9aea8d50
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/OrRuleElementMatcher.java
@@ -0,0 +1,65 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+
+/**
+ * @author RS211865
+ */
+public class OrRuleElementMatcher implements IInvariantElementMatcher<OrRule> {
+
+ protected List<IElementMatcher> composedMatchers;
+
+ /**
+ *
+ */
+ public OrRuleElementMatcher() {
+ // nothing here
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean matches(EObject eObject) {
+ // deactivate if list of rules is empty
+ if (composedMatchers == null || composedMatchers.isEmpty()) {
+ return false;
+ }
+ for (IElementMatcher matcher : composedMatchers) {
+ if (matcher.matches(eObject)) {
+ return true;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void init(OrRule configuration) {
+ // for each children configuraton, generates the matcher class and then, the 'matches' method of this matcher will delegate to the matches of the sub rules, and will add all results together
+ // configuration should be a AndRule as declared in the extension point
+ composedMatchers = new ArrayList<IElementMatcher>();
+ for (InvariantRuleConfiguration composedRule : configuration.getComposedRules()) {
+ IElementMatcher matcher = RuleConfigurationFactoryRegistry.getInstance().createMatcher(composedRule);
+ if (matcher != null) {
+ composedMatchers.add(matcher);
+ }
+ }
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/RuleConfigurationFactoryRegistry.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/RuleConfigurationFactoryRegistry.java
new file mode 100644
index 00000000000..1f5c0f214f8
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/invariantsemantictypeconfiguration/RuleConfigurationFactoryRegistry.java
@@ -0,0 +1,348 @@
+/*****************************************************************************
+ * Copyright (c) 2013, 2016 CEA LIST, Christian W. Damus, 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ * Christian W. Damus - bug 485220
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.invariantsemantictypeconfiguration;
+
+import static org.eclipse.papyrus.infra.extendedtypes.util.InternalUtils.loadClass;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+import org.eclipse.papyrus.infra.extendedtypes.Activator;
+
+/**
+ * Registry for all matcher factories.
+ */
+public class RuleConfigurationFactoryRegistry {
+
+ /** private singleton instance */
+ private static RuleConfigurationFactoryRegistry registry;
+
+ /** map configuration type to matcher descriptor */
+ protected Map<String, ConfigurableClassDescriptor> configurationTypeToClassDescriptor = null;
+
+ /**
+ * returns the singleton instance of this registry
+ *
+ * @return the singleton instance of this registry
+ */
+ public static synchronized RuleConfigurationFactoryRegistry getInstance() {
+ if (registry == null) {
+ registry = new RuleConfigurationFactoryRegistry();
+ registry.init();
+ }
+ return registry;
+ }
+
+ /**
+ * Inits the registry.
+ */
+ protected void init() {
+ configurationTypeToClassDescriptor = new HashMap<String, RuleConfigurationFactoryRegistry.ConfigurableClassDescriptor>();
+ // read invariant rule configuration etension point
+ IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(IInvariantRuleExtensionPoint.EXTENSION_POINT_ID);
+ // for each element, parses and retrieve the model file. then loads it and returns the root element
+ for (IConfigurationElement configurationElement : elements) {
+ // contributor will always be the same, but implementation could be different.
+ String contributorName = configurationElement.getContributor().getName();
+
+ String configurationClass = configurationElement.getAttribute(IInvariantRuleExtensionPoint.RULE_CONFIGURATION_CLASS);
+
+ String matcherClassName = configurationElement.getAttribute(IInvariantRuleExtensionPoint.ELEMENT_MATCHER_CLASS);
+ String editHelperAdviceClassName = configurationElement.getAttribute(IInvariantRuleExtensionPoint.EDIT_HELPER_ADVICE_CLASS);
+ String containerDescriptorClassName = configurationElement.getAttribute(IInvariantRuleExtensionPoint.CONTAINER_DESCRIPTOR_CLASS);
+ String creationElementValidatorClassName = configurationElement.getAttribute(IInvariantRuleExtensionPoint.CREATION_ELEMENT_VALIDATOR_CLASS);
+
+ ConfigurableClassDescriptor configurableClassDescriptor = new ConfigurableClassDescriptor(contributorName, matcherClassName, contributorName, editHelperAdviceClassName, contributorName, containerDescriptorClassName, contributorName,
+ creationElementValidatorClassName);
+ configurationTypeToClassDescriptor.put(configurationClass, configurableClassDescriptor);
+ }
+
+ }
+
+ /**
+ * Creates the {@link IElementMatcher} specific to the given rule configuration
+ *
+ * @param ruleConfiguration
+ * the rule configuration that will configure the created matcher
+ * @return the {@link IElementMatcher} created or <code>null</code> if none could be created
+ */
+ public IInvariantElementMatcher<InvariantRuleConfiguration> createMatcher(InvariantRuleConfiguration ruleConfiguration) {
+ // creates the matcher from the extension points
+ Class<IInvariantElementMatcher<InvariantRuleConfiguration>> elementMatcherClass = getMatcherClass(ruleConfiguration);
+ if (elementMatcherClass == null) {
+ return null;
+ }
+ try {
+ IInvariantElementMatcher<InvariantRuleConfiguration> matcher = elementMatcherClass.newInstance();
+ if (matcher != null) {
+ matcher.init(ruleConfiguration);
+ }
+ return matcher;
+ } catch (InstantiationException e) {
+ Activator.log.error(e);
+ } catch (IllegalAccessException e) {
+ Activator.log.error(e);
+ }
+ return null;
+ }
+
+ /**
+ * @param ruleConfiguration
+ * @return
+ */
+ public IInvariantContainerDescriptor<InvariantRuleConfiguration> createContainerDescriptor(InvariantRuleConfiguration ruleConfiguration) {
+ Class<IInvariantContainerDescriptor<InvariantRuleConfiguration>> containerDescriptorClass = getContainerDescriptorClass(ruleConfiguration);
+ if (containerDescriptorClass == null) {
+ return null;
+ }
+ try {
+ IInvariantContainerDescriptor<InvariantRuleConfiguration> containerDescriptor = containerDescriptorClass.newInstance();
+ if (containerDescriptor != null) {
+ containerDescriptor.init(ruleConfiguration);
+ }
+ return containerDescriptor;
+ } catch (InstantiationException e) {
+ Activator.log.error(e);
+ } catch (IllegalAccessException e) {
+ Activator.log.error(e);
+ }
+ return null;
+ }
+
+ /**
+ * @param ruleConfiguration
+ * @return
+ */
+ public IInvariantEditHelperAdvice<InvariantRuleConfiguration> createEditHelperAdvice(InvariantRuleConfiguration ruleConfiguration) {
+ Class<IInvariantEditHelperAdvice<InvariantRuleConfiguration>> editHelperAdviceClass = getEditHelperAdviceClass(ruleConfiguration);
+ if (editHelperAdviceClass == null) {
+ Activator.log.error("impossible to find the edit helper advice implementation for configuration type : " + ((ruleConfiguration != null) ? ruleConfiguration.eClass().getName() : "null"), null);
+ return null;
+ }
+ try {
+ IInvariantEditHelperAdvice<InvariantRuleConfiguration> editHelperAdvice = editHelperAdviceClass.newInstance();
+ if (editHelperAdvice != null) {
+ editHelperAdvice.init(ruleConfiguration);
+ }
+ return editHelperAdvice;
+ } catch (InstantiationException e) {
+ Activator.log.error(e);
+ } catch (IllegalAccessException e) {
+ Activator.log.error(e);
+ }
+ return null;
+ }
+
+ /**
+ * @param ruleConfiguration
+ * @return
+ */
+ public IInvariantCreationElementValidator<InvariantRuleConfiguration> createCreationElementValidator(InvariantRuleConfiguration ruleConfiguration) {
+ Class<IInvariantCreationElementValidator<InvariantRuleConfiguration>> creationElementValidatorClass = getCreationElementValidatorClass(ruleConfiguration);
+ if (creationElementValidatorClass == null) {
+ // Activator.log.error("impossible to find the Creation Element Validator for configuration type : " + ((ruleConfiguration!=null) ? ruleConfiguration.eClass().getName() : "null"), null);
+ return null;
+ }
+ try {
+ IInvariantCreationElementValidator<InvariantRuleConfiguration> creationElementValidator = creationElementValidatorClass.newInstance();
+ if (creationElementValidator != null) {
+ creationElementValidator.init(ruleConfiguration);
+ }
+ return creationElementValidator;
+ } catch (InstantiationException e) {
+ Activator.log.error(e);
+ } catch (IllegalAccessException e) {
+ Activator.log.error(e);
+ }
+ return null;
+ }
+
+
+ /**
+ * @param ruleConfiguration
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ protected Class<IInvariantCreationElementValidator<InvariantRuleConfiguration>> getCreationElementValidatorClass(InvariantRuleConfiguration configuration) {
+ String configurationType = configuration.eClass().getInstanceClassName();
+ String className = configurationTypeToClassDescriptor.get(configurationType).getCreationElementValidatorClassName();
+ String contributorName = configurationTypeToClassDescriptor.get(configurationType).getCreationElementValidatorContributorName();
+
+ // look in the list of registered matcher for the right one
+ if (className == null) {
+ // Activator.log.error("There should be an implementation class for the configuration "+configurationType+ " from contributor "+contributorName, null);
+ } else if (contributorName != null) {
+ return (Class<IInvariantCreationElementValidator<InvariantRuleConfiguration>>) loadClass(className, contributorName);
+ }
+ return null;
+ }
+
+ /**
+ * @param configurationType
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ protected Class<IInvariantElementMatcher<InvariantRuleConfiguration>> getMatcherClass(InvariantRuleConfiguration configuration) {
+
+ String configurationType = configuration.eClass().getInstanceClassName();
+ String className = configurationTypeToClassDescriptor.get(configurationType).getElementMatcherClassName();
+ String contributorName = configurationTypeToClassDescriptor.get(configurationType).getElementMatcherContributorName();
+
+ // look in the list of registered matcher for the right one
+ if (className != null && contributorName != null) {
+ return (Class<IInvariantElementMatcher<InvariantRuleConfiguration>>) loadClass(className, contributorName);
+ }
+ return null;
+ }
+
+ /**
+ * @param configurationType
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ protected Class<IInvariantEditHelperAdvice<InvariantRuleConfiguration>> getEditHelperAdviceClass(InvariantRuleConfiguration configuration) {
+ String configurationType = configuration.eClass().getInstanceClassName();
+ String className = configurationTypeToClassDescriptor.get(configurationType).getEditHelperAdviceClassName();
+ String contributorName = configurationTypeToClassDescriptor.get(configurationType).getEditHelperAdviceContributorName();
+
+ // look in the list of registered edit helper advices for the right one
+ return (Class<IInvariantEditHelperAdvice<InvariantRuleConfiguration>>) loadClass(className, contributorName);
+ }
+
+ /**
+ * @param configurationType
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ protected Class<IInvariantContainerDescriptor<InvariantRuleConfiguration>> getContainerDescriptorClass(InvariantRuleConfiguration configuration) {
+ String configurationType = configuration.eClass().getInstanceClassName();
+ String className = configurationTypeToClassDescriptor.get(configurationType).getContainerDescriptorClassName();
+ String contributorName = configurationTypeToClassDescriptor.get(configurationType).getContainerDescriptorContributorName();
+
+
+ // look in the list of registered edit helper advices for the right one
+ if (className != null && contributorName != null) {
+ return (Class<IInvariantContainerDescriptor<InvariantRuleConfiguration>>) loadClass(className, contributorName);
+ }
+ return null;
+ }
+
+ protected static class ConfigurableClassDescriptor {
+
+ /**
+ * @param elementMatcherContributorName
+ * @param elementMatcherClassName
+ * @param editHelperAdviceContributorName
+ * @param editHelperAdviceClassName
+ * @param containerDescriptorContributorName
+ * @param containerDescriptorClassName
+ */
+ public ConfigurableClassDescriptor(String elementMatcherContributorName, String elementMatcherClassName, String editHelperAdviceContributorName, String editHelperAdviceClassName, String containerDescriptorContributorName,
+ String containerDescriptorClassName, String creationElementValidatorContributorName, String creationElementValidatorClassName) {
+ this.elementMatcherContributorName = elementMatcherContributorName;
+ this.elementMatcherClassName = elementMatcherClassName;
+ this.editHelperAdviceContributorName = editHelperAdviceContributorName;
+ this.editHelperAdviceClassName = editHelperAdviceClassName;
+ this.containerDescriptorContributorName = containerDescriptorContributorName;
+ this.containerDescriptorClassName = containerDescriptorClassName;
+ this.creationElementValidatorContributorName = creationElementValidatorContributorName;
+ this.creationElementValidatorClassName = creationElementValidatorClassName;
+ }
+
+ private final String elementMatcherContributorName;
+
+ private final String elementMatcherClassName;
+
+ private final String editHelperAdviceContributorName;
+
+ private final String editHelperAdviceClassName;
+
+ private final String containerDescriptorContributorName;
+
+ private final String containerDescriptorClassName;
+
+ private final String creationElementValidatorContributorName;
+
+ private final String creationElementValidatorClassName;
+
+ /**
+ * @return
+ */
+ public String getCreationElementValidatorContributorName() {
+ return creationElementValidatorContributorName;
+ }
+
+ /**
+ * @return
+ */
+ public String getCreationElementValidatorClassName() {
+ return creationElementValidatorClassName;
+ }
+
+ /**
+ * @return the elementMatcherContributorName
+ */
+ public String getElementMatcherContributorName() {
+ return elementMatcherContributorName;
+ }
+
+
+ /**
+ * @return the elementMatcherClassName
+ */
+ public String getElementMatcherClassName() {
+ return elementMatcherClassName;
+ }
+
+
+ /**
+ * @return the editHelperAdviceContributorName
+ */
+ public String getEditHelperAdviceContributorName() {
+ return editHelperAdviceContributorName;
+ }
+
+
+ /**
+ * @return the editHelperAdviceClassName
+ */
+ public String getEditHelperAdviceClassName() {
+ return editHelperAdviceClassName;
+ }
+
+
+ /**
+ * @return the containerDescriptorContributorName
+ */
+ public String getContainerDescriptorContributorName() {
+ return containerDescriptorContributorName;
+ }
+
+
+ /**
+ * @return the containerDescriptorClassName
+ */
+ public String getContainerDescriptorClassName() {
+ return containerDescriptorClassName;
+ }
+
+ }
+
+ // /////////////////////////////////////////////////////////////////////////
+ // loading resource
+ // /////////////////////////////////////////////////////////////////////////
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/semantic/ISemanticTypeFactory.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/semantic/ISemanticTypeFactory.java
new file mode 100644
index 00000000000..2502447d1f9
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/semantic/ISemanticTypeFactory.java
@@ -0,0 +1,23 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.semantic;
+
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+
+/**
+ * Interface that must be implemented by each factory relying on the semanticTypeFactory extension point.
+ */
+public interface ISemanticTypeFactory {
+
+ /** creates the element type from the given configuration */
+ IElementType createElementType();
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/types/ExtendedHintedElementType.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/types/ExtendedHintedElementType.java
new file mode 100644
index 00000000000..8c75f235bf1
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/types/ExtendedHintedElementType.java
@@ -0,0 +1,72 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.types;
+
+import java.net.URL;
+
+import org.eclipse.gmf.runtime.emf.type.core.IContainerDescriptor;
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.SpecializationType;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.papyrus.infra.extendedtypes.ICreationElementValidator;
+
+
+/**
+ * @author RS211865
+ */
+public class ExtendedHintedElementType extends SpecializationType implements IExtendedHintedElementType {
+
+ private String semanticHint;
+
+ protected ICreationElementValidator creationElementValidator;
+
+ /**
+ * @param id
+ * @param iconURL
+ * @param displayName
+ * @param elementTypes
+ * @param matcher
+ * @param descriptor
+ * @param editHelperAdvice
+ * @param iElementCreationValidator
+ */
+ public ExtendedHintedElementType(String id, URL iconURL, String displayName, IElementType[] elementTypes, IElementMatcher matcher, IContainerDescriptor descriptor, IEditHelperAdvice editHelperAdvice, String semanticHint,
+ ICreationElementValidator creationElementValidator) {
+ super(id, iconURL, displayName, elementTypes, matcher, descriptor, editHelperAdvice);
+ this.semanticHint = semanticHint;
+ this.creationElementValidator = creationElementValidator;
+ }
+
+ /**
+ * Gets the semantic hint.
+ */
+ public String getSemanticHint() {
+ return semanticHint;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ICreationElementValidator getCreationElementValidator() {
+ return creationElementValidator;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return "Extended Type: " + getDisplayName() + " [" + getId() + "]";
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/types/IExtendedHintedElementType.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/types/IExtendedHintedElementType.java
new file mode 100644
index 00000000000..c33df0e396f
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/types/IExtendedHintedElementType.java
@@ -0,0 +1,27 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.types;
+
+import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
+import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType;
+import org.eclipse.papyrus.infra.extendedtypes.ICreationElementValidator;
+
+
+/**
+ * interface implemented by all configurable element types specializations
+ */
+public interface IExtendedHintedElementType extends ISpecializationType, IHintedType {
+
+ public ICreationElementValidator getCreationElementValidator();
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/util/ElementTypeUtils.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/util/ElementTypeUtils.java
new file mode 100644
index 00000000000..0be7bad9d21
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/util/ElementTypeUtils.java
@@ -0,0 +1,183 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.extendedtypes.util;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.IMetamodelType;
+import org.eclipse.papyrus.infra.extendedtypes.types.IExtendedHintedElementType;
+
+/**
+ * Utility class for {@link IElementType}.
+ */
+public class ElementTypeUtils {
+
+ /**
+ * Tests if two elements types are equivalent
+ *
+ * @param referenceType
+ * the reference type for the comparison
+ * @param typeToCompare
+ * the type that is compared to the reference one
+ * @return <code>true</code> if both types are equivalent semantically
+ */
+ public static boolean isSemanticallyEquivalent(IElementType referenceType, IElementType typeToCompare) {
+ boolean isEquivalent = true;
+ // first : easy test...
+ if (typeToCompare.equals(referenceType)) {
+ return true;
+ }
+ // 2. test the kind of element.
+ if (referenceType instanceof IMetamodelType) {
+ if (!(typeToCompare instanceof IMetamodelType)) {
+ return false;
+ } else {
+ EClass referenceEclass = ((IMetamodelType) referenceType).getEClass();
+ EClass eclassToCompare = ((IMetamodelType) typeToCompare).getEClass();
+ isEquivalent = isEquivalent && referenceEclass.equals(eclassToCompare);
+ }
+ } else {
+ if ((typeToCompare instanceof IMetamodelType)) {
+ return false;
+ }
+ }
+ // metaclasses are equivalent. check for extended types now...
+ if (referenceType instanceof IExtendedHintedElementType) {
+ if (typeToCompare instanceof IExtendedHintedElementType) {
+ isEquivalent = isEquivalent && isSemanticallyEquivalent((IExtendedHintedElementType) referenceType, (IExtendedHintedElementType) typeToCompare);
+ }
+ }
+ return isEquivalent;
+ }
+
+ /**
+ * Tests if two elements types are equivalent (configuration)
+ *
+ * @param referenceType
+ * the reference type for the comparison
+ * @param typeToCompare
+ * the type that is compared to the reference one
+ * @return <code>true</code> if both types are equivalent semantically
+ */
+ public static boolean isSemanticallyEquivalent(IExtendedHintedElementType referenceType, IExtendedHintedElementType typeToCompare) {
+ boolean isEquivalent = true;
+ // check all pre/post action and validation
+ // ExtendedElementTypeConfiguration referenceConfiguration = referenceType.getConfiguration();
+ // ExtendedElementTypeConfiguration configurationToCompare = typeToCompare.getConfiguration();
+ // List<QueryConfiguration> referencePrevalidation = referenceConfiguration.getPreValidation();
+ // List<QueryConfiguration> prevalidationToCompare = configurationToCompare.getPreValidation();
+ // if(referencePrevalidation != null) {
+ // isEquivalent = isEquivalent && isEquivalent(referencePrevalidation, prevalidationToCompare);
+ // } else if(prevalidationToCompare != null) {
+ // isEquivalent = false;
+ // }
+ // List<PreActionConfiguration> referencePreaction = referenceConfiguration.getPreAction();
+ // List<PreActionConfiguration> preactionToCompare = configurationToCompare.getPreAction();
+ // if(referencePreaction != null) {
+ // isEquivalent = isEquivalent && isEquivalent(referencePreaction, preactionToCompare);
+ // } else if(preactionToCompare != null) {
+ // isEquivalent = false;
+ // }
+ // List<PostActionConfiguration> referencePostaction = referenceConfiguration.getPostAction();
+ // List<PostActionConfiguration> postactionToCompare = configurationToCompare.getPostAction();
+ // if(referencePostaction != null) {
+ // isEquivalent = isEquivalent && isEquivalent(referencePostaction, postactionToCompare);
+ // } else if(postactionToCompare != null) {
+ // isEquivalent = false;
+ // }
+ return isEquivalent;
+ }
+
+ public static boolean isEquivalent(List<? extends EObject> referenceList, List<? extends EObject> listToCompare) {
+ boolean isEquivalent = true;
+ if (referenceList == null) {
+ // only one is null : false
+ if (listToCompare != null) {
+ return false;
+ } else {
+ // both are null: true
+ return true;
+ }
+ } else {
+ // only one is null: false
+ if (listToCompare == null) {
+ return false;
+ }
+ }
+ // check emptyness. If both empty : equivalent
+ if (referenceList.isEmpty() && listToCompare.isEmpty()) {
+ return true;
+ }
+ // check size. If different, false
+ if (referenceList.size() != listToCompare.size()) {
+ return false;
+ }
+ for (int i = 0; i < referenceList.size(); i++) {
+ EObject reference = referenceList.get(i);
+ EObject compared = listToCompare.get(i);
+ isEquivalent = isEquivalent && EcoreUtil.equals(reference, compared);
+ }
+ return isEquivalent;
+ }
+
+ /**
+ * Returns the closest non Extended element type for a given extended type
+ *
+ * @param requestElementType
+ * the element type to study
+ * @return the closest non extended element type or <code>null</code> if none was found.
+ */
+ public static IElementType findClosestNonExtendedElementType(IExtendedHintedElementType requestElementType) {
+ List<IElementType> superTypes = new ArrayList<IElementType>(Arrays.asList(requestElementType.getAllSuperTypes()));
+ // reverse order for the list, because super type returns all super types from furthest to closest, we want the other order
+ Collections.reverse(superTypes);
+ for (IElementType superType : superTypes) {
+ if (!(superType instanceof IExtendedHintedElementType)) {
+ return superType;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the closest super type which is not an extended type
+ *
+ * @param elementType
+ * the element type for which the super type is searched.
+ * @return the closest super type non extended or <code>null</code> if none was found
+ */
+ public static IElementType getClosestDiagramType(IElementType elementType) {
+ if (!(elementType instanceof IExtendedHintedElementType)) {
+ return elementType;
+ }
+ // // this is an extended type
+ // String diagramElementTypeID = ((IExtendedHintedElementType)elementType).getSpecializedTypeIds();
+ // if(diagramElementTypeID != null) {
+ // return getClosestDiagramType(ElementTypeRegistry.getInstance().getType(diagramElementTypeID));
+ // } else {
+ // IElementType[] superTypes = elementType.getAllSuperTypes();
+ // if(superTypes.length > 1) {
+ // return getClosestDiagramType(superTypes[superTypes.length - 1]);
+ // }
+ // }
+ return null;
+ }
+}
diff --git a/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/util/InternalUtils.java b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/util/InternalUtils.java
new file mode 100644
index 00000000000..8ae43cff4e3
--- /dev/null
+++ b/plugins/infra/xtypes/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/util/InternalUtils.java
@@ -0,0 +1,157 @@
+/*****************************************************************************
+ * Copyright (c) 2013, 2016 CEA LIST, Christian W. Damus, 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:
+ * CEA LIST - Initial API and implementation
+ * Christian W. Damus - bug 485220
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.extendedtypes.util;
+
+import java.lang.ref.WeakReference;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.runtime.Platform;
+import org.osgi.framework.Bundle;
+
+/**
+ * Utilities for internal use by rthe ExtendedTypes bundle.
+ */
+public class InternalUtils {
+
+ /** A map of classes that have been successfully loaded, keyed on the class name optionally prepended by the plugin ID, if specified. */
+ private static Map<String, WeakReference<Class<?>>> successLookupTable = new HashMap<String, WeakReference<Class<?>>>();
+
+ /** A map of classes that could not be loaded, keyed on the class name, optionally prepended by the plugin ID if specified. */
+ private static Set<String> failureLookupTable = new HashSet<String>();
+
+ /** A map to hold the bundle to exception list */
+ private static Map<Bundle, Set<String>> bundleToExceptionsSetMap = new HashMap<Bundle, Set<String>>();
+
+ private InternalUtils() {
+ super();
+ }
+
+ /**
+ * A utility method to load a class using its name and a given class loader.
+ *
+ * @param className
+ * The class name
+ * @param bundle
+ * The class loader
+ * @return The loaded class or <code>null</code> if could not be loaded
+ */
+ public static Class<?> loadClass(String className, String pluginId) {
+ // FIXME: This method is grossly flawed, as it requires the class being loaded to be contained within the identified bundle, not anywhere on its classpath
+ StringBuffer keyStringBuf = new StringBuffer(className.length() + pluginId.length() + 2); // 2 is for . and extra.
+ keyStringBuf.append(pluginId);
+ keyStringBuf.append('.');
+ keyStringBuf.append(className);
+ String keyString = keyStringBuf.toString();
+ WeakReference<Class<?>> ref = successLookupTable.get(keyString);
+ Class<?> found = (ref != null) ? ref.get() : null;
+ if (found == null) {
+ if (ref != null) {
+ successLookupTable.remove(keyString);
+ }
+ if (!failureLookupTable.contains(keyString)) {
+ try {
+ Bundle bundle = basicGetPluginBundle(pluginId);
+ if (bundle != null) {
+ // never load the class if the bundle is not active other wise
+ // we will cause the plugin to load
+ // unless the class is in the exception list
+ int state = bundle.getState();
+ if (state == org.osgi.framework.Bundle.ACTIVE || isInExceptionList(bundle, className)) {
+ found = bundle.loadClass(className);
+ successLookupTable.put(keyString, new WeakReference<Class<?>>(found));
+ if (state == org.osgi.framework.Bundle.ACTIVE) {
+ bundleToExceptionsSetMap.remove(bundle);
+ }
+ }
+ } else {
+ failureLookupTable.add(keyString);
+ }
+ } catch (ClassNotFoundException e) {
+ failureLookupTable.add(keyString);
+ }
+ }
+ }
+ return found;
+ }
+
+ private static boolean isInExceptionList(Bundle bundle, String className) {
+ String packageName = className.substring(0, className.lastIndexOf('.'));
+ Set<String> exceptionSet = bundleToExceptionsSetMap.get(bundle);
+ if (exceptionSet == null) {
+ Dictionary<String, String> dict = bundle.getHeaders();
+ int index = -1;
+ String value = dict.get("Bundle-ActivationPolicy"); //$NON-NLS-1$
+ if (value != null) {
+ index = value.indexOf("lazy"); //$NON-NLS-1$
+ if (index >= 0) {
+ index = value.indexOf("exclude", index); //$NON-NLS-1$
+ }
+ }
+ if (index < 0) {
+ // Try the (very) old way
+ value = dict.get("Eclipse-LazyStart"); //$NON-NLS-1$
+ if (value != null) {
+ index = value.indexOf("exceptions"); //$NON-NLS-1$
+ }
+ }
+ if (index >= 0) {
+ try {
+ int start = value.indexOf('"', index + 1);
+ int end = value.indexOf('"', start + 1);
+ String exceptions = value.substring(start + 1, end);
+ exceptionSet = new HashSet<String>(2);
+ StringTokenizer tokenizer = new StringTokenizer(exceptions, ","); //$NON-NLS-1$
+ while (tokenizer.hasMoreTokens()) {
+ exceptionSet.add(tokenizer.nextToken().trim());
+ }
+ } catch (IndexOutOfBoundsException exception) {
+ // this means the MF did not follow the documented format for the exceptions list so i'll consider it empty
+ exceptionSet = Collections.emptySet();
+ }
+ } else {
+ exceptionSet = Collections.emptySet();
+ }
+ bundleToExceptionsSetMap.put(bundle, exceptionSet);
+ }
+ return exceptionSet.contains(packageName);
+ }
+
+ /**
+ * Given a bundle id, it checks if the bundle is found and activated. If it
+ * is, the method returns the bundle, otherwise it returns <code>null</code>.
+ *
+ * @param pluginId
+ * the bundle ID
+ * @return the bundle, if found
+ */
+ private static Bundle getPluginBundle(String pluginId) {
+ Bundle bundle = basicGetPluginBundle(pluginId);
+ if (null != bundle && bundle.getState() == org.osgi.framework.Bundle.ACTIVE) {
+ return bundle;
+ }
+ return null;
+ }
+
+ private static Bundle basicGetPluginBundle(String pluginId) {
+ return Platform.getBundle(pluginId);
+ }
+
+}

Back to the top