Skip to content

Package: TableRevealProvider

TableRevealProvider

nameinstructionbranchcomplexitylinemethod
TableRevealProvider()
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(VTableControl, EObject, ViewModelContext)
M: 0 C: 11
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
contains(ViewModelContext, VTableControl, EObject)
M: 1 C: 19
95%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
doReveal(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%
lambda$0(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: 14
100%
M: 1 C: 1
50%
M: 1 C: 1
50%
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.emf.ecp.view.internal.table.swt;
15:
16: import org.eclipse.core.databinding.observable.list.IObservableList;
17: import org.eclipse.emf.ecore.EObject;
18: import org.eclipse.emf.ecp.view.model.common.di.annotations.Renderer;
19: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
20: import org.eclipse.emf.ecp.view.spi.table.model.VTableControl;
21: import org.eclipse.emf.ecp.view.spi.table.swt.TableControlSWTRenderer;
22: import org.eclipse.emfforms.bazaar.Bid;
23: import org.eclipse.emfforms.bazaar.Create;
24: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
25: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
26: import org.eclipse.emfforms.spi.core.services.reveal.EMFFormsRevealProvider;
27: import org.eclipse.emfforms.spi.core.services.reveal.Reveal;
28: import org.eclipse.emfforms.spi.core.services.reveal.RevealHelper;
29: import org.eclipse.emfforms.spi.core.services.reveal.RevealStep;
30: import org.osgi.service.component.annotations.Component;
31:
32: /**
33: * A reveal provider for {@link VTableControl}s that reveals objects contained (as rows)
34: * in the table.
35: *
36: * @since 1.22
37: */
38: @Component(name = "tableRevealProvider")
39: public class TableRevealProvider implements EMFFormsRevealProvider {
40:
41:         private final Double tableBid = 5.0;
42:
43:         /**
44:          * I bid on the {@code element} if it is a {@link VTableControl} that has a row
45:          * representing the {@code object} to be revealed.
46:          *
47:          * @param tableControl the table control to bid on
48:          * @param object the object to be revealed
49:          * @param context the context in which the table is rendered
50:          *
51:          * @return my bid
52:          */
53:         @Bid
54:         public Double canReveal(VTableControl tableControl, EObject object, ViewModelContext context) {
55:•                return contains(context, tableControl, object) ? tableBid : null;
56:         }
57:
58:         private boolean contains(ViewModelContext context, VTableControl tableControl, EObject object) {
59:                 boolean result = false;
60:
61:                 try {
62:                         final IObservableList<?> list = context.getService(EMFFormsDatabinding.class)
63:                                 .getObservableList(tableControl.getDomainModelReference(), context.getDomainModel());
64:                         result = list.contains(object);
65:                 } catch (final DatabindingFailedException e) {
66:                         // The object cannot be in this table, then
67:                 }
68:
69:                 return result;
70:         }
71:
72:         /**
73:          * Create a terminal reveal step to drill down into a table control.
74:          *
75:          * @param context the view model context in which to find a renderer for the table
76:          * @param helper a helper for deferred revealing
77:          * @param tableControl the table in which to drill down
78:          * @param object the object to reveal
79:          * @return the drill-down reveal step
80:          */
81:         @Create
82:         public RevealStep reveal(ViewModelContext context, RevealHelper helper, VTableControl tableControl,
83:                 EObject object) {
84:
85:                 RevealStep result = RevealStep.fail();
86:
87:•                if (contains(context, tableControl, object)) {
88:                         // It's in this table. Defer the access to the renderer because
89:                         // in a categorization it may not yet exist
90:                         result = helper.defer(this);
91:                 }
92:
93:                 return result;
94:         }
95:
96:         @Reveal
97:         private RevealStep doReveal(@Renderer TableControlSWTRenderer renderer, EObject object) {
98:                 final VTableControl tableControl = renderer.getVElement();
99:                 return RevealStep.reveal(tableControl, object, () -> renderer.reveal(object));
100:         }
101:
102: }