Skip to content

Package: RevealStep

RevealStep

nameinstructionbranchcomplexitylinemethod
drillDown(VElement, EObject, RevealStep)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
drillDown(VElement, EObject, RevealStep, Runnable)
M: 0 C: 13
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
fail()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
ifPresent(Consumer)
M: 0 C: 7
100%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 3
100%
M: 0 C: 1
100%
is(RevealStepKind)
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isDone()
M: 0 C: 8
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isFailed()
M: 0 C: 8
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$0(RevealStepKind, RevealStep)
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
preferredOrdering()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
reveal(VElement, EObject, EStructuralFeature, Runnable)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
reveal(VElement, EObject, Runnable)
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%
static {...}
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%

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.spi.core.services.reveal;
15:
16: import java.util.Comparator;
17: import java.util.function.Consumer;
18: import java.util.function.Predicate;
19:
20: import org.eclipse.emf.ecore.EObject;
21: import org.eclipse.emf.ecore.EStructuralFeature;
22: import org.eclipse.emf.ecp.view.spi.model.VElement;
23:
24: /**
25: * A step in the progressive reveal of an object.
26: *
27: * @since 1.22
28: * @noimplement This interface is not intended to be implemented by clients.
29: * @noextend This interface is not intended to be extended by clients.
30: */
31: public interface RevealStep {
32:
33:         /**
34:          * The step indicating failure to reveal the object.
35:          *
36:          * @see RevealStepKind#FAILED
37:          *
38:          * @see #fail()
39:          */
40:         RevealStep FAILED = new FailedStep();
41:
42:         /**
43:          * Query the type of reveal step that I am.
44:          *
45:          * @return my type
46:          */
47:         RevealStepKind getType();
48:
49:         /**
50:          * Query whether I am a {@linkplain RevealStepKind#FAILED failed} reveal step.
51:          *
52:          * @return whether I represent failure to reveal the requested object
53:          */
54:         default boolean isFailed() {
55:•                return getType() == RevealStepKind.FAILED;
56:         }
57:
58:         /**
59:          * Query whether I am a {@linkplain RevealStepKind#INTERMEDIATE non-intermediate} reveal step.
60:          *
61:          * @return {@code true} if there is no further progress to be made in revealing;
62:          * {@code false}, otherwise
63:          */
64:         default boolean isDone() {
65:•                return getType() != RevealStepKind.INTERMEDIATE;
66:         }
67:
68:         /**
69:          * Query the view model element in which I reveal my {@linkplain #getDomainModel() domain model}.
70:          *
71:          * @return my view model scope, or {@code null} if {@linkplain #isFailed() I am failed}
72:          */
73:         VElement getViewModel();
74:
75:         /**
76:          * Query the domain object that I reveal in my {@linkplain #getViewModel() view model element}.
77:          *
78:          * @return my domain model scope, or {@code null} if {@linkplain #isFailed() I am failed}
79:          */
80:         EObject getDomainModel();
81:
82:         /**
83:          * Query the feature that I reveal, if any. If I am not a {@link RevealStepKind#TERMINAL terminal step},
84:          * then I should not reveal any feature.
85:          *
86:          * @return the feature that I reveal, or {@code null} if none or if {@linkplain #isFailed() I am failed}
87:          */
88:         EStructuralFeature getFeature();
89:
90:         /**
91:          * Drills down into me to reveal the next step in the nested reveal.
92:          *
93:          * @return the next step in the progressive reveal, or {@code null} if I am the
94:          * {@linkplain RevealStepKind#TERMINAL terminal step}
95:          *
96:          * @throws IllegalStateException if {@linkplain #isFailed() I am failed}
97:          */
98:         RevealStep drillDown();
99:
100:         /**
101:          * Reveal my {@linkplain #getDomainModel() domain object} in my
102:          * {@linkplain #getViewModel() view model element}.
103:          *
104:          * @throws IllegalStateException if {@linkplain #isFailed() I am failed}
105:          */
106:         void reveal();
107:
108:         /**
109:          * Invoke an {@code action} on me if I am {@linkplain #isFailed() not failed}.
110:          *
111:          * @param action an action to invoke
112:          */
113:         default void ifPresent(Consumer<? super RevealStep> action) {
114:•                if (!isFailed()) {
115:                         action.accept(this);
116:                 }
117:         }
118:
119:         /**
120:          * Create an intermediate step that drills down into another step.
121:          *
122:          * @param viewModel the view model element that is rendered and revealed
123:          * @param domainModel the domain model object that is revealed in that view
124:          * @param nextStep the next step to drill down into in the reveal operation
125:          * @return the intermediate reveal step
126:          */
127:         static RevealStep drillDown(VElement viewModel, EObject domainModel, RevealStep nextStep) {
128:                 return drillDown(viewModel, domainModel, nextStep, null);
129:         }
130:
131:         /**
132:          * Create an intermediate step that reveals some kind of container and drills
133:          * down into another step.
134:          *
135:          * @param viewModel the view model element that is rendered and revealed
136:          * @param domainModel the domain model object that is revealed in that view
137:          * @param nextStep the next step to drill down into in the reveal operation
138:          * @param revealAction a rendering-specific action that actually reveals the rendered
139:          * container element in the UI
140:          * @return the intermediate reveal step
141:          */
142:         static RevealStep drillDown(VElement viewModel, EObject domainModel, RevealStep nextStep, Runnable revealAction) {
143:                 // Short-circuit to failure
144:•                return nextStep.isFailed() ? nextStep : new IntermediateStep(viewModel, domainModel, nextStep, revealAction);
145:         }
146:
147:         /**
148:          * Create a terminal step that reveals the object in the editor UI.
149:          *
150:          * @param viewModel the view model element that is rendered and revealed
151:          * @param domainModel the domain model object that is revealed in that view
152:          * @param revealAction a rendering-specific action that actually reveals the rendered
153:          * element that presents the object in the UI
154:          * @return the terminal reveal step
155:          */
156:         static RevealStep reveal(VElement viewModel, EObject domainModel, Runnable revealAction) {
157:                 return reveal(viewModel, domainModel, null, revealAction);
158:         }
159:
160:         /**
161:          * Create a terminal step that reveals a {@code feature} of the object in the editor UI.
162:          *
163:          * @param viewModel the view model element that is rendered and revealed
164:          * @param domainModel the domain model object that is revealed in that view
165:          * @param feature the feature of the domain model object that I specfically revealed
166:          * @param revealAction a rendering-specific action that actually reveals the rendered
167:          * element that presents the object in the UI
168:          * @return the terminal reveal step
169:          */
170:         static RevealStep reveal(VElement viewModel, EObject domainModel, EStructuralFeature feature,
171:                 Runnable revealAction) {
172:
173:                 return new TerminalStep(viewModel, domainModel, feature, revealAction);
174:         }
175:
176:         /**
177:          * Obtain a reveal failure step that signals absence of any UI element that can be
178:          * activated to reveal the object.
179:          *
180:          * @return the failed reveal step
181:          *
182:          * @see #FAILED
183:          */
184:         static RevealStep fail() {
185:                 return FAILED;
186:         }
187:
188:         /**
189:          * Obtain a predicate that matches reveal steps of a particular {@code type}.
190:          *
191:          * @param type the type of step to match
192:          * @return the predicate
193:          *
194:          * @see #getType()
195:          */
196:         static Predicate<RevealStep> is(RevealStepKind type) {
197:•                return step -> step.getType() == type;
198:         }
199:
200:         /**
201:          * Obtain a comparator that sorts reveal steps in preferential order by
202:          * {@link #getType type}, with the {@link RevealStepKind#TERMINAL} the most
203:          * preferred and {@link RevealStepKind#FAILED} the least preferred.
204:          *
205:          * @return the ordering
206:          *
207:          * @see #getType()
208:          */
209:         static Comparator<RevealStep> preferredOrdering() {
210:                 return Comparator.comparing(RevealStep::getType);
211:         }
212:
213: }