blob: 5df7496103b38fc0e8bf4db98618c696aa6e4fbb (
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
|
/*****************************************************************************
* Copyright (c) 2014 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:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
*****************************************************************************/
package org.eclipse.papyrus.emf.facet.custom.ui.internal.query;
import java.util.Collection;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.papyrus.emf.facet.efacet.core.IFacetManager;
import org.eclipse.papyrus.emf.facet.efacet.core.exception.DerivedTypedElementException;
import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetReference;
import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.ParameterValue;
import org.eclipse.papyrus.emf.facet.query.java.core.IJavaQuery2;
import org.eclipse.papyrus.emf.facet.query.java.core.IParameterValueList2;
/**
* Determines the default value for visibility
*
* False for EAttributes and empty references, true otherwise
*
* Default implementation in EMF Facet is always true (TrueLiteralQuery)
*
* @author Camille Letavernier
*
*/
public class DefaultVisibilityQuery implements IJavaQuery2<EObject, Boolean> {
public Boolean evaluate(EObject source, IParameterValueList2 parameterValues, IFacetManager facetManager) throws DerivedTypedElementException {
ParameterValue paramValue = parameterValues.getParameterValueByName("eStructuralFeature");
if(paramValue == null) {
return true;
}
EStructuralFeature feature = (EStructuralFeature)paramValue.getValue();
if(feature == null) {
return true;
}
if(feature instanceof EAttribute) {
return false;
}
if(feature instanceof FacetReference) {
return true;
}
if(feature instanceof EReference) {
Object value = source.eGet(feature);
if(value == null) {
return false;
}
if(value instanceof Collection<?>) {
return !((Collection<?>)value).isEmpty();
}
}
return true;
}
}
|