Skip to content

Package: AbstractControlSWTRendererUtil

AbstractControlSWTRendererUtil

nameinstructionbranchcomplexitylinemethod
getDefaultMandatoryStyle()
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%
getLabelStyleBits(VTViewTemplateProvider, VElement, ViewModelContext)
M: 0 C: 43
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 19
100%
M: 0 C: 1
100%
getMandatoryStyle(VTViewTemplateProvider, VControl, ViewModelContext)
M: 5 C: 24
83%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 2 C: 6
75%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2018 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.emf.ecp.view.spi.core.swt;
15:
16: import java.util.Set;
17:
18: import org.eclipse.emf.ecp.view.model.common.util.RendererUtil;
19: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
20: import org.eclipse.emf.ecp.view.spi.model.VControl;
21: import org.eclipse.emf.ecp.view.spi.model.VElement;
22: import org.eclipse.emf.ecp.view.template.model.VTStyleProperty;
23: import org.eclipse.emf.ecp.view.template.model.VTViewTemplateProvider;
24: import org.eclipse.emf.ecp.view.template.style.alignment.model.VTControlLabelAlignmentStyleProperty;
25: import org.eclipse.emf.ecp.view.template.style.mandatory.model.VTMandatoryFactory;
26: import org.eclipse.emf.ecp.view.template.style.mandatory.model.VTMandatoryStyleProperty;
27: import org.eclipse.emf.ecp.view.template.style.wrap.model.VTLabelWrapStyleProperty;
28: import org.eclipse.swt.SWT;
29:
30: /**
31: * Holds some Util methods for the {@link AbstractControlSWTRendererUtil} which may be reused by renderers which cannot
32: * inherit from {@link AbstractControlSWTRendererUtil} but want to reuse functionality.
33: *
34: * @author Johannes Faltermeier
35: * @since 1.17
36: *
37: */
38: public final class AbstractControlSWTRendererUtil {
39:
40:         private AbstractControlSWTRendererUtil() {
41:                 /* util */
42:         }
43:
44:         /**
45:          * The style bits for a control label.
46:          *
47:          * @param viewTemplateProvider the {@link VTViewTemplateProvider}
48:          * @param control the {@link VElement}
49:          * @param viewModelContext the {@link ViewModelContext}
50:          * @return the style bits
51:          * @since 1.18
52:          */
53:         public static int getLabelStyleBits(VTViewTemplateProvider viewTemplateProvider, VElement control,
54:                 ViewModelContext viewModelContext) {
55:                 final VTControlLabelAlignmentStyleProperty alignmentStyleProperty = RendererUtil.getStyleProperty(
56:                         viewTemplateProvider,
57:                         control,
58:                         viewModelContext,
59:                         VTControlLabelAlignmentStyleProperty.class);
60:
61:                 int bits = SWT.NONE;
62:
63:•                if (alignmentStyleProperty != null) {
64:•                        switch (alignmentStyleProperty.getType()) {
65:                         case RIGHT:
66:                                 bits |= SWT.RIGHT;
67:                                 break;
68:                         default:
69:                                 break;
70:                         }
71:                 }
72:
73:                 final VTLabelWrapStyleProperty wrapStyleProperty = RendererUtil.getStyleProperty(
74:                         viewTemplateProvider,
75:                         control,
76:                         viewModelContext,
77:                         VTLabelWrapStyleProperty.class);
78:
79:•                if (wrapStyleProperty != null) {
80:•                        if (VTLabelWrapStyleProperty.class.cast(wrapStyleProperty).isWrapLabel()) {
81:                                 bits |= SWT.WRAP;
82:                         }
83:                 }
84:
85:                 return bits;
86:         }
87:
88:         /**
89:          * The {@link VTMandatoryStyleProperty} property.
90:          *
91:          * @param vtViewTemplateProvider the {@link VTViewTemplateProvider}
92:          * @param control the {@link VControl}
93:          * @param viewModelContext the {@link ViewModelContext}
94:          * @return the property
95:          */
96:         public static VTMandatoryStyleProperty getMandatoryStyle(
97:                 VTViewTemplateProvider vtViewTemplateProvider,
98:                 VControl control,
99:                 ViewModelContext viewModelContext) {
100:
101:•                if (vtViewTemplateProvider == null) {
102:                         return getDefaultMandatoryStyle();
103:                 }
104:                 final Set<VTStyleProperty> styleProperties = vtViewTemplateProvider
105:                         .getStyleProperties(control, viewModelContext);
106:•                for (final VTStyleProperty styleProperty : styleProperties) {
107:•                        if (VTMandatoryStyleProperty.class.isInstance(styleProperty)) {
108:                                 return (VTMandatoryStyleProperty) styleProperty;
109:                         }
110:                 }
111:                 return getDefaultMandatoryStyle();
112:         }
113:
114:         private static VTMandatoryStyleProperty getDefaultMandatoryStyle() {
115:                 return VTMandatoryFactory.eINSTANCE.createMandatoryStyleProperty();
116:         }
117:
118: }