diff options
Diffstat (limited to 'plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra')
64 files changed, 3949 insertions, 0 deletions
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/Activator.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/Activator.java new file mode 100644 index 00000000000..0aa038b9c17 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/Activator.java @@ -0,0 +1,62 @@ +/***************************************************************************** + * 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.types.core; + +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.types.core"; //$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/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/IConfiguredContainerDescriptor.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/IConfiguredContainerDescriptor.java new file mode 100644 index 00000000000..1f669657cfd --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/IConfiguredContainerDescriptor.java @@ -0,0 +1,25 @@ +/*****************************************************************************
+ * Copyright (c) 2014 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.types.core;
+
+import org.eclipse.gmf.runtime.emf.type.core.IContainerDescriptor;
+import org.eclipse.papyrus.infra.types.ContainerConfiguration;
+
+
+/**
+ * Descriptor for the configurable container descriptor
+ */
+public interface IConfiguredContainerDescriptor<T extends ContainerConfiguration> extends IContainerDescriptor {
+
+ void init(T containerConfiguration);
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/IConfiguredEditHelperAdviceDescriptor.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/IConfiguredEditHelperAdviceDescriptor.java new file mode 100644 index 00000000000..872b2a3c651 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/IConfiguredEditHelperAdviceDescriptor.java @@ -0,0 +1,22 @@ +/*****************************************************************************
+ * Copyright (c) 2014, 2015 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 459174
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core;
+
+import org.eclipse.gmf.runtime.emf.type.core.IAdviceBindingDescriptor;
+import org.eclipse.papyrus.infra.types.AdviceConfiguration;
+
+public interface IConfiguredEditHelperAdviceDescriptor<T extends AdviceConfiguration> extends IAdviceBindingDescriptor {
+
+ public void init(T configuration);
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/IConfiguredHintedElementType.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/IConfiguredHintedElementType.java new file mode 100644 index 00000000000..4547c75c070 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/IConfiguredHintedElementType.java @@ -0,0 +1,24 @@ +/*****************************************************************************
+ * Copyright (c) 2015 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.types.core;
+
+import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
+import org.eclipse.papyrus.infra.types.ElementTypeConfiguration;
+
+
+public interface IConfiguredHintedElementType extends IHintedType {
+
+ ElementTypeConfiguration getConfiguration();
+
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/TypesConfigurationsRegistryService.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/TypesConfigurationsRegistryService.java new file mode 100644 index 00000000000..ce1c5c024f9 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/TypesConfigurationsRegistryService.java @@ -0,0 +1,49 @@ +/***************************************************************************** + * Copyright (c) 2014 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.types.core; + +import org.eclipse.papyrus.infra.core.services.IService; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.core.services.ServicesRegistry; +import org.eclipse.papyrus.infra.types.core.registries.ElementTypeSetConfigurationRegistry; + +/** + * Service to register elementTypes configurations + */ +public class TypesConfigurationsRegistryService implements IService { + + /** + * {@inheritDoc} + */ + public void init(ServicesRegistry servicesRegistry) throws ServiceException { + } + + /** + * {@inheritDoc} + */ + public void startService() throws ServiceException { + // register elements in elementType registry + ElementTypeSetConfigurationRegistry.getInstance(); + } + + /** + * {@inheritDoc} + */ + public void disposeService() throws ServiceException { + // Do nothing because registered elementtypes may be used somewhere else. + } + + public ElementTypeSetConfigurationRegistry getElementTypeSetRegistry() { + return ElementTypeSetConfigurationRegistry.getInstance(); + } +} diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/extensionpoints/IAdviceKindExtensionPoint.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/extensionpoints/IAdviceKindExtensionPoint.java new file mode 100644 index 00000000000..1def9adfa2c --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/extensionpoints/IAdviceKindExtensionPoint.java @@ -0,0 +1,25 @@ +/***************************************************************************** + * Copyright (c) 2014 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.types.core.extensionpoints; + +import org.eclipse.papyrus.infra.types.core.Activator; + +public interface IAdviceKindExtensionPoint { + + /** ID of the extension point */ + public final static String EXTENSION_POINT_ID = Activator.PLUGIN_ID + ".adviceConfigurationKind"; + + public static final String FACTORY_CLASS = "factoryClass"; + + public static final String CONFIGURATION_CLASS = "configurationClass"; +} diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/extensionpoints/IContainerConfigurationKindExtensionPoint.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/extensionpoints/IContainerConfigurationKindExtensionPoint.java new file mode 100644 index 00000000000..6acdfbe21e8 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/extensionpoints/IContainerConfigurationKindExtensionPoint.java @@ -0,0 +1,25 @@ +/***************************************************************************** + * Copyright (c) 2014 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.types.core.extensionpoints; + +import org.eclipse.papyrus.infra.types.core.Activator; + +public interface IContainerConfigurationKindExtensionPoint { + + /** ID of the extension point */ + public final static String EXTENSION_POINT_ID = Activator.PLUGIN_ID + ".containerConfigurationKind"; + + public static final String FACTORY_CLASS = "factoryClass"; + + public static final String CONFIGURATION_CLASS = "configurationClass"; +} diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/extensionpoints/IElementTypeConfigurationKindExtensionPoint.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/extensionpoints/IElementTypeConfigurationKindExtensionPoint.java new file mode 100644 index 00000000000..a39a19da6d4 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/extensionpoints/IElementTypeConfigurationKindExtensionPoint.java @@ -0,0 +1,30 @@ +/***************************************************************************** + * Copyright (c) 2014 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.types.core.extensionpoints; + +import org.eclipse.papyrus.infra.types.core.Activator; + +/** + * Constants for the extension point elementTypeConfigurationType + */ +public interface IElementTypeConfigurationKindExtensionPoint { + + /** ID of the extension point */ + public final static String EXTENSION_POINT_ID = Activator.PLUGIN_ID + ".elementTypeConfigurationKind"; + + /** attribute factoryClass */ + public static final String FACTORY_CLASS = "factoryClass"; + + /** attribute configurationClass */ + public static final String CONFIGURATION_CLASS = "configurationClass"; +} diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/extensionpoints/IElementTypeSetExtensionPoint.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/extensionpoints/IElementTypeSetExtensionPoint.java new file mode 100644 index 00000000000..24a09884fed --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/extensionpoints/IElementTypeSetExtensionPoint.java @@ -0,0 +1,27 @@ +/***************************************************************************** + * Copyright (c) 2014 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.types.core.extensionpoints; + +import org.eclipse.papyrus.infra.types.core.Activator; + +public interface IElementTypeSetExtensionPoint { + + /** ID of the extension point */ + public final static String EXTENSION_POINT_ID = Activator.PLUGIN_ID + ".elementTypeSetConfiguration"; + + /** attribute: path to the model file in the bundle */ + public static final String PATH = "path"; + + /** attribute: identifier of the clientContext in which to register the elementTypeConfigurationSet */ + public static final String CLIENT_CONTEXT_ID = "clientContextID"; +} diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/extensionpoints/IMatcherConfigurationKindExtensionPoint.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/extensionpoints/IMatcherConfigurationKindExtensionPoint.java new file mode 100644 index 00000000000..819e9d32814 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/extensionpoints/IMatcherConfigurationKindExtensionPoint.java @@ -0,0 +1,30 @@ +/***************************************************************************** + * Copyright (c) 2014 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.types.core.extensionpoints; + +import org.eclipse.papyrus.infra.types.core.Activator; + +/** + * Constants for the extension point matcherConfigurationType + */ +public interface IMatcherConfigurationKindExtensionPoint { + + /** ID of the extension point */ + public final static String EXTENSION_POINT_ID = Activator.PLUGIN_ID + ".matcherConfigurationKind"; + + /** attribute factoryClass */ + public static final String FACTORY_CLASS = "factoryClass"; + + /** attribute configurationClass */ + public static final String CONFIGURATION_CLASS = "configurationClass"; +} diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/IContainerFactory.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/IContainerFactory.java new file mode 100644 index 00000000000..676136c7be3 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/IContainerFactory.java @@ -0,0 +1,21 @@ +/***************************************************************************** + * Copyright (c) 2014 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.types.core.factories; + +import org.eclipse.papyrus.infra.types.ContainerConfiguration; +import org.eclipse.papyrus.infra.types.core.IConfiguredContainerDescriptor; + +public interface IContainerFactory<T extends ContainerConfiguration> { + + public IConfiguredContainerDescriptor<T> createContainerDescriptor(T configuration); +} diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/IEditHelperAdviceFactory.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/IEditHelperAdviceFactory.java new file mode 100644 index 00000000000..7a3831cbc76 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/IEditHelperAdviceFactory.java @@ -0,0 +1,21 @@ +/***************************************************************************** + * Copyright (c) 2014 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.types.core.factories; + +import org.eclipse.papyrus.infra.types.AdviceConfiguration; +import org.eclipse.papyrus.infra.types.core.IConfiguredEditHelperAdviceDescriptor; + +public interface IEditHelperAdviceFactory<T extends AdviceConfiguration> { + + public IConfiguredEditHelperAdviceDescriptor<T> createEditHelperAdviceDescriptor(T configuration); +} diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/IElementTypeConfigurationFactory.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/IElementTypeConfigurationFactory.java new file mode 100644 index 00000000000..2d5007089dd --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/IElementTypeConfigurationFactory.java @@ -0,0 +1,21 @@ +/***************************************************************************** + * Copyright (c) 2014 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.types.core.factories; + +import org.eclipse.gmf.runtime.emf.type.core.IHintedType; +import org.eclipse.papyrus.infra.types.ElementTypeConfiguration; + +public interface IElementTypeConfigurationFactory<T extends ElementTypeConfiguration> { + + IHintedType createElementType(T elementTypeConfiguration); +} diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/IMatcherFactory.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/IMatcherFactory.java new file mode 100644 index 00000000000..f72433f2090 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/IMatcherFactory.java @@ -0,0 +1,21 @@ +/***************************************************************************** + * Copyright (c) 2014 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.types.core.factories; + +import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher; +import org.eclipse.papyrus.infra.types.AbstractMatcherConfiguration; + +public interface IMatcherFactory<T extends AbstractMatcherConfiguration> { + + public IElementMatcher createElementMatcher(T configuration); +} diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/AbstractAdviceBindingFactory.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/AbstractAdviceBindingFactory.java new file mode 100644 index 00000000000..1bb0959254d --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/AbstractAdviceBindingFactory.java @@ -0,0 +1,60 @@ +/*****************************************************************************
+ * Copyright (c) 2014 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.types.core.factories.impl;
+
+import org.eclipse.gmf.runtime.emf.type.core.AdviceBindingInheritance;
+import org.eclipse.gmf.runtime.emf.type.core.IContainerDescriptor;
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+import org.eclipse.papyrus.infra.types.AbstractAdviceBindingConfiguration;
+import org.eclipse.papyrus.infra.types.AbstractMatcherConfiguration;
+import org.eclipse.papyrus.infra.types.ContainerConfiguration;
+import org.eclipse.papyrus.infra.types.core.registries.ContainerConfigurationTypeRegistry;
+import org.eclipse.papyrus.infra.types.core.registries.MatcherConfigurationTypeRegistry;
+
+public abstract class AbstractAdviceBindingFactory<T extends AbstractAdviceBindingConfiguration> extends AbstractAdviceFactory<T> {
+
+ @Override
+ protected String getTypeId(T adviceConfiguration) {
+ return adviceConfiguration.getTarget().getIdentifier();
+ }
+
+ @Override
+ protected IContainerDescriptor getContainerDescriptor(T adviceConfiguration) {
+ ContainerConfiguration containerConfiguration = adviceConfiguration.getContainerConfiguration();
+ if (containerConfiguration == null) {
+ return null;
+ }
+ IContainerDescriptor containerDescriptor = ContainerConfigurationTypeRegistry.getInstance().getContainerDescriptor(containerConfiguration);
+ return containerDescriptor;
+ }
+
+ @Override
+ protected IElementMatcher getMatcher(T adviceConfiguration) {
+ AbstractMatcherConfiguration matcherConfiguration = adviceConfiguration.getMatcherConfiguration();
+ if (matcherConfiguration == null) {
+ return null;
+ }
+ IElementMatcher matcher = MatcherConfigurationTypeRegistry.getInstance().getMatcher(matcherConfiguration);
+ return matcher;
+ }
+
+ @Override
+ protected AdviceBindingInheritance getInheritance(T adviceConfiguration) {
+ return AdviceBindingInheritance.getAdviceBindingInheritance(adviceConfiguration.getInheritance().getName());
+ }
+
+ @Override
+ protected String getId(T adviceConfiguration) {
+ return adviceConfiguration.getIdentifier();
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/AbstractAdviceFactory.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/AbstractAdviceFactory.java new file mode 100644 index 00000000000..b00a766e027 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/AbstractAdviceFactory.java @@ -0,0 +1,44 @@ +/***************************************************************************** + * Copyright (c) 2014, 2015 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 459174 + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.types.core.factories.impl; + +import org.eclipse.gmf.runtime.emf.type.core.AdviceBindingInheritance; +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.types.AdviceConfiguration; +import org.eclipse.papyrus.infra.types.core.IConfiguredEditHelperAdviceDescriptor; +import org.eclipse.papyrus.infra.types.core.factories.IEditHelperAdviceFactory; +import org.eclipse.papyrus.infra.types.core.impl.ConfiguredEditHelperAdviceDescriptor; + +public abstract class AbstractAdviceFactory<T extends AdviceConfiguration> implements IEditHelperAdviceFactory<T> { + + @Override + public IConfiguredEditHelperAdviceDescriptor<T> createEditHelperAdviceDescriptor(T adviceConfiguration) { + return new ConfiguredEditHelperAdviceDescriptor<T>(getId(adviceConfiguration), getTypeId(adviceConfiguration), getMatcher(adviceConfiguration), getContainerDescriptor(adviceConfiguration), getEditHelperAdvice(adviceConfiguration), + getInheritance(adviceConfiguration)); + } + + abstract protected String getId(T adviceConfiguration); + + abstract protected String getTypeId(T adviceConfiguration); + + abstract protected IElementMatcher getMatcher(T adviceConfiguration); + + abstract protected IContainerDescriptor getContainerDescriptor(T adviceConfiguration); + + abstract protected IEditHelperAdvice getEditHelperAdvice(T adviceConfiguration); + + abstract protected AdviceBindingInheritance getInheritance(T adviceConfiguration); +} diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/AbstractEditHelperAdviceFactory.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/AbstractEditHelperAdviceFactory.java new file mode 100644 index 00000000000..17c8f5e0983 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/AbstractEditHelperAdviceFactory.java @@ -0,0 +1,61 @@ +/*****************************************************************************
+ * Copyright (c) 2014 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.types.core.factories.impl;
+
+import org.eclipse.gmf.runtime.emf.type.core.AdviceBindingInheritance;
+import org.eclipse.gmf.runtime.emf.type.core.IContainerDescriptor;
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+import org.eclipse.papyrus.infra.types.AbstractEditHelperAdviceConfiguration;
+import org.eclipse.papyrus.infra.types.AbstractMatcherConfiguration;
+import org.eclipse.papyrus.infra.types.ContainerConfiguration;
+import org.eclipse.papyrus.infra.types.SpecializationTypeConfiguration;
+import org.eclipse.papyrus.infra.types.core.registries.ContainerConfigurationTypeRegistry;
+import org.eclipse.papyrus.infra.types.core.registries.MatcherConfigurationTypeRegistry;
+
+public abstract class AbstractEditHelperAdviceFactory<T extends AbstractEditHelperAdviceConfiguration> extends AbstractAdviceFactory<T> {
+
+ @Override
+ protected String getTypeId(T adviceConfiguration) {
+ return adviceConfiguration.getTarget().getIdentifier();
+ }
+
+ @Override
+ protected AdviceBindingInheritance getInheritance(T adviceConfiguration) {
+ return AdviceBindingInheritance.ALL;
+ }
+
+ @Override
+ protected IContainerDescriptor getContainerDescriptor(T adviceConfiguration) {
+ ContainerConfiguration containerConfiguration = ((SpecializationTypeConfiguration) adviceConfiguration.eContainer()).getContainerConfiguration();
+ if (containerConfiguration == null) {
+ return null;
+ }
+ IContainerDescriptor containerDescriptor = ContainerConfigurationTypeRegistry.getInstance().getContainerDescriptor(containerConfiguration);
+ return containerDescriptor;
+ }
+
+ @Override
+ protected IElementMatcher getMatcher(T adviceConfiguration) {
+ AbstractMatcherConfiguration matcherConfiguration = ((SpecializationTypeConfiguration) adviceConfiguration.eContainer()).getMatcherConfiguration();
+ if (matcherConfiguration == null) {
+ return null;
+ }
+ IElementMatcher matcher = MatcherConfigurationTypeRegistry.getInstance().getMatcher(matcherConfiguration);
+ return matcher;
+ }
+
+ @Override
+ protected String getId(T adviceConfiguration) {
+ return adviceConfiguration.getTarget().getIdentifier();
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/AbstractElementTypeConfigurationFactory.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/AbstractElementTypeConfigurationFactory.java new file mode 100644 index 00000000000..f23e83cba80 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/AbstractElementTypeConfigurationFactory.java @@ -0,0 +1,70 @@ +/***************************************************************************** + * Copyright (c) 2014 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.types.core.factories.impl; + +import java.net.MalformedURLException; +import java.net.URL; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.papyrus.infra.types.ElementTypeConfiguration; +import org.eclipse.papyrus.infra.types.IconEntry; +import org.eclipse.papyrus.infra.types.core.factories.IElementTypeConfigurationFactory; +import org.osgi.framework.Bundle; + +public abstract class AbstractElementTypeConfigurationFactory<T extends ElementTypeConfiguration> implements IElementTypeConfigurationFactory<T> { + + protected String getDisplayName(T elementTypeConfiguration) { + return elementTypeConfiguration.getName(); + } + + protected URL getIconURL(T elementTypeConfiguration) { + // icon associated to the elementType (GUI) + IconEntry entry = elementTypeConfiguration.getIconEntry(); + URL iconURL = null; + if (entry != null) { + iconURL = getURLFromEntry(entry); + } + return iconURL; + } + + protected String getID(T elementTypeConfiguration) { + return elementTypeConfiguration.getIdentifier(); + } + + /** + * Returns the semantic hint for the elementType from the given configuration + */ + protected String getSemanticHint(T elementTypeConfiguration) { + return elementTypeConfiguration.getHint(); + } + + /** + * @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/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/DefaultAdviceBindingFactory.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/DefaultAdviceBindingFactory.java new file mode 100644 index 00000000000..36a8af3bf9d --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/DefaultAdviceBindingFactory.java @@ -0,0 +1,34 @@ +/*****************************************************************************
+ * Copyright (c) 2014 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.types.core.factories.impl;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.papyrus.infra.tools.util.ClassLoaderHelper;
+import org.eclipse.papyrus.infra.types.AdviceBindingConfiguration;
+
+public class DefaultAdviceBindingFactory extends AbstractAdviceBindingFactory<AdviceBindingConfiguration> {
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.types.core.factories.impl.AbstractAdviceFactory#getEditHelperAdvice(org.eclipse.papyrus.infra.types.AdviceConfiguration)
+ *
+ * @param adviceConfiguration
+ * @return
+ */
+ @Override
+ protected IEditHelperAdvice getEditHelperAdvice(AdviceBindingConfiguration adviceConfiguration) {
+ IEditHelperAdvice editHelperAdvice = ClassLoaderHelper.newInstance(adviceConfiguration.getEditHelperAdviceClassName(), IEditHelperAdvice.class);
+ return editHelperAdvice;
+ }
+
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/DefaultEditHelperAdviceFactory.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/DefaultEditHelperAdviceFactory.java new file mode 100644 index 00000000000..e4557022b85 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/DefaultEditHelperAdviceFactory.java @@ -0,0 +1,34 @@ +/*****************************************************************************
+ * Copyright (c) 2014 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.types.core.factories.impl;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.papyrus.infra.tools.util.ClassLoaderHelper;
+import org.eclipse.papyrus.infra.types.EditHelperAdviceConfiguration;
+
+public class DefaultEditHelperAdviceFactory extends AbstractEditHelperAdviceFactory<EditHelperAdviceConfiguration> {
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.types.core.factories.impl.AbstractAdviceFactory#getEditHelperAdvice(org.eclipse.papyrus.infra.types.AdviceConfiguration)
+ *
+ * @param adviceConfiguration
+ * @return
+ */
+ @Override
+ protected IEditHelperAdvice getEditHelperAdvice(EditHelperAdviceConfiguration adviceConfiguration) {
+ IEditHelperAdvice editHelperAdvice = ClassLoaderHelper.newInstance(adviceConfiguration.getEditHelperAdviceClassName(), IEditHelperAdvice.class);
+ return editHelperAdvice;
+ }
+
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/DefaultMatcherFactory.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/DefaultMatcherFactory.java new file mode 100644 index 00000000000..ba4cf0ae713 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/DefaultMatcherFactory.java @@ -0,0 +1,35 @@ +/*****************************************************************************
+ * Copyright (c) 2014 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.types.core.factories.impl;
+
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+import org.eclipse.papyrus.infra.tools.util.ClassLoaderHelper;
+import org.eclipse.papyrus.infra.types.MatcherConfiguration;
+import org.eclipse.papyrus.infra.types.core.factories.IMatcherFactory;
+
+public class DefaultMatcherFactory implements IMatcherFactory<MatcherConfiguration> {
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.types.core.factories.IMatcherFactory#createElementMatcher(org.eclipse.papyrus.infra.types.AbstractMatcherConfiguration)
+ *
+ * @param matcherConfiguration
+ * @return
+ */
+ @Override
+ public IElementMatcher createElementMatcher(MatcherConfiguration matcherConfiguration) {
+ String matcherClassName = matcherConfiguration.getMatcherClassName();
+ IElementMatcher matcher = ClassLoaderHelper.newInstance(matcherClassName, IElementMatcher.class);
+ return matcher;
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/MetamodelTypeFactory.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/MetamodelTypeFactory.java new file mode 100644 index 00000000000..5bf6f755a67 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/MetamodelTypeFactory.java @@ -0,0 +1,43 @@ +/***************************************************************************** + * Copyright (c) 2014 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.types.core.factories.impl; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.gmf.runtime.emf.type.core.IHintedType; +import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper; +import org.eclipse.papyrus.infra.tools.util.ClassLoaderHelper; +import org.eclipse.papyrus.infra.types.MetamodelTypeConfiguration; +import org.eclipse.papyrus.infra.types.core.impl.ConfiguredHintedMetamodelElementType; + +public class MetamodelTypeFactory extends AbstractElementTypeConfigurationFactory<MetamodelTypeConfiguration> { + + /** + * {@inheritDoc} + */ + public IHintedType createElementType(MetamodelTypeConfiguration configuration) { + return new ConfiguredHintedMetamodelElementType(getID(configuration), getIconURL(configuration), getDisplayName(configuration), getEClass(configuration), createEditHelper(configuration), getSemanticHint(configuration), configuration); + } + + protected EClass getEClass(MetamodelTypeConfiguration configuration) { + return configuration.getEClass(); + } + + protected IEditHelper createEditHelper(MetamodelTypeConfiguration configuration) { + String editHelperClassName = configuration.getEditHelperClassName(); + if (editHelperClassName == null) { + return null; + } + IEditHelper editHelper = ClassLoaderHelper.newInstance(editHelperClassName, IEditHelper.class); + return editHelper; + } +} diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/SpecializationTypeFactory.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/SpecializationTypeFactory.java new file mode 100644 index 00000000000..f790f9f6127 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/factories/impl/SpecializationTypeFactory.java @@ -0,0 +1,89 @@ +/*****************************************************************************
+ * Copyright (c) 2014, 2015 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 459174
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.factories.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.IAdviceBindingDescriptor;
+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.IHintedType;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.papyrus.infra.types.AbstractEditHelperAdviceConfiguration;
+import org.eclipse.papyrus.infra.types.AbstractMatcherConfiguration;
+import org.eclipse.papyrus.infra.types.ContainerConfiguration;
+import org.eclipse.papyrus.infra.types.SpecializationTypeConfiguration;
+import org.eclipse.papyrus.infra.types.core.Activator;
+import org.eclipse.papyrus.infra.types.core.impl.ConfiguredHintedSpecializationElementType;
+import org.eclipse.papyrus.infra.types.core.impl.NullEditHelperAdvice;
+import org.eclipse.papyrus.infra.types.core.registries.AdviceConfigurationTypeRegistry;
+import org.eclipse.papyrus.infra.types.core.registries.ContainerConfigurationTypeRegistry;
+import org.eclipse.papyrus.infra.types.core.registries.MatcherConfigurationTypeRegistry;
+
+public class SpecializationTypeFactory extends AbstractElementTypeConfigurationFactory<SpecializationTypeConfiguration> {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IHintedType createElementType(SpecializationTypeConfiguration elementTypeConfiguration) {
+ return new ConfiguredHintedSpecializationElementType(getID(elementTypeConfiguration), getIconURL(elementTypeConfiguration), getDisplayName(elementTypeConfiguration), getSpecializedID(elementTypeConfiguration),
+ createElementMatcher(elementTypeConfiguration), createContainerDescriptor(elementTypeConfiguration), getEditHelperAdvice(elementTypeConfiguration), getSemanticHint(elementTypeConfiguration), elementTypeConfiguration);
+ }
+
+ protected IEditHelperAdvice getEditHelperAdvice(SpecializationTypeConfiguration elementTypeConfiguration) {
+ AbstractEditHelperAdviceConfiguration editHelperAdviceConfiguration = elementTypeConfiguration.getEditHelperAdviceConfiguration();
+ if (editHelperAdviceConfiguration == null) {
+ return NullEditHelperAdvice.getInstance();
+ }
+ IAdviceBindingDescriptor editHelperAdviceDescriptor = AdviceConfigurationTypeRegistry.getInstance().getEditHelperAdviceDecriptor(editHelperAdviceConfiguration);
+ return editHelperAdviceDescriptor.getEditHelperAdvice();
+ }
+
+ protected IContainerDescriptor createContainerDescriptor(SpecializationTypeConfiguration elementTypeConfiguration) {
+ ContainerConfiguration containerConfiguration = elementTypeConfiguration.getContainerConfiguration();
+ if (containerConfiguration == null) {
+ return null;
+ }
+ IContainerDescriptor containerDescriptor = ContainerConfigurationTypeRegistry.getInstance().getContainerDescriptor(containerConfiguration);
+ return containerDescriptor;
+ }
+
+ protected IElementType[] getSpecializedID(SpecializationTypeConfiguration elementTypeConfiguration) {
+ // Specialized elementTypes
+ List<IElementType> specializedTypes = new ArrayList<IElementType>((elementTypeConfiguration).getSpecializedTypesID().size());
+ for (String specializedTypeId : (elementTypeConfiguration).getSpecializedTypesID()) {
+ IElementType specializedType = ElementTypeRegistry.getInstance().getType(specializedTypeId);
+ if (specializedType != null) {
+ specializedTypes.add(specializedType);
+ } else {
+ Activator.log.info("Unable to add specialization \"" + getID(elementTypeConfiguration) + "\" to \"" + specializedTypeId + "\"");
+ }
+ }
+ IElementType[] elementTypes = specializedTypes.toArray(new IElementType[] {});
+ return elementTypes;
+ }
+
+ protected IElementMatcher createElementMatcher(SpecializationTypeConfiguration configuration) {
+ AbstractMatcherConfiguration matcherConfiguration = configuration.getMatcherConfiguration();
+ if (matcherConfiguration == null) {
+ return null;
+ }
+ IElementMatcher matcher = MatcherConfigurationTypeRegistry.getInstance().getMatcher(matcherConfiguration);
+ return matcher;
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/impl/ConfiguredEditHelperAdviceDescriptor.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/impl/ConfiguredEditHelperAdviceDescriptor.java new file mode 100644 index 00000000000..88b47929651 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/impl/ConfiguredEditHelperAdviceDescriptor.java @@ -0,0 +1,74 @@ +/*****************************************************************************
+ * Copyright (c) 2014 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.types.core.impl;
+
+import org.eclipse.gmf.runtime.emf.type.core.AdviceBindingInheritance;
+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.types.AdviceConfiguration;
+import org.eclipse.papyrus.infra.types.core.IConfiguredEditHelperAdviceDescriptor;
+
+public class ConfiguredEditHelperAdviceDescriptor<T extends AdviceConfiguration> implements IConfiguredEditHelperAdviceDescriptor<T> {
+
+ protected T editHelperAdviceConfiguration;
+
+ protected String id;
+
+ protected String typeId;
+
+ protected IElementMatcher matcher;
+
+ protected IContainerDescriptor containerDescriptor;
+
+ protected IEditHelperAdvice editHelperAdvice;
+
+ protected AdviceBindingInheritance inheritance;
+
+ public ConfiguredEditHelperAdviceDescriptor(String id, String typeId, IElementMatcher matcher, IContainerDescriptor containerDescriptor, IEditHelperAdvice editHelperAdvice, AdviceBindingInheritance inheritance) {
+ this.id = id;
+ this.typeId = typeId;
+ this.matcher = matcher;
+ this.containerDescriptor = containerDescriptor;
+ this.editHelperAdvice = editHelperAdvice;
+ this.inheritance = inheritance;
+ }
+
+ public String getId() {
+ return this.id;
+ }
+
+ public String getTypeId() {
+ return this.typeId;
+ }
+
+ public IElementMatcher getMatcher() {
+ return this.matcher;
+ }
+
+ public IContainerDescriptor getContainerDescriptor() {
+ return this.containerDescriptor;
+ }
+
+ public IEditHelperAdvice getEditHelperAdvice() {
+ return this.editHelperAdvice;
+ }
+
+ public AdviceBindingInheritance getInheritance() {
+ return this.inheritance;
+ }
+
+ public void init(T editHelperAdviceConfiguration) {
+ this.editHelperAdviceConfiguration = editHelperAdviceConfiguration;
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/impl/ConfiguredHintedMetamodelElementType.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/impl/ConfiguredHintedMetamodelElementType.java new file mode 100644 index 00000000000..c14be0aecb6 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/impl/ConfiguredHintedMetamodelElementType.java @@ -0,0 +1,61 @@ +/***************************************************************************** + * Copyright (c) 2014 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.types.core.impl; + +import java.net.URL; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.gmf.runtime.emf.type.core.MetamodelType; +import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper; +import org.eclipse.papyrus.infra.types.ElementTypeConfiguration; +import org.eclipse.papyrus.infra.types.MetamodelTypeConfiguration; +import org.eclipse.papyrus.infra.types.core.IConfiguredHintedElementType; + +public class ConfiguredHintedMetamodelElementType extends MetamodelType implements IConfiguredHintedElementType { + + private String semanticHint; + + private ElementTypeConfiguration configuration; + + public ConfiguredHintedMetamodelElementType(String id, URL iconURL, String displayName, EClass eClass, IEditHelper editHelper, String semanticHint, MetamodelTypeConfiguration configuration) { + super(id, iconURL, displayName, eClass, editHelper); + this.semanticHint = semanticHint; + this.configuration = configuration; + } + + public String getSemanticHint() { + return semanticHint; + } + + public void setSemanticHint(String semanticHint) { + this.semanticHint = semanticHint; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return "Configured Metamodel Type: " + getDisplayName() + " [" + getId() + "]"; + } + + /** + * @see org.eclipse.papyrus.infra.types.IConfiguredHintedElementType#getConfiguration() + * + * @return + */ + @Override + public ElementTypeConfiguration getConfiguration() { + return configuration; + } +} diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/impl/ConfiguredHintedSpecializationElementType.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/impl/ConfiguredHintedSpecializationElementType.java new file mode 100644 index 00000000000..58d4818e7e9 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/impl/ConfiguredHintedSpecializationElementType.java @@ -0,0 +1,75 @@ +/***************************************************************************** + * Copyright (c) 2014 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.types.core.impl; + +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.types.ElementTypeConfiguration; +import org.eclipse.papyrus.infra.types.SpecializationTypeConfiguration; +import org.eclipse.papyrus.infra.types.core.IConfiguredHintedElementType; + + +public class ConfiguredHintedSpecializationElementType extends SpecializationType implements IConfiguredHintedElementType { + + private String semanticHint; + + private ElementTypeConfiguration configuration; + + /** + * @param id + * @param iconURL + * @param displayName + * @param elementTypes + * @param matcher + * @param descriptor + * @param editHelperAdvice + * @param iElementCreationValidator + */ + public ConfiguredHintedSpecializationElementType(String id, URL iconURL, String displayName, IElementType[] elementTypes, IElementMatcher matcher, IContainerDescriptor containerDescriptor, IEditHelperAdvice editHelperAdvice, String semanticHint, + SpecializationTypeConfiguration configuration) { + super(id, iconURL, displayName, elementTypes, matcher, containerDescriptor, editHelperAdvice); + this.semanticHint = semanticHint; + this.configuration = configuration; + } + + public String getSemanticHint() { + return semanticHint; + } + + public void setSemanticHint(String semanticHint) { + this.semanticHint = semanticHint; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return "Configured Specialization Type: " + getDisplayName() + " [" + getId() + "]"; + } + + /** + * @see org.eclipse.papyrus.infra.types.IConfiguredHintedElementType#getConfiguration() + * + * @return + */ + @Override + public ElementTypeConfiguration getConfiguration() { + return configuration; + } +} diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/impl/NullEditHelperAdvice.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/impl/NullEditHelperAdvice.java new file mode 100644 index 00000000000..944ba6058f1 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/impl/NullEditHelperAdvice.java @@ -0,0 +1,31 @@ +/*****************************************************************************
+ * Copyright (c) 2014 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.types.core.impl;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
+
+public class NullEditHelperAdvice extends AbstractEditHelperAdvice {
+
+ private static NullEditHelperAdvice instance = null;
+
+ private NullEditHelperAdvice() {
+ super();
+ }
+
+ public final static synchronized NullEditHelperAdvice getInstance() {
+ if(instance == null) {
+ instance = new NullEditHelperAdvice();
+ }
+ return instance;
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/AbstractNotifierEditHelper.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/AbstractNotifierEditHelper.java new file mode 100644 index 00000000000..0a030fda643 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/AbstractNotifierEditHelper.java @@ -0,0 +1,258 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.common.core.command.ICompositeCommand;
+import org.eclipse.gmf.runtime.common.core.command.IdentityCommand;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.papyrus.infra.types.core.notification.events.AdviceApprovedEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.AdviceDisapprovedEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.AdvicePhase;
+import org.eclipse.papyrus.infra.types.core.notification.events.AdviceRequestEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.EditHelperApprovedEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.EditHelperDisapprovedEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.EditHelperRequestEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.ExecutableAdviceEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.ExecutableEditHelperEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.IdentityAdviceEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.IdentityEditHelperEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.UnexecutableAdviceEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.UnexecutableEditHelperEvent;
+
+/**
+ * An override of the {@link AbstractEditHelper} to provide Notifications during edithelper execution.
+ * The notifications provide EditHelper trace information for testing and debugging purpose.
+ */
+public abstract class AbstractNotifierEditHelper extends AbstractEditHelper {
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelper#getEditCommand(org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest)
+ *
+ * @param req
+ * @return
+ */
+ @Override
+ public ICommand getEditCommand(IEditCommandRequest req) {
+ TypesEventsChain eventsChain = new TypesEventsChain(this, req);
+ // Get the matching edit helper advice
+ IEditHelperAdvice[] advice = getEditHelperAdvice(req);
+ // Consult advisors to allow them to configure the request
+ configureRequest(req, advice, eventsChain);
+ // Consult advisors to allow them approve the request
+ boolean approved = approveRequest(req, advice, eventsChain);
+ if (!approved) {
+ // Notify listeners
+ if (Platform.inDebugMode()) {
+ TypesListenersRegistry.getInstance().notifyChain(eventsChain);
+ }
+ return null;
+ }
+ ICommand result = getEditCommand(req, advice, eventsChain);
+ if (result != null) {
+ // Notify listeners
+ if (Platform.inDebugMode()) {
+ TypesListenersRegistry.getInstance().notifyChain(eventsChain);
+ }
+ return result.reduce();
+ }
+ // Notify listeners
+ if (Platform.inDebugMode()) {
+ TypesListenersRegistry.getInstance().notifyChain(eventsChain);
+ }
+ return result;
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelper#getEditCommand(IEditCommandRequest, IEditHelperAdvice[])
+ *
+ * @param req
+ * @param advice
+ * @param eventsChain
+ * @return
+ */
+ private ICommand getEditCommand(IEditCommandRequest req, IEditHelperAdvice[] advice, TypesEventsChain eventsChain) {
+ ICompositeCommand command = createCommand(req);
+ // Get 'before' commands from matching element type
+ // specializations
+ if (advice != null) {
+ for (int i = 0; i < advice.length; i++) {
+ IEditHelperAdvice nextAdvice = advice[i];
+ // Before commands
+ ICommand beforeAdvice = nextAdvice.getBeforeEditCommand(req);
+ if (beforeAdvice != null) {
+ if (beforeAdvice.canExecute()) {
+ if (Platform.inDebugMode()) {
+ if (beforeAdvice.equals(IdentityCommand.INSTANCE)) {
+ IdentityAdviceEvent event = new IdentityAdviceEvent(req, this, nextAdvice, advice, AdvicePhase.before);
+ eventsChain.addBeforeAdvicesCommandsEvent(event);
+ TypesListenersRegistry.getInstance().notifyEvent(event);
+ } else {
+ ExecutableAdviceEvent event = new ExecutableAdviceEvent(req, this, nextAdvice, beforeAdvice, advice, AdvicePhase.before);
+ eventsChain.addBeforeAdvicesCommandsEvent(event);
+ TypesListenersRegistry.getInstance().notifyEvent(event);
+ }
+ }
+ command.compose(beforeAdvice);
+ } else {
+ if (Platform.inDebugMode()) {
+ UnexecutableAdviceEvent event = new UnexecutableAdviceEvent(req, this, nextAdvice, beforeAdvice, advice, AdvicePhase.before);
+ eventsChain.addBeforeAdvicesCommandsEvent(event);
+ TypesListenersRegistry.getInstance().notifyEvent(event);
+ }
+ return beforeAdvice;
+ }
+ }
+ }
+ }
+ // Check if the parameter has been set to ignore the default edit command.
+ Object replaceParam = req.getParameter(IEditCommandRequest.REPLACE_DEFAULT_COMMAND);
+ if (replaceParam != Boolean.TRUE) {
+ // Get 'instead' command from this edit helper
+ ICommand insteadCommand = getInsteadCommand(req);
+ if (insteadCommand != null) {
+ if (insteadCommand.canExecute()) {
+ if (Platform.inDebugMode()) {
+ if (insteadCommand.equals(IdentityCommand.INSTANCE)) {
+ IdentityEditHelperEvent event = new IdentityEditHelperEvent(req, this);
+ eventsChain.setEditHelperCommandEvent(event);
+ TypesListenersRegistry.getInstance().notifyEvent(event);
+ } else {
+ ExecutableEditHelperEvent event = new ExecutableEditHelperEvent(req, this, insteadCommand);
+ eventsChain.setEditHelperCommandEvent(event);
+ TypesListenersRegistry.getInstance().notifyEvent(event);
+ }
+ }
+ command.compose(insteadCommand);
+ } else {
+ if (Platform.inDebugMode()) {
+ UnexecutableEditHelperEvent event = new UnexecutableEditHelperEvent(req, this, insteadCommand);
+ eventsChain.setEditHelperCommandEvent(event);
+ TypesListenersRegistry.getInstance().notifyEvent(event);
+ }
+ return insteadCommand;
+ }
+ }
+ }
+ // Get 'after' commands from matching element type
+ // specializations
+ if (advice != null) {
+ for (int i = 0; i < advice.length; i++) {
+ IEditHelperAdvice nextAdvice = advice[i];
+ // After commands
+ ICommand afterAdvice = nextAdvice.getAfterEditCommand(req);
+ if (afterAdvice != null) {
+ if (afterAdvice.canExecute()) {
+ if (Platform.inDebugMode()) {
+ if (afterAdvice.equals(IdentityCommand.INSTANCE)) {
+ IdentityAdviceEvent event = new IdentityAdviceEvent(req, this, nextAdvice, advice, AdvicePhase.after);
+ eventsChain.addBeforeAdvicesCommandsEvent(event);
+ TypesListenersRegistry.getInstance().notifyEvent(event);
+ } else {
+ ExecutableAdviceEvent event = new ExecutableAdviceEvent(req, this, nextAdvice, afterAdvice, advice, AdvicePhase.after);
+ eventsChain.addBeforeAdvicesCommandsEvent(event);
+ TypesListenersRegistry.getInstance().notifyEvent(event);
+ }
+ }
+ command.compose(afterAdvice);
+ } else {
+ if (Platform.inDebugMode()) {
+ UnexecutableAdviceEvent event = new UnexecutableAdviceEvent(req, this, nextAdvice, afterAdvice, advice, AdvicePhase.after);
+ eventsChain.addBeforeAdvicesCommandsEvent(event);
+ TypesListenersRegistry.getInstance().notifyEvent(event);
+ }
+ return afterAdvice;
+ }
+ }
+ }
+ }
+ return command.isEmpty() ? null : command;
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelper#configureRequest(IEditCommandRequest, IEditHelperAdvice[])
+ *
+ * @param req
+ * @param advice
+ * @param eventsChain
+ */
+ private void configureRequest(IEditCommandRequest req, IEditHelperAdvice[] advice, TypesEventsChain eventsChain) {
+ if (advice != null) {
+ for (int i = 0; i < advice.length; i++) {
+ IEditHelperAdvice nextAdvice = advice[i];
+ nextAdvice.configureRequest(req);
+ if (Platform.inDebugMode()) {
+ AdviceRequestEvent event = new AdviceRequestEvent(req, this, nextAdvice, advice);
+ eventsChain.addAdviceRequestConfigurationEvent(event);
+ TypesListenersRegistry.getInstance().notifyEvent(event);
+ }
+ }
+ }
+ // All advice has configured the request. Now consult this edit helper.
+ configureRequest(req);
+ if (Platform.inDebugMode()) {
+ EditHelperRequestEvent event = new EditHelperRequestEvent(req, this);
+ eventsChain.setEditHelperRequestConfigurationEvent(event);
+ TypesListenersRegistry.getInstance().notifyEvent(event);
+ }
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelper#approveRequest(IEditCommandRequest, IEditHelperAdvice[])
+ *
+ * @param req
+ * @param advice
+ * @param eventsChain
+ * @return
+ */
+ private boolean approveRequest(IEditCommandRequest req, IEditHelperAdvice[] advice, TypesEventsChain eventsChain) {
+ if (advice != null) {
+ for (int i = 0; i < advice.length; i++) {
+ IEditHelperAdvice nextAdvice = advice[i];
+ boolean approved = nextAdvice.approveRequest(req);
+ if (!approved) {
+ if (Platform.inDebugMode()) {
+ AdviceDisapprovedEvent event = new AdviceDisapprovedEvent(req, this, nextAdvice, advice);
+ eventsChain.addAdviceApprovalEvent(event);
+ TypesListenersRegistry.getInstance().notifyEvent(event);
+ }
+ return false;
+ } else {
+ if (Platform.inDebugMode()) {
+ AdviceApprovedEvent event = new AdviceApprovedEvent(req, this, nextAdvice, advice);
+ eventsChain.addAdviceApprovalEvent(event);
+ TypesListenersRegistry.getInstance().notifyEvent(event);
+ }
+ }
+ }
+ }
+ // All advice has approved the request. Now consult this edit helper.
+ boolean approved = approveRequest(req);
+ if (Platform.inDebugMode()) {
+ if (!approved) {
+ EditHelperDisapprovedEvent event = new EditHelperDisapprovedEvent(req, this);
+ eventsChain.setEditHelperApprovalEvent(event);
+ TypesListenersRegistry.getInstance().notifyEvent(event);
+ } else {
+ EditHelperApprovedEvent event = new EditHelperApprovedEvent(req, this);
+ eventsChain.setEditHelperApprovalEvent(event);
+ TypesListenersRegistry.getInstance().notifyEvent(event);
+ }
+ }
+ return approved;
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/ITypesEventsChainListener.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/ITypesEventsChainListener.java new file mode 100644 index 00000000000..a149575e756 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/ITypesEventsChainListener.java @@ -0,0 +1,21 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification;
+
+/**
+ * Interface to implemented by listeners that want to be notified of {@link TypesEventsChain}
+ */
+public interface ITypesEventsChainListener {
+
+ public void notifyChain(TypesEventsChain chain);
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/ITypesEventsListener.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/ITypesEventsListener.java new file mode 100644 index 00000000000..5dbbb5ab15b --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/ITypesEventsListener.java @@ -0,0 +1,20 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification;
+
+import org.eclipse.papyrus.infra.types.core.notification.events.ITypesEvent;
+
+public interface ITypesEventsListener {
+
+ public void notifyEvent(ITypesEvent event);
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/TypesEventsChain.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/TypesEventsChain.java new file mode 100644 index 00000000000..1743aa3632d --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/TypesEventsChain.java @@ -0,0 +1,245 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.papyrus.infra.types.core.notification.events.AbstractTypesEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.AdviceApprovedEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.AdviceDisapprovedEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.AdviceRequestEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.EditHelperApprovedEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.EditHelperDisapprovedEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.ExecutableAdviceEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.ExecutableEditHelperEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.IdentityAdviceEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.IdentityEditHelperEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.UnexecutableAdviceEvent;
+import org.eclipse.papyrus.infra.types.core.notification.events.UnexecutableEditHelperEvent;
+
+public class TypesEventsChain {
+
+ /**
+ * Timestamp of the creation of the chain
+ */
+ private long timestamp;
+
+ /**
+ * The {@link IEditHelper} that triggered the {@link TypesEventsChain}
+ */
+ private IEditHelper editHelper;
+
+ /**
+ * The {@link IEditCommandRequest} that triggered the {@link TypesEventsChain}
+ */
+ private IEditCommandRequest req;
+
+ TypesEventsChain(IEditHelper editHelper, IEditCommandRequest req) {
+ timestamp = System.currentTimeMillis();
+ this.editHelper = editHelper;
+ this.req = req;
+ }
+
+ /**
+ * The various categories of events that occur during the execution of the {@link IEditHelper}
+ */
+ private List<AbstractTypesEvent> adviceRequestConfigurationEvents = new ArrayList<AbstractTypesEvent>();
+
+ private AbstractTypesEvent editHelperRequestConfigurationEvent = null;
+
+ private List<AbstractTypesEvent> adviceApprovalEvents = new ArrayList<AbstractTypesEvent>();
+
+ private AbstractTypesEvent editHelperApprovalEvent = null;
+
+ private List<AbstractTypesEvent> beforeAdvicesCommandsEvents = new ArrayList<AbstractTypesEvent>();
+
+ private List<AbstractTypesEvent> afterAdvicesCommandsEvents = new ArrayList<AbstractTypesEvent>();
+
+ private AbstractTypesEvent editHelperCommandEvent = null;
+
+ /**
+ * @return the adviceApprovalEvents
+ */
+ public List<AbstractTypesEvent> getAdviceApprovalEvents() {
+ return adviceApprovalEvents;
+ }
+
+ /**
+ * Add a {@link AdviceDisapprovedEvent} or {@link AdviceApprovedEvent} event
+ *
+ * @param adviceApprovalEvent
+ */
+ public void addAdviceApprovalEvent(AbstractTypesEvent adviceApprovalEvent) {
+ if (adviceApprovalEvent instanceof AdviceDisapprovedEvent || adviceApprovalEvent instanceof AdviceApprovedEvent) {
+ adviceApprovalEvents.add(adviceApprovalEvent);
+ }
+ }
+
+ /**
+ * @return the editHelperAprrovalEvent
+ */
+ public AbstractTypesEvent getEditHelperApprovalEvent() {
+ return editHelperApprovalEvent;
+ }
+
+ /**
+ * @param editHelperAprrovalEvent
+ * the editHelperAprrovalEvent to set
+ */
+ public void setEditHelperApprovalEvent(AbstractTypesEvent editHelperApprovalEvent) {
+ if (editHelperApprovalEvent instanceof EditHelperDisapprovedEvent || editHelperApprovalEvent instanceof EditHelperApprovedEvent) {
+ this.editHelperApprovalEvent = editHelperApprovalEvent;
+ }
+ }
+
+ /**
+ * @return the beforeAdvicesCommandsEvents
+ */
+ public List<AbstractTypesEvent> getBeforeAdvicesCommandsEvents() {
+ return beforeAdvicesCommandsEvents;
+ }
+
+ /**
+ * Add a {@link ExecutableAdviceEvent}, {@link UnexecutableAdviceEvent} or {@link IdentityAdviceEvent} event
+ *
+ * @param beforeAdvicesCommandsEvents
+ * the beforeAdvicesCommandsEvents to set
+ */
+ public void addBeforeAdvicesCommandsEvent(AbstractTypesEvent beforeAdvicesCommandEvent) {
+ if (beforeAdvicesCommandEvent instanceof ExecutableAdviceEvent || beforeAdvicesCommandEvent instanceof UnexecutableAdviceEvent || beforeAdvicesCommandEvent instanceof IdentityAdviceEvent) {
+ beforeAdvicesCommandsEvents.add(beforeAdvicesCommandEvent);
+ }
+ }
+
+ /**
+ * @return the afterAdvicesCommandsEvents
+ */
+ public List<AbstractTypesEvent> getAfterAdvicesCommandsEvents() {
+ return afterAdvicesCommandsEvents;
+ }
+
+ /**
+ * Add a {@link ExecutableAdviceEvent}, {@link UnexecutableAdviceEvent} or {@link IdentityAdviceEvent} event
+ *
+ * @param afterAdvicesCommandEvent
+ */
+ public void addAfterAdvicesCommandsEvent(AbstractTypesEvent afterAdvicesCommandEvent) {
+ if (afterAdvicesCommandEvent instanceof ExecutableAdviceEvent || afterAdvicesCommandEvent instanceof UnexecutableAdviceEvent || afterAdvicesCommandEvent instanceof IdentityAdviceEvent) {
+ afterAdvicesCommandsEvents.add(afterAdvicesCommandEvent);
+ }
+ }
+
+ /**
+ * @return the editHelperCommandEvent
+ */
+ public AbstractTypesEvent getEditHelperCommandEvent() {
+ return editHelperCommandEvent;
+ }
+
+ /**
+ * @param editHelperCommandEvent
+ * the editHelperCommandEvent to set ({@link ExecutableEditHelperEvent}, {@link UnexecutableEditHelperEvent} or
+ * {@link IdentityEditHelperEvent})
+ */
+ public void setEditHelperCommandEvent(AbstractTypesEvent editHelperCommandEvent) {
+ if (editHelperCommandEvent instanceof ExecutableEditHelperEvent || editHelperCommandEvent instanceof UnexecutableEditHelperEvent || editHelperCommandEvent instanceof IdentityEditHelperEvent) {
+ this.editHelperCommandEvent = editHelperCommandEvent;
+ }
+ }
+
+ /**
+ * Returns all the events that occurred during the execution of the {@link IEditHelper} (i.e. all events categories)
+ *
+ * @return
+ */
+ public List<AbstractTypesEvent> getAllEvents() {
+ List<AbstractTypesEvent> result = new ArrayList<AbstractTypesEvent>();
+ if (!adviceRequestConfigurationEvents.isEmpty()) {
+ result.addAll(adviceRequestConfigurationEvents);
+ }
+ if (editHelperRequestConfigurationEvent != null) {
+ result.add(editHelperRequestConfigurationEvent);
+ }
+ if (!adviceApprovalEvents.isEmpty()) {
+ result.addAll(adviceApprovalEvents);
+ }
+ if (editHelperApprovalEvent != null) {
+ result.add(editHelperApprovalEvent);
+ }
+ if (!beforeAdvicesCommandsEvents.isEmpty()) {
+ result.addAll(beforeAdvicesCommandsEvents);
+ }
+ if (editHelperCommandEvent != null) {
+ result.add(editHelperCommandEvent);
+ }
+ if (!afterAdvicesCommandsEvents.isEmpty()) {
+ result.addAll(afterAdvicesCommandsEvents);
+ }
+ return result;
+ }
+
+ /**
+ * @return the timestamp creation of this {@link TypesEventsChain}
+ */
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+ /**
+ * @return the req
+ */
+ public IEditCommandRequest getRequest() {
+ return req;
+ }
+
+ /**
+ * The Simple Name of the class of the {@link IEditHelper} that triggered this {@link TypesEventsChain}
+ *
+ * @return
+ */
+ public String getName() {
+ return editHelper.getClass().getSimpleName();
+ }
+
+ /**
+ * @return the adviceRequestConfigurationEvents
+ */
+ public List<AbstractTypesEvent> getAdviceRequestConfigurationEvents() {
+ return adviceRequestConfigurationEvents;
+ }
+
+ /**
+ * @param adviceConfigureEvent
+ */
+ public void addAdviceRequestConfigurationEvent(AdviceRequestEvent adviceConfigureEvent) {
+ adviceRequestConfigurationEvents.add(adviceConfigureEvent);
+ }
+
+ /**
+ * @return the editHelperRequestConfigurationEvent
+ */
+ public AbstractTypesEvent getEditHelperRequestConfigurationEvent() {
+ return editHelperRequestConfigurationEvent;
+ }
+
+ /**
+ * @param editHelperRequestConfigurationEvent
+ * the editHelperRequestConfigurationEvent to set
+ */
+ public void setEditHelperRequestConfigurationEvent(AbstractTypesEvent editHelperRequestConfigurationEvent) {
+ this.editHelperRequestConfigurationEvent = editHelperRequestConfigurationEvent;
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/TypesListenersRegistry.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/TypesListenersRegistry.java new file mode 100644 index 00000000000..e27face6403 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/TypesListenersRegistry.java @@ -0,0 +1,74 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.papyrus.infra.types.core.notification.events.ITypesEvent;
+
+/**
+ * Singleton used to register eventsChains listeners ({@link ITypesEventsChainListener})
+ */
+public class TypesListenersRegistry {
+
+ private static Set<ITypesEventsChainListener> eventChainListeners = null;
+
+ private static Set<ITypesEventsListener> eventListeners = null;
+
+ private static TypesListenersRegistry instance = null;
+
+ private TypesListenersRegistry() {
+ }
+
+ public static synchronized TypesListenersRegistry getInstance() {
+ if (instance == null) {
+ instance = new TypesListenersRegistry();
+ init();
+ }
+ return instance;
+ }
+
+ public static void init() {
+ eventChainListeners = new HashSet<ITypesEventsChainListener>();
+ eventListeners = new HashSet<ITypesEventsListener>();
+ }
+
+ public void addEventChainListener(ITypesEventsChainListener listener) {
+ eventChainListeners.add(listener);
+ }
+
+ public void removeEventChainListener(ITypesEventsChainListener listener) {
+ eventChainListeners.remove(listener);
+ }
+
+ public void addEventListener(ITypesEventsListener listener) {
+ eventListeners.add(listener);
+ }
+
+ public void removeEventChainListener(ITypesEventsListener listener) {
+ eventListeners.remove(listener);
+ }
+
+ public void notifyChain(TypesEventsChain chain) {
+ for (ITypesEventsChainListener eventsChainListener : eventChainListeners) {
+ eventsChainListener.notifyChain(chain);
+ }
+ }
+
+ public void notifyEvent(ITypesEvent event) {
+ for (ITypesEventsListener eventsListener : eventListeners) {
+ eventsListener.notifyEvent(event);
+ }
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractApprovedEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractApprovedEvent.java new file mode 100644 index 00000000000..c651ef40cad --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractApprovedEvent.java @@ -0,0 +1,34 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public abstract class AbstractApprovedEvent extends AbstractTypesEvent {
+
+ public AbstractApprovedEvent(IEditCommandRequest req, IEditHelper editHelper) {
+ super(req, editHelper);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.types.core.notification.events.ITypesEvent#getEventType()
+ *
+ * @return
+ */
+ @Override
+ public TypesEventKind getEventType() {
+ return TypesEventKind.Approved;
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractDisapprovedEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractDisapprovedEvent.java new file mode 100644 index 00000000000..a535db4dcd4 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractDisapprovedEvent.java @@ -0,0 +1,34 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public abstract class AbstractDisapprovedEvent extends AbstractTypesEvent {
+
+ public AbstractDisapprovedEvent(IEditCommandRequest req, IEditHelper editHelper) {
+ super(req, editHelper);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.types.core.notification.events.ITypesEvent#getEventType()
+ *
+ * @return
+ */
+ @Override
+ public TypesEventKind getEventType() {
+ return TypesEventKind.Disapproved;
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractExecutableEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractExecutableEvent.java new file mode 100644 index 00000000000..a1b2fb6fd8d --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractExecutableEvent.java @@ -0,0 +1,46 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public abstract class AbstractExecutableEvent extends AbstractTypesEvent {
+
+ private ICommand command;
+
+
+ public AbstractExecutableEvent(IEditCommandRequest req, IEditHelper editHelper, ICommand command) {
+ super(req, editHelper);
+ this.command = command;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.types.core.notification.events.ITypesEvent#getEventType()
+ *
+ * @return
+ */
+ @Override
+ public TypesEventKind getEventType() {
+ return TypesEventKind.Executable;
+ }
+
+ /**
+ * @return the command
+ */
+ public ICommand getCommand() {
+ return command;
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractIdentityEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractIdentityEvent.java new file mode 100644 index 00000000000..2042399d0bc --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractIdentityEvent.java @@ -0,0 +1,34 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public abstract class AbstractIdentityEvent extends AbstractTypesEvent {
+
+ public AbstractIdentityEvent(IEditCommandRequest req, IEditHelper editHelper) {
+ super(req, editHelper);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.types.core.notification.events.ITypesEvent#getEventType()
+ *
+ * @return
+ */
+ @Override
+ public TypesEventKind getEventType() {
+ return TypesEventKind.Identity;
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractRequestEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractRequestEvent.java new file mode 100644 index 00000000000..4f3ef2055b3 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractRequestEvent.java @@ -0,0 +1,34 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public abstract class AbstractRequestEvent extends AbstractTypesEvent {
+
+ public AbstractRequestEvent(IEditCommandRequest req, IEditHelper editHelper) {
+ super(req, editHelper);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.types.core.notification.events.ITypesEvent#getEventType()
+ *
+ * @return
+ */
+ @Override
+ public TypesEventKind getEventType() {
+ return TypesEventKind.RequestConfiguration;
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractTypesEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractTypesEvent.java new file mode 100644 index 00000000000..89d2bcc28e5 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractTypesEvent.java @@ -0,0 +1,77 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public abstract class AbstractTypesEvent implements ITypesEvent {
+
+ /**
+ * Timestamp of the creation of this event
+ */
+ private long timestamp;
+
+ /**
+ * The {@link IEditCommandRequest} that triggered this {@link ITypesEvent}
+ */
+ private IEditCommandRequest request;
+
+ private IEditHelper editHelper;
+
+ public AbstractTypesEvent(IEditCommandRequest req, IEditHelper editHelper) {
+ this();
+ this.request = req;
+ this.editHelper = editHelper;
+ }
+
+ /**
+ * @return the {@link IEditCommandRequest} that triggered the event
+ */
+ public IEditCommandRequest getRequest() {
+ return request;
+ }
+
+ /**
+ * @return the {@link IEditHelper} that triggered the event
+ */
+ public IEditHelper getEditHelper() {
+ return editHelper;
+ }
+
+ AbstractTypesEvent() {
+ timestamp = System.currentTimeMillis();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.types.core.notification.events.ITypesEvent#getTimestamp()
+ *
+ * @return
+ */
+ @Override
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.types.core.notification.events.ITypesEvent#getEventName()
+ *
+ * @return
+ */
+ @Override
+ public String getEventName() {
+ return this.getClass().getSimpleName();
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractUnexecutableEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractUnexecutableEvent.java new file mode 100644 index 00000000000..b80125a14db --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AbstractUnexecutableEvent.java @@ -0,0 +1,48 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public abstract class AbstractUnexecutableEvent extends AbstractTypesEvent {
+
+ public AbstractUnexecutableEvent(IEditCommandRequest req, IEditHelper editHelper, ICommand command) {
+ super(req, editHelper);
+ this.command = command;
+ }
+
+ /**
+ * @return the command
+ */
+ public ICommand getCommand() {
+ return command;
+ }
+
+ private ICommand command;
+
+
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.types.core.notification.events.ITypesEvent#getEventType()
+ *
+ * @return
+ */
+ @Override
+ public TypesEventKind getEventType() {
+ return TypesEventKind.Unexecutable;
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AdviceApprovedEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AdviceApprovedEvent.java new file mode 100644 index 00000000000..031a6c45e21 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AdviceApprovedEvent.java @@ -0,0 +1,46 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public class AdviceApprovedEvent extends AbstractApprovedEvent implements IAdviceEvent {
+
+ private IEditHelperAdvice advice;
+
+ private IEditHelperAdvice[] advices;
+
+ public AdviceApprovedEvent(IEditCommandRequest req, IEditHelper editHelper, IEditHelperAdvice nextAdvice, IEditHelperAdvice[] advices) {
+ super(req, editHelper);
+ this.advice = nextAdvice;
+ this.advices = advices;
+ }
+
+ /**
+ * @return the advice
+ */
+ @Override
+ public IEditHelperAdvice getAdvice() {
+ return advice;
+ }
+
+ /**
+ * @return the advices
+ */
+ @Override
+ public IEditHelperAdvice[] getAdvices() {
+ return advices;
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AdviceDisapprovedEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AdviceDisapprovedEvent.java new file mode 100644 index 00000000000..6dc87187828 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AdviceDisapprovedEvent.java @@ -0,0 +1,46 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public class AdviceDisapprovedEvent extends AbstractDisapprovedEvent implements IAdviceEvent {
+
+ private IEditHelperAdvice advice;
+
+ IEditHelperAdvice[] advices;
+
+ /**
+ * @return the advice
+ */
+ @Override
+ public IEditHelperAdvice getAdvice() {
+ return advice;
+ }
+
+ /**
+ * @return the advices
+ */
+ @Override
+ public IEditHelperAdvice[] getAdvices() {
+ return advices;
+ }
+
+ public AdviceDisapprovedEvent(IEditCommandRequest req, IEditHelper editHelper, IEditHelperAdvice nextAdvice, IEditHelperAdvice[] advices) {
+ super(req, editHelper);
+ this.advice = nextAdvice;
+ this.advices = advices;
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AdvicePhase.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AdvicePhase.java new file mode 100644 index 00000000000..cee10473d8a --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AdvicePhase.java @@ -0,0 +1,17 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+public enum AdvicePhase {
+ before, after
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AdviceRequestEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AdviceRequestEvent.java new file mode 100644 index 00000000000..f83e1ebcd36 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/AdviceRequestEvent.java @@ -0,0 +1,50 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public class AdviceRequestEvent extends AbstractRequestEvent implements IAdviceEvent {
+
+ private IEditHelperAdvice advice;
+
+ private IEditHelperAdvice[] advices;
+
+ public AdviceRequestEvent(IEditCommandRequest req, IEditHelper editHelper, IEditHelperAdvice advice, IEditHelperAdvice[] advices) {
+ super(req, editHelper);
+ this.advice = advice;
+ this.advices = advices;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.types.notification.events.IAdviceEvent#getAdvice()
+ *
+ * @return
+ */
+ @Override
+ public IEditHelperAdvice getAdvice() {
+ return advice;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.types.notification.events.IAdviceEvent#getAdvices()
+ *
+ * @return
+ */
+ @Override
+ public IEditHelperAdvice[] getAdvices() {
+ return advices;
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/EditHelperApprovedEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/EditHelperApprovedEvent.java new file mode 100644 index 00000000000..de929f2a089 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/EditHelperApprovedEvent.java @@ -0,0 +1,23 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public class EditHelperApprovedEvent extends AbstractApprovedEvent {
+
+ public EditHelperApprovedEvent(IEditCommandRequest req, IEditHelper editHelper) {
+ super(req, editHelper);
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/EditHelperDisapprovedEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/EditHelperDisapprovedEvent.java new file mode 100644 index 00000000000..3f736c2b299 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/EditHelperDisapprovedEvent.java @@ -0,0 +1,23 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public class EditHelperDisapprovedEvent extends AbstractDisapprovedEvent {
+
+ public EditHelperDisapprovedEvent(IEditCommandRequest req, IEditHelper editHelper) {
+ super(req, editHelper);
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/EditHelperRequestEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/EditHelperRequestEvent.java new file mode 100644 index 00000000000..2ab1cd9a095 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/EditHelperRequestEvent.java @@ -0,0 +1,23 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public class EditHelperRequestEvent extends AbstractRequestEvent {
+
+ public EditHelperRequestEvent(IEditCommandRequest req, IEditHelper editHelper) {
+ super(req, editHelper);
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/ExecutableAdviceEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/ExecutableAdviceEvent.java new file mode 100644 index 00000000000..e36c736393f --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/ExecutableAdviceEvent.java @@ -0,0 +1,57 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public class ExecutableAdviceEvent extends AbstractExecutableEvent implements IAdviceEvent {
+
+ private IEditHelperAdvice advice;
+
+ private IEditHelperAdvice[] advices;
+
+ private AdvicePhase advicePhase;
+
+ public ExecutableAdviceEvent(IEditCommandRequest req, IEditHelper editHelper, IEditHelperAdvice advice, ICommand command, IEditHelperAdvice[] advices, AdvicePhase advicePhase) {
+ super(req, editHelper, command);
+ this.advice = advice;
+ this.advices = advices;
+ this.advicePhase = advicePhase;
+ }
+
+ /**
+ * @return the advice
+ */
+ @Override
+ public IEditHelperAdvice getAdvice() {
+ return advice;
+ }
+
+ /**
+ * @return the advices
+ */
+ @Override
+ public IEditHelperAdvice[] getAdvices() {
+ return advices;
+ }
+
+ /**
+ * @return the advicePhase
+ */
+ public AdvicePhase getAdvicePhase() {
+ return advicePhase;
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/ExecutableEditHelperEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/ExecutableEditHelperEvent.java new file mode 100644 index 00000000000..28736d0503d --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/ExecutableEditHelperEvent.java @@ -0,0 +1,24 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public class ExecutableEditHelperEvent extends AbstractExecutableEvent {
+
+ public ExecutableEditHelperEvent(IEditCommandRequest req, IEditHelper editHelper, ICommand command) {
+ super(req, editHelper, command);
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/IAdviceEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/IAdviceEvent.java new file mode 100644 index 00000000000..e4c1c07caec --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/IAdviceEvent.java @@ -0,0 +1,28 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+
+public interface IAdviceEvent extends ITypesEvent {
+
+ /**
+ * @return the advice
+ */
+ public IEditHelperAdvice getAdvice();
+
+ /**
+ * @return the advices
+ */
+ public IEditHelperAdvice[] getAdvices();
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/ITypesEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/ITypesEvent.java new file mode 100644 index 00000000000..b72c243279d --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/ITypesEvent.java @@ -0,0 +1,29 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public interface ITypesEvent {
+
+ public long getTimestamp();
+
+ public String getEventName();
+
+ public TypesEventKind getEventType();
+
+ public IEditCommandRequest getRequest();
+
+ public IEditHelper getEditHelper();
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/IdentityAdviceEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/IdentityAdviceEvent.java new file mode 100644 index 00000000000..ceaebb3abb7 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/IdentityAdviceEvent.java @@ -0,0 +1,56 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public class IdentityAdviceEvent extends AbstractIdentityEvent implements IAdviceEvent {
+
+ private IEditHelperAdvice advice;
+
+ private IEditHelperAdvice[] advices;
+
+ private AdvicePhase advicePhase;
+
+ public IdentityAdviceEvent(IEditCommandRequest req, IEditHelper editHelper, IEditHelperAdvice advice, IEditHelperAdvice[] advices, AdvicePhase advicePhase) {
+ super(req, editHelper);
+ this.advice = advice;
+ this.advices = advices;
+ this.advicePhase = advicePhase;
+ }
+
+ /**
+ * @return the advice
+ */
+ @Override
+ public IEditHelperAdvice getAdvice() {
+ return advice;
+ }
+
+ /**
+ * @return the advices
+ */
+ @Override
+ public IEditHelperAdvice[] getAdvices() {
+ return advices;
+ }
+
+ /**
+ * @return the advicePhase
+ */
+ public AdvicePhase getAdvicePhase() {
+ return advicePhase;
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/IdentityEditHelperEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/IdentityEditHelperEvent.java new file mode 100644 index 00000000000..cef227624ba --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/IdentityEditHelperEvent.java @@ -0,0 +1,24 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public class IdentityEditHelperEvent extends AbstractIdentityEvent {
+
+
+ public IdentityEditHelperEvent(IEditCommandRequest req, IEditHelper editHelper) {
+ super(req, editHelper);
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/TypesEventKind.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/TypesEventKind.java new file mode 100644 index 00000000000..1333067dd5b --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/TypesEventKind.java @@ -0,0 +1,17 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+public enum TypesEventKind {
+ Disapproved, Unexecutable, Approved, Executable, Identity, RequestConfiguration
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/UnexecutableAdviceEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/UnexecutableAdviceEvent.java new file mode 100644 index 00000000000..155f1415426 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/UnexecutableAdviceEvent.java @@ -0,0 +1,57 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public class UnexecutableAdviceEvent extends AbstractUnexecutableEvent implements IAdviceEvent {
+
+ private IEditHelperAdvice advice;
+
+ private IEditHelperAdvice[] advices;
+
+ private AdvicePhase advicePhase;
+
+ public UnexecutableAdviceEvent(IEditCommandRequest req, IEditHelper editHelper, IEditHelperAdvice advice, ICommand command, IEditHelperAdvice[] advices, AdvicePhase advicePhase) {
+ super(req, editHelper, command);
+ this.advice = advice;
+ this.advices = advices;
+ this.advicePhase = advicePhase;
+ }
+
+ /**
+ * @return the advice
+ */
+ @Override
+ public IEditHelperAdvice getAdvice() {
+ return advice;
+ }
+
+ /**
+ * @return the advices
+ */
+ @Override
+ public IEditHelperAdvice[] getAdvices() {
+ return advices;
+ }
+
+ /**
+ * @return the advicePhase
+ */
+ public AdvicePhase getAdvicePhase() {
+ return advicePhase;
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/UnexecutableEditHelperEvent.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/UnexecutableEditHelperEvent.java new file mode 100644 index 00000000000..05448d6b297 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/notification/events/UnexecutableEditHelperEvent.java @@ -0,0 +1,24 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.notification.events;
+
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public class UnexecutableEditHelperEvent extends AbstractUnexecutableEvent {
+
+ public UnexecutableEditHelperEvent(IEditCommandRequest req, IEditHelper editHelper, ICommand command) {
+ super(req, editHelper, command);
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/registries/AdviceConfigurationTypeRegistry.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/registries/AdviceConfigurationTypeRegistry.java new file mode 100644 index 00000000000..35bd5225e06 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/registries/AdviceConfigurationTypeRegistry.java @@ -0,0 +1,133 @@ +/***************************************************************************** + * Copyright (c) 2014, 2015 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 459174 + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.types.core.registries; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.Platform; +import org.eclipse.emf.common.notify.impl.AdapterImpl; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.gmf.runtime.emf.type.core.IAdviceBindingDescriptor; +import org.eclipse.papyrus.infra.types.AdviceConfiguration; +import org.eclipse.papyrus.infra.types.ElementTypesConfigurationsPackage; +import org.eclipse.papyrus.infra.types.core.Activator; +import org.eclipse.papyrus.infra.types.core.IConfiguredEditHelperAdviceDescriptor; +import org.eclipse.papyrus.infra.types.core.extensionpoints.IAdviceKindExtensionPoint; +import org.eclipse.papyrus.infra.types.core.factories.IEditHelperAdviceFactory; +import org.eclipse.papyrus.infra.types.core.factories.impl.DefaultAdviceBindingFactory; +import org.eclipse.papyrus.infra.types.core.factories.impl.DefaultEditHelperAdviceFactory; + +public class AdviceConfigurationTypeRegistry { + + private static AdviceConfigurationTypeRegistry registry; + + protected Map<String, IEditHelperAdviceFactory<? extends AdviceConfiguration>> adviceConfigurationTypeToFactory = null; + + /** + * returns the singleton instance of this registry + * + * @return the singleton instance of this registry + */ + public static synchronized AdviceConfigurationTypeRegistry getInstance() { + if (registry == null) { + registry = new AdviceConfigurationTypeRegistry(); + registry.init(); + } + return registry; + } + + /** + * Inits the registry. + */ + protected void init() { + adviceConfigurationTypeToFactory = new HashMap<String, IEditHelperAdviceFactory<? extends AdviceConfiguration>>(); + IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(IAdviceKindExtensionPoint.EXTENSION_POINT_ID); + for (IConfigurationElement configurationElement : elements) { + String configurationClass = configurationElement.getAttribute(IAdviceKindExtensionPoint.CONFIGURATION_CLASS); + try { + Object factoryClass = configurationElement.createExecutableExtension(IAdviceKindExtensionPoint.FACTORY_CLASS); + if (factoryClass instanceof IEditHelperAdviceFactory) { + adviceConfigurationTypeToFactory.put(configurationClass, (IEditHelperAdviceFactory<?>) factoryClass); + } + } catch (CoreException e) { + Activator.log.error(e); + } + } + // Register default interpretations + adviceConfigurationTypeToFactory.put(ElementTypesConfigurationsPackage.eINSTANCE.getEditHelperAdviceConfiguration().getInstanceTypeName(), new DefaultEditHelperAdviceFactory()); + adviceConfigurationTypeToFactory.put(ElementTypesConfigurationsPackage.eINSTANCE.getAdviceBindingConfiguration().getInstanceTypeName(), new DefaultAdviceBindingFactory()); + } + + public <T extends AdviceConfiguration> IEditHelperAdviceFactory<T> getFactory(AdviceConfiguration adviceConfiguration) { + String adviceConfigurationType = adviceConfiguration.eClass().getInstanceTypeName(); + // We assume here that the right factory is registered for the right AdviceConfiguration + @SuppressWarnings("unchecked") + IEditHelperAdviceFactory<T> factory = (IEditHelperAdviceFactory<T>) adviceConfigurationTypeToFactory.get(adviceConfigurationType); + + return factory; + } + + public <T extends AdviceConfiguration> IAdviceBindingDescriptor getEditHelperAdviceDecriptor(T adviceConfiguration) { + IAdviceBindingDescriptor result = null; + + if (adviceConfiguration != null) { + AdviceDescriptorAdapter adapter = AdviceDescriptorAdapter.get(adviceConfiguration); + if (adapter == null) { + IEditHelperAdviceFactory<T> factory = getFactory(adviceConfiguration); + if (factory != null) { + IConfiguredEditHelperAdviceDescriptor<T> editHelperAdvice = factory.createEditHelperAdviceDescriptor(adviceConfiguration); + editHelperAdvice.init(adviceConfiguration); + adapter = new AdviceDescriptorAdapter(editHelperAdvice); + adviceConfiguration.eAdapters().add(adapter); + } + } + + if (adapter != null) { + result = adapter.getAdviceDescriptor(); + } + } + + return result; + } + + // + // Nested types + // + + private static class AdviceDescriptorAdapter extends AdapterImpl { + private final IAdviceBindingDescriptor adviceDescriptor; + + AdviceDescriptorAdapter(IAdviceBindingDescriptor adviceDescriptor) { + super(); + + this.adviceDescriptor = adviceDescriptor; + } + + @Override + public boolean isAdapterForType(Object type) { + return type == IAdviceBindingDescriptor.class; + } + + public IAdviceBindingDescriptor getAdviceDescriptor() { + return adviceDescriptor; + } + + static AdviceDescriptorAdapter get(AdviceConfiguration configuration) { + return (AdviceDescriptorAdapter) EcoreUtil.getExistingAdapter(configuration, IAdviceBindingDescriptor.class); + } + } +} diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/registries/ContainerConfigurationTypeRegistry.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/registries/ContainerConfigurationTypeRegistry.java new file mode 100644 index 00000000000..32159cd95e7 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/registries/ContainerConfigurationTypeRegistry.java @@ -0,0 +1,125 @@ +/***************************************************************************** + * Copyright (c) 2014 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.types.core.registries; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.Platform; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.gmf.runtime.emf.type.core.IContainerDescriptor; +import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher; +import org.eclipse.papyrus.infra.types.AbstractMatcherConfiguration; +import org.eclipse.papyrus.infra.types.ContainerConfiguration; +import org.eclipse.papyrus.infra.types.core.Activator; +import org.eclipse.papyrus.infra.types.core.IConfiguredContainerDescriptor; +import org.eclipse.papyrus.infra.types.core.extensionpoints.IContainerConfigurationKindExtensionPoint; +import org.eclipse.papyrus.infra.types.core.factories.IContainerFactory; + +/** + * Registry that manages all possible containerConfiguration + */ +public class ContainerConfigurationTypeRegistry { + + private static ContainerConfigurationTypeRegistry registry; + + protected Map<String, IContainerFactory<? extends ContainerConfiguration>> containerConfigurationTypeToFactory = null; + + /** + * returns the singleton instance of this registry + * + * @return the singleton instance of this registry + */ + public static synchronized ContainerConfigurationTypeRegistry getInstance() { + if (registry == null) { + registry = new ContainerConfigurationTypeRegistry(); + registry.init(); + } + return registry; + } + + /** + * Inits the registry. + */ + protected void init() { + containerConfigurationTypeToFactory = new HashMap<String, IContainerFactory<? extends ContainerConfiguration>>(); + IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(IContainerConfigurationKindExtensionPoint.EXTENSION_POINT_ID); + for (IConfigurationElement configurationElement : elements) { + String configurationClass = configurationElement.getAttribute(IContainerConfigurationKindExtensionPoint.CONFIGURATION_CLASS); + try { + Object factoryClass = configurationElement.createExecutableExtension(IContainerConfigurationKindExtensionPoint.FACTORY_CLASS); + if (factoryClass instanceof IContainerFactory) { + containerConfigurationTypeToFactory.put(configurationClass, (IContainerFactory<?>) factoryClass); + } + } catch (CoreException e) { + Activator.log.error(e); + } + } + } + + protected <T extends ContainerConfiguration> IContainerFactory<T> getFactory(ContainerConfiguration containerConfiguration) { + String containerConfigurationType = containerConfiguration.eClass().getInstanceTypeName(); + // We assume here that the right factory is registered for the right ContainerConfiguration + @SuppressWarnings("unchecked") + IContainerFactory<T> factory = (IContainerFactory<T>) containerConfigurationTypeToFactory.get(containerConfigurationType); + return factory; + } + + public <T extends ContainerConfiguration> IContainerDescriptor getContainerDescriptor(T containerConfiguration) { + if (containerConfiguration == null) { + return null; + } else { + IContainerFactory<T> factory = getFactory(containerConfiguration); + IConfiguredContainerDescriptor<T> containerDescriptor; + if (factory == null) { + // Provide default interpretation + containerDescriptor = new DefaultContainerDescriptor<T>(containerConfiguration); + } else { + containerDescriptor = factory.createContainerDescriptor(containerConfiguration); + } + containerDescriptor.init(containerConfiguration); + return containerDescriptor; + } + } + + public class DefaultContainerDescriptor<T extends ContainerConfiguration> implements IConfiguredContainerDescriptor<T> { + + protected ContainerConfiguration containerConfiguration; + + protected IElementMatcher matcher; + + protected EReference[] references; + + public DefaultContainerDescriptor(ContainerConfiguration containerConfiguration) { + AbstractMatcherConfiguration matcherConfiguration = containerConfiguration.getContainerMatcherConfiguration(); + matcher = MatcherConfigurationTypeRegistry.getInstance().getMatcher(matcherConfiguration); + EList<EReference> eContainmentFeatures = containerConfiguration.getEContainmentFeatures(); + references = eContainmentFeatures.toArray(new EReference[] {}); + } + + public IElementMatcher getMatcher() { + return matcher; + } + + public EReference[] getContainmentFeatures() { + return references; + } + + public void init(ContainerConfiguration containerConfiguration) { + this.containerConfiguration = containerConfiguration; + } + } +} diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/registries/ElementTypeConfigurationTypeRegistry.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/registries/ElementTypeConfigurationTypeRegistry.java new file mode 100644 index 00000000000..b65a2ec732f --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/registries/ElementTypeConfigurationTypeRegistry.java @@ -0,0 +1,95 @@ +/***************************************************************************** + * Copyright (c) 2014 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.types.core.registries; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.Platform; +import org.eclipse.gmf.runtime.emf.type.core.IElementType; +import org.eclipse.gmf.runtime.emf.type.core.IHintedType; +import org.eclipse.papyrus.infra.types.ElementTypeConfiguration; +import org.eclipse.papyrus.infra.types.ElementTypesConfigurationsPackage; +import org.eclipse.papyrus.infra.types.core.Activator; +import org.eclipse.papyrus.infra.types.core.extensionpoints.IElementTypeConfigurationKindExtensionPoint; +import org.eclipse.papyrus.infra.types.core.factories.IElementTypeConfigurationFactory; +import org.eclipse.papyrus.infra.types.core.factories.impl.MetamodelTypeFactory; +import org.eclipse.papyrus.infra.types.core.factories.impl.SpecializationTypeFactory; + +/** + * Registry that manages all possible elementTypeConfigurationTypes + */ +public class ElementTypeConfigurationTypeRegistry { + + private static ElementTypeConfigurationTypeRegistry registry; + + protected Map<String, IElementTypeConfigurationFactory<? extends ElementTypeConfiguration>> elementTypeConfigurationTypeToFactory = null; + + /** + * returns the singleton instance of this registry + * + * @return the singleton instance of this registry + */ + public static synchronized ElementTypeConfigurationTypeRegistry getInstance() { + if (registry == null) { + registry = new ElementTypeConfigurationTypeRegistry(); + registry.init(); + } + return registry; + } + + /** + * Inits the registry. + */ + protected void init() { + elementTypeConfigurationTypeToFactory = new HashMap<String, IElementTypeConfigurationFactory<? extends ElementTypeConfiguration>>(); + IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(IElementTypeConfigurationKindExtensionPoint.EXTENSION_POINT_ID); + for (IConfigurationElement configurationElement : elements) { + String configurationClass = configurationElement.getAttribute(IElementTypeConfigurationKindExtensionPoint.CONFIGURATION_CLASS); + try { + Object factoryClass = configurationElement.createExecutableExtension(IElementTypeConfigurationKindExtensionPoint.FACTORY_CLASS); + if (factoryClass instanceof IElementTypeConfigurationFactory) { + elementTypeConfigurationTypeToFactory.put(configurationClass, (IElementTypeConfigurationFactory<?>) factoryClass); + } + } catch (CoreException e) { + Activator.log.error(e); + } + } + // Register default interpretations + elementTypeConfigurationTypeToFactory.put(ElementTypesConfigurationsPackage.eINSTANCE.getMetamodelTypeConfiguration().getInstanceTypeName(), new MetamodelTypeFactory()); + elementTypeConfigurationTypeToFactory.put(ElementTypesConfigurationsPackage.eINSTANCE.getSpecializationTypeConfiguration().getInstanceTypeName(), new SpecializationTypeFactory()); + } + + protected <T extends ElementTypeConfiguration> IElementTypeConfigurationFactory<T> getFactory(ElementTypeConfiguration elementTypeConfiguration) { + String elementTypeConfigurationType = elementTypeConfiguration.eClass().getInstanceTypeName(); + // We assume here that the right factory is registered for the right ElementTypeConfiguration + @SuppressWarnings("unchecked") + IElementTypeConfigurationFactory<T> factory = (IElementTypeConfigurationFactory<T>) elementTypeConfigurationTypeToFactory.get(elementTypeConfigurationType); + return factory; + } + + public <T extends ElementTypeConfiguration> IElementType getElementType(T elementTypeConfiguration) { + if (elementTypeConfiguration == null) { + return null; + } else { + IElementTypeConfigurationFactory<T> factory = getFactory(elementTypeConfiguration); + if (factory != null) { + IHintedType elementType = factory.createElementType(elementTypeConfiguration); + return elementType; + } + } + return null; + } +} diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/registries/ElementTypeSetConfigurationRegistry.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/registries/ElementTypeSetConfigurationRegistry.java new file mode 100644 index 00000000000..65f8e6e4ac3 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/registries/ElementTypeSetConfigurationRegistry.java @@ -0,0 +1,566 @@ +/***************************************************************************** + * Copyright (c) 2014, 2015 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 459174 + * Christian W. Damus - bug 467207 + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.types.core.registries; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +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.TreeIterator; +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.ClientContextManager; +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.IAdviceBindingDescriptor; +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.IMetamodelType; +import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType; +import org.eclipse.gmf.runtime.emf.type.core.NullElementType; +import org.eclipse.papyrus.infra.types.AbstractAdviceBindingConfiguration; +import org.eclipse.papyrus.infra.types.AdviceConfiguration; +import org.eclipse.papyrus.infra.types.ElementTypeConfiguration; +import org.eclipse.papyrus.infra.types.ElementTypeSetConfiguration; +import org.eclipse.papyrus.infra.types.SpecializationTypeConfiguration; +import org.eclipse.papyrus.infra.types.core.Activator; +import org.eclipse.papyrus.infra.types.core.extensionpoints.IElementTypeSetExtensionPoint; +import org.eclipse.papyrus.infra.types.core.utils.ElementTypeRegistryUtils; +import org.eclipse.papyrus.infra.types.core.utils.OrientedGraph; +import org.eclipse.papyrus.infra.types.core.utils.TypesConfigurationsCycleUtil; +import org.osgi.framework.Bundle; + +/** + * Registry to manage load/unloaded {@link ElementTypeSetConfiguration}. + */ +public class ElementTypeSetConfigurationRegistry { + + protected static ElementTypeSetConfigurationRegistry elementTypeSetConfigurationRegistry; + + /** Map of retrieved elementType sets, key is their identifier */ + protected Map<String, Map<String, ElementTypeSetConfiguration>> elementTypeSetConfigurations = null; + + protected OrientedGraph<String> advicesDeps = null; + + + /** unique resource set to load all elementType sets models */ + protected ResourceSet elementTypeSetConfigurationResourceSet = null; + + /** + * returns the singleton instance of this registry + * + * @return the singleton instance of this registry + */ + public static synchronized ElementTypeSetConfigurationRegistry getInstance() { + if (elementTypeSetConfigurationRegistry == null) { + elementTypeSetConfigurationRegistry = new ElementTypeSetConfigurationRegistry(); + elementTypeSetConfigurationRegistry.init(); + } + return elementTypeSetConfigurationRegistry; + } + + /** + * Inits the registry. + */ + protected void init() { + // 0. Resets values + elementTypeSetConfigurationResourceSet = null; + elementTypeSetConfigurations = new HashMap<String, Map<String, ElementTypeSetConfiguration>>(); + // 1. creates the resource set + elementTypeSetConfigurationResourceSet = createResourceSet(); + // 2. creates the list only when registry is acceded for the first time, + Map<String, Set<ElementTypeSetConfiguration>> elementTypeSetConfigurationsToLoad = readElementTypeSetConfigurationModelsFromExtensionPoints(); + // Try to load all elementType set definitions + for (String contexId : elementTypeSetConfigurationsToLoad.keySet()) { + loadElementTypeSetConfigurations(contexId, elementTypeSetConfigurationsToLoad.get(contexId)); + } + + } + + + protected Map<String, Set<ElementTypeSetConfiguration>> readElementTypeSetConfigurationModels() { + Map<String, Set<ElementTypeSetConfiguration>> elementTypeSetConfigurations = new HashMap<String, Set<ElementTypeSetConfiguration>>(); + + + + return elementTypeSetConfigurations; + } + + /** + * Dispose this registry, i.e. remove all contribution on the elementType registry. + */ + public synchronized void dispose() { + if (elementTypeSetConfigurations == null) { + return; + } + + for (String contextId : elementTypeSetConfigurations.keySet()) { + for (String elementTypeSetId : elementTypeSetConfigurations.get(contextId).keySet()) { + unload(contextId, elementTypeSetId); + } + + } + elementTypeSetConfigurationResourceSet = null; + elementTypeSetConfigurations = null; + elementTypeSetConfigurationRegistry = null; + } + + /** + * Loads a given elementType set from a given identifier + */ + public boolean loadElementTypeSetConfiguration(String contextId, String path) { + + if (path == null) { + Activator.log.warn("Path must not be null" + path); + return false; + } + + if (contextId == null) { + Activator.log.warn("contextId must not be null" + path); + return false; + } + URI localURI = URI.createPlatformResourceURI(path, true); + Resource resource = elementTypeSetConfigurationResourceSet.createResource(localURI); + try { + resource.load(null); + EObject content = resource.getContents().get(0); + if (content instanceof ElementTypeSetConfiguration) { + return loadElementTypeSetConfiguration(contextId, (ElementTypeSetConfiguration) content); + } + } catch (IOException e) { + Activator.log.error(e); + } + + return false; + + } + + public boolean loadElementTypeSetConfiguration(String clientContextID, ElementTypeSetConfiguration elementTypeSetConfiguration) { + return loadElementTypeSetConfigurations(clientContextID, Collections.singleton(elementTypeSetConfiguration)); + } + + public OrientedGraph<String> getAdvicesDeps() { + if (advicesDeps == null) { + advicesDeps = new OrientedGraph<>(); + } + return advicesDeps; + } + + protected boolean isAlreadyRegistred(String elementTypeID, IClientContext context) { + if (ElementTypeRegistry.getInstance().getType(elementTypeID) != null) { + if (!elementTypeID.equals(NullElementType.ID)) { + if (ElementTypeRegistryUtils.getType(context, elementTypeID) == null) { + // The elementType is already existing but not binded yet + context.bindId(elementTypeID); + Activator.log.info(elementTypeID + " is already registred elementtype but it is not binded yet. It has been binded to Papyrus context. "); + } + } + return true; + } + + return false; + } + + protected boolean registerElementTypeConfiguration(ElementTypeConfiguration elementTypeConfiguration, Map<String, ElementTypeConfiguration> elementTypeConfigurationsDefinitions, IClientContext context) { + String elementTypeID = elementTypeConfiguration.getIdentifier(); + if (isAlreadyRegistred(elementTypeID, context)) { + return true; + } + + if (elementTypeConfiguration instanceof SpecializationTypeConfiguration) { + // First, check if dependencies are registered + for (String specializedTypeId : ((SpecializationTypeConfiguration) elementTypeConfiguration).getSpecializedTypesID()) { + + if (!isAlreadyRegistred(specializedTypeId, context)) { + // try to register the dependency + ElementTypeConfiguration specializedTypeConfiguration = elementTypeConfigurationsDefinitions.get(specializedTypeId); + if (specializedTypeConfiguration != null) { + boolean registred = registerElementTypeConfiguration(specializedTypeConfiguration, elementTypeConfigurationsDefinitions, context); + if (!registred) { + Activator.log.info("Failed to register " + specializedTypeId); + return false; + } + } else { + if (!specializedTypeId.equals(NullElementType.ID)) { + Activator.log.info("Cannot find ElementTypeConfiguration for " + specializedTypeId); + return false; + } + } + } + } + + } + + IElementType elementType = ElementTypeConfigurationTypeRegistry.getInstance().getElementType(elementTypeConfiguration); + if (elementType != null) { + // register elementType + if (elementType instanceof ISpecializationType) { + if (ElementTypeRegistry.getInstance().register((ISpecializationType) elementType)) { + context.bindId(elementType.getId()); + return true; + } else { + Activator.log.info("SpecializationType not added: " + elementType); + } + } else if (elementType instanceof IMetamodelType) { + if (ElementTypeRegistry.getInstance().register((IMetamodelType) elementType)) { + context.bindId(elementType.getId()); + return true; + } else { + Activator.log.info("MetamodelType not added: " + elementType); + ElementTypeRegistry.getInstance().register((IMetamodelType) elementType); + } + } + } + + return false; + + } + + public boolean loadElementTypeSetConfigurations(String contexId, Collection<ElementTypeSetConfiguration> elementTypeSetConfigurationsToRegister) { + + if (contexId == null) { + Activator.log.warn("contexId must not be null. Loading aborted. "); + return false; + } + + IClientContext context = ClientContextManager.getInstance().getClientContext(contexId); + if (context == null) { + Activator.log.warn("contexId couldn't be found. Loading aborted. "); + return false; + } + + Map<String, ElementTypeConfiguration> elementTypeConfigurationsDefinitions = new HashMap<String, ElementTypeConfiguration>(); + + + + // Read from elementTypeSetConfigurations + Set<ElementTypeSetConfiguration> registrableElementTypeSetConfiguration = new HashSet<ElementTypeSetConfiguration>(); + for (ElementTypeSetConfiguration elementTypeSetConfiguration : elementTypeSetConfigurationsToRegister) { + if (elementTypeSetConfiguration == null) { + Activator.log.warn("The collection of elementTypesconfigurations contains a null value. Loading aborted. "); + return false; + } + // Check if not already registered + if (elementTypeSetConfigurations.containsKey(elementTypeSetConfiguration.getIdentifier())) { + Activator.log.warn("The following ElementTypesSetConfiguration has been ignored because the same ID already registreted: " + elementTypeSetConfiguration.getIdentifier()); + } else { + registrableElementTypeSetConfiguration.add(elementTypeSetConfiguration); + for (ElementTypeConfiguration elementTypeConfiguration : elementTypeSetConfiguration.getElementTypeConfigurations()) { + elementTypeConfigurationsDefinitions.put(elementTypeConfiguration.getIdentifier(), elementTypeConfiguration); + } + } + } + + // Check there is no cyclic dependencies among elementTypes introduced by this loading + HashSet<ElementTypeConfiguration> elementTypesToCheck = new HashSet<ElementTypeConfiguration>(); + // The old ones already registered + if (elementTypeSetConfigurations.containsKey(contexId)) { + for (ElementTypeSetConfiguration elementTypeSetConfiguration : elementTypeSetConfigurations.get(contexId).values()) { + elementTypesToCheck.addAll(elementTypeSetConfiguration.getElementTypeConfigurations()); + } + } + // The new ones we wan to register + elementTypesToCheck.addAll(elementTypeConfigurationsDefinitions.values()); + OrientedGraph<String> elementTypesDeps = TypesConfigurationsCycleUtil.getDependenciesAmongElementTypes(elementTypesToCheck); + + Collection<Collection<Object>> cyclesElementTypes = TypesConfigurationsCycleUtil.getCyclesAmongElementTypes(elementTypesDeps.getVertices(), elementTypesDeps.getEdges()); + if (!cyclesElementTypes.isEmpty()) { + Activator.log.warn("The ElementTypesConfiguration registration has been aborted because there is at least a cyclic-dependency in the ElementTypes definitions: " + cyclesElementTypes); + return false; + } + + // Collect all advicesconfiguration + HashSet<AdviceConfiguration> adviceToCheck = new HashSet<AdviceConfiguration>(); + // The old ones already registered + if (elementTypeSetConfigurations.containsKey(contexId)) { + for (ElementTypeSetConfiguration elementTypeSetConfiguration : elementTypeSetConfigurations.get(contexId).values()) { + TreeIterator<EObject> it = elementTypeSetConfiguration.eAllContents(); + while (it.hasNext()) { + EObject element = (EObject) it.next(); + if (element instanceof AdviceConfiguration) { + adviceToCheck.add((AdviceConfiguration) element); + } + + } + } + } + // The new ones we want to register + for (ElementTypeSetConfiguration elementTypeSetConfiguration : registrableElementTypeSetConfiguration) { + TreeIterator<EObject> it = elementTypeSetConfiguration.eAllContents(); + while (it.hasNext()) { + EObject element = (EObject) it.next(); + if (element instanceof AdviceConfiguration) { + adviceToCheck.add((AdviceConfiguration) element); + + } + } + } + + // Check that there is no cyclic dependencies among advices introduced by this loading + advicesDeps = TypesConfigurationsCycleUtil.getDependenciesAmongAdvices(adviceToCheck); + Collection<Collection<Object>> cyclesAdvices = TypesConfigurationsCycleUtil.getCyclesInAdvices(advicesDeps.getVertices(), advicesDeps.getEdges()); + if (!cyclesAdvices.isEmpty()) { + Activator.log.warn("The ElementTypesConfiguration registration has been aborted because there is at least a cyclic-dependencies in the Advices definitions: " + cyclesAdvices); + return false; + } + + // If we reached that point, we should be able to register safely the none already registered elementTypeSets + for (ElementTypeSetConfiguration elementTypeSetConfiguration : registrableElementTypeSetConfiguration) { + if (!elementTypeSetConfigurations.containsKey(contexId)) { + elementTypeSetConfigurations.put(contexId, new HashMap<String, ElementTypeSetConfiguration>()); + } + elementTypeSetConfigurations.get(contexId).put(elementTypeSetConfiguration.getIdentifier(), elementTypeSetConfiguration); + } + + // New ElementTypesConfigurations can be registered + for (ElementTypeConfiguration elementTypeConfiguration : elementTypeConfigurationsDefinitions.values()) { + registerElementTypeConfiguration(elementTypeConfiguration, elementTypeConfigurationsDefinitions, context); + } + + // Register adviceBindings + for (ElementTypeSetConfiguration elementTypeSetConfiguration : registrableElementTypeSetConfiguration) { + List<AbstractAdviceBindingConfiguration> adviceBindingConfigurations = elementTypeSetConfiguration.getAdviceBindingsConfigurations(); + for (AbstractAdviceBindingConfiguration adviceBindingConfiguration : adviceBindingConfigurations) { + IAdviceBindingDescriptor editHelperAdviceDecriptor = AdviceConfigurationTypeRegistry.getInstance().getEditHelperAdviceDecriptor(adviceBindingConfiguration); + ElementTypeRegistryUtils.registerAdviceBinding(editHelperAdviceDecriptor); + context.bindId(editHelperAdviceDecriptor.getId()); + } + } + + return true; + } + + + public boolean unload(String contextId, String elementTypeSetId) { + if (elementTypeSetConfigurations == null) { + return false; + } + if (!elementTypeSetConfigurations.containsKey(contextId)) { + return false; + } + Map<String, ElementTypeSetConfiguration> map = elementTypeSetConfigurations.get(contextId); + ElementTypeSetConfiguration elementTypeSet = map.remove(elementTypeSetId); + if (elementTypeSet == null) { + return false; + } + + // Remove elementTypes + ElementTypeRegistry registry = ElementTypeRegistry.getInstance(); + List<IElementType> elementTypes = new ArrayList<IElementType>(elementTypeSet.getElementTypeConfigurations().size()); + for (ElementTypeConfiguration elementTypeConfiguration : elementTypeSet.getElementTypeConfigurations()) { + if (elementTypeConfiguration != null && elementTypeConfiguration.getIdentifier() != null) { + String configIdentifier = elementTypeConfiguration.getIdentifier(); + IElementType elementType = registry.getType(configIdentifier); + if (elementType != null) { + elementTypes.add(elementType); + } + } + } + + ElementTypeUtil.deregisterElementTypes(elementTypes, ElementTypeUtil.ALL_DEPENDENTS); + + // Remove adviceBindings + List<AbstractAdviceBindingConfiguration> adviceBindingConfigurations = elementTypeSet.getAdviceBindingsConfigurations(); + for (AbstractAdviceBindingConfiguration adviceBindingConfiguration : adviceBindingConfigurations) { + IAdviceBindingDescriptor advice = AdviceConfigurationTypeRegistry.getInstance().getEditHelperAdviceDecriptor(adviceBindingConfiguration); + if (advice != null) { + ElementTypeRegistryUtils.removeAdviceDescriptorFromBindings(advice); + } + } + + // If I loaded this element-types configuration model, I should now unload it. Otherwise, + // I don't own this resource so I should not attempt to manage it + if (elementTypeSetConfigurationResourceSet != null) { + Resource resource = elementTypeSet.eResource(); + if ((resource != null) && (resource.getResourceSet() == elementTypeSetConfigurationResourceSet)) { + resource.unload(); + elementTypeSetConfigurationResourceSet.getResources().remove(resource); + } + } + + // Recompute adviceDependencies + HashSet<AdviceConfiguration> advices = new HashSet<AdviceConfiguration>(); + // The ones still registered + for (ElementTypeSetConfiguration elementTypeSetConfiguration : elementTypeSetConfigurations.get(contextId).values()) { + TreeIterator<EObject> it = elementTypeSetConfiguration.eAllContents(); + while (it.hasNext()) { + EObject element = (EObject) it.next(); + if (element instanceof AdviceConfiguration) { + advices.add((AdviceConfiguration) element); + } + + } + } + advicesDeps = TypesConfigurationsCycleUtil.getDependenciesAmongAdvices(advices); + + return true; + } + + + + protected void addElementTypeSetConfigurationToDefinitions(ElementTypeSetConfiguration set, String clientContextId, Map<String, Set<ElementTypeSetConfiguration>> existingDefinitions) { + if (set.getIdentifier() == null) { + Activator.log.warn("The following ElementTypesSetConfiguration has ill-defined ID and is therefore ignored: " + set.eResource().getURI()); + } else { + if (set != null) { + if (existingDefinitions.get(clientContextId) != null && containsElementTypeSet(existingDefinitions.get(clientContextId), set.getIdentifier())) { + Activator.log.warn("The following ElementTypesSetConfiguration has been ignored because the same ID already registreted: " + set.getIdentifier()); + } else { + if (!existingDefinitions.containsKey(clientContextId)) { + existingDefinitions.put(clientContextId, new HashSet<ElementTypeSetConfiguration>()); + } + existingDefinitions.get(clientContextId).add(set); + } + } + } + } + + protected Map<String, Set<ElementTypeSetConfiguration>> readElementTypeSetConfigurationModelsFromExtensionPoints() { + Map<String, Set<ElementTypeSetConfiguration>> existingDefinitions = new HashMap<>(); + IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(IElementTypeSetExtensionPoint.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(IElementTypeSetExtensionPoint.PATH); + String clientContextId = element.getAttribute(IElementTypeSetExtensionPoint.CLIENT_CONTEXT_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("- ClientContext the model should be registreted to: " + clientContextId); + Activator.log.debug("- id of the container bundle: " + contributorID); + } + ElementTypeSetConfiguration set = getElementTypeSetConfiguration(modelPath, contributorID); + + if (set != null) { + addElementTypeSetConfigurationToDefinitions(set, clientContextId, existingDefinitions); + } + + } + return existingDefinitions; + } + + protected boolean containsElementTypeSet(Set<ElementTypeSetConfiguration> elementTypeSets, String elementTypeSetConfigurationId) { + if (elementTypeSets == null) { + return false; + } + + for (ElementTypeSetConfiguration elementTypeSetConfiguration : elementTypeSets) { + if (elementTypeSetConfiguration.getIdentifier().equals(elementTypeSetConfigurationId)) { + return true; + } + } + return false; + } + + /** + * <p> + * Loads the resource containing the elementType 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 elementTypesID + * id of the elementType 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 ElementTypeSetConfiguration getElementTypeSetConfiguration(String modelPath, String bundleId) { + + Bundle bundle = Platform.getBundle(bundleId); + if (Platform.isFragment(bundle)) { + ElementTypeSetConfiguration configuration = getElementTypeSetConfigurationInBundle(modelPath, bundleId); + if (configuration == null) { + Activator.log.warn("Cannot find resource " + modelPath + " in bundle " + bundleId); + } + return configuration; + } 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 getElementTypeSetConfigurationInBundle(modelPath, bundleId); + } else { + + ElementTypeSetConfiguration elementTypeSetConfiguration = null; + + for (Bundle fragment : fragments) { + elementTypeSetConfiguration = getElementTypeSetConfigurationInBundle(modelPath, fragment.getSymbolicName()); + if (elementTypeSetConfiguration != null) { + break; + } + } + + if (elementTypeSetConfiguration == null) { + // not found in fragments. Look in the plugin itself + elementTypeSetConfiguration = getElementTypeSetConfigurationInBundle(modelPath, bundleId); + } + + if (elementTypeSetConfiguration == null) { + Activator.log.warn("Cannot find resource " + modelPath + " in bundle " + bundleId); + } + + return elementTypeSetConfiguration; + } + } + } + + /** + * + * @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 ElementTypeSetConfiguration getElementTypeSetConfigurationInBundle(String modelPath, String bundleID) { + String path = bundleID + IPath.SEPARATOR + modelPath; + Resource resource = elementTypeSetConfigurationResourceSet.createResource(URI.createPlatformPluginURI(path, true)); + try { + resource.load(null); + } catch (IOException e) { + return null; // Don't log the error yet; we're trying several options + } + EObject content = resource.getContents().get(0); + if (content instanceof ElementTypeSetConfiguration) { + return (ElementTypeSetConfiguration) content; + } + return null; + } + + protected ResourceSet createResourceSet() { + ResourceSet set = new ResourceSetImpl(); + return set; + } + + public Map<String, Map<String, ElementTypeSetConfiguration>> getElementTypeSetConfigurations() { + return elementTypeSetConfigurations; + } +} diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/registries/MatcherConfigurationTypeRegistry.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/registries/MatcherConfigurationTypeRegistry.java new file mode 100644 index 00000000000..572a9397348 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/registries/MatcherConfigurationTypeRegistry.java @@ -0,0 +1,100 @@ +/***************************************************************************** + * Copyright (c) 2014 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.types.core.registries; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.Platform; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher; +import org.eclipse.papyrus.infra.types.AbstractMatcherConfiguration; +import org.eclipse.papyrus.infra.types.ElementTypesConfigurationsPackage; +import org.eclipse.papyrus.infra.types.core.Activator; +import org.eclipse.papyrus.infra.types.core.extensionpoints.IMatcherConfigurationKindExtensionPoint; +import org.eclipse.papyrus.infra.types.core.factories.IMatcherFactory; +import org.eclipse.papyrus.infra.types.core.factories.impl.DefaultMatcherFactory; + +public class MatcherConfigurationTypeRegistry { + + private static MatcherConfigurationTypeRegistry registry; + + protected Map<String, IMatcherFactory<? extends AbstractMatcherConfiguration>> matcherConfigurationTypeToFactory = null; + + public static synchronized MatcherConfigurationTypeRegistry getInstance() { + if (registry == null) { + registry = new MatcherConfigurationTypeRegistry(); + registry.init(); + } + return registry; + } + + protected void init() { + matcherConfigurationTypeToFactory = new HashMap<String, IMatcherFactory<? extends AbstractMatcherConfiguration>>(); + IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(IMatcherConfigurationKindExtensionPoint.EXTENSION_POINT_ID); + for (IConfigurationElement configurationElement : elements) { + String configurationClass = configurationElement.getAttribute(IMatcherConfigurationKindExtensionPoint.CONFIGURATION_CLASS); + try { + Object factoryClass = configurationElement.createExecutableExtension(IMatcherConfigurationKindExtensionPoint.FACTORY_CLASS); + if (factoryClass instanceof IMatcherFactory) { + matcherConfigurationTypeToFactory.put(configurationClass, (IMatcherFactory<?>) factoryClass); + } + } catch (CoreException e) { + Activator.log.error(e); + } + } + // Register default interpretation + matcherConfigurationTypeToFactory.put(ElementTypesConfigurationsPackage.eINSTANCE.getMatcherConfiguration().getInstanceTypeName(), new DefaultMatcherFactory()); + } + + protected <T extends AbstractMatcherConfiguration> IMatcherFactory<T> getFactory(T matcherConfiguration) { + String matcherConfigurationType = matcherConfiguration.eClass().getInstanceTypeName(); + // We assume here that the right factory is registered for the right MatcherConfiguration + @SuppressWarnings("unchecked") + IMatcherFactory<T> factory = (IMatcherFactory<T>) matcherConfigurationTypeToFactory.get(matcherConfigurationType); + return factory; + } + + public <T extends AbstractMatcherConfiguration> IElementMatcher getMatcher(T matcherConfiguration) { + if (matcherConfiguration == null) { + return null; + } else { + IMatcherFactory<T> factory = getFactory(matcherConfiguration); + if (factory == null) { + // Provide dummy interpretation + IElementMatcher matcher = new DummyElementMatcher(); + return matcher; + } else { + IElementMatcher matcher = factory.createElementMatcher(matcherConfiguration); + return matcher; + } + } + } + + public class DummyElementMatcher implements IElementMatcher { + + /** + * @see org.eclipse.gmf.runtime.emf.type.core.IElementMatcher#matches(org.eclipse.emf.ecore.EObject) + * + * @param eObject + * @return + */ + @Override + public boolean matches(EObject eObject) { + return true; + } + + } +} diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/AdviceComparator.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/AdviceComparator.java new file mode 100644 index 00000000000..5f8c3befd49 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/AdviceComparator.java @@ -0,0 +1,47 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.types.core.utils;
+
+import java.util.Comparator;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.papyrus.infra.types.core.registries.ElementTypeSetConfigurationRegistry;
+
+
+public class AdviceComparator implements Comparator<IEditHelperAdvice> {
+
+ OrientedGraph<String> dependencies;
+
+ public AdviceComparator() {
+ this.dependencies = ElementTypeSetConfigurationRegistry.getInstance().getAdvicesDeps();
+ }
+
+ @Override
+ public int compare(IEditHelperAdvice arg0, IEditHelperAdvice arg1) {
+ String arg0Name = arg0.getClass().getName();
+ String arg1Name = arg1.getClass().getName();
+ if (dependencies.getEdges().containsKey(arg0Name)) {
+ if (dependencies.getAllConnex(arg0Name).contains(arg1Name)) {
+ return -1;
+ }
+ }
+ if (dependencies.getEdges().containsKey(arg1Name)) {
+ if (dependencies.getAllConnex(arg1Name).contains(arg0Name)) {
+ return 1;
+ }
+ }
+ return 0;
+ }
+
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/ElementTypeRegistryUtils.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/ElementTypeRegistryUtils.java new file mode 100644 index 00000000000..0981619d310 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/ElementTypeRegistryUtils.java @@ -0,0 +1,76 @@ +/*****************************************************************************
+ * Copyright (c) 2014, 2015 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 459174
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.types.core.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.gmf.runtime.emf.type.core.ClientContext;
+import org.eclipse.gmf.runtime.emf.type.core.ClientContextManager;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.IAdviceBindingDescriptor;
+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.IHintedType;
+import org.eclipse.papyrus.infra.types.core.Activator;
+
+public class ElementTypeRegistryUtils {
+
+ static public IElementType getType(IClientContext context, String elementTypeID) {
+ IElementType[] elementTypes = ElementTypeRegistry.getInstance().getElementTypes(context);
+ for (IElementType iElementType : elementTypes) {
+ if (iElementType.getId().equals(elementTypeID)) {
+ return iElementType;
+ }
+ }
+ return null;
+ }
+
+ static public void registerAdviceBinding(IAdviceBindingDescriptor adviceDescriptor) {
+ ElementTypeRegistry.getInstance().registerAdvice(adviceDescriptor);
+ }
+
+ static public void removeAdviceDescriptorFromBindings(IAdviceBindingDescriptor adviceDescriptor) {
+ ElementTypeRegistry.getInstance().deregisterAdvice(adviceDescriptor);
+ }
+
+ static public void unBindID(IClientContext context, String typeId) {
+ if (context instanceof ClientContext) {
+ ((ClientContext) context).unbindId(typeId);
+ } else if (context != null) {
+ Activator.log.warn("Cannot unbind type ID from context of unknown class: " + context.getClass().getName());
+ }
+ }
+
+ static public List<IElementType> getElementTypesBySemanticHint(String semanticHint, String contextId) {
+ List<IElementType> matchingElementTypes = new ArrayList<IElementType>();
+
+ IClientContext context = ClientContextManager.getInstance().getClientContext(contextId);
+
+ if (context != null) {
+
+ IElementType[] elementTypes = ElementTypeRegistry.getInstance().getElementTypes(context);
+
+ for (IElementType iElementType : elementTypes) {
+ if (iElementType instanceof IHintedType) {
+ if (((IHintedType) iElementType).getSemanticHint().equals(semanticHint)) {
+ matchingElementTypes.add(iElementType);
+ }
+ }
+ }
+ }
+
+ return matchingElementTypes;
+ }
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/OrientedGraph.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/OrientedGraph.java new file mode 100644 index 00000000000..ea61fc8a1dd --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/OrientedGraph.java @@ -0,0 +1,97 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.types.core.utils;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+public class OrientedGraph<T extends Object> {
+ private Map<T, Set<T>> graph;
+
+ /**
+ * @return the vertices
+ */
+ public Set<T> getVertices() {
+ return graph.keySet();
+ }
+
+ /**
+ * @return the edges
+ */
+ public Map<T, Set<T>> getEdges() {
+ return graph;
+ }
+
+ public Set<T> getAllConnex(T element) {
+ Set<T> result = new HashSet<T>();
+
+ Set<T> directChildren = graph.get(element);
+
+ result.addAll(directChildren);
+
+ for (T child : directChildren) {
+ Set<T> childChildren = getAllConnex(child);
+ result.addAll(childChildren);
+ }
+
+ return result;
+ }
+
+
+ public OrientedGraph() {
+ graph = new HashMap<T, Set<T>>();
+ }
+
+ public OrientedGraph(Map<T, Set<T>> edges) {
+ this.graph = edges;
+ }
+
+ public void clear() {
+ graph.clear();
+ }
+
+ public void addEdge(T source, T target) {
+ if (!graph.containsKey(source)) {
+ addVertex(source);
+ }
+ if (!graph.containsKey(target)) {
+ addVertex(target);
+ }
+
+ graph.get(source).add(target);
+ }
+
+ public void addVertex(T vertex) {
+ if (!graph.containsKey(vertex)) {
+ graph.put(vertex, new HashSet<T>());
+ }
+
+ }
+
+ public String toString() {
+ String result = "";
+ for (T element : graph.keySet()) {
+ result += "- " + element + "\n";
+ for (T target : graph.get(element)) {
+ result += "\t-> " + target + "\n";
+ }
+ }
+
+ return result;
+
+ }
+
+}
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/TypesConfigurationsCycleUtil.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/TypesConfigurationsCycleUtil.java new file mode 100644 index 00000000000..7ea83f59f05 --- /dev/null +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/TypesConfigurationsCycleUtil.java @@ -0,0 +1,127 @@ +package org.eclipse.papyrus.infra.types.core.utils;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
+
+import org.eclipse.gmf.runtime.emf.type.core.IAdviceBindingDescriptor;
+import org.eclipse.papyrus.infra.types.AdviceConfiguration;
+import org.eclipse.papyrus.infra.types.ElementTypeConfiguration;
+import org.eclipse.papyrus.infra.types.SpecializationTypeConfiguration;
+import org.eclipse.papyrus.infra.types.core.Activator;
+import org.eclipse.papyrus.infra.types.core.registries.AdviceConfigurationTypeRegistry;
+
+//Implements Tarjan's strongly connected components algorithm
+public class TypesConfigurationsCycleUtil {
+
+
+ protected static Collection<Collection<Object>> computeStronglyConnectedComponents(Set<String> vertices, Map<String, Set<String>> edges) {
+ int index = 0;
+ Map<String, Integer> lowIndex = new HashMap<String, Integer>();
+ Collection<String> visitedVertices = new HashSet<String>();
+ Stack<String> stack = new Stack<String>();
+ Collection<Collection<Object>> stronglyConnnectedComponents = new ArrayList<Collection<Object>>();
+
+ for (String vertex : vertices) {
+ if (!visitedVertices.contains(vertex))
+ dfs(vertex, vertices, edges, stronglyConnnectedComponents, stack, lowIndex, visitedVertices, index);
+ }
+
+ return stronglyConnnectedComponents;
+ }
+
+
+ protected static void dfs(String vertex, Set<String> vertices, Map<String, Set<String>> map, Collection<Collection<Object>> stronglyConnnectedComponents, Stack<String> stack, Map<String, Integer> lowIndex, Collection<String> visitedVertices,
+ int index) {
+ lowIndex.put(vertex, index++);
+ visitedVertices.add(vertex);
+ stack.push(vertex);
+ int minIndex = lowIndex.get(vertex);
+ for (String targetVertex : map.get(vertex)) {
+ if (!visitedVertices.contains(targetVertex))
+ dfs(targetVertex, vertices, map, stronglyConnnectedComponents, stack, lowIndex, visitedVertices, index);
+ if (lowIndex.get(targetVertex) < minIndex)
+ minIndex = lowIndex.get(targetVertex);
+ }
+ if (minIndex < lowIndex.get(vertex)) {
+ lowIndex.put(vertex, minIndex);
+ return;
+ }
+ List<Object> component = new ArrayList<Object>();
+ String memberVertex;
+ do {
+ memberVertex = stack.pop();
+ component.add(memberVertex);
+ lowIndex.put(memberVertex, vertices.size());
+ } while (!memberVertex.equals(vertex));
+
+ if (component.size() > 1) {
+ stronglyConnnectedComponents.add(component);
+ }
+ }
+
+ static public OrientedGraph<String> getDependenciesAmongAdvices(Collection<AdviceConfiguration> adviceConfigurations) {
+ OrientedGraph<String> adviceDependencies = new OrientedGraph<String>();
+ for (AdviceConfiguration adviceConfiguration : adviceConfigurations) {
+ IAdviceBindingDescriptor descriptor = AdviceConfigurationTypeRegistry.getInstance().getEditHelperAdviceDecriptor(adviceConfiguration);
+
+ String currentAdviceConfigurationClassName = descriptor.getEditHelperAdvice().getClass().getName();
+ // Add current to the vertices
+ adviceDependencies.addVertex(currentAdviceConfigurationClassName);
+
+ // Add dependencies vertices
+ for (String after : adviceConfiguration.getAfter()) {
+ if (after == null) {
+ Activator.log.warn("The following AdviceConfiguration has ill-defined after : " + adviceConfiguration);
+ break;
+ }
+ adviceDependencies.addEdge(currentAdviceConfigurationClassName, after);
+ }
+
+ for (String before : adviceConfiguration.getBefore()) {
+ if (before == null) {
+ Activator.log.warn("The following AdviceConfiguration has ill-defined before : " + adviceConfiguration);
+ break;
+ }
+ adviceDependencies.addEdge(before, currentAdviceConfigurationClassName);
+ }
+
+ }
+
+ return adviceDependencies;
+ }
+
+ static public Collection<Collection<Object>> getCyclesInAdvices(Set<String> vertices, Map<String, Set<String>> edges) {
+
+ return computeStronglyConnectedComponents(vertices, edges);
+ }
+
+ static public OrientedGraph<String> getDependenciesAmongElementTypes(Collection<ElementTypeConfiguration> elementTypesConfigurations) {
+ OrientedGraph<String> elementTypeDependencies = new OrientedGraph<String>();
+
+ for (ElementTypeConfiguration elementTypeConfiguration : elementTypesConfigurations) {
+ String currentElementTypeID = elementTypeConfiguration.getIdentifier();
+
+ // Add current to the vertices
+ elementTypeDependencies.addVertex(currentElementTypeID);
+
+ // Add dependencies vertices
+ if (elementTypeConfiguration instanceof SpecializationTypeConfiguration) {
+ for (String specializedTypeID : ((SpecializationTypeConfiguration) elementTypeConfiguration).getSpecializedTypesID()) {
+ elementTypeDependencies.addEdge(currentElementTypeID, specializedTypeID);
+ }
+ }
+ }
+
+ return elementTypeDependencies;
+ }
+
+ static public Collection<Collection<Object>> getCyclesAmongElementTypes(Set<String> vertices, Map<String, Set<String>> edges) {
+ return computeStronglyConnectedComponents(vertices, edges);
+ }
+}
|