Skip to content

Package: TableColumnsDmrViewService

TableColumnsDmrViewService

nameinstructionbranchcomplexitylinemethod
TableColumnsDmrViewService(EMFFormsViewContext)
M: 0 C: 60
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
lambda$0(List, EObject)
M: 0 C: 19
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2019 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: * Lucas Koehler - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.internal.editor.handler;
15:
16: import java.util.LinkedList;
17: import java.util.List;
18: import java.util.stream.Collectors;
19:
20: import org.eclipse.emf.ecore.EObject;
21: import org.eclipse.emf.ecp.view.spi.model.VControl;
22: import org.eclipse.emf.ecp.view.spi.model.VElement;
23: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
24: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
25: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
26: import org.eclipse.emf.ecp.view.spi.table.model.VTablePackage;
27: import org.eclipse.emf.emfforms.spi.view.annotation.model.VAnnotation;
28: import org.eclipse.emfforms.spi.core.services.view.EMFFormsViewContext;
29:
30: /**
31: * This view service searches a view model for a control annotated with <code>showChildDomainModelReferences</code>.
32: * If the legacy mode is used, the control's dmr is changed to point to the table dmr's list of column dmrs.
33: *
34: * @author Lucas Koehler
35: *
36: */
37: public class TableColumnsDmrViewService {
38:
39:         /**
40:          * Key of the annotation that defines that the child dmrs of a dmr's multi segment should be rendered.
41:          */
42:         private static final String SHOW_CHILD_DOMAIN_MODEL_REFERENCES = "showChildDomainModelReferences"; //$NON-NLS-1$
43:
44:         /**
45:          * Creates the view service.
46:          *
47:          * @param viewContext The {@link EMFFormsViewContext} for which the service is instantiated
48:          */
49:         public TableColumnsDmrViewService(EMFFormsViewContext viewContext) {
50:
51:                 final VElement view = viewContext.getViewModel();
52:                 final List<VAnnotation> annotations = new LinkedList<>();
53:                 view.eAllContents().forEachRemaining(object -> {
54:•                        if (object instanceof VAnnotation) {
55:                                 final String key = VAnnotation.class.cast(object).getKey();
56:•                                if (SHOW_CHILD_DOMAIN_MODEL_REFERENCES.equals(key)) {
57:                                         annotations.add((VAnnotation) object);
58:                                 }
59:                         }
60:                 });
61:
62:                 final List<VControl> controls = annotations.stream().map(EObject::eContainer).filter(VControl.class::isInstance)
63:                         .map(VControl.class::cast).collect(Collectors.toList());
64:•                for (final VControl control : controls) {
65:                         final VFeaturePathDomainModelReference dmr = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
66:                         dmr.getDomainModelEReferencePath().add(VViewPackage.Literals.CONTROL__DOMAIN_MODEL_REFERENCE);
67:                         dmr.setDomainModelEFeature(
68:                                 VTablePackage.Literals.TABLE_DOMAIN_MODEL_REFERENCE__COLUMN_DOMAIN_MODEL_REFERENCES);
69:                         control.setDomainModelReference(dmr);
70:                 }
71:         }
72: }