Skip to content

Package: MultiReferenceRevealProvider

MultiReferenceRevealProvider

nameinstructionbranchcomplexitylinemethod
MultiReferenceRevealProvider()
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(ViewModelContext, VControl, EMFFormsDatabinding)
M: 12 C: 25
68%
M: 6 C: 4
40%
M: 4 C: 2
33%
M: 2 C: 9
82%
M: 0 C: 1
100%
doReveal(MultiReferenceSWTRenderer, EObject)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
lambda$0(MultiReferenceSWTRenderer, EObject)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
reveal(ViewModelContext, RevealHelper, VControl, EObject, EMFFormsDatabinding)
M: 21 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%

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.emf.ecp.view.internal.control.multireference;
15:
16: import org.eclipse.core.databinding.observable.list.IObservableList;
17: import org.eclipse.core.databinding.property.value.IValueProperty;
18: import org.eclipse.emf.ecore.EObject;
19: import org.eclipse.emf.ecore.EReference;
20: import org.eclipse.emf.ecp.view.model.common.di.annotations.Renderer;
21: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
22: import org.eclipse.emf.ecp.view.spi.model.VControl;
23: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
24: import org.eclipse.emfforms.bazaar.Bid;
25: import org.eclipse.emfforms.bazaar.Create;
26: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
27: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
28: import org.eclipse.emfforms.spi.core.services.reveal.EMFFormsRevealProvider;
29: import org.eclipse.emfforms.spi.core.services.reveal.Reveal;
30: import org.eclipse.emfforms.spi.core.services.reveal.RevealHelper;
31: import org.eclipse.emfforms.spi.core.services.reveal.RevealStep;
32: import org.osgi.service.component.annotations.Component;
33:
34: /**
35: * A reveal provider for multi-reference controls that show contained objects
36: * (not just cross-referenced).
37: */
38: @Component(name = "multiReferenceRevealProvider")
39: public class MultiReferenceRevealProvider implements EMFFormsRevealProvider {
40:
41:         private final Double basicBid = 1.0;
42:
43:         /**
44:          * I bid on the {@code element} if it is a simple {@link VControl} specified by
45:          * a DMR that resolves to a multi-valued containment reference.
46:          *
47:          * @param context the view model context in which to resolve the DMR
48:          * @param control the control to bid on
49:          * @param databinding the databinding service in which to resolve the DMR
50:          * @return my bid
51:          * @throws DatabindingFailedException on failure to resolve the DMR
52:          */
53:         @Bid
54:         public Double canReveal(ViewModelContext context, VControl control, EMFFormsDatabinding databinding)
55:                 throws DatabindingFailedException {
56:
57:                 Double result = null;
58:
59:                 EReference resolvedReference = null;
60:
61:                 // Not a specialization like TableControl
62:•                if (control.eClass() == VViewPackage.Literals.CONTROL) {
63:                         final IValueProperty<?, ?> property = databinding.getValueProperty(control.getDomainModelReference(),
64:                                 context.getDomainModel());
65:                         final Object propertyType = property.getValueType();
66:•                        if (propertyType instanceof EReference) {
67:                                 resolvedReference = (EReference) propertyType;
68:                         }
69:                 }
70:
71:•                if (resolvedReference != null && resolvedReference.isMany() && resolvedReference.isContainment()) {
72:                         result = basicBid;
73:                 }
74:
75:                 return result;
76:         }
77:
78:         /**
79:          * Create a terminal reveal step to select and reveal the {@code object} in the
80:          * rendered {@code element}.
81:          *
82:          * @param context the view model context in which to find a renderer for the tree
83:          * @param helper a helper for deferred revealing
84:          * @param control the multi-reference control view model
85:          * @param object the object to reveal
86:          * @param databinding the databinding service in which to resolve the DMR
87:          * @return the drill-down reveal step
88:          * @throws DatabindingFailedException on failure to resolve the DMR
89:          */
90:         @Create
91:         public RevealStep reveal(ViewModelContext context, RevealHelper helper, VControl control, EObject object,
92:                 EMFFormsDatabinding databinding) throws DatabindingFailedException {
93:
94:                 RevealStep result = RevealStep.FAILED;
95:
96:                 final IObservableList<?> list = databinding.getObservableList(control.getDomainModelReference(),
97:                         context.getDomainModel());
98:•                if (list != null && list.contains(object)) {
99:                         result = helper.defer(this);
100:                 }
101:
102:                 return result;
103:         }
104:
105:         @Reveal
106:         private RevealStep doReveal(@Renderer MultiReferenceSWTRenderer renderer, EObject object) {
107:                 final VControl control = renderer.getVElement();
108:                 return RevealStep.reveal(control, object, () -> renderer.reveal(object));
109:         }
110:
111: }