Skip to content

Package: ContainerRevealProvider

ContainerRevealProvider

nameinstructionbranchcomplexitylinemethod
ContainerRevealProvider()
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
canReveal(VElement)
M: 0 C: 14
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
drillDown(EObject, AbstractSWTRenderer, RevealStep)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
reveal(VElement, EObject, RevealHelper)
M: 0 C: 6
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) 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 org.eclipse.emf.common.util.ECollections;
17: import org.eclipse.emf.common.util.EList;
18: import org.eclipse.emf.ecore.EObject;
19: import org.eclipse.emf.ecore.util.Switch;
20: import org.eclipse.emf.ecp.view.model.common.di.annotations.Renderer;
21: import org.eclipse.emf.ecp.view.spi.model.VContainer;
22: import org.eclipse.emf.ecp.view.spi.model.VElement;
23: import org.eclipse.emf.ecp.view.spi.model.VView;
24: import org.eclipse.emf.ecp.view.spi.model.util.ViewSwitch;
25: import org.eclipse.emfforms.bazaar.Bid;
26: import org.eclipse.emfforms.bazaar.Create;
27: import org.eclipse.emfforms.spi.core.services.reveal.DrillDown;
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.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer;
33: import org.osgi.service.component.annotations.Component;
34:
35: /**
36: * A reveal provider for {@link VContainer}s and {@link VView}s.
37: *
38: * @since 1.22
39: */
40: @Component(name = "containerRevealProvider")
41: public class ContainerRevealProvider implements EMFFormsRevealProvider {
42:
43:         private final Double containerBid = 5.0;
44:         private final Double viewBid = 1.0;
45:
46:         private final Switch<EList<? extends VElement>> childrenSwitch = new ViewSwitch<EList<? extends VElement>>() {
47:                 @Override
48:                 public EList<? extends VElement> caseView(VView object) {
49:                         return object.getChildren();
50:                 }
51:
52:                 @Override
53:                 public EList<? extends VElement> caseContainer(VContainer object) {
54:                         return object.getChildren();
55:                 }
56:
57:                 @Override
58:                 public EList<? extends VElement> defaultCase(EObject object) {
59:                         return ECollections.emptyEList();
60:                 }
61:
62:                 @DrillDown
63:                 private Iterable<? extends VElement> drillDown(VElement element) {
64:                         return childrenSwitch.doSwitch(element);
65:                 }
66:         };
67:
68:         /**
69:          * I bid on the {@code element} if it is a {@link VContainer}
70:          * or a {@link VView}.
71:          *
72:          * @param element the element to bid on
73:          * @return my bid
74:          */
75:         @Bid
76:         public Double canReveal(VElement element) {
77:•                return element instanceof VContainer ? containerBid
78:•                        : element instanceof VView ? viewBid
79:                                 : null;
80:         }
81:
82:         /**
83:          * Create an intermediate reveal step to drill down into a container {@code element}.
84:          *
85:          * @param element the container in which to drill down
86:          * @param object the object to reveal
87:          * @param helper the reveal helper for drill-down
88:          * @return the drill-down reveal step
89:          */
90:         @Create
91:         public RevealStep reveal(VElement element, EObject object, RevealHelper helper) {
92:                 return helper.drillDown(this, childrenSwitch);
93:         }
94:
95:         @Reveal
96:         private RevealStep drillDown(EObject object, @Renderer AbstractSWTRenderer<?> renderer,
97:                 RevealStep nextStep) {
98:
99:                 return RevealStep.reveal(nextStep.getViewModel(), object, renderer::scrollToReveal);
100:         }
101:
102: }