diff options
author | Laurent Fasani | 2016-05-17 13:44:28 +0000 |
---|---|---|
committer | Pierre-Charles David | 2016-05-18 08:12:18 +0000 |
commit | 4ca4d24b663c72d528d6f0af9b8e49f4cb0f6588 (patch) | |
tree | 28b2b5b3729ba8c0831b81d49e86d0b69f58de6f | |
parent | dae72c3b23e70ef74da6437a40c749a7781d6f45 (diff) | |
download | org.eclipse.sirius-4ca4d24b663c72d528d6f0af9b8e49f4cb0f6588.tar.gz org.eclipse.sirius-4ca4d24b663c72d528d6f0af9b8e49f4cb0f6588.tar.xz org.eclipse.sirius-4ca4d24b663c72d528d6f0af9b8e49f4cb0f6588.zip |
Add meta-model validation constraint which checks that at least one
meta-model is declared on RepresentationDescription.
Bug: 493330
Change-Id: I899df43b8a0e79b57dcf00f2c9828e697888e21a
Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
5 files changed, 105 insertions, 6 deletions
diff --git a/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/DiagramPlugin.java b/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/DiagramPlugin.java index 5eed0f251b..e8278f2026 100644 --- a/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/DiagramPlugin.java +++ b/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/DiagramPlugin.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2014 THALES GLOBAL SERVICES and others. + * Copyright (c) 2007, 2016 THALES GLOBAL SERVICES 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 @@ -15,6 +15,10 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.emf.common.EMFPlugin; import org.eclipse.emf.common.util.ResourceLocator; +import org.eclipse.emf.ecore.EValidator; +import org.eclipse.sirius.diagram.description.DescriptionPackage; +import org.eclipse.sirius.diagram.description.tool.ToolPackage; +import org.eclipse.sirius.tools.internal.validation.EValidatorAdapter; import org.osgi.framework.BundleContext; /** @@ -174,6 +178,16 @@ public class DiagramPlugin extends EMFPlugin { } @Override + public void start(BundleContext context) throws Exception { + super.start(context); + + // Sets the validator for these model. + EValidator.Registry.INSTANCE.put(DiagramPackage.eINSTANCE, new EValidatorAdapter()); + EValidator.Registry.INSTANCE.put(DescriptionPackage.eINSTANCE, new EValidatorAdapter()); + EValidator.Registry.INSTANCE.put(ToolPackage.eINSTANCE, new EValidatorAdapter()); + } + + @Override public void stop(BundleContext context) throws Exception { try { InstanceScope.INSTANCE.getNode(ID).flush(); diff --git a/plugins/org.eclipse.sirius/plugin.properties b/plugins/org.eclipse.sirius/plugin.properties index 524b402131..daaa9573e0 100644 --- a/plugins/org.eclipse.sirius/plugin.properties +++ b/plugins/org.eclipse.sirius/plugin.properties @@ -1,5 +1,5 @@ # ==================================================================== -# Copyright (c) 2007, 2015 THALES GLOBAL SERVICES +# Copyright (c) 2007, 2016 THALES GLOBAL SERVICES # 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 @@ -25,6 +25,9 @@ pluginName = Sirius Core Runtime providerName = Eclipse Modeling Project constraint.category.name = Sirius Constraints +constraint.metaModels.description = Check that one meta-model is declared as RepresentationDescription meta-models. +constraint.metaModels.message = {0} +constraint.metaModels.name = Meta-models constraint constraint.validAppliedOn.message = {0} constraint.validAppliedOn.name = Empty appliedOn list validation constraint.validAttributeCustomization.description = Check the constraint that EAttributeCustomization.attributeName is the name of a common EAttribute to all referenced style description or a description element owned by a style description through EAttributeCustomization.appliedOn. @@ -210,7 +213,7 @@ RemoveElementTask_label = Remove an element RemoveElementTask_notAViewErrorMsg = The element is not a view ! Do not delete ! RemoveSemanticResourceCommand_label = Remove model RenameRepresentationCommand_label = Rename representation -XMIModelFileHandler_parsingStopedMsg = All needed informations have been reached. Stop the parsing. +RepresentationDescriptionMetaModelsConstraint_noMetaModel = There is no associated meta-model. RestoreModelElementStateCommand_label = restor model elements RuntimeLoggerInterpreterImpl_evaluationConditionErrorMsg = Evaluation condition error SaveSessionJob_sessionSavingMsg = Session saving @@ -340,4 +343,5 @@ ViewpointRegistryImpl_FileLoadingErrorMsg = The viewpoint registry was not able ViewpointRegistryImpl_cantDeployVSMErrorMsg = Can't deploy VSM. ViewpointRegistryImpl_cantLoadVSMErrorMsg = The viewpoint specification model : {0} can''t be loaded, it may need to be migrated. ViewpointRegistryImpl_unableToUnloadFileErrorMsg = The viewpoint registry was not able to unload this file {0} +XMIModelFileHandler_parsingStopedMsg = All needed informations have been reached. Stop the parsing. XMIModelFileHandler_stopTheParsingMsg = We try to access external elements. Stop the parsing. diff --git a/plugins/org.eclipse.sirius/plugin.xml b/plugins/org.eclipse.sirius/plugin.xml index 2cb3fe8f5b..0a1538c4e1 100644 --- a/plugins/org.eclipse.sirius/plugin.xml +++ b/plugins/org.eclipse.sirius/plugin.xml @@ -259,6 +259,22 @@ class="AbstractVariable"> </target> </constraint> + <constraint + class="org.eclipse.sirius.tools.internal.validation.description.constraints.RepresentationDescriptionMetaModelsConstraint" + id="org.eclipse.sirius.tools.internal.validation.description.constraints.metaModelConstraint" + isEnabledByDefault="true" + lang="Java" + mode="Batch" + name="%constraint.metaModels.name" + severity="WARNING" + statusCode="1"> + <description> + %constraint.metaModels.description + </description> + <message> + %constraint.metaModels.message + </message> + </constraint> </constraints> </constraintProvider> </extension> diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/RepresentationDescriptionMetaModelsConstraint.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/RepresentationDescriptionMetaModelsConstraint.java new file mode 100644 index 0000000000..6f1ca67560 --- /dev/null +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/RepresentationDescriptionMetaModelsConstraint.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2016 Obeo. + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.tools.internal.validation.description.constraints; + +import java.util.Collection; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.validation.IValidationContext; +import org.eclipse.sirius.tools.internal.validation.AbstractConstraint; +import org.eclipse.sirius.viewpoint.Messages; +import org.eclipse.sirius.viewpoint.description.RepresentationDescription; +import org.eclipse.sirius.viewpoint.description.RepresentationExtensionDescription; + +/** + * Constraint ensuring that there is at least one meta-model associated to + * RepresentationDescription. + * + * @author <a href="mailto:laurent.fasani@obeo.fr">Laurent Fasani</a> + */ +public class RepresentationDescriptionMetaModelsConstraint extends AbstractConstraint { + + @Override + public IStatus validate(IValidationContext ctx) { + final EObject target = ctx.getTarget(); + + if (target instanceof RepresentationDescription || target instanceof RepresentationExtensionDescription) { + Collection<EPackage> availableMetamodels = getAvailableMetamodels(target); + if (availableMetamodels.isEmpty()) { + return ctx.createFailureStatus(Messages.RepresentationDescriptionMetaModelsConstraint_noMetaModel); + } + } + + return ctx.createSuccessStatus(); + } + + /** + * Return the Meta-models associated to the containing parent description. + * + * @param parentDescription + * the parentDescription. + * @return the available meta-models. + */ + private Collection<EPackage> getAvailableMetamodels(final EObject parentDescription) { + Collection<EPackage> metamodel = null; + if (parentDescription instanceof RepresentationDescription) { + metamodel = ((RepresentationDescription) parentDescription).getMetamodel(); + } else if (parentDescription instanceof RepresentationExtensionDescription) { + metamodel = ((RepresentationExtensionDescription) parentDescription).getMetamodel(); + } + return metamodel; + } +} diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/viewpoint/Messages.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/viewpoint/Messages.java index c3af6c8cb2..657a59fff8 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/viewpoint/Messages.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/viewpoint/Messages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Obeo. + * Copyright (c) 2015, 2016 Obeo. * 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 @@ -247,7 +247,7 @@ public final class Messages { @TranslatableMessage public static String ExecuteToolOperationTask_label; - + @TranslatableMessage public static String ExecuteToolOperationTask_sessionNotFound; @@ -450,7 +450,7 @@ public final class Messages { public static String RenameRepresentationCommand_label; @TranslatableMessage - public static String XMIModelFileHandler_parsingStopedMsg; + public static String RepresentationDescriptionMetaModelsConstraint_noMetaModel; @TranslatableMessage public static String RestoreModelElementStateCommand_label; @@ -840,6 +840,9 @@ public final class Messages { public static String ViewpointRegistryImpl_unableToUnloadFileErrorMsg; @TranslatableMessage + public static String XMIModelFileHandler_parsingStopedMsg; + + @TranslatableMessage public static String XMIModelFileHandler_stopTheParsingMsg; // CHECKSTYLE:ON |