Skip to content

Package: ReferenceStrategyUtil$1

ReferenceStrategyUtil$1

nameinstructionbranchcomplexitylinemethod
collectEClasses(EObject, EReference, Collection)
M: 0 C: 32
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
{...}
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
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: * Christian W. Damus - bug 547787
14: ******************************************************************************/
15: package org.eclipse.emf.ecp.ui.view.swt.reference;
16:
17: import java.util.Collection;
18: import java.util.Collections;
19: import java.util.List;
20:
21: import org.eclipse.emf.ecore.EClass;
22: import org.eclipse.emf.ecore.EObject;
23: import org.eclipse.emf.ecore.EReference;
24: import org.eclipse.emfforms.bazaar.Bazaar;
25: import org.eclipse.emfforms.bazaar.BazaarContext;
26: import org.eclipse.emfforms.spi.bazaar.BazaarUtil;
27: import org.osgi.service.component.ComponentContext;
28:
29: /**
30: * Common functionality for the creation strategies for the DefaultReferenceService.
31: *
32: * @author Lucas Koehler
33: * @since 1.17
34: *
35: */
36: public final class ReferenceStrategyUtil {
37:         /**
38:          * Prevent instantiation of this utility class.
39:          */
40:         private ReferenceStrategyUtil() {
41:         }
42:
43:         /**
44:          * Creates an {@link EClassSelectionStrategy} which uses all {@link EClassSelectionStrategy
45:          * EClassSelectionStrategies} registered to the given bazaar. When
46:          * {@link EClassSelectionStrategy#collectEClasses(EObject, EReference, Collection)} of the created strategy is
47:          * called, all applicable strategies are applied one after another.
48:          *
49:          * @param bazaar The {@link Bazaar} providing the {@link EClassSelectionStrategy EClassSelectionStrategies}
50:          * @param context The receiver's ComponentContext
51:          * @return The dynamic composite {@link EClassSelectionStrategy}
52:          */
53:         public static EClassSelectionStrategy createDynamicEClassSelectionStrategy(
54:                 final Bazaar<EClassSelectionStrategy> bazaar, final ComponentContext context) {
55:                 return new EClassSelectionStrategy() {
56:
57:                         @Override
58:                         public Collection<EClass> collectEClasses(EObject owner, EReference reference,
59:                                 Collection<EClass> eclasses) {
60:
61:                                 Collection<EClass> result = eclasses;
62:
63:                                 final List<EClassSelectionStrategy> delegates = bazaar.createProducts(
64:                                         createBazaarContext(context, owner, reference));
65:                                 // sort from low to high
66:                                 Collections.reverse(delegates);
67:
68:•                                for (final EClassSelectionStrategy next : delegates) {
69:                                         result = next.collectEClasses(owner, reference, result);
70:                                 }
71:
72:                                 return result;
73:                         }
74:                 };
75:         }
76:
77:         /**
78:          * Creates a basic {@link BazaarContext} that contains the properties of the {@link ComponentContext}. Adds the
79:          * <code>owner</code> as a context value for class {@link EObject} and the <code>reference</code> for class
80:          * {@link EReference}.
81:          *
82:          * @param context The {@link ComponentContext}
83:          * @param owner The {@link EObject} containing a reference
84:          * @param reference The {@link EReference}
85:          * @return The configured {@link BazaarContext}
86:          */
87:         public static BazaarContext createBazaarContext(ComponentContext context, EObject owner, EReference reference) {
88:                 return bazaarContextBuilder(context, owner, reference).build();
89:         }
90:
91:         /**
92:          * Creates a {@link BazaarContext} builder that seeds the context with the properties of the
93:          * {@link ComponentContext}, the <code>owner</code> as a context value for class {@link EObject},
94:          * and the <code>reference</code> for class {@link EReference}.
95:          *
96:          * @param context The {@link ComponentContext}
97:          * @param owner The {@link EObject} containing a reference
98:          * @param reference The {@link EReference}
99:          * @return The configured {@link BazaarContext}
100:          *
101:          * @since 1.22
102:          */
103:         public static BazaarContext.Builder bazaarContextBuilder(ComponentContext context, EObject owner,
104:                 EReference reference) {
105:                 return BazaarUtil.createBaseContext(context.getProperties())
106:                         .put(EObject.class, owner)
107:                         .put(EReference.class, reference);
108:         }
109:
110: }