Skip to content

Package: TableDetailRevealProvider

TableDetailRevealProvider

nameinstructionbranchcomplexitylinemethod
TableDetailRevealProvider()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
canReveal(VTableControl, EObject, EStructuralFeature, ViewModelContext)
M: 3 C: 17
85%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 1 C: 5
83%
M: 0 C: 1
100%
containsRecursively(ViewModelContext, VTableControl, EObject)
M: 0 C: 25
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getParent(ViewModelContext, VTableControl, EObject)
M: 0 C: 31
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getTableInput(ViewModelContext, VTableControl)
M: 1 C: 15
94%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
lambda$2(EObject, EObject)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$5(EObject, EObject)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$6(TableControlSWTRenderer, EObject)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
reveal(ViewModelContext, RevealHelper, VTableControl, EObject)
M: 0 C: 15
100%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 4
100%
M: 0 C: 1
100%
revealMaster(TableControlSWTRenderer, EObject)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
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.emf.ecp.view.internal.table.swt;
15:
16: import org.eclipse.core.databinding.observable.Observables;
17: import org.eclipse.core.databinding.observable.list.IObservableList;
18: import org.eclipse.e4.core.di.annotations.Optional;
19: import org.eclipse.emf.ecore.EObject;
20: import org.eclipse.emf.ecore.EStructuralFeature;
21: import org.eclipse.emf.ecore.util.EcoreUtil;
22: import org.eclipse.emf.ecp.view.model.common.di.annotations.Renderer;
23: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
24: import org.eclipse.emf.ecp.view.spi.table.model.DetailEditing;
25: import org.eclipse.emf.ecp.view.spi.table.model.VTableControl;
26: import org.eclipse.emf.ecp.view.spi.table.swt.TableControlSWTRenderer;
27: import org.eclipse.emfforms.bazaar.Bid;
28: import org.eclipse.emfforms.bazaar.Create;
29: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
30: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
31: import org.eclipse.emfforms.spi.core.services.reveal.DrillUp;
32: import org.eclipse.emfforms.spi.core.services.reveal.EMFFormsRevealProvider;
33: import org.eclipse.emfforms.spi.core.services.reveal.Reveal;
34: import org.eclipse.emfforms.spi.core.services.reveal.RevealHelper;
35: import org.eclipse.emfforms.spi.core.services.reveal.RevealStep;
36: import org.osgi.service.component.annotations.Component;
37:
38: /**
39: * A reveal provider for {@link VTableControl}s that reveals objects presented in the details
40: * of some object in the table. This is a heuristic guess based on containment (recursively)
41: * of the object to be revealed within some object in the table. Applications are advised
42: * to provide higher bids to more reliably/appropriately reveal objects in these master-detail
43: * configurations.
44: *
45: * @since 1.22
46: */
47: @Component(name = "tableDetailRevealProvider")
48: public class TableDetailRevealProvider implements EMFFormsRevealProvider {
49:
50:         private final Double featureBid = 11.0;
51:         private final Double tableBid = 1.0;
52:
53:         /**
54:          * I bid on the {@code element} if it is a {@link VTableControl} that has a row
55:          * representing an {@link EObject} containing (recursively) the {@code object}
56:          * to be revealed and the table control has a detail panel.
57:          *
58:          * @param tableControl the table control to bid on
59:          * @param object the object to be revealed
60:          * @param feature provider of the optional feature being revealed
61:          * @param context the context in which the table is rendered
62:          *
63:          * @return my bid
64:          */
65:         @Bid
66:         public Double canReveal(VTableControl tableControl, EObject object,
67:                 @Optional EStructuralFeature feature, ViewModelContext context) {
68:
69:•                return tableControl.getDetailEditing() == DetailEditing.WITH_PANEL
70:•                        && containsRecursively(context, tableControl, object)
71:•                                ? feature != null
72:                                         ? featureBid // Expect that we can reveal this property of the object
73:                                         : tableBid
74:                                 : null;
75:         }
76:
77:         private boolean containsRecursively(ViewModelContext context, VTableControl tableControl, EObject object) {
78:                 boolean result;
79:
80:                 final IObservableList<?> list = getTableInput(context, tableControl);
81:                 result = list.stream().filter(EObject.class::isInstance).map(EObject.class::cast)
82:                         .anyMatch(ancestor -> EcoreUtil.isAncestor(ancestor, object));
83:
84:                 return result;
85:         }
86:
87:         private IObservableList<?> getTableInput(ViewModelContext context, VTableControl tableControl) {
88:                 IObservableList<?> result = Observables.emptyObservableList();
89:
90:                 try {
91:                         result = context.getService(EMFFormsDatabinding.class)
92:                                 .getObservableList(tableControl.getDomainModelReference(), context.getDomainModel());
93:                 } catch (final DatabindingFailedException e) {
94:                         // The object cannot be in this table, then
95:                 }
96:
97:                 return result;
98:         }
99:
100:         /**
101:          * Create a reveal step to drill down into the table's details.
102:          *
103:          * @param context the view model context in which to find a renderer for the table
104:          * @param helper a helper for deferred revealing
105:          * @param tableControl the table in which to drill down
106:          * @param object the object to reveal
107:          * @return the drill-down reveal step
108:          */
109:         @Create
110:         public RevealStep reveal(ViewModelContext context, RevealHelper helper, VTableControl tableControl,
111:                 EObject object) {
112:
113:                 RevealStep result = RevealStep.fail();
114:
115:•                if (containsRecursively(context, tableControl, object)) {
116:                         // It's in this table. Defer the access to the renderer because
117:                         // in a categorization it may not yet exist
118:                         result = helper.masterDetail(this, this);
119:                 }
120:
121:                 return result;
122:         }
123:
124:         @DrillUp
125:         private EObject getParent(ViewModelContext context, VTableControl tableControl, EObject object) {
126:                 EObject result = null;
127:
128:                 final IObservableList<?> list = getTableInput(context, tableControl);
129:                 result = list.stream().filter(EObject.class::isInstance).map(EObject.class::cast)
130:                         .filter(ancestor -> EcoreUtil.isAncestor(ancestor, object))
131:                         .findAny().orElse(null);
132:
133:                 return result;
134:         }
135:
136:         @Reveal
137:         private RevealStep revealMaster(@Renderer TableControlSWTRenderer renderer, EObject masterSelection) {
138:                 final VTableControl tableControl = renderer.getVElement();
139:                 return RevealStep.reveal(tableControl, masterSelection, () -> renderer.reveal(masterSelection));
140:         }
141:
142: }