Skip to content

Package: RenderingConfiguration

RenderingConfiguration

nameinstructionbranchcomplexitylinemethod
RenderingConfiguration()
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getCurrent()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getLayoutHelper(Class)
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%
getRenderingRowFactory(Class)
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%
readExtensionPoint()
M: 102 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 23 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2013 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: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.spi.renderer;
15:
16: import java.lang.reflect.ParameterizedType;
17: import java.util.LinkedHashMap;
18: import java.util.Map;
19:
20: import org.eclipse.core.runtime.CoreException;
21: import org.eclipse.core.runtime.IConfigurationElement;
22: import org.eclipse.core.runtime.IExtensionRegistry;
23: import org.eclipse.core.runtime.Platform;
24: import org.eclipse.emf.ecp.view.internal.ui.Activator;
25:
26: /**
27: * This class allows to get a fitting {@link LayoutHelper} based on the provided {@link Class} as well as to get a
28: * fitting {@link RenderingResultRowFactory} based on a {@link Class}.
29: *
30: * @author Eugen Neufeld
31: * @since 1.2
32: *
33: */
34: @Deprecated
35: public final class RenderingConfiguration {
36:
37:         private static final String RENDERING_LAYOUT_HELPER = "renderingLayoutHelper"; //$NON-NLS-1$
38:
39:         private static final String RENDERING_RESULT_ROW_FACTORY = "renderingResultRowFactory"; //$NON-NLS-1$
40:
41:         private static final String RENDERING_CONFIGURATION_EXTENSION_POINT = "org.eclipse.emf.ecp.ui.view.renderingConfiguration"; //$NON-NLS-1$
42:
43:         private static final String CLASS_ATTRIBUTE = "class";//$NON-NLS-1$
44:
45:         private static final RenderingConfiguration INSTANCE = new RenderingConfiguration();
46:         private final Map<Class<?>, RenderingResultRowFactory<?>> rowFactories = new LinkedHashMap<Class<?>, RenderingResultRowFactory<?>>();
47:         private final Map<Class<?>, LayoutHelper<?>> layoutHelpers = new LinkedHashMap<Class<?>, LayoutHelper<?>>();
48:
49:         /**
50:          * Returns the singleton instance.
51:          *
52:          * @return the singleton
53:          */
54:         public static RenderingConfiguration getCurrent() {
55:                 return INSTANCE;
56:         }
57:
58:         private RenderingConfiguration() {
59:                 readExtensionPoint();
60:         }
61:
62:         private void readExtensionPoint() {
63:                 final IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
64:•                if (extensionRegistry == null) {
65:                         return;
66:                 }
67:                 final IConfigurationElement[] controls = extensionRegistry.getConfigurationElementsFor(
68:                         RENDERING_CONFIGURATION_EXTENSION_POINT);
69:•                for (final IConfigurationElement e : controls) {
70:•                        for (final IConfigurationElement e2 : e.getChildren()) {
71:                                 try {
72:•                                        if (RENDERING_RESULT_ROW_FACTORY.equalsIgnoreCase(e2.getName())) {
73:                                                 final RenderingResultRowFactory<?> rrrf = (RenderingResultRowFactory<?>) e2
74:                                                         .createExecutableExtension(CLASS_ATTRIBUTE);
75:                                                 final Class<?> clazz = (Class<?>) ((ParameterizedType) rrrf.getClass()
76:                                                         .getGenericInterfaces()[0])
77:                                                                 .getActualTypeArguments()[0];
78:                                                 rowFactories.put(clazz, rrrf);
79:•                                        } else if (RENDERING_LAYOUT_HELPER.equalsIgnoreCase(e2.getName())) {
80:                                                 final LayoutHelper<?> layoutHelper = (LayoutHelper<?>) e2
81:                                                         .createExecutableExtension(CLASS_ATTRIBUTE);
82:                                                 final Class<?> clazz = (Class<?>) ((ParameterizedType) layoutHelper.getClass()
83:                                                         .getGenericInterfaces()[0]).getActualTypeArguments()[0];
84:                                                 layoutHelpers.put(clazz, layoutHelper);
85:                                         }
86:                                 } catch (final CoreException ex) {
87:                                         Activator.log(ex);
88:                                 }
89:                         }
90:                 }
91:
92:         }
93:
94:         /**
95:          * Returns the {@link RenderingResultRowFactory} registered for a specific {@link Class}.
96:          *
97:          * @param controlClazz the class to get the {@link RenderingResultRowFactory} for
98:          * @param <CONTROL> the type of the control, the factory is working on
99:          * @return the registered {@link RenderingResultRowFactory} or null if none is registered for the provided
100:          * {@link Class}
101:          */
102:         @SuppressWarnings("unchecked")
103:         public <CONTROL> RenderingResultRowFactory<CONTROL> getRenderingRowFactory(Class<CONTROL> controlClazz) {
104:                 return (RenderingResultRowFactory<CONTROL>) rowFactories.get(controlClazz);
105:         }
106:
107:         /**
108:          * Returns the layout helper registered for a specific {@link Class}.
109:          *
110:          * @param layoutClazz the class to get the {@link LayoutHelper} for
111:          * @param <LAYOUT> the type of the layout, the layout helper should create
112:          * @return the registered {@link LayoutHelper} or null if none is registered for the provided {@link Class}
113:          */
114:         @SuppressWarnings("unchecked")
115:         public <LAYOUT> LayoutHelper<LAYOUT> getLayoutHelper(Class<LAYOUT> layoutClazz) {
116:                 return (LayoutHelper<LAYOUT>) layoutHelpers.get(layoutClazz);
117:         }
118: }