Skip to content

Package: ReferenceMultiControlTester

ReferenceMultiControlTester

nameinstructionbranchcomplexitylinemethod
ReferenceMultiControlTester()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getTesterPriority(ECPStaticApplicableTester, EStructuralFeature, EObject)
M: 45 C: 11
20%
M: 15 C: 3
17%
M: 8 C: 2
20%
M: 11 C: 4
27%
M: 0 C: 1
100%
isApplicable(EObject, EStructuralFeature)
M: 6 C: 50
89%
M: 2 C: 8
80%
M: 2 C: 4
67%
M: 3 C: 11
79%
M: 0 C: 1
100%
isApplicable(IItemPropertyDescriptor, EObject)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isApplicable(VDomainModelReference)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2013 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Eugen Neufeld - initial API and implementation
13: *
14: *******************************************************************************/
15: package org.eclipse.emf.ecp.edit.internal.swt.reference;
16:
17: import org.eclipse.emf.ecore.EAttribute;
18: import org.eclipse.emf.ecore.EObject;
19: import org.eclipse.emf.ecore.EReference;
20: import org.eclipse.emf.ecore.EStructuralFeature;
21: import org.eclipse.emf.ecp.edit.internal.swt.Activator;
22: import org.eclipse.emf.ecp.edit.spi.ECPControlDescription;
23: import org.eclipse.emf.ecp.edit.spi.ECPControlFactory;
24: import org.eclipse.emf.ecp.edit.spi.util.ECPApplicableTester;
25: import org.eclipse.emf.ecp.edit.spi.util.ECPStaticApplicableTester;
26: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
27: import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
28:
29: /**
30: * This is a dynamic tester for an reference multi control. It tests whether there is a control with a static tester
31: * which would fit.
32: *
33: * @author Eugen Neufeld
34: *
35: */
36: @Deprecated
37: public class ReferenceMultiControlTester implements ECPApplicableTester {
38:
39:         /**
40:          * {@inheritDoc}
41:          *
42:          * @deprecated
43:          **/
44:         @Override
45:         @Deprecated
46:         public int isApplicable(IItemPropertyDescriptor itemPropertyDescriptor, EObject eObject) {
47:                 return isApplicable(eObject, (EStructuralFeature) itemPropertyDescriptor.getFeature(eObject));
48:         }
49:
50:         /**
51:          *
52:          * {@inheritDoc}
53:          *
54:          * @see org.eclipse.emf.ecp.edit.spi.util.ECPApplicableTester#isApplicable(org.eclipse.emf.ecore.EObject,
55:          * org.eclipse.emf.ecore.EStructuralFeature)
56:          */
57:         @Override
58:         public int isApplicable(EObject eObject, EStructuralFeature eStructuralFeature) {
59:                 int bestPriority = NOT_APPLICABLE;
60:                 final ECPControlFactory controlFactory = Activator.getDefault().getECPControlFactory();
61:•                if (controlFactory == null) {
62:                         Activator.getDefault().ungetECPControlFactory();
63:                         return bestPriority;
64:                 }
65:•                for (final ECPControlDescription description : controlFactory.getControlDescriptors()) {
66:•                        for (final ECPApplicableTester tester : description.getTester()) {
67:•                                if (ECPStaticApplicableTester.class.isInstance(tester)) {
68:                                         final ECPStaticApplicableTester test = (ECPStaticApplicableTester) tester;
69:                                         final int priority = getTesterPriority(test, eStructuralFeature, eObject);
70:•                                        if (bestPriority < priority) {
71:                                                 bestPriority = priority;
72:                                         }
73:                                 } else {
74:                                         continue;
75:                                 }
76:                         }
77:                 }
78:                 Activator.getDefault().ungetECPControlFactory();
79:                 return bestPriority;
80:         }
81:
82:         /**
83:          * Calculates the priority of the attribute tester.
84:          *
85:          * @param tester the tester to get the priority for
86:          * @param feature the {@link EStructuralFeature}
87:          * @param eObject the {@link EObject}
88:          * @return the priority
89:          */
90:         public static int getTesterPriority(ECPStaticApplicableTester tester,
91:                 EStructuralFeature feature, EObject eObject) {
92:
93:•                if (!feature.isMany()) {
94:                         return NOT_APPLICABLE;
95:                 }
96:•                if (EAttribute.class.isInstance(feature)) {
97:                         return NOT_APPLICABLE;
98:•                } else if (EReference.class.isInstance(feature)) {
99:                         // if (((EReference) feature).isContainment()) {
100:                         // return NOT_APPLICABLE;
101:                         // }
102:                         final Class<?> instanceClass = feature.getEType().getInstanceClass();
103:•                        if (instanceClass != null && !tester.getSupportedClassType().isAssignableFrom(instanceClass)) {
104:                                 return NOT_APPLICABLE;
105:                         }
106:                 }
107:•                if (!tester.isSingleValue()) {
108:                         return NOT_APPLICABLE;
109:                 }
110:•                if (tester.getSupportedEObject().isInstance(eObject)
111:•                        && (tester.getSupportedFeature() == null || feature.equals(eObject.eClass().getEStructuralFeature(
112:•                                tester.getSupportedFeature())))) {
113:                         return tester.getPriority() + 1;
114:                 }
115:                 return NOT_APPLICABLE;
116:         }
117:
118:         /**
119:          * {@inheritDoc}
120:          *
121:          * @see org.eclipse.emf.ecp.edit.spi.util.ECPApplicableTester#isApplicable(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference)
122:          * @deprecated
123:          */
124:         @Override
125:         @Deprecated
126:         public int isApplicable(VDomainModelReference domainModelReference) {
127:                 return NOT_APPLICABLE;
128:         }
129:
130: }