blob: 03731883a90aede8224f48c82a8d5dab89568118 (
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
83
84
85
86
87
88
89
90
91
|
/*****************************************************************************
* Copyright (c) 2019 CEA LIST and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Jeremie TATIBOUET (CEA LIST) <jeremie.tatibouet@cea.fr>
*
*****************************************************************************/
package org.eclipse.papyrus.uml.properties.constraints;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.papyrus.infra.architecture.ArchitectureDescriptionUtils;
import org.eclipse.papyrus.infra.constraints.SimpleConstraint;
import org.eclipse.papyrus.infra.constraints.constraints.AbstractConstraint;
import org.eclipse.papyrus.infra.constraints.constraints.Constraint;
import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureContext;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.emf.edit.domain.PapyrusTransactionalEditingDomain;
import org.eclipse.papyrus.uml.tools.utils.UMLUtil;
import org.eclipse.uml2.uml.Element;
/**
* @since 3.5
*/
public class IsValidArchitectureContext extends AbstractConstraint {
private final static String ARCHITECTURE_CONTEXT_PROPERTY_NAME = "architectureContext"; //$NON-NLS-1$
/**
* Architecture context ID in which this constraint returns true
*/
protected String expectedArchitectureContextId;
/**
* @see org.eclipse.papyrus.infra.constraints.constraints.AbstractConstraint#setDescriptor(org.eclipse.papyrus.infra.constraints.SimpleConstraint)
*
* Read the value defined for the property ARCHITECTURE_CONTEXT_PROPERTY_NAME
*/
@Override
protected void setDescriptor(SimpleConstraint descriptor) {
expectedArchitectureContextId = getValue(ARCHITECTURE_CONTEXT_PROPERTY_NAME);
}
/**
* @see org.eclipse.papyrus.infra.constraints.constraints.AbstractConstraint#match(java.lang.Object)
*
* If the selection is a UML element and the edition occurs in the expected architecture
* context then return true; false otherwise.
*/
@Override
protected boolean match(Object selection) {
boolean match = false;
Element element = UMLUtil.resolveUMLElement(selection);
if (element != null) {
EditingDomain domain = UMLUtil.resolveEditingDomain(element);
if (domain instanceof PapyrusTransactionalEditingDomain) {
ArchitectureDescriptionUtils adUtils = new ArchitectureDescriptionUtils(
(ModelSet) ((PapyrusTransactionalEditingDomain) domain).getResourceSet());
MergedArchitectureContext architectureContext = adUtils.getArchitectureContext();
if (architectureContext != null) {
match = architectureContext.getId().equals(expectedArchitectureContextId);
}
}
}
return match;
}
/**
* @see org.eclipse.papyrus.infra.constraints.constraints.AbstractConstraint#equivalent(org.eclipse.papyrus.infra.constraints.constraints.Constraint)
*
* Two constraints can only be equivalent if (1) they designate the same object or (2) they are different object of the same type with equal values for their properties
*/
@Override
protected boolean equivalent(Constraint constraint) {
boolean equivalent = this == constraint;
if (!equivalent) {
if (constraint != null && constraint instanceof IsValidArchitectureContext) {
equivalent = expectedArchitectureContextId.equals(((IsValidArchitectureContext) constraint).expectedArchitectureContextId);
}
}
return equivalent;
}
}
|