blob: 3b46e6ca37674bce81b59409d5b1b9303d49b88f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/*****************************************************************************
* Copyright (c) 2018 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:
* Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.textedit.tests.editor;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConstraint;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.uml2.uml.Constraint;
import org.eclipse.uml2.uml.LiteralString;
import org.eclipse.uml2.uml.OpaqueExpression;
import org.eclipse.uml2.uml.ValueSpecification;
/**
* Assure that a C++ editor is used, if the constraint contains an opaque expression with "C++" as language
*/
public class CppDirectEditorConstraint implements IDirectEditorConstraint {
private static final String CPP_LANGUAGE_CONSTRAINT = "C++ Language Constraint"; //$NON-NLS-1$
private static final String CPP_LANGUAGE_BODY = "C++"; //$NON-NLS-1$
/**
* Constructor.
*
*/
public CppDirectEditorConstraint() {
}
/**
* @see org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConstraint#getLabel()
*
* @return
*/
public String getLabel() {
return CPP_LANGUAGE_CONSTRAINT;
}
/**
* @see org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConstraint#appliesTo(java.lang.Object)
*
* @param selection
* @return
*/
public boolean appliesTo(Object selection) {
boolean appliedConstraint = false;
EObject resolvedEObject = EMFHelper.getEObject(selection);
if (resolvedEObject instanceof Constraint) {
Constraint selectedConstraint = (Constraint) resolvedEObject;
appliedConstraint = checkValueSpecification(selectedConstraint.getSpecification());
}
else if (resolvedEObject instanceof ValueSpecification) {
appliedConstraint = checkValueSpecification((ValueSpecification) resolvedEObject);
}
return appliedConstraint;
}
/**
* check whether a value specification complies with C++ editor
* @param specification
* @return true, if either opaque-expression (empty or C++ as language) or a literal string
*/
public boolean checkValueSpecification(ValueSpecification specification) {
if (specification instanceof OpaqueExpression) {
return ((OpaqueExpression) specification).getBodies().isEmpty() || ((OpaqueExpression) specification).getLanguages().contains(CPP_LANGUAGE_BODY);
}
else {
return specification instanceof LiteralString;
}
}
}
|