Skip to content

Package: ContextUtil

ContextUtil

nameinstructionbranchcomplexitylinemethod
setAbstractRendererObjects(IEclipseContext, VElement, ViewModelContext)
M: 38 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 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: * Johannes Faltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.model.common.di.util;
15:
16: import org.eclipse.e4.core.contexts.IEclipseContext;
17: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
18: import org.eclipse.emf.ecp.view.spi.model.VElement;
19:
20: /**
21: * Util class for injection all needed objects in an {@link IEclipseContext}.
22: *
23: * @author jfaltermeier
24: *
25: */
26: public final class ContextUtil {
27:
28:         /**
29:          * Named key for the domain model.
30:          */
31:         public static final String EMF_FORMS_DOMAIN_MODEL = "EMFForms_DomainModel"; //$NON-NLS-1$
32:
33:         private ContextUtil() {
34:
35:         }
36:
37:         /**
38:          * Adds the objects of an AbstractRenderer to the {@link IEclipseContext}.
39:          *
40:          * @param eclipseContext the eclipse context
41:          * @param element the {@link VElement}
42:          * @param viewModelContext the {@link ViewModelContext}
43:          */
44:         public static void setAbstractRendererObjects(IEclipseContext eclipseContext, VElement element,
45:                 ViewModelContext viewModelContext) {
46:                 eclipseContext.set(VElement.class, element);
47:                 eclipseContext.set(ViewModelContext.class, viewModelContext);
48:                 eclipseContext.set(EMF_FORMS_DOMAIN_MODEL, viewModelContext.getDomainModel());
49:
50:                 final Class<?> elementClass = element.eClass().getInstanceClass();
51:                 eclipseContext.set(elementClass.getName(), elementClass.cast(element));
52:
53:                 final Class<?> domainClass = viewModelContext.getDomainModel().eClass().getInstanceClass();
54:                 eclipseContext.set(domainClass.getName(), domainClass.cast(viewModelContext.getDomainModel()));
55:         }
56: }