Skip to content

Package: ECPSubstitutionLabelProvider

ECPSubstitutionLabelProvider

nameinstructionbranchcomplexitylinemethod
ECPSubstitutionLabelProvider(AdapterFactory)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getFeatureLabel(EStructuralFeature)
M: 0 C: 39
100%
M: 1 C: 7
88%
M: 1 C: 4
80%
M: 0 C: 12
100%
M: 0 C: 1
100%
getObjectLabel(EObject)
M: 0 C: 22
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 6
100%
M: 0 C: 1
100%
getValueLabel(EDataType, Object)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 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: package org.eclipse.emf.ecp.view.internal.validation;
15:
16: import org.eclipse.emf.common.notify.AdapterFactory;
17: import org.eclipse.emf.ecore.EClass;
18: import org.eclipse.emf.ecore.EDataType;
19: import org.eclipse.emf.ecore.EObject;
20: import org.eclipse.emf.ecore.EStructuralFeature;
21: import org.eclipse.emf.ecore.EValidator;
22: import org.eclipse.emf.ecore.impl.DynamicEObjectImpl;
23: import org.eclipse.emf.ecore.util.EcoreUtil;
24: import org.eclipse.emf.edit.provider.AdapterFactoryItemDelegator;
25: import org.eclipse.emf.edit.provider.IItemLabelProvider;
26: import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
27:
28: /**
29: * An ECP ECPSubstitutionLabelProvider used in the validation context.
30: *
31: * @author Eugen Neufeld
32: *
33: */
34: public final class ECPSubstitutionLabelProvider implements EValidator.SubstitutionLabelProvider {
35:
36:         private final AdapterFactory factory;
37:         private final AdapterFactoryItemDelegator adapterFactoryItemDelegator;
38:
39:         /**
40:          * Creates an {@link ECPSubstitutionLabelProvider}.
41:          *
42:          * @param factory the {@link AdapterFactory} to use
43:          */
44:         public ECPSubstitutionLabelProvider(AdapterFactory factory) {
45:                 this.factory = factory;
46:                 adapterFactoryItemDelegator = new AdapterFactoryItemDelegator(factory);
47:         }
48:
49:         @Override
50:         public String getObjectLabel(EObject eObject) {
51:                 final Object provider = factory.adapt(
52:                         eObject,
53:                         IItemLabelProvider.class);
54:•                if (provider == null || !IItemLabelProvider.class.isInstance(provider)) {
55:                         return EcoreUtil.getIdentification(eObject);
56:                 }
57:                 return IItemLabelProvider.class.cast(provider).getText(eObject);
58:         }
59:
60:         @Override
61:         public String getFeatureLabel(EStructuralFeature eStructuralFeature) {
62:                 final EClass eClass = eStructuralFeature.getEContainingClass();
63:•                if (eClass.isInterface() || eClass.isAbstract()) {
64:                         return eStructuralFeature.getName();
65:                 }
66:                 EObject tempInstance;
67:•                if (eClass.getInstanceClass() != null) {
68:                         tempInstance = EcoreUtil.create(eClass);
69:                 } else {
70:                         tempInstance = new DynamicEObjectImpl(eClass);
71:                 }
72:                 final IItemPropertyDescriptor itemPropertyDescriptor = adapterFactoryItemDelegator.getPropertyDescriptor(
73:                         tempInstance, eStructuralFeature);
74:
75:•                if (itemPropertyDescriptor == null) {
76:                         return eStructuralFeature.getName();
77:                 }
78:                 return itemPropertyDescriptor.getDisplayName(eStructuralFeature);
79:         }
80:
81:         /**
82:          * {@inheritDoc}
83:          *
84:          * @see org.eclipse.emf.ecore.EValidator.SubstitutionLabelProvider#getValueLabel(org.eclipse.emf.ecore.EDataType,
85:          * java.lang.Object)
86:          */
87:         @Override
88:         public String getValueLabel(EDataType eDataType, Object value) {
89:                 return EcoreUtil.convertToString(eDataType, value);
90:         }
91: }