Skip to content

Package: ControlRevealProvider

ControlRevealProvider

nameinstructionbranchcomplexitylinemethod
ControlRevealProvider()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
canReveal(VControl, EObject, EStructuralFeature, EMFFormsSettingToControlMapper)
M: 0 C: 16
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 4
100%
M: 0 C: 1
100%
lambda$0(VControl, ViewModelContext)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$1(VControl, ViewModelContext)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
reveal(VControl, EObject, EStructuralFeature, ViewModelContext)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
scrollToReveal(VControl, ViewModelContext)
M: 0 C: 11
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2019 Christian W. Damus 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: * Christian W. Damus - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.swt.core;
15:
16: import static org.eclipse.emf.ecp.common.spi.UniqueSetting.createSetting;
17:
18: import org.eclipse.emf.ecore.EObject;
19: import org.eclipse.emf.ecore.EStructuralFeature;
20: import org.eclipse.emf.ecp.view.model.common.AbstractRenderer;
21: import org.eclipse.emf.ecp.view.model.common.di.annotations.ViewService;
22: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
23: import org.eclipse.emf.ecp.view.spi.model.VControl;
24: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
25: import org.eclipse.emfforms.bazaar.Bid;
26: import org.eclipse.emfforms.bazaar.Create;
27: import org.eclipse.emfforms.spi.core.services.controlmapper.EMFFormsSettingToControlMapper;
28: import org.eclipse.emfforms.spi.core.services.reveal.EMFFormsRevealProvider;
29: import org.eclipse.emfforms.spi.core.services.reveal.RevealStep;
30: import org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer;
31: import org.eclipse.swt.widgets.Display;
32: import org.osgi.service.component.annotations.Component;
33:
34: /**
35: * A reveal provider for {@link VControl}s that reveals a specific {@link EStructuralFeature} setting.
36: *
37: * @since 1.22
38: */
39: @Component(name = "controlRevealProvider")
40: public class ControlRevealProvider implements EMFFormsRevealProvider {
41:
42:         private final Double controlBid = 10.0;
43:
44:         /**
45:          * I bid on the {@code control} if it is presents the given {@code feature} of the domain
46:          * model {@code object}.
47:          *
48:          * @param control the element to bid on
49:          * @param object the domain object to bid on
50:          * @param feature the feature of the domain {@code object} to bid on
51:          * @param settingMapper the setting-to-control mapper service
52:          * @return my bid
53:          */
54:         @Bid
55:         public Double canReveal(VControl control, EObject object, EStructuralFeature feature,
56:                 @ViewService EMFFormsSettingToControlMapper settingMapper) {
57:
58:                 // Not a complex control such as table that is handled separately
59:•                return control.eClass() == VViewPackage.Literals.CONTROL
60:•                        && settingMapper.hasMapping(createSetting(object, feature), control)
61:                                 ? controlBid
62:                                 : null;
63:         }
64:
65:         /**
66:          * Create a terminal reveal step to focus into the specific setting {@code control}
67:          * in a that presents a {@code feature} or an {@code object}.
68:          *
69:          * @param control the control to reveal
70:          * @param object the object to reveal
71:          * @param feature the feature of the domain {@code object} to reveal
72:          * @param context the view-model context in which the {@code control} is rendered
73:          * @return the specific control reveal step
74:          */
75:         @Create
76:         public RevealStep reveal(VControl control, EObject object,
77:                 EStructuralFeature feature, ViewModelContext context) {
78:
79:                 return RevealStep.reveal(control, object, feature,
80:                         // Scroll to reveal the control in the future, when it has been
81:                         // rendered by the previous reveal step (bug 551066)
82:                         () -> Display.getDefault().asyncExec(() -> scrollToReveal(control, context)));
83:         }
84:
85:         /**
86:          * Scroll to reveal the rendered {@code control}.
87:          *
88:          * @param control a control rendered in some {@code context}
89:          * @param context the context in which the {@code control} is rendered
90:          */
91:         private void scrollToReveal(VControl control, ViewModelContext context) {
92:                 final AbstractRenderer<?> renderer = AbstractRenderer.getRenderer(control, context);
93:•                if (renderer instanceof AbstractSWTRenderer<?>) {
94:                         ((AbstractSWTRenderer<?>) renderer).scrollToReveal();
95:                 }
96:         }
97:
98: }