Skip to content

Package: ECPMenuContributionsEnablementTester

ECPMenuContributionsEnablementTester

nameinstructionbranchcomplexitylinemethod
ECPMenuContributionsEnablementTester()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
test(Object, String, Object[], Object)
M: 92 C: 0
0%
M: 18 C: 0
0%
M: 10 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2008-2011 Chair for Applied Software Engineering,
3: * Technische Universitaet Muenchen.
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: ******************************************************************************/
13: package org.eclipse.emf.ecp.internal.ui.tester;
14:
15: import org.eclipse.core.expressions.PropertyTester;
16: import org.eclipse.core.runtime.IConfigurationElement;
17: import org.eclipse.core.runtime.Platform;
18:
19: /**
20: * Tests the enablement of ECP Menu contributions. The contributions are enabled by default and can be disabled by an
21: * extension point.
22: *
23: * @author koegel
24: * @since 1.3
25: *
26: */
27: public class ECPMenuContributionsEnablementTester extends PropertyTester {
28:
29:         /**
30:          * {@inheritDoc}
31:          *
32:          * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[],
33:          * java.lang.Object)
34:          */
35:         @Override
36:         public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
37:
38:•                if (expectedValue instanceof Boolean) {
39:                         // default behavior, display menu contribution
40:                         Boolean menuContributionEnabled = true;
41:                         // fetch contribution configuration
42:                         final IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(
43:                                 "org.eclipse.emf.ecp.ui.menuContributionEnablement");
44:•                        if (elements != null && elements.length > 0) {
45:•                                for (final IConfigurationElement configurationElement : elements) {
46:
47:                                         // fetch configured default option. true = blacklist; false = whitelist
48:                                         menuContributionEnabled = Boolean.parseBoolean(configurationElement.getAttribute("enabled"));
49:                                         // iterate over configured exceptions
50:•                                        for (final IConfigurationElement child : configurationElement.getChildren()) {
51:                                                 final String commandID = child.getAttribute("commandID");
52:                                                 // if blacklist & command on list -> block
53:•                                                if (menuContributionEnabled && args[0].equals(commandID)) {
54:                                                         return expectedValue.equals(false);
55:                                                         // if whitelist & command on list -> don't block
56:•                                                } else if (!menuContributionEnabled && args[0].equals(commandID)) {
57:                                                         return expectedValue.equals(true);
58:                                                 }
59:                                         }
60:                                 }
61:                         }
62:
63:                         return expectedValue.equals(menuContributionEnabled);
64:                 }
65:                 return false;
66:         }
67:
68: }