Skip to content

Package: ViewModelContextFactory

ViewModelContextFactory

nameinstructionbranchcomplexitylinemethod
createViewModelContext(VElement, EObject)
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%
createViewModelContext(VElement, EObject, Map)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createViewModelContext(VElement, EObject, ViewModelServiceProvider)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createViewModelContext(VElement, EObject, ViewModelServiceProvider, Map)
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%
createViewModelContext(VElement, EObject, ViewModelService[])
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
provide(ViewModelService[])
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%
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) 2011-2019 EclipseSource Muenchen GmbH 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: * Eugen Neufeld - initial API and implementation
13: * Christian W. Damus - bugs 527740, 545686
14: ******************************************************************************/
15: package org.eclipse.emf.ecp.view.spi.context;
16:
17: import java.util.Map;
18:
19: import org.eclipse.emf.ecore.EObject;
20: import org.eclipse.emf.ecp.view.internal.context.ArrayOnceViewModelServiceProvider;
21: import org.eclipse.emf.ecp.view.internal.context.ViewModelContextImpl;
22: import org.eclipse.emf.ecp.view.spi.model.VElement;
23:
24: /**
25: * This Factory can be used to instantiate {@link ViewModelContext ViewModelContexts}.
26: *
27: * @author Eugen Neufeld
28: * @since 1.2
29: *
30: */
31: public final class ViewModelContextFactory {
32:         /**
33:          * The singleton instance of the factory.
34:          */
35:         public static final ViewModelContextFactory INSTANCE = new ViewModelContextFactory();
36:
37:         private ViewModelContextFactory() {
38:         }
39:
40:         /**
41:          * Instantiates a new view model context.
42:          *
43:          * @param view the view
44:          * @param domainObject the domain object
45:          * @return the created {@link ViewModelContext}
46:          */
47:         public ViewModelContext createViewModelContext(VElement view, EObject domainObject) {
48:                 return new ViewModelContextImpl(view, domainObject);
49:         }
50:
51:         /**
52:          * Instantiates a new view model context with specific services. Note that this is useful for
53:          * services that are not registered externally (via extension point or OSGi). If any of these
54:          * services locally override registered implementations of the same interface, then it is better
55:          * to use a {@link ViewModelServiceProvider} that can propagate the override to child contexts.
56:          *
57:          * @param view the view
58:          * @param domainObject the domain object
59:          * @param modelServices an array of services to use in the {@link ViewModelContext}
60:          * @return the created {@link ViewModelContext}
61:          *
62:          * @see #createViewModelContext(VElement, EObject, ViewModelServiceProvider)
63:          * @see ViewModelContext#getChildContext(EObject, VElement, org.eclipse.emf.ecp.view.spi.model.VView,
64:          * ViewModelService...)
65:          */
66:         public ViewModelContext createViewModelContext(VElement view, EObject domainObject,
67:                 ViewModelService... modelServices) {
68:                 return createViewModelContext(view, domainObject, provide(modelServices));
69:         }
70:
71:         /**
72:          * Instantiates a new view model context with a provider of local service overrides.
73:          * The {@code serviceProvider} is propagated to child contexts to override registered
74:          * services in their scope, too.
75:          *
76:          * @param view the view
77:          * @param domainObject the domain object
78:          * @param serviceProvider a provider of local view-model services to override any
79:          * statically registered services of the same types. May be {@code null} if
80:          * local service overrides are not needed
81:          * @return the created {@link ViewModelContext}
82:          *
83:          * @since 1.16
84:          */
85:         public ViewModelContext createViewModelContext(VElement view, EObject domainObject,
86:                 ViewModelServiceProvider serviceProvider) {
87:                 return new ViewModelContextImpl(view, domainObject, serviceProvider);
88:         }
89:
90:         /**
91:          * Instantiates a new view model context with initial {@linkplain ViewModelContext#getContextValue(String) context
92:          * values}.
93:          * The {@code serviceProvider} is propagated to child contexts to override registered
94:          * services in their scope, too.
95:          *
96:          * @param view the view
97:          * @param domainObject the domain object
98:          * @param contextValues initial context values to set
99:          * @return the created {@link ViewModelContext}
100:          *
101:          * @since 1.21
102:          * @see ViewModelContext#getContextValue(String)
103:          */
104:         public ViewModelContext createViewModelContext(VElement view, EObject domainObject,
105:                 Map<String, ?> contextValues) {
106:
107:                 return new ViewModelContextImpl(view, domainObject, contextValues);
108:         }
109:
110:         /**
111:          * Instantiates a new view model context with a provider of local service overrides and
112:          * initial {@linkplain ViewModelContext#getContextValue(String) context values}.
113:          * The {@code serviceProvider} is propagated to child contexts to override registered
114:          * services in their scope, too.
115:          *
116:          * @param view the view
117:          * @param domainObject the domain object
118:          * @param serviceProvider a provider of local view-model services to override any
119:          * statically registered services of the same types. May be {@code null} if
120:          * local service overrides are not needed
121:          * @param contextValues initial context values to set
122:          * @return the created {@link ViewModelContext}
123:          *
124:          * @since 1.21
125:          */
126:         public ViewModelContext createViewModelContext(VElement view, EObject domainObject,
127:                 ViewModelServiceProvider serviceProvider, Map<String, ?> contextValues) {
128:
129:                 return new ViewModelContextImpl(view, domainObject, serviceProvider, contextValues);
130:         }
131:
132:         /**
133:          * Obtain a view-model service provider that statically provides a set of services.
134:          *
135:          * @param modelServices model services to provider
136:          * @return the static provider of those services
137:          *
138:          * @since 1.22
139:          */
140:         public static ViewModelServiceProvider provide(ViewModelService... modelServices) {
141:                 return new ArrayOnceViewModelServiceProvider(modelServices);
142:         }
143:
144: }