Skip to content

Package: DICustomControlSWTRenderer

DICustomControlSWTRenderer

nameinstructionbranchcomplexitylinemethod
DICustomControlSWTRenderer(VCustomControl, ViewModelContext, ReportService)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
DICustomControlSWTRenderer(VCustomControl, ViewModelContext, ReportService, SWTValidationUiService)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
loadCustomControl(VCustomControl)
M: 37 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
loadPOJO(String, String)
M: 23 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
renderControl(SWTGridCell, Composite)
M: 18 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 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.custom.ui.swt.di.renderer;
15:
16: import org.eclipse.core.runtime.Platform;
17: import org.eclipse.e4.core.contexts.IEclipseContext;
18: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
19: import org.eclipse.emf.ecp.view.spi.custom.model.VCustomControl;
20: import org.eclipse.emf.ecp.view.spi.custom.swt.CustomControlSWTRenderer;
21: import org.eclipse.emf.ecp.view.spi.custom.swt.ECPAbstractCustomControlSWT;
22: import org.eclipse.emf.ecp.view.spi.renderer.NoPropertyDescriptorFoundExeption;
23: import org.eclipse.emf.ecp.view.spi.renderer.NoRendererFoundException;
24: import org.eclipse.emfforms.spi.common.report.ReportService;
25: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridCell;
26: import org.eclipse.emfforms.spi.swt.core.ui.SWTValidationUiService;
27: import org.eclipse.swt.widgets.Composite;
28: import org.eclipse.swt.widgets.Control;
29: import org.osgi.framework.Bundle;
30:
31: /**
32: * Custom control SWTRenderer for Dependency Injection.
33: *
34: * @author jfaltermeier
35: *
36: */
37: public class DICustomControlSWTRenderer extends CustomControlSWTRenderer {
38:
39:         /**
40:          * Legacy constructor.
41:          *
42:          * @param vElement the view model element to be rendered
43:          * @param viewContext the view context
44:          * @param factory the {@link ReportService}
45:          */
46:         public DICustomControlSWTRenderer(VCustomControl vElement, ViewModelContext viewContext, ReportService factory) {
47:                 super(vElement, viewContext, factory);
48:         }
49:
50:         /**
51:          * Default constructor.
52:          *
53:          * @param vElement the view model element to be rendered
54:          * @param viewContext the view context
55:          * @param factory the {@link ReportService}
56:          * @param validationUiService the {@link SWTValidationUiService} to use
57:          */
58:         public DICustomControlSWTRenderer(VCustomControl vElement, ViewModelContext viewContext, ReportService factory,
59:                 SWTValidationUiService validationUiService) {
60:                 super(vElement, viewContext, factory, validationUiService);
61:         }
62:
63:         private IEclipseContext eclipseContext;
64:
65:         /**
66:          * {@inheritDoc}
67:          *
68:          * @see org.eclipse.emf.ecp.view.spi.custom.swt.CustomControlSWTRenderer#loadCustomControl(org.eclipse.emf.ecp.view.spi.custom.model.VCustomControl)
69:          */
70:         @SuppressWarnings("restriction")
71:         @Override
72:         protected ECPAbstractCustomControlSWT loadCustomControl(VCustomControl customControl) {
73:                 String bundleName = customControl.getBundleName();
74:                 String className = customControl.getClassName();
75:                 if (customControl.getBundleName() != null) {
76:                 }
77:•                if (bundleName == null) {
78:                         bundleName = ""; //$NON-NLS-1$
79:                 }
80:•                if (className == null) {
81:                         className = ""; //$NON-NLS-1$
82:                 }
83:                 final Object pojo = loadPOJO(bundleName, className);
84:                 eclipseContext = org.eclipse.emf.ecp.view.model.common.di.renderer.DIRendererUtil.getContextForElement(
85:                         getVElement(), getViewModelContext());
86:                 final DICustomControlSWT customControlSWT = new DICustomControlSWT(pojo, eclipseContext);
87:                 return customControlSWT;
88:         }
89:
90:         private static Object loadPOJO(String bundleName, String clazz) {
91:                 final Bundle bundle = Platform.getBundle(bundleName);
92:•                if (bundle == null) {
93:                         return null;
94:                 }
95:                 try {
96:                         final Class<?> loadClass = bundle.loadClass(clazz);
97:                         return loadClass.newInstance();
98:                 } catch (final ClassNotFoundException ex) {
99:                         return null;
100:                 } catch (final InstantiationException ex) {
101:                         return null;
102:                 } catch (final IllegalAccessException ex) {
103:                         return null;
104:                 }
105:         }
106:
107:         /**
108:          * {@inheritDoc}
109:          *
110:          * @see org.eclipse.emf.ecp.view.spi.custom.swt.CustomControlSWTRenderer#renderControl(org.eclipse.emfforms.spi.swt.core.layout.SWTGridCell,
111:          * org.eclipse.swt.widgets.Composite)
112:          */
113:         @SuppressWarnings("restriction")
114:         @Override
115:         protected Control renderControl(SWTGridCell cell, Composite parent) throws NoRendererFoundException,
116:                 NoPropertyDescriptorFoundExeption {
117:                 org.eclipse.emf.ecp.ui.view.swt.di.util.SWTContextUtil.setAbstractSWTRendererObjects(eclipseContext,
118:                         getVElement(), getViewModelContext(), parent);
119:                 eclipseContext.set(SWTGridCell.class, cell);
120:                 return super.renderControl(cell, parent);
121:         }
122:
123: }