Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: eab9de0f72fc7a8f0de7c140de8d48b3357b6edb (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
/*****************************************************************************
 * Copyright (c) 2012 CEA LIST.
 * 
 * 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
 *****************************************************************************/
package org.eclipse.papyrus.infra.emf.appearance.helper;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EModelElement;
import org.eclipse.papyrus.infra.emf.appearance.Activator;
import org.eclipse.papyrus.infra.emf.appearance.style.AnnotationStyleProvider;
import org.eclipse.papyrus.infra.emf.appearance.style.AppearanceStyleProvider;


public class AppearanceHelper {

	public static String EXTENSION_ID = Activator.PLUGIN_ID + ".styleProvider";

	public static boolean showElementIcon(EModelElement modelElement) {
		return styleProvider.showElementIcon(modelElement);
	}

	public static int getQualifiedNameDepth(EModelElement modelElement) {
		return styleProvider.getQualifiedNameDepth(modelElement);
	}

	public static boolean showShadow(EModelElement modelElement) {
		return styleProvider.showShadow(modelElement);
	}

	private static AppearanceStyleProvider findStyleProvider() {
		//Default style provider
		AppearanceStyleProvider provider = new AnnotationStyleProvider();

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

		int currentPriority = Integer.MAX_VALUE;
		for(IConfigurationElement e : config) {
			try {
				int priority = Integer.parseInt(e.getAttribute("priority")); //$NON-NLS-1$
				if(priority < currentPriority) {
					provider = (AppearanceStyleProvider)e.createExecutableExtension("styleProvider"); //$NON-NLS-1$
					currentPriority = priority;
				}
			} catch (Exception ex) {
				Activator.log.error("The plugin " + e.getContributor() + " contributed an invalid extension for " + EXTENSION_ID, ex); //$NON-NLS-1$//$NON-NLS-2$
			}
		}

		return provider;
	}

	private static AppearanceStyleProvider styleProvider = findStyleProvider();
}

Back to the top