Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Grouhan2015-02-11 09:46:30 +0000
committerPierre-Charles David2015-02-18 10:56:53 +0000
commitd702ae161d41df2b957e73135d3831d8e2b69c03 (patch)
treea7704c69b7a8a9524d909c465f8eb729a083e74f
parentc2b81eeebf06dfdbf7e0ee21c02832788edec400 (diff)
downloadorg.eclipse.sirius-d702ae161d41df2b957e73135d3831d8e2b69c03.tar.gz
org.eclipse.sirius-d702ae161d41df2b957e73135d3831d8e2b69c03.tar.xz
org.eclipse.sirius-d702ae161d41df2b957e73135d3831d8e2b69c03.zip
[460014] Add generic constraints for validating static image paths
Add generic constraints for validating static image paths, add the associated JUnit tests in org.eclipse.sirius.tests.unit.diagram.vsm.VSMValidationTest, correct some typo errors in plugin.xml files, and modify two another existing tests that failed due to the previously mentioned modifications. Bug: 460014 Change-Id: I0537b539be08a9a2ff8e8c79f67bf1b3978b60ce Signed-off-by: Benjamin Grouhan <benjamin.grouhan@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram/plugin.xml23
-rw-r--r--plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/validation/description/constraints/ValidDiagramImageConstraint.java38
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/validateImagePathVSM.odesign44
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/valideDomainClassVSM.odesign2
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/interpreter/acceleo/mtl/IInterpreterValidationExpressionTest.java4
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/vsm/VSMValidationTest.java39
-rw-r--r--plugins/org.eclipse.sirius/plugin.xml17
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/AbstractValidImageConstraint.java99
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/ValidImagePathConstraint.java40
9 files changed, 295 insertions, 11 deletions
diff --git a/plugins/org.eclipse.sirius.diagram/plugin.xml b/plugins/org.eclipse.sirius.diagram/plugin.xml
index 8ee7e54bd7..8022203ac5 100644
--- a/plugins/org.eclipse.sirius.diagram/plugin.xml
+++ b/plugins/org.eclipse.sirius.diagram/plugin.xml
@@ -398,7 +398,22 @@
Invalid Class
</description>
<message>
- The Class {0} doesn&apos;t exist.
+ The Class {0} does not exist.
+ </message>
+ </constraint>
+ <constraint
+ lang="Java"
+ class="org.eclipse.sirius.diagram.tools.internal.validation.description.constraints.ValidDiagramImageConstraint"
+ severity="ERROR"
+ mode="Batch"
+ name="Valid Diagram Images"
+ id="org.eclipse.sirius.diagram.constraints.ValidDiagramImage"
+ statusCode="1">
+ <description>
+ Invalid Diagram Image
+ </description>
+ <message>
+ {0}
</message>
</constraint>
<constraint
@@ -410,7 +425,7 @@
severity="ERROR"
statusCode="1">
<message>
- The SemanticCandidatesExpression field of {0} doesn''t accept a blank value because it's recursively imported by another ContainerMapping ({1}). This can cause infinite loop, StackOverflowError (except in case of not synchronized mapping).
+ The SemanticCandidatesExpression field of {0} does not accept a blank value because it is recursively imported by another ContainerMapping ({1}). This can cause infinite loop, StackOverflowError (except in case of not synchronized mapping).
</message>
<description>
Validates that there is no blank SemanticCandidatesExpression for a recursive ContainerMapping
@@ -425,7 +440,7 @@
severity="ERROR"
statusCode="1">
<message>
- The SizeComputationExpression field of {0} doesn&apos;&apos;t accept a blank value.
+ The SizeComputationExpression field of {0} does not accept a blank value.
</message>
<description>
Validates that the size computation expression of an EdgeStyleDecription is set
@@ -458,7 +473,7 @@
Invalid variable
</description>
<message>
- The expression {0} of {1} doesn&apos;t accept the {2} variable.
+ The expression {0} of {1} does not accept the {2} variable.
</message>
</constraint>
<constraint
diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/validation/description/constraints/ValidDiagramImageConstraint.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/validation/description/constraints/ValidDiagramImageConstraint.java
new file mode 100644
index 0000000000..a3c1dce7b2
--- /dev/null
+++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/validation/description/constraints/ValidDiagramImageConstraint.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.diagram.tools.internal.validation.description.constraints;
+
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.sirius.diagram.description.DescriptionPackage;
+import org.eclipse.sirius.diagram.description.style.StylePackage;
+import org.eclipse.sirius.diagram.description.tool.ToolPackage;
+import org.eclipse.sirius.tools.internal.validation.description.constraints.AbstractValidImageConstraint;
+
+/**
+ * Validate the images referenced in diagrams.
+ *
+ * @author bgrouhan
+ *
+ */
+public class ValidDiagramImageConstraint extends AbstractValidImageConstraint {
+ private static final EAttribute[] attrs = {DescriptionPackage.eINSTANCE.getLayer_Icon(),
+ StylePackage.eINSTANCE.getWorkspaceImageDescription_WorkspacePath(),
+ ToolPackage.eINSTANCE.getContainerCreationDescription_IconPath(),
+ ToolPackage.eINSTANCE.getEdgeCreationDescription_IconPath(),
+ ToolPackage.eINSTANCE.getNodeCreationDescription_IconPath(),
+ ToolPackage.eINSTANCE.getToolSection_Icon()};
+
+ @Override
+ public EAttribute[] getImagePathAttributes() {
+ return attrs;
+ }
+
+}
diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/validateImagePathVSM.odesign b/plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/validateImagePathVSM.odesign
new file mode 100644
index 0000000000..0db99d2147
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/validateImagePathVSM.odesign
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<description:Group xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/diagram/description/1.1.0" xmlns:style="http://www.eclipse.org/sirius/diagram/description/style/1.1.0" xmlns:tool="http://www.eclipse.org/sirius/description/tool/1.1.0" name="My" version="10.0.0.201411061000">
+ <ownedViewpoints name="V">
+ <ownedRepresentations xsi:type="description_1:DiagramDescription" name="D" domainClass="EClass">
+ <defaultLayer name="Default" icon=" /org.eclipse.sirius.tests.junit/images/logo_o.png ">
+ <containerMappings name="C1" domainClass="EAttribute">
+ <style xsi:type="style:WorkspaceImageDescription" workspacePath="/org.eclipse.sirius.tests.junit/images/Actor.png">
+ <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
+ <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
+ </style>
+ </containerMappings>
+ <containerMappings name="C2" domainClass="EAttribute">
+ <style xsi:type="style:WorkspaceImageDescription" workspacePath="/test/noimage.gif">
+ <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
+ <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
+ </style>
+ </containerMappings>
+ <toolSections name="Tool" icon="icon">
+ <ownedTools xsi:type="tool:PaneBasedSelectionWizardDescription" name="Wizard" iconPath="/org.eclipse.sirius.tests.junit/icons/DiagramMatchEngine.gif" candidatesExpression="[self/]">
+ <element name="element"/>
+ <containerView name="containerView"/>
+ <container name="container"/>
+ <initialOperation>
+ <firstModelOperations xsi:type="tool:ChangeContext" browseExpression="[self/]"/>
+ </initialOperation>
+ </ownedTools>
+ <ownedTools xsi:type="tool:SelectionWizardDescription" name="Wizard2" candidatesExpression="[self/]" iconPath="/org.eclipse.sirius.tests.junit/plugin.xml" windowImagePath="C:\images\image.png">
+ <element name="element"/>
+ <containerView name="containerView"/>
+ <container name="container"/>
+ <initialOperation>
+ <firstModelOperations xsi:type="tool:ChangeContext" browseExpression="[self/]"/>
+ </initialOperation>
+ </ownedTools>
+ </toolSections>
+ <decorationDescriptionsSet>
+ <decorationDescriptions xsi:type="description:SemanticBasedDecoration" name="DecorationSemantic" domainClass="EAttribute"/>
+ <decorationDescriptions xsi:type="description_1:MappingBasedDecoration" name="DecorationMapping" decoratorPath="/org.eclipse.sirius.tests.junit/images/notexisting.png" mappings="//@ownedViewpoints[name='V']/@ownedRepresentations[name='D']/@defaultLayer/@containerMappings[name='C1']"/>
+ <decorationDescriptions xsi:type="description_1:MappingBasedDecoration" name="DecoMap" decoratorPath="/Project/es.png" mappings="//@ownedViewpoints[name='V']/@ownedRepresentations[name='D']/@defaultLayer/@containerMappings[name='C2']"/>
+ </decorationDescriptionsSet>
+ </defaultLayer>
+ </ownedRepresentations>
+ </ownedViewpoints>
+</description:Group>
diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/valideDomainClassVSM.odesign b/plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/valideDomainClassVSM.odesign
index 393ae0bf29..753a70aa35 100644
--- a/plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/valideDomainClassVSM.odesign
+++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/valideDomainClassVSM.odesign
@@ -52,7 +52,7 @@
</style>
</containerMappings>
<decorationDescriptionsSet>
- <decorationDescriptions xsi:type="description:SemanticBasedDecoration" name="Deco" decoratorPath="\platform" domainClass="EClass"/>
+ <decorationDescriptions xsi:type="description:SemanticBasedDecoration" name="Deco" decoratorPath="" domainClass="EClass"/>
</decorationDescriptionsSet>
</defaultLayer>
</ownedRepresentations>
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/interpreter/acceleo/mtl/IInterpreterValidationExpressionTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/interpreter/acceleo/mtl/IInterpreterValidationExpressionTest.java
index cd1d35475f..1c2f611c69 100644
--- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/interpreter/acceleo/mtl/IInterpreterValidationExpressionTest.java
+++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/interpreter/acceleo/mtl/IInterpreterValidationExpressionTest.java
@@ -178,10 +178,10 @@ public class IInterpreterValidationExpressionTest extends SiriusDiagramTestCase
ContainerMapping nodeMapping = getContainerMapping(acceleo3Layer, "EC EClass");
// invalidFeature ECLass : a validation error should be raised, but not
// InterpreterException
- ensureExpressionValidationRaisedExpectedErrors(nodeMapping, "domainClass", "Nothing", "The Class Nothing doesn't exist.");
+ ensureExpressionValidationRaisedExpectedErrors(nodeMapping, "domainClass", "Nothing", "The Class Nothing does not exist.");
// invalidFeature ECLass : a validation error should be raised
ensureExpressionValidationRaisedExpectedErrors(nodeMapping, "semanticElements", "[self.invalidFeature/]", "Invalid Type: Nothing", "Unrecognized variable: (invalidFeature)",
- "The Class Nothing doesn't exist.");
+ "The Class Nothing does not exist.");
// valid EClass : interpreter exceptions should now be raised
ensureExpressionValidationRaisedExpectedErrors(nodeMapping, "domainClass", "EClass", "Unrecognized variable: (invalidFeature)");
}
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/vsm/VSMValidationTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/vsm/VSMValidationTest.java
index ba5c78380f..5668acaf1d 100644
--- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/vsm/VSMValidationTest.java
+++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/vsm/VSMValidationTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2014 THALES GLOBAL SERVICES.
+ * Copyright (c) 2010, 2015 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
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.sirius.tests.unit.diagram.vsm;
+import java.util.List;
+
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
@@ -19,6 +21,8 @@ import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.sirius.ecore.extender.tool.api.ModelUtils;
+import org.eclipse.sirius.tests.SiriusTestsPlugin;
+import org.eclipse.sirius.tests.support.api.EclipseTestsSupportHelper;
import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase;
import org.eclipse.sirius.viewpoint.description.Group;
@@ -39,13 +43,18 @@ public class VSMValidationTest extends SiriusDiagramTestCase {
private Group modelerForVariableNameValidation;
+ private Group modelerForImagePathValidation;
+
public void setUp() throws Exception {
ResourceSet set = new ResourceSetImpl();
+ EclipseTestsSupportHelper.INSTANCE.createProject("Project");
+ EclipseTestsSupportHelper.INSTANCE.copyFile(SiriusTestsPlugin.PLUGIN_ID, "/images/es.png", "/Project/es.png");
modeler = (Group) ModelUtils.load(URI.createPlatformPluginURI("/org.eclipse.sirius.tests.junit/data/unit/vsm/valideVSM.odesign", true), set);
modelerWithNoStyle = (Group) ModelUtils.load(URI.createPlatformPluginURI("/org.eclipse.sirius.tests.junit/data/unit/vsm/validateVSMWithNoStyle.odesign", true), set);
modelerWithDiagramExtension = (Group) ModelUtils.load(URI.createPlatformPluginURI("/org.eclipse.sirius.tests.junit/data/unit/vsm/valideVSMWithDiagramExtension.odesign", true), set);
modelerForDomainClassValidation = (Group) ModelUtils.load(URI.createPlatformPluginURI("/org.eclipse.sirius.tests.junit/data/unit/vsm/valideDomainClassVSM.odesign", true), set);
modelerForVariableNameValidation = (Group) ModelUtils.load(URI.createPlatformPluginURI("/org.eclipse.sirius.tests.junit/data/unit/vsm/valideVariableNameVSM.odesign", true), set);
+ modelerForImagePathValidation = (Group) ModelUtils.load(URI.createPlatformPluginURI("/org.eclipse.sirius.tests.junit/data/unit/vsm/validateImagePathVSM.odesign", true), set);
}
/**
@@ -86,9 +95,9 @@ public class VSMValidationTest extends SiriusDiagramTestCase {
// with conditional style without style, a element based edge without
// style with conditional style without style and node,container and
// edge import without style (this 3 items with no style are valid)
- assertEquals("The diagnostic must be contains 6 elements no validate", 6, diagnostic.getChildren().size());
+ assertEquals("The diagnostic must contain 6 elements invalidated", 6, diagnostic.getChildren().size());
for (Diagnostic diag : diagnostic.getChildren()) {
- assertEquals("The list of no validate element must be 'A style is missing for' and not other", "A style is missing for", diag.getMessage().substring(0, 22));
+ assertEquals("The list of invalidated elements must start by 'A style is missing for' and nothing else", "A style is missing for", diag.getMessage().substring(0, 22));
}
}
@@ -165,6 +174,30 @@ public class VSMValidationTest extends SiriusDiagramTestCase {
assertEquals("The VSM is valid, it should not have popup error message", Diagnostic.OK, diagnostic.getSeverity());
}
+ /**
+ * Test VSM validation with diferent paths for images (there are valid and
+ * invalid paths).
+ */
+ public void testValidationImagePathVSM() {
+ Diagnostician diagnostician = new Diagnostician();
+ Diagnostic diagnostic = diagnostician.validate(modelerForImagePathValidation);
+ // Check that there is a pop up for validation problems
+ assertEquals("The VSM is not valid, it should have popup error message", Diagnostic.ERROR, diagnostic.getSeverity());
+ List<Diagnostic> children = diagnostic.getChildren();
+ // test if there is 7 errors and if each one corresponds to the awaited
+ // one
+ assertEquals("The diagnostic must contain 7 elements invalidated", 7, children.size());
+ assertEquals("The first error do not match the awaited one", "The path ' /org.eclipse.sirius.tests.junit/images/logo_o.png ' does not correspond to an image.", children.get(0).getMessage());
+ assertEquals("The second error do not match the awaited one", "The image '/test/noimage.gif' does not exist.", children.get(1).getMessage());
+ assertEquals("The third error do not match the awaited one", "The path 'icon' does not correspond to an image.", children.get(2).getMessage());
+ assertEquals("The fourth error do not match the awaited one", "The path '/org.eclipse.sirius.tests.junit/plugin.xml' does not correspond to an image.", children.get(3).getMessage());
+ assertEquals("The fifth error do not match the awaited one", "The image 'C:\\images\\image.png' does not exist.", children.get(4).getMessage());
+ assertEquals("The sixth error do not match the awaited one", "The image '/org.eclipse.sirius.tests.junit/images/notexisting.png' does not exist.", children.get(5).getMessage());
+ // partial assert because the full message references the object with by
+ // its toString(), so it contains the its instance id, which is variable
+ assertEquals("The seventh error do not match the awaited one", "The required feature 'decoratorPath' of", children.get(6).getMessage().substring(0, 39));
+ }
+
private void addSpaceInDomainClassValue(EObject current, EAttribute attribute, int iterate) {
switch (iterate) {
diff --git a/plugins/org.eclipse.sirius/plugin.xml b/plugins/org.eclipse.sirius/plugin.xml
index a0e1168953..9478416bbc 100644
--- a/plugins/org.eclipse.sirius/plugin.xml
+++ b/plugins/org.eclipse.sirius/plugin.xml
@@ -136,10 +136,25 @@
Invalid variable
</description>
<message>
- The expression {0} of {1} doesn&apos;t accept the {2} variable.
+ The expression {0} of {1} does not accept the {2} variable.
</message>
</constraint>
<constraint
+ class="org.eclipse.sirius.tools.internal.validation.description.constraints.ValidImagePathConstraint"
+ id="org.eclipse.sirius.constraints.ValidImagePathConstraint"
+ lang="Java"
+ mode="Batch"
+ name="Invalid Image Path"
+ severity="ERROR"
+ statusCode="1">
+ <message>
+ {0}
+ </message>
+ <description>
+ Validates that image paths are valid
+ </description>
+ </constraint>
+ <constraint
class="org.eclipse.sirius.tools.internal.validation.description.constraints.ValidInterpretedExpressionConstraint"
id="org.eclipse.sirius.constraints.ValidInterpretedExpressionConstraint"
lang="Java"
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/AbstractValidImageConstraint.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/AbstractValidImageConstraint.java
new file mode 100644
index 0000000000..3a2671140e
--- /dev/null
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/AbstractValidImageConstraint.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.ArrayList;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.URIConverter;
+import org.eclipse.emf.validation.EMFEventType;
+import org.eclipse.emf.validation.IValidationContext;
+import org.eclipse.emf.validation.model.ConstraintStatus;
+import org.eclipse.sirius.common.tools.api.resource.ImageFileFormat;
+import org.eclipse.sirius.common.tools.api.util.StringUtil;
+import org.eclipse.sirius.tools.internal.validation.AbstractConstraint;
+
+/**
+ * Abstract Constraint to validate image references.
+ *
+ * @author bgrouhan
+ */
+public abstract class AbstractValidImageConstraint extends AbstractConstraint {
+
+ @Override
+ public IStatus validate(IValidationContext ctx) {
+ IStatus status = ctx.createSuccessStatus();
+ // In the case of batch mode.
+ if (ctx.getEventType() == EMFEventType.NULL) {
+ EObject eObj = ctx.getTarget();
+ String path = "";
+ EAttribute[] attrs = getImagePathAttributes();
+ ArrayList<IStatus> statuses = new ArrayList<IStatus>();
+ ResourceSet rs = eObj.eResource().getResourceSet();
+ for (EAttribute attr : attrs) {
+ if (attr.getEContainingClass().isInstance(eObj)) {
+ path = (String) eObj.eGet(attr);
+ statuses.add(validateImagePath(ctx, rs, path));
+ }
+ }
+ if (statuses.size() > 0) {
+ status = ConstraintStatus.createMultiStatus(ctx, statuses);
+ }
+ }
+ return status;
+ }
+
+ /**
+ * Method to get all the EAttributes corresponding to image paths in the
+ * package.
+ *
+ * @return An array of the EAttributes.
+ */
+ public abstract EAttribute[] getImagePathAttributes();
+
+ private IStatus validateImagePath(IValidationContext ctx, ResourceSet rs, String path) {
+ // when path is empty, success (even when a path is needed, because
+ // there is another validation rule for that)
+ if (!StringUtil.isEmpty(path)) {
+ if (!validateExtension(path)) {
+ return ctx.createFailureStatus(new Object[] { "The path '" + path + "' does not correspond to an image." });
+ }
+ if (!validateExistence(path, rs)) {
+ return ctx.createFailureStatus(new Object[] { "The image '" + path + "' does not exist." });
+ }
+ }
+ return ctx.createSuccessStatus();
+ }
+
+ private boolean validateExistence(String path, ResourceSet rs) {
+ URIConverter uriConverter = rs.getURIConverter();
+ URI workspaceURI = URI.createPlatformResourceURI(path, true);
+ URI pluginsURI = URI.createPlatformPluginURI(path, true);
+ return uriConverter.exists(workspaceURI, null) || uriConverter.exists(pluginsURI, null);
+ }
+
+ private boolean validateExtension(String path) {
+ boolean isValid = false;
+ String extension = new Path(path).getFileExtension();
+ for (ImageFileFormat element : ImageFileFormat.VALUES) {
+ if (element.getName().equalsIgnoreCase(extension)) {
+ isValid = true;
+ break;
+ }
+ }
+ return isValid;
+ }
+}
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/ValidImagePathConstraint.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/ValidImagePathConstraint.java
new file mode 100644
index 0000000000..270bdcf7cc
--- /dev/null
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/ValidImagePathConstraint.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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 org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.sirius.viewpoint.description.DescriptionPackage;
+import org.eclipse.sirius.viewpoint.description.style.StylePackage;
+import org.eclipse.sirius.viewpoint.description.tool.ToolPackage;
+
+/**
+ * Validate image references.
+ *
+ * @author bgrouhan
+ *
+ */
+public class ValidImagePathConstraint extends AbstractValidImageConstraint{
+ private static final EAttribute[] attrs = {DescriptionPackage.eINSTANCE.getViewpoint_Icon(),
+ DescriptionPackage.eINSTANCE.getDecorationDescription_DecoratorPath(),
+ StylePackage.eINSTANCE.getBasicLabelStyleDescription_IconPath(),
+ ToolPackage.eINSTANCE.getMenuItemDescription_Icon(),
+ ToolPackage.eINSTANCE.getPaneBasedSelectionWizardDescription_IconPath(),
+ ToolPackage.eINSTANCE.getPaneBasedSelectionWizardDescription_WindowImagePath(),
+ ToolPackage.eINSTANCE.getSelectionWizardDescription_IconPath(),
+ ToolPackage.eINSTANCE.getSelectionWizardDescription_WindowImagePath(),
+ ToolPackage.eINSTANCE.getToolDescription_IconPath()};
+
+ @Override
+ public EAttribute[] getImagePathAttributes() {
+ return attrs;
+ }
+
+}

Back to the top