Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 415557182257cd1a05dbd95fe95e244a92bc8a4d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*****************************************************************************
 * Copyright (c) 2015, 2016 CEA LIST, Christian W. Damus, and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
 *  Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - adds isVisible implementation
 *  Christian W. Damus - bugs 469188, 485220
 *  
 *****************************************************************************/
package org.eclipse.papyrus.infra.properties.internal.ui.extensions;

import java.util.function.BiConsumer;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.papyrus.infra.properties.internal.ui.Activator;

/**
 * Handles the extension point <tt>org.eclipse.papyrus.infra.properties.ui.context</tt>
 * Registers the given Context preference page bindings.
 *
 * @author Camille Letavernier
 */
public class ContextBindingsExtensionPoint {


	private static final String PREFPAGE_BINDING = "preferencePageBinding"; //$NON-NLS-1$

	private static final String CONTEXT = "context"; //$NON-NLS-1$

	private static final String PAGE = "page"; //$NON-NLS-1$

	/** The extension id. */
	private final String EXTENSION_ID = "org.eclipse.papyrus.infra.properties.ui.context"; //$NON-NLS-1$

	/**
	 * Constructor
	 */
	public ContextBindingsExtensionPoint(BiConsumer<String, String> bindingProcessor) {
		super();

		IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);

		for (IConfigurationElement e : config) {
			try {
				switch (e.getName()) {
				case PREFPAGE_BINDING:
					processPrefPageBinding(e, bindingProcessor);
					break;
				}
			} catch (Exception ex) {
				Activator.log.error(ex);
			}
		}
	}

	private void processPrefPageBinding(IConfigurationElement config, BiConsumer<String, String> bindingProcessor) {
		boolean valid = true;

		String context = config.getAttribute(CONTEXT);
		if ((context == null) || context.isEmpty()) {
			valid = false;
			Activator.log.warn(String.format("Missing context name in preference page binding extension in plug-in %s", config.getContributor().getName()));
		}

		String page = config.getAttribute(PAGE);
		if ((page == null) || page.isEmpty()) {
			valid = false;
			Activator.log.warn(String.format("Missing page ID in preference page binding extension in plug-in %s", config.getContributor().getName()));
		}

		if (valid) {
			bindingProcessor.accept(context, page);
		}
	}
}

Back to the top