Skip to content

Package: CellReadOnlyTesterHelper

CellReadOnlyTesterHelper

nameinstructionbranchcomplexitylinemethod
CellReadOnlyTesterHelper()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getInstance()
M: 0 C: 8
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
isReadOnly(VTableControl, EStructuralFeature.Setting)
M: 0 C: 23
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
readExtensionPoint()
M: 21 C: 20
49%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 5 C: 6
55%
M: 0 C: 1
100%
registerCellReadOnlyTester(ECPCellReadOnlyTester)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 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: * Eugen Neufeld - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.internal.table.swt;
15:
16: import java.util.LinkedHashSet;
17: import java.util.Set;
18:
19: import org.eclipse.core.runtime.CoreException;
20: import org.eclipse.core.runtime.IConfigurationElement;
21: import org.eclipse.core.runtime.IExtensionRegistry;
22: import org.eclipse.core.runtime.Platform;
23: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
24: import org.eclipse.emf.ecp.view.spi.table.model.VTableControl;
25: import org.eclipse.emf.ecp.view.spi.table.swt.ECPCellReadOnlyTester;
26:
27: /**
28: * Helper class which collects the cell testers and allows to iterate over all to check whether a cell should be read
29: * only.
30: *
31: * @author Eugen Neufeld
32: *
33: */
34: public final class CellReadOnlyTesterHelper {
35:
36:         private static CellReadOnlyTesterHelper instance;
37:
38:         /**
39:          * The CellReadOnlyTesterHelper instance.
40:          *
41:          * @return the CellReadOnlyTesterHelper instance
42:          */
43:         public static CellReadOnlyTesterHelper getInstance() {
44:•                if (instance == null) {
45:                         instance = new CellReadOnlyTesterHelper();
46:                 }
47:                 return instance;
48:         }
49:
50:         private final Set<ECPCellReadOnlyTester> testers = new LinkedHashSet<ECPCellReadOnlyTester>();
51:
52:         private CellReadOnlyTesterHelper() {
53:                 readExtensionPoint();
54:         }
55:
56:         private void readExtensionPoint() {
57:
58:                 final IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
59:•                if (extensionRegistry == null) {
60:                         return;
61:                 }
62:                 final IConfigurationElement[] controls = extensionRegistry
63:                         .getConfigurationElementsFor("org.eclipse.emf.ecp.view.table.ui.swt.cellReadOnly"); //$NON-NLS-1$
64:•                for (final IConfigurationElement e : controls) {
65:                         try {
66:                                 final ECPCellReadOnlyTester tester = (ECPCellReadOnlyTester) e.createExecutableExtension("class"); //$NON-NLS-1$
67:                                 testers.add(tester);
68:                         } catch (final CoreException e1) {
69:                                 Activator.getInstance().log(e1);
70:                         }
71:                 }
72:         }
73:
74:         /**
75:          * Register an {@link ECPCellReadOnlyTester} programmatically.
76:          *
77:          * @param tester the {@link ECPCellReadOnlyTester} to register
78:          */
79:         public void registerCellReadOnlyTester(ECPCellReadOnlyTester tester) {
80:                 testers.add(tester);
81:         }
82:
83:         /**
84:          * Check all {@link ECPCellReadOnlyTester} for the cell.
85:          *
86:          * @param vTableControl the {@link VTableControl}
87:          * @param setting the {@link Setting} of the cell
88:          * @return true if any {@link ECPCellReadOnlyTester} wants the cell to be readonly false otherwise.
89:          */
90:         public boolean isReadOnly(VTableControl vTableControl, Setting setting) {
91:                 boolean result = false;
92:•                for (final ECPCellReadOnlyTester tester : testers) {
93:                         result |= tester.isCellReadOnly(vTableControl, setting);
94:                 }
95:                 return result;
96:         }
97: }