Skip to content

Package: ECPSWTViewRendererImpl

ECPSWTViewRendererImpl

nameinstructionbranchcomplexitylinemethod
ECPSWTViewRendererImpl()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
render(Composite, EObject)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
render(Composite, EObject, Map)
M: 29 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
render(Composite, EObject, VView)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
render(Composite, EObject, VViewModelProperties)
M: 3 C: 12
80%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 3
75%
M: 0 C: 1
100%
render(Composite, ViewModelContext)
M: 21 C: 80
79%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 5 C: 22
81%
M: 0 C: 1
100%

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: * Jonas - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.internal.swt;
15:
16: import java.util.Map;
17: import java.util.Map.Entry;
18:
19: import org.eclipse.emf.ecore.EObject;
20: import org.eclipse.emf.ecp.ui.view.ECPRendererException;
21: import org.eclipse.emf.ecp.ui.view.swt.ECPSWTView;
22: import org.eclipse.emf.ecp.ui.view.swt.ECPSWTViewRenderer;
23: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
24: import org.eclipse.emf.ecp.view.spi.context.ViewModelContextFactory;
25: import org.eclipse.emf.ecp.view.spi.model.VElement;
26: import org.eclipse.emf.ecp.view.spi.model.VView;
27: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
28: import org.eclipse.emf.ecp.view.spi.model.VViewModelProperties;
29: import org.eclipse.emf.ecp.view.spi.provider.ViewProviderHelper;
30: import org.eclipse.emf.ecp.view.spi.renderer.NoPropertyDescriptorFoundExeption;
31: import org.eclipse.emf.ecp.view.spi.renderer.NoRendererFoundException;
32: import org.eclipse.emf.ecp.view.spi.swt.reporting.InvalidGridDescriptionReport;
33: import org.eclipse.emf.ecp.view.spi.swt.reporting.RenderingFailedReport;
34: import org.eclipse.emfforms.spi.common.report.ReportService;
35: import org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer;
36: import org.eclipse.emfforms.spi.swt.core.EMFFormsNoRendererException;
37: import org.eclipse.emfforms.spi.swt.core.EMFFormsRendererFactory;
38: import org.eclipse.emfforms.spi.swt.core.layout.GridDescriptionFactory;
39: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridDescription;
40: import org.eclipse.swt.SWT;
41: import org.eclipse.swt.layout.GridData;
42: import org.eclipse.swt.widgets.Composite;
43: import org.osgi.framework.BundleContext;
44: import org.osgi.framework.FrameworkUtil;
45: import org.osgi.framework.ServiceReference;
46:
47: /**
48: * @author Jonas
49: *
50: */
51: public class ECPSWTViewRendererImpl implements ECPSWTViewRenderer {
52:
53:         /**
54:          * Constructor.
55:          */
56:         public ECPSWTViewRendererImpl() {
57:         }
58:
59:         /**
60:          * {@inheritDoc}
61:          *
62:          * @see org.eclipse.emf.ecp.ui.view.swt.ECPSWTViewRenderer#render(org.eclipse.swt.widgets.Composite,
63:          * org.eclipse.emf.ecore.EObject)
64:          */
65:         @Override
66:         public ECPSWTView render(Composite parent, EObject domainObject) throws ECPRendererException {
67:                 return render(parent, domainObject, ViewProviderHelper.getView(domainObject, null));
68:         }
69:
70:         /**
71:          * {@inheritDoc}
72:          *
73:          * @see org.eclipse.emf.ecp.ui.view.swt.ECPSWTViewRenderer#render(org.eclipse.swt.widgets.Composite,
74:          * org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecp.view.spi.model.VView)
75:          */
76:         @Override
77:         public ECPSWTView render(Composite parent, EObject domainObject, VView viewModel) throws ECPRendererException {
78:                 final ViewModelContext viewContext = ViewModelContextFactory.INSTANCE.createViewModelContext(viewModel,
79:                         domainObject);
80:                 return render(parent, viewContext);
81:         }
82:
83:         /**
84:          * {@inheritDoc}
85:          *
86:          * @see org.eclipse.emf.ecp.ui.view.swt.ECPSWTViewRenderer#render(org.eclipse.swt.widgets.Composite,
87:          * org.eclipse.emf.ecp.view.spi.context.ViewModelContext)
88:          */
89:         @Override
90:         public ECPSWTView render(Composite parent, ViewModelContext viewModelContext) throws ECPRendererException {
91:                 final BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
92:                 final ServiceReference<EMFFormsRendererFactory> serviceReference = bundleContext
93:                         .getServiceReference(EMFFormsRendererFactory.class);
94:                 final EMFFormsRendererFactory factory = bundleContext.getService(serviceReference);
95:
96:                 AbstractSWTRenderer<VElement> renderer;
97:                 try {
98:                         renderer = factory.getRendererInstance(
99:                                 viewModelContext.getViewModel(),
100:                                 viewModelContext);
101:                 } catch (final EMFFormsNoRendererException ex) {
102:                         throw new ECPRendererException(ex.getMessage());
103:                 } finally {
104:                         bundleContext.ungetService(serviceReference);
105:                 }
106:
107:                 final ReportService reportService = Activator.getDefault().getReportService();
108:
109:                 final SWTGridDescription gridDescription = renderer.getGridDescription(GridDescriptionFactory.INSTANCE
110:                         .createEmptyGridDescription());
111:•                if (gridDescription.getGrid().size() != 1) {
112:                         reportService.report(
113:                                 new InvalidGridDescriptionReport("Invalid number of cells, expected exactly one cell!")); //$NON-NLS-1$
114:                         // TODO: RS
115:                         // do sth. if wrong number of controls
116:                         // throw new IllegalStateException("Invalid number of cells, expected exactly one cell!"); //$NON-NLS-1$
117:                 }
118:
119:                 // a view returns always a composite and always only one row with one control
120:                 ECPSWTView swtView = null;
121:                 try {
122:                         final Composite composite = (Composite) renderer.render(gridDescription.getGrid().get(0), parent);
123:                         renderer.finalizeRendering(parent);
124:                         final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
125:                         composite.setLayoutData(gridData);
126:                         swtView = new ECPSWTViewImpl(composite, viewModelContext);
127:                 } catch (final NoRendererFoundException e) {
128:                         reportService.report(new RenderingFailedReport(e));
129:                 } catch (final NoPropertyDescriptorFoundExeption e) {
130:                         reportService.report(new RenderingFailedReport(e));
131:                 }
132:
133:                 return swtView;
134:         }
135:
136:         @Deprecated
137:         @Override
138:         public ECPSWTView render(Composite parent, EObject domainObject, Map<String, Object> context)
139:                 throws ECPRendererException {
140:                 final VViewModelProperties properties = VViewFactory.eINSTANCE.createViewModelLoadingProperties();
141:•                for (final Entry<String, Object> entry : context.entrySet()) {
142:                         properties.addNonInheritableProperty(entry.getKey(), entry.getValue());
143:                 }
144:                 return render(parent, domainObject, properties);
145:         }
146:
147:         @Override
148:         public ECPSWTView render(Composite parent, EObject domainObject, VViewModelProperties properties)
149:                 throws ECPRendererException {
150:•                if (properties == null) {
151:                         properties = VViewFactory.eINSTANCE.createViewModelLoadingProperties();
152:                 }
153:                 final VView view = ViewProviderHelper.getView(domainObject, properties);
154:                 return render(parent, domainObject, view);
155:         }
156:
157: }