Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf')
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/ICustomizationActions.java44
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/ICustomizationCommandFactory.java61
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/ICustomizationCommandFactoryFactory.java39
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/Activator.java54
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/CustomizationActionsImpl.java69
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/CustomizationCommandFactory.java93
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/CustomizationCommandFactoryFactory.java26
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/validation/AvoidEClassOverlayConstraint.java57
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/validation/CustomizationValidationBuilder.java116
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/validation/ValidationDelegateClientSelector.java23
10 files changed, 582 insertions, 0 deletions
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/ICustomizationActions.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/ICustomizationActions.java
new file mode 100644
index 00000000000..cbe214e96bf
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/ICustomizationActions.java
@@ -0,0 +1,44 @@
+/**
+ * Copyright (c) 2012 Mia-Software.
+ *
+ * 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:
+ * Alban Ménager (Soft-Maint) - Bug 387470 - [EFacet][Custom] Editors
+ */
+package org.eclipse.emf.facet.custom.sdk.core;
+
+import java.io.IOException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.Customization;
+import org.eclipse.emf.facet.custom.sdk.core.internal.CustomizationActionsImpl;
+import org.eclipse.emf.facet.util.emf.core.exception.InvalidFacetSetException;
+
+/**
+ * This interface provides the creation of a new customization model file.
+ *
+ * @see CustomizationActionsImpl
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+public interface ICustomizationActions {
+
+ ICustomizationActions INSTANCE = new CustomizationActionsImpl();
+
+ /**
+ * Add the given customization to the given customization model file, which
+ * will be created.
+ *
+ * @param customization
+ * the customization to be created. Cannot be <code>null</code>
+ * @param file
+ * the new file in which the customization has to be created.
+ * Cannot be <code>null</code>, and cannot already exist
+ */
+ void saveCustomization(Customization customization, IFile file)
+ throws IOException, InvalidFacetSetException;
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/ICustomizationCommandFactory.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/ICustomizationCommandFactory.java
new file mode 100644
index 00000000000..b25fd22378e
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/ICustomizationCommandFactory.java
@@ -0,0 +1,61 @@
+/**
+ * Copyright (c) 2012 Mia-Software.
+ *
+ * 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:
+ * Alban Ménager (Soft-Maint) - Bug 387470 - [EFacet][Custom] Editors
+ * Grégoire Dupé (Mia-Software) - Bug 387470 - [EFacet][Custom] Editors
+ */
+package org.eclipse.emf.facet.custom.sdk.core;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.Customization;
+import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.EClassCustomization;
+import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.ETypedElementCase;
+import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.FacetCustomization;
+import org.eclipse.emf.facet.custom.sdk.core.internal.CustomizationCommandFactory;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.extensible.Query;
+
+/**
+ * This interface provide a command factory. A command modify the editingDomain.
+ *
+ * @since 0.3
+ * @see CustomizationCommandFactory
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+public interface ICustomizationCommandFactory {
+
+ /**
+ * Create the command to add a eClassCustomization to an existing
+ * customization (parent).
+ *
+ * @param Customization
+ * the parent of the eClassCustomization to add.
+ * @param eClassCustom
+ * the eClassCustomization to add.
+ * @return the command.
+ */
+ Command createEClassCustomization(Customization parent,
+ EClassCustomization eClassCustom);
+
+ /**
+ * Create the command to add a facetCustomization to an existing
+ * customization (parent).
+ *
+ * @param parent
+ * the parent of the facetCustomization to add.
+ * @param facetCustom
+ * the facetCustomization to add.
+ * @return the command.
+ */
+ Command createFacetCustomization(Customization parent,
+ FacetCustomization facetCustom);
+
+ Command addValueInCase(final ETypedElementCase elementCase,
+ final Query value);
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/ICustomizationCommandFactoryFactory.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/ICustomizationCommandFactoryFactory.java
new file mode 100644
index 00000000000..3e038315588
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/ICustomizationCommandFactoryFactory.java
@@ -0,0 +1,39 @@
+/**
+ * Copyright (c) 2012 Mia-Software.
+ *
+ * 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:
+ * Grégoire Dupé (Mia-Software) - Bug 387470 - [EFacet][Custom] Editors
+ */
+package org.eclipse.emf.facet.custom.sdk.core;
+
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.facet.custom.sdk.core.internal.CustomizationCommandFactoryFactory;
+import org.eclipse.emf.facet.custom.sdk.core.internal.CustomizationCommandFactory;
+
+/**
+ * This interface provide a command factory. A command modify the editingDomain.
+ *
+ * @since 0.3
+ * @see CustomizationCommandFactory
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+public interface ICustomizationCommandFactoryFactory {
+
+ ICustomizationCommandFactoryFactory DEFAULT = new CustomizationCommandFactoryFactory();
+
+ /**
+ * Set the editingDomain.
+ *
+ * @param editingDomain
+ * the current editing domain.
+ */
+ ICustomizationCommandFactory createICustomizationCommandFactory(
+ EditingDomain editingDomain);
+
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/Activator.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/Activator.java
new file mode 100644
index 00000000000..fdf1b570d8c
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/Activator.java
@@ -0,0 +1,54 @@
+/**
+ * Copyright (c) 2012 CEA LIST.
+ * Copyright (c) 2012 Mia-Software.
+ *
+ * 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:
+ * Nicolas Bros (Mia-Software) - Bug 375054 - Add validation warning for overlay on EClass
+ * Alban Ménager (Soft-Maint) - Bug 387470 - [EFacet][Custom] Editors
+ */
+package org.eclipse.emf.facet.custom.sdk.core.internal;
+
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+@SuppressWarnings("PMD.UseSingleton")
+// @SuppressWarnings("PMD.UseSingleton") We cannot conforms to this rule because
+// this class is an Eclipse plug-in activator which will be instantiated by the
+// Eclipse framework.
+public class Activator extends Plugin {
+
+ private static Activator plugin;
+
+ @Override
+ @SuppressWarnings("PMD.SignatureDeclareThrowsException")
+ // @SuppressWarnings("PMD.SignatureDeclareThrowsException") We have to use
+ // this signature because this is an override of an Eclipse framework's
+ // method.
+ public void start(final BundleContext bundleContext) throws Exception {
+ super.start(bundleContext);
+ Activator.plugin = this;
+ }
+
+ @Override
+ @SuppressWarnings({ "PMD.SignatureDeclareThrowsException",
+ "PMD.NullAssignment" })
+ // @SuppressWarnings("PMD.SignatureDeclareThrowsException") We have to use
+ // this signature because this is an override of an Eclipse framework's
+ // method.
+ // @SuppressWarnings("PMD.NullAssignment")
+ // No choice to right it in another way : this is an Eclipse pattern.
+ public void stop(final BundleContext bundleContext) throws Exception {
+ Activator.plugin = null;
+ super.stop(bundleContext);
+ }
+
+ public static Plugin getDefault() {
+ return Activator.plugin;
+ }
+
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/CustomizationActionsImpl.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/CustomizationActionsImpl.java
new file mode 100644
index 00000000000..e8efe00ed91
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/CustomizationActionsImpl.java
@@ -0,0 +1,69 @@
+/**
+ * Copyright (c) 2012 Mia-Software.
+ *
+ * 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:
+ * Alban Ménager (Soft-Maint) - Bug 387470 - [EFacet][Custom] Editors
+ */
+package org.eclipse.emf.facet.custom.sdk.core.internal;
+
+import java.io.IOException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.common.util.URI;
+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.emf.facet.custom.metamodel.v0_2_0.custom.Customization;
+import org.eclipse.emf.facet.custom.sdk.core.ICustomizationActions;
+import org.eclipse.emf.facet.util.core.Logger;
+import org.eclipse.emf.facet.util.emf.core.ICatalogSetManager2;
+import org.eclipse.emf.facet.util.emf.core.ICatalogSetManagerFactory;
+import org.eclipse.emf.facet.util.emf.core.exception.InvalidFacetSetException;
+import org.eclipse.emf.facet.util.pde.core.internal.exported.BuildPropertiesUtils;
+
+/**
+ * Concrete implementation of {@link ICustomizationActions}.
+ */
+public class CustomizationActionsImpl implements ICustomizationActions {
+
+ public void saveCustomization(final Customization customization,
+ final IFile file) throws IOException, InvalidFacetSetException {
+
+ if (customization == null) {
+ throw new IllegalArgumentException(
+ "The given customization cannot be null"); //$NON-NLS-1$
+ }
+ if (file == null) {
+ throw new IllegalArgumentException("The given file cannot be null"); //$NON-NLS-1$
+ }
+ if (file.exists()) {
+ throw new IllegalArgumentException("The given file already exists"); //$NON-NLS-1$
+ }
+ // Create a resource set
+ final ResourceSet resourceSet = new ResourceSetImpl();
+ // Get the URI of the model file.
+ final URI fileURI = URI.createPlatformResourceURI(file.getFullPath()
+ .toString(), true);
+ // Create a resource for this file.
+ final Resource resource = resourceSet.createResource(fileURI);
+ // Add the facetSet the resource contents.
+ resource.getContents().add(customization);
+ // Save the contents of the resource to the file system.
+ resource.save(null);
+ try {
+ BuildPropertiesUtils.addToBuild(file);
+ } catch (final Exception e) {
+ Logger.logError(e, "Error adding file " + file.getFullPath() //$NON-NLS-1$
+ + " to the build.properties", Activator.getDefault()); //$NON-NLS-1$
+ }
+ final ICatalogSetManager2 catalogSetManager = ICatalogSetManagerFactory.DEFAULT
+ .createICatalogSetManager(resourceSet);
+ catalogSetManager.registerModelDeclaration(file);
+ }
+
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/CustomizationCommandFactory.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/CustomizationCommandFactory.java
new file mode 100644
index 00000000000..98454ba3191
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/CustomizationCommandFactory.java
@@ -0,0 +1,93 @@
+/**
+ * Copyright (c) 2012 Mia-Software.
+ *
+ * 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:
+ * Alban Ménager (Soft-Maint) - Bug 387470 - [EFacet][Custom] Editors
+ * Grégoire Dupé (Mia-Software) - Bug 387470 - [EFacet][Custom] Editors
+ */
+package org.eclipse.emf.facet.custom.sdk.core.internal;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.edit.command.AddCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.Customization;
+import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.EClassCustomization;
+import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.ETypedElementCase;
+import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.FacetCustomization;
+import org.eclipse.emf.facet.custom.sdk.core.ICustomizationCommandFactory;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.extensible.Query;
+
+/**
+ * Concrete implementation of {@link ICustomizationCommandFactory}.
+ */
+public class CustomizationCommandFactory implements
+ ICustomizationCommandFactory {
+
+ private final EditingDomain editingDomain;
+
+ public CustomizationCommandFactory(final EditingDomain editingDomain) {
+ if (editingDomain == null) {
+ throw new IllegalArgumentException(
+ "The given EditingDomain cannot be null"); //$NON-NLS-1$
+ }
+ this.editingDomain = editingDomain;
+ }
+
+ /**
+ * Create an {@link AddCommand} to add the element to the owner.
+ *
+ * @param owner
+ * the owner.
+ * @param element
+ * the element to add.
+ * @return the command.
+ */
+ private Command createAddCommand(final Object owner, final Object element) {
+ if (owner == null) {
+ throw new IllegalArgumentException("The given owner cannot be null"); //$NON-NLS-1$
+ }
+ if (element == null) {
+ throw new IllegalArgumentException(
+ "The given element cannot be null"); //$NON-NLS-1$
+ }
+ return AddCommand.create(this.editingDomain, owner,
+ getEStructuralFeature(element), element);
+ }
+
+ /**
+ * Return the {@link EStructuralFeature} for a given element.
+ *
+ * @param element
+ * the element.
+ * @return the eStructuralFeature for the element.
+ */
+ private static EStructuralFeature getEStructuralFeature(final Object element) {
+ EStructuralFeature result = null;
+ if (element instanceof EClassCustomization) {
+ result = EcorePackage.eINSTANCE.getEPackage_EClassifiers();
+ }
+ return result;
+ }
+
+ public Command createEClassCustomization(final Customization parent,
+ final EClassCustomization eClassCustom) {
+ return createAddCommand(parent, eClassCustom);
+ }
+
+ public Command createFacetCustomization(final Customization parent,
+ final FacetCustomization facetCustom) {
+ return createAddCommand(parent, facetCustom);
+ }
+
+ public Command addValueInCase(final ETypedElementCase elementCase,
+ final Query value) {
+ return createAddCommand(elementCase, value);
+ }
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/CustomizationCommandFactoryFactory.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/CustomizationCommandFactoryFactory.java
new file mode 100644
index 00000000000..b96f8240d28
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/CustomizationCommandFactoryFactory.java
@@ -0,0 +1,26 @@
+/**
+ * Copyright (c) 2012 Mia-Software.
+ *
+ * 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:
+ * Grégoire Dupé (Mia-Software) - Bug 387470 - [EFacet][Custom] Editors
+ */
+package org.eclipse.emf.facet.custom.sdk.core.internal;
+
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.facet.custom.sdk.core.ICustomizationCommandFactory;
+import org.eclipse.emf.facet.custom.sdk.core.ICustomizationCommandFactoryFactory;
+
+public class CustomizationCommandFactoryFactory implements
+ ICustomizationCommandFactoryFactory {
+
+ public ICustomizationCommandFactory createICustomizationCommandFactory(
+ final EditingDomain editingDomain) {
+ return new CustomizationCommandFactory(editingDomain);
+ }
+
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/validation/AvoidEClassOverlayConstraint.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/validation/AvoidEClassOverlayConstraint.java
new file mode 100644
index 00000000000..b8081af3e8d
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/validation/AvoidEClassOverlayConstraint.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Nicolas Bros (Mia-Software) - Bug 375054 - Add validation warning for overlay on EClass
+ *******************************************************************************/
+package org.eclipse.emf.facet.custom.sdk.core.internal.validation;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.EClassCustomization;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.DerivedTypedElement;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetOperation;
+import org.eclipse.emf.validation.AbstractModelConstraint;
+import org.eclipse.emf.validation.IValidationContext;
+
+/**
+ * Creates a warning if a {@link FacetOperation} defined in an {@link EClassCustomization} overrides (i.e. customizes)
+ * an overlay operation.
+ */
+public class AvoidEClassOverlayConstraint extends AbstractModelConstraint {
+
+ private static final List<String> OVERLAY_OPS = Arrays.asList(
+ "platform:/plugin/org.eclipse.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/topLeftOverlay", //$NON-NLS-1$
+ "platform:/plugin/org.eclipse.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/topMiddleOverlay", //$NON-NLS-1$
+ "platform:/plugin/org.eclipse.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/topRightOverlay", //$NON-NLS-1$
+ "platform:/plugin/org.eclipse.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/bottomLeftOverlay", //$NON-NLS-1$
+ "platform:/plugin/org.eclipse.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/bottomMiddleOverlay", //$NON-NLS-1$
+ "platform:/plugin/org.eclipse.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/bottomRightOverlay" //$NON-NLS-1$
+ );
+
+ @Override
+ public IStatus validate(final IValidationContext ctx) {
+ IStatus result = ctx.createSuccessStatus();
+ final EObject target = ctx.getTarget();
+ if (target instanceof FacetOperation) {
+ final FacetOperation facetOperation = (FacetOperation) target;
+ final DerivedTypedElement override = facetOperation.getOverride();
+ final URI overrideURI = EcoreUtil.getURI(override);
+ if (facetOperation.eContainer() instanceof EClassCustomization
+ && AvoidEClassOverlayConstraint.OVERLAY_OPS.contains(overrideURI.toString())) {
+ result = ctx.createFailureStatus();
+ }
+ }
+ return result;
+ }
+
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/validation/CustomizationValidationBuilder.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/validation/CustomizationValidationBuilder.java
new file mode 100644
index 00000000000..666d02d586b
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/validation/CustomizationValidationBuilder.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Nicolas Bros (Mia-Software) - Bug 375054 - Add validation warning for overlay on EClass
+ *******************************************************************************/
+package org.eclipse.emf.facet.custom.sdk.core.internal.validation;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+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.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.facet.common.sdk.core.internal.exported.IEmfFacetProjectBuilder;
+import org.eclipse.emf.facet.custom.core.internal.exported.Constants;
+import org.eclipse.emf.validation.marker.MarkerUtil;
+import org.eclipse.emf.validation.model.EvaluationMode;
+import org.eclipse.emf.validation.service.IBatchValidator;
+import org.eclipse.emf.validation.service.ModelValidationService;
+
+/** A builder that validates customization model files. */
+public class CustomizationValidationBuilder implements IEmfFacetProjectBuilder, IResourceDeltaVisitor, IResourceVisitor {
+
+ public IProject[] build(final IncrementalProjectBuilder builder, final int kind, final Map<?, ?> args, final IProgressMonitor monitor) throws CoreException {
+ if (kind == IncrementalProjectBuilder.FULL_BUILD) {
+ fullBuild(builder);
+ } else {
+ final IResourceDelta delta = builder.getDelta(builder.getProject());
+ if (delta == null) {
+ fullBuild(builder);
+ } else {
+ incrementalBuild(delta);
+ }
+ }
+ return new IProject[0];
+ }
+
+ public void clean(final IncrementalProjectBuilder builder, final IProgressMonitor monitor) throws CoreException {
+ builder.getProject().accept(new IResourceVisitor() {
+ public boolean visit(final IResource resource) throws CoreException {
+ if (isCustomizationFile(resource)) {
+ resource.deleteMarkers(MarkerUtil.VALIDATION_MARKER_TYPE, true, IResource.DEPTH_INFINITE);
+ }
+ return true;
+ }
+ });
+ }
+
+ private void incrementalBuild(final IResourceDelta delta) throws CoreException {
+ delta.accept(this);
+ }
+
+ private void fullBuild(final IncrementalProjectBuilder builder) throws CoreException {
+ builder.getProject().accept(this);
+ }
+
+ protected static boolean isCustomizationFile(final IResource resource) {
+ return resource.getType() == IResource.FILE
+ && Constants.CUSTOM_FILE_EXT
+ .equals(resource.getFileExtension());
+ }
+
+ public boolean visit(final IResourceDelta delta) throws CoreException {
+ if (isCustomizationFile(delta.getResource())) {
+ validate(delta.getResource());
+ }
+ return true;
+ }
+
+ public boolean visit(final IResource resource) throws CoreException {
+ if (Constants.CUSTOM_FILE_EXT.equals(resource.getFileExtension())) {
+ validate(resource);
+ }
+ return true;
+ }
+
+ protected static void validate(final IResource resource) throws CoreException {
+ if (resource.exists()) {
+ final IBatchValidator validator = (IBatchValidator) ModelValidationService.getInstance()
+ .newValidator(EvaluationMode.BATCH);
+ validator.setOption(IBatchValidator.OPTION_TRACK_RESOURCES, Boolean.TRUE);
+ final IStatus multiStatus = validator.validate(getAllContents(resource));
+ MarkerUtil.updateMarkers(multiStatus);
+ }
+ }
+
+ /** @return all the model elements contained in the given platform resource. */
+ public static List<EObject> getAllContents(final IResource resource) {
+ final List<EObject> result = new ArrayList<EObject>();
+ final ResourceSetImpl resourceSet = new ResourceSetImpl();
+ final Resource modelResource = resourceSet.getResource(URI.createPlatformResourceURI(resource.getFullPath().toString(), true), true);
+ final TreeIterator<EObject> allContents = EcoreUtil.getAllContents(modelResource, true);
+ while (allContents.hasNext()) {
+ result.add(allContents.next());
+ }
+ return result;
+ }
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/validation/ValidationDelegateClientSelector.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/validation/ValidationDelegateClientSelector.java
new file mode 100644
index 00000000000..cc56ae119af
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.sdk.core/src/org/eclipse/papyrus/emf/facet/custom/sdk/core/internal/validation/ValidationDelegateClientSelector.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Nicolas Bros (Mia-Software) - Bug 375054 - Add validation warning for overlay on EClass
+ *******************************************************************************/
+package org.eclipse.emf.facet.custom.sdk.core.internal.validation;
+
+import org.eclipse.emf.validation.model.IClientSelector;
+
+/** Enables validation depending on a client context. */
+public class ValidationDelegateClientSelector implements IClientSelector {
+
+ public boolean selects(final Object object) {
+ // always enabled
+ return true;
+ }
+
+}

Back to the top