Skip to content

Package: ColumnConfigurationDMRRendererReferenceService

ColumnConfigurationDMRRendererReferenceService

nameinstructionbranchcomplexitylinemethod
ColumnConfigurationDMRRendererReferenceService(Class)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
addExistingModelElements(EObject, EReference)
M: 44 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 18 C: 0
0%
M: 1 C: 0
0%
addNewModelElements(EObject, EReference)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
addNewModelElements(EObject, EReference, boolean)
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%
dispose()
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getConfiguredColumns(VTableControl, EReference)
M: 42 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
getPriority()
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%
getUnconfiguredColumns(VDomainModelReference)
M: 36 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
instantiate(ViewModelContext)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
openInNewContext(EObject)
M: 1 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) 2017-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: * Johannes Faltermeier - initial API and implementation
13: * Lucas Koehler - adapt to work with segments, too
14: ******************************************************************************/
15: package org.eclipse.emf.ecp.view.internal.editor.controls;
16:
17: import java.util.HashSet;
18: import java.util.LinkedHashSet;
19: import java.util.Optional;
20: import java.util.Set;
21:
22: import org.eclipse.emf.common.util.EList;
23: import org.eclipse.emf.ecore.EObject;
24: import org.eclipse.emf.ecore.EReference;
25: import org.eclipse.emf.ecp.edit.spi.ReferenceService;
26: import org.eclipse.emf.ecp.spi.common.ui.SelectModelElementWizardFactory;
27: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
28: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
29: import org.eclipse.emf.ecp.view.spi.table.model.VTableColumnConfiguration;
30: import org.eclipse.emf.ecp.view.spi.table.model.VTableControl;
31: import org.eclipse.emf.ecp.view.spi.table.model.VTableDomainModelReference;
32: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
33: import org.eclipse.emfforms.view.spi.multisegment.model.MultiSegmentUtil;
34: import org.eclipse.emfforms.view.spi.multisegment.model.VMultiDomainModelReferenceSegment;
35:
36: /**
37: * Special {@link ReferenceService} allowing stream lined DMR selection for {@link VTableColumnConfiguration
38: * VTableColumnConfigurations}.
39: *
40: * @author Johannes Faltermeier
41: *
42: */
43: public class ColumnConfigurationDMRRendererReferenceService implements ReferenceService {
44:
45:         private final Class<? extends VTableColumnConfiguration> columnConfigClass;
46:
47:         /**
48:          * Constructor.
49:          *
50:          * @param columnConfigClass the {@link VTableColumnConfiguration} based class to be filtered
51:          */
52:         public ColumnConfigurationDMRRendererReferenceService(
53:                 Class<? extends VTableColumnConfiguration> columnConfigClass) {
54:                 this.columnConfigClass = columnConfigClass;
55:         }
56:
57:         @Override
58:         public void instantiate(ViewModelContext context) {
59:                 /* no-op */
60:         }
61:
62:         @Override
63:         public void dispose() {
64:                 /* no-op */
65:         }
66:
67:         @Override
68:         public int getPriority() {
69:                 /* no-op */
70:                 return 0;
71:         }
72:
73:         @Deprecated
74:         @Override
75:         public void addNewModelElements(EObject eObject, EReference eReference) {
76:                 /* no-op */
77:         }
78:
79:         @Override
80:         public org.eclipse.emfforms.common.Optional<EObject> addNewModelElements(EObject eObject, EReference eReference,
81:                 boolean openInNewContext) {
82:                 /* no-op */
83:                 return org.eclipse.emfforms.common.Optional.empty();
84:         }
85:
86:         @SuppressWarnings("restriction")
87:         @Override
88:         public void addExistingModelElements(EObject eObject, EReference eReference) {
89:•                if (!VTableControl.class.isInstance(eObject.eContainer())) {
90:                         return;
91:                 }
92:                 final VTableControl tableControl = VTableControl.class.cast(eObject.eContainer());
93:                 final Optional<Set<EObject>> unconfiguredColumns = getUnconfiguredColumns(
94:                         tableControl.getDomainModelReference());
95:•                if (!unconfiguredColumns.isPresent()) {
96:                         return;
97:                 }
98:
99:                 unconfiguredColumns.get().removeAll(getConfiguredColumns(tableControl, eReference));
100:
101:                 final Set<EObject> selectedColumns = SelectModelElementWizardFactory
102:                         .openModelElementSelectionDialog(
103:                                 unconfiguredColumns.get(),
104:                                 eReference.isMany());
105:
106:                 org.eclipse.emf.ecp.internal.edit.ECPControlHelper.addModelElementsInReference(
107:                         eObject,
108:                         selectedColumns,
109:                         eReference,
110:                         AdapterFactoryEditingDomain.getEditingDomainFor(eObject));
111:         }
112:
113:         /**
114:          * @param dmr The DMR defining the table
115:          * @return The set of all column dmrs which are not configured by a configuration of this service's
116:          * <code>columnConfigClass</code>. Returns nothing if the list of column dmrs cannot be retrieved from the
117:          * given dmr.
118:          */
119:         private Optional<Set<EObject>> getUnconfiguredColumns(VDomainModelReference dmr) {
120:                 Set<EObject> result = null;
121:•                if (!dmr.getSegments().isEmpty()) {
122:                         final Optional<VMultiDomainModelReferenceSegment> multiSegment = MultiSegmentUtil.getMultiSegment(dmr);
123:•                        if (multiSegment.isPresent()) {
124:                                 result = new LinkedHashSet<>(multiSegment.get().getChildDomainModelReferences());
125:                         }
126:•                } else if (dmr instanceof VTableDomainModelReference) {
127:                         final VTableDomainModelReference tableDmr = (VTableDomainModelReference) dmr;
128:                         result = new LinkedHashSet<>(tableDmr.getColumnDomainModelReferences());
129:                 }
130:                 return Optional.ofNullable(result);
131:         }
132:
133:         /**
134:          * @return The set of all column dmrs which are already configured by a configuration of this service's
135:          * <code>columnConfigClass</code>. May return an empty set but never <code>null</code>.
136:          */
137:         @SuppressWarnings("unchecked")
138:         private Set<EObject> getConfiguredColumns(VTableControl tableControl, EReference eReference) {
139:                 final Set<EObject> result = new HashSet<>();
140:•                for (final VTableColumnConfiguration columnConfiguration : tableControl.getColumnConfigurations()) {
141:•                        if (!columnConfigClass.isInstance(columnConfiguration)) {
142:                                 continue;
143:                         }
144:•                        if (eReference.isMany()) {
145:                                 result.addAll((EList<EObject>) columnConfiguration.eGet(eReference));
146:                         } else {
147:                                 result.add((EObject) columnConfiguration.eGet(eReference));
148:                         }
149:                 }
150:                 return result;
151:         }
152:
153:         @Override
154:         public void openInNewContext(EObject eObject) {
155:                 /* no-op */
156:         }
157:
158: }