Skip to content

Package: AddColumnService

AddColumnService

nameinstructionbranchcomplexitylinemethod
AddColumnService()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
addColumnsIfNeeded(VTableControl)
M: 24 C: 96
80%
M: 7 C: 11
61%
M: 6 C: 4
40%
M: 7 C: 26
79%
M: 0 C: 1
100%
dispose()
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getPriority()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
instantiate(ViewModelContext)
M: 0 C: 35
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 12
100%
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: * Johannes Faltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.internal.table.columnservice;
15:
16: import org.eclipse.core.databinding.property.value.IValueProperty;
17: import org.eclipse.emf.common.util.TreeIterator;
18: import org.eclipse.emf.ecore.EClass;
19: import org.eclipse.emf.ecore.EClassifier;
20: import org.eclipse.emf.ecore.EObject;
21: import org.eclipse.emf.ecore.EStructuralFeature;
22: import org.eclipse.emf.ecp.view.internal.table.generator.TableColumnGenerator;
23: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
24: import org.eclipse.emf.ecp.view.spi.context.ViewModelService;
25: import org.eclipse.emf.ecp.view.spi.model.VElement;
26: import org.eclipse.emf.ecp.view.spi.table.model.VTableControl;
27: import org.eclipse.emf.ecp.view.spi.table.model.VTableDomainModelReference;
28: import org.eclipse.emfforms.spi.common.report.ReportService;
29: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
30: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedReport;
31: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
32: import org.eclipse.emfforms.view.spi.multisegment.model.VMultiDomainModelReferenceSegment;
33:
34: /**
35: * This service will iterate over all contents of the {@link org.eclipse.emf.ecp.view.spi.model.VView VView} and will
36: * add {@link org.eclipse.emf.ecp.view.spi.model.VDomainModelReference VDomainModelReferences} for every
37: * {@link VTableControl} without columns.
38: *
39: * @author jfaltermeier
40: *
41: */
42: public class AddColumnService implements ViewModelService {
43:
44:         private ViewModelContext context;
45:
46:         /**
47:          * {@inheritDoc}
48:          *
49:          * @see org.eclipse.emf.ecp.view.spi.context.ViewModelService#instantiate(org.eclipse.emf.ecp.view.spi.context.ViewModelContext)
50:          */
51:         @Override
52:         public void instantiate(ViewModelContext context) {
53:                 this.context = context;
54:                 final VElement viewModel = context.getViewModel();
55:•                if (viewModel instanceof VTableControl) {
56:                         addColumnsIfNeeded((VTableControl) viewModel);
57:                         return;
58:                 }
59:                 final TreeIterator<EObject> contents = viewModel.eAllContents();
60:•                while (contents.hasNext()) {
61:                         final EObject current = contents.next();
62:•                        if (current instanceof VTableControl) {
63:                                 final VTableControl tableControl = (VTableControl) current;
64:                                 addColumnsIfNeeded(tableControl);
65:                         }
66:                 }
67:         }
68:
69:         private void addColumnsIfNeeded(VTableControl tableControl) {
70:•                if (tableControl.getDomainModelReference() == null) {
71:                         return;
72:                 }
73:•                if (!VTableDomainModelReference.class.isInstance(tableControl.getDomainModelReference())) {
74:                         return;
75:                 }
76:                 final VTableDomainModelReference tableDmr = VTableDomainModelReference.class
77:                         .cast(tableControl.getDomainModelReference());
78:
79:                 boolean addColumns = false;
80:                 boolean segments = false;
81:•                if (tableDmr.getSegments().size() > 0) {
82:                         final VMultiDomainModelReferenceSegment multiSegment = (VMultiDomainModelReferenceSegment) tableDmr
83:                                 .getSegments().get(tableDmr.getSegments().size() - 1);
84:•                        addColumns = multiSegment.getChildDomainModelReferences().size() < 1;
85:                         segments = true;
86:                 } else {
87:•                        addColumns = tableDmr.getColumnDomainModelReferences().size() < 1;
88:                 }
89:
90:•                if (addColumns) {
91:                         final VTableDomainModelReference tableDMR = (VTableDomainModelReference) tableControl
92:                                 .getDomainModelReference();
93:                         final IValueProperty valueProperty;
94:                         try {
95:•                                if (segments || tableDMR.getDomainModelReference() == null) {
96:                                         valueProperty = context.getService(EMFFormsDatabinding.class)
97:                                                 .getValueProperty(tableDMR, context.getDomainModel());
98:                                 } else {
99:                                         valueProperty = context.getService(EMFFormsDatabinding.class)
100:                                                 .getValueProperty(tableDMR.getDomainModelReference(), context.getDomainModel());
101:                                 }
102:                         } catch (final DatabindingFailedException ex) {
103:                                 context.getService(ReportService.class).report(new DatabindingFailedReport(ex));
104:                                 return;
105:                         }
106:
107:                         final EStructuralFeature structuralFeature = (EStructuralFeature) valueProperty.getValueType();
108:                         final EClassifier eType = structuralFeature.getEType();
109:•                        if (eType instanceof EClass) {
110:                                 final EClass clazz = (EClass) eType;
111:                                 TableColumnGenerator.generateColumns(clazz, tableControl);
112:                         }
113:                 }
114:         }
115:
116:         /**
117:          * {@inheritDoc}
118:          *
119:          * @see org.eclipse.emf.ecp.view.spi.context.ViewModelService#dispose()
120:          */
121:         @Override
122:         public void dispose() {
123:                 // nothing to dispose
124:         }
125:
126:         /**
127:          * {@inheritDoc}
128:          *
129:          * @see org.eclipse.emf.ecp.view.spi.context.ViewModelService#getPriority()
130:          */
131:         @Override
132:         public int getPriority() {
133:                 return -1;
134:         }
135:
136: }