Skip to content

Package: RichTextControlSWTRendererService

RichTextControlSWTRendererService

nameinstructionbranchcomplexitylinemethod
RichTextControlSWTRendererService()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getRendererClass()
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%
hasAutoCompleteAnnotation(EStructuralFeature)
M: 13 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
isApplicable(VElement, ViewModelContext)
M: 75 C: 0
0%
M: 14 C: 0
0%
M: 8 C: 0
0%
M: 23 C: 0
0%
M: 1 C: 0
0%
setDatabinding(EMFFormsDatabinding)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setEMFFormsEditSupport(EMFFormsEditSupport)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2015 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: * Johannes Faltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.swt.control.text.richtext.renderer;
15:
16: import org.eclipse.core.databinding.property.value.IValueProperty;
17: import org.eclipse.emf.ecore.EAttribute;
18: import org.eclipse.emf.ecore.EStructuralFeature;
19: import org.eclipse.emf.ecore.util.EcoreUtil;
20: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
21: import org.eclipse.emf.ecp.view.spi.model.VControl;
22: import org.eclipse.emf.ecp.view.spi.model.VElement;
23: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
24: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
25: import org.eclipse.emfforms.spi.core.services.editsupport.EMFFormsEditSupport;
26: import org.eclipse.emfforms.spi.swt.control.text.richtext.renderer.RichTextControlSWTRenderer;
27: import org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer;
28: import org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService;
29: import org.osgi.service.component.annotations.Component;
30: import org.osgi.service.component.annotations.Reference;
31:
32: /**
33: * {@link EMFFormsDIRendererService Renderer service} for the {@link RichTextControlSWTRenderer}.
34: *
35: * @author jfaltermeier
36: *
37: */
38: @Component
39: public class RichTextControlSWTRendererService implements EMFFormsDIRendererService<VControl> {
40:
41:         private static final String ANNOTATION_SOURCE = "org.eclipse.emfforms"; //$NON-NLS-1$
42:         private static final String ANNOTATION_KEY = "autocomplete"; //$NON-NLS-1$
43:         private static final String ANNOTATION_VALUE = "true"; //$NON-NLS-1$
44:
45:         private EMFFormsDatabinding databinding;
46:         private EMFFormsEditSupport emfFormsEditSupport;
47:
48:         /**
49:          * Sets the {@link EMFFormsDatabinding} service.
50:          *
51:          * @param databinding service
52:          */
53:         @Reference(unbind = "-")
54:         public void setDatabinding(EMFFormsDatabinding databinding) {
55:                 this.databinding = databinding;
56:         }
57:
58:         /**
59:          * Sets the {@link EMFFormsEditSupport}.
60:          *
61:          * @param emfFormsEditSupport {@link EMFFormsEditSupport}
62:          */
63:         @Reference(unbind = "-")
64:         public void setEMFFormsEditSupport(EMFFormsEditSupport emfFormsEditSupport) {
65:                 this.emfFormsEditSupport = emfFormsEditSupport;
66:
67:         }
68:
69:         /**
70:          * {@inheritDoc}
71:          *
72:          * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#isApplicable(org.eclipse.emf.ecp.view.spi.model.VElement,
73:          * org.eclipse.emf.ecp.view.spi.context.ViewModelContext)
74:          */
75:         @Override
76:         public double isApplicable(VElement vElement, ViewModelContext viewModelContext) {
77:                 try {
78:•                        if (!VControl.class.isInstance(vElement)) {
79:                                 return NOT_APPLICABLE;
80:                         }
81:
82:                         final VControl control = VControl.class.cast(vElement);
83:
84:•                        if (control.getDomainModelReference() == null) {
85:                                 return NOT_APPLICABLE;
86:                         }
87:
88:                         @SuppressWarnings("rawtypes")
89:                         final IValueProperty valueProperty = databinding.getValueProperty(control.getDomainModelReference(),
90:                                 viewModelContext.getDomainModel());
91:                         final EStructuralFeature feature = EStructuralFeature.class.cast(valueProperty.getValueType());
92:
93:•                        if (feature.isMany()) {
94:                                 return NOT_APPLICABLE;
95:                         }
96:
97:•                        if (!EAttribute.class.isInstance(feature)) {
98:                                 return NOT_APPLICABLE;
99:                         }
100:
101:                         final EAttribute attribute = EAttribute.class.cast(feature);
102:                         final Class<?> instanceClass = attribute.getEAttributeType().getInstanceClass();
103:•                        if (instanceClass == null) {
104:                                 return NOT_APPLICABLE;
105:                         }
106:
107:•                        if (!String.class.isAssignableFrom(instanceClass)) {
108:                                 return NOT_APPLICABLE;
109:                         }
110:
111:•                        if (emfFormsEditSupport.isMultiLine(control.getDomainModelReference(), viewModelContext.getDomainModel())) {
112:                                 return 10;
113:                         }
114:
115:                 } catch (final DatabindingFailedException ex) {
116:                         return NOT_APPLICABLE;
117:                 }
118:
119:                 return NOT_APPLICABLE;
120:         }
121:
122:         /**
123:          * Checks whether the given feature has an autocomplete annotation which is set to true.
124:          *
125:          * @param feature the feature to check
126:          * @return <code>true</code> if autocomplete should be used, <code>false</code> othwise
127:          */
128:         boolean hasAutoCompleteAnnotation(EStructuralFeature feature) {
129:                 final String annotation = EcoreUtil.getAnnotation(feature, ANNOTATION_SOURCE, ANNOTATION_KEY);
130:•                if (annotation == null) {
131:                         return false;
132:                 }
133:                 return ANNOTATION_VALUE.equalsIgnoreCase(annotation);
134:         }
135:
136:         /**
137:          * {@inheritDoc}
138:          *
139:          * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#getRendererClass()
140:          */
141:         @Override
142:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
143:                 return RichTextControlSWTRenderer.class;
144:         }
145:
146: }