Skip to content

Package: AttributeMultiControlTester

AttributeMultiControlTester

nameinstructionbranchcomplexitylinemethod
AttributeMultiControlTester()
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: 44 C: 42
49%
M: 13 C: 11
46%
M: 10 C: 3
23%
M: 16 C: 11
41%
M: 0 C: 1
100%
isApplicable(EObject, EStructuralFeature)
M: 4 C: 52
93%
M: 1 C: 9
90%
M: 1 C: 5
83%
M: 2 C: 12
86%
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.controls;
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 attribute 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 AttributeMultiControlTester 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:          * {@inheritDoc}
52:          *
53:          * @see org.eclipse.emf.ecp.edit.spi.util.ECPApplicableTester#isApplicable(org.eclipse.emf.ecore.EObject,
54:          * org.eclipse.emf.ecore.EStructuralFeature)
55:          */
56:         @Override
57:         public int isApplicable(EObject eObject, EStructuralFeature feature) {
58:                 int bestPriority = NOT_APPLICABLE;
59:                 final ECPControlFactory controlFactory = Activator.getDefault().getECPControlFactory();
60:•                if (controlFactory == null) {
61:                         Activator.getDefault().ungetECPControlFactory();
62:                         return bestPriority;
63:                 }
64:•                for (final ECPControlDescription description : controlFactory.getControlDescriptors()) {
65:•                        for (final ECPApplicableTester tester : description.getTester()) {
66:•                                if (ECPStaticApplicableTester.class.isInstance(tester)) {
67:                                         final ECPStaticApplicableTester test = (ECPStaticApplicableTester) tester;
68:                                         final int priority = getTesterPriority(test, feature, eObject);
69:•                                        if (bestPriority < priority) {
70:                                                 bestPriority = priority;
71:                                         }
72:                                 } else {
73:                                         continue;
74:                                 }
75:                         }
76:                 }
77:                 Activator.getDefault().ungetECPControlFactory();
78:                 return bestPriority;
79:         }
80:
81:         /**
82:          * Calculates the priority of the attribute tester.
83:          *
84:          * @param tester the tester to get the priority for
85:          * @param feature the {@link EStructuralFeature}
86:          * @param eObject the {@link EObject}
87:          * @return the priority
88:          */
89:         public static int getTesterPriority(ECPStaticApplicableTester tester,
90:                 EStructuralFeature feature, EObject eObject) {
91:•                if (!feature.isMany()) {
92:                         return NOT_APPLICABLE;
93:                 }
94:
95:•                if (EAttribute.class.isInstance(feature)) {
96:                         final Class<?> instanceClass = ((EAttribute) feature).getEAttributeType().getInstanceClass();
97:•                        if (instanceClass != null && instanceClass.isPrimitive()) {
98:                                 try {
99:                                         final Class<?> primitive = (Class<?>) tester.getSupportedClassType().getField("TYPE").get(null);//$NON-NLS-1$
100:•                                        if (!primitive.equals(instanceClass)) {
101:                                                 return NOT_APPLICABLE;
102:                                         }
103:
104:                                 } catch (final IllegalArgumentException e) {
105:                                         return NOT_APPLICABLE;
106:                                 } catch (final SecurityException e) {
107:                                         return NOT_APPLICABLE;
108:                                 } catch (final IllegalAccessException e) {
109:                                         return NOT_APPLICABLE;
110:                                 } catch (final NoSuchFieldException e) {
111:                                         return NOT_APPLICABLE;
112:                                 }
113:•                        } else if (instanceClass != null && !tester.getSupportedClassType().isAssignableFrom(instanceClass)) {
114:                                 return NOT_APPLICABLE;
115:                         }
116:•                } else if (EReference.class.isInstance(feature)) {
117:                         return NOT_APPLICABLE;
118:                 }
119:•                if (!tester.isSingleValue()) {
120:                         return NOT_APPLICABLE;
121:                 }
122:•                if (tester.getSupportedEObject().isInstance(eObject)
123:•                        && (tester.getSupportedFeature() == null || feature.equals(eObject.eClass().getEStructuralFeature(
124:•                                tester.getSupportedFeature())))) {
125:                         return tester.getPriority();
126:                 }
127:                 return NOT_APPLICABLE;
128:         }
129:
130:         /**
131:          * {@inheritDoc}
132:          *
133:          * @see org.eclipse.emf.ecp.edit.spi.util.ECPApplicableTester#isApplicable(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference)
134:          * @deprecated
135:          *
136:          */
137:         @Override
138:         @Deprecated
139:         public int isApplicable(VDomainModelReference domainModelReference) {
140:                 return NOT_APPLICABLE;
141:         }
142:
143: }