Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 365a24b99bce3c32fa83488bc2aba36a7bb8948f (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
/*******************************************************************************
 * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) 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:
 *     Soyatec - initial API and implementation
 *     Anyware-tech - add multiple loaders
 *******************************************************************************/
package org.eclipse.papyrus.xwt;

/**
 * Class allowing to keep the reference on the XWT loader active
 */
public class XWTLoaderManager {

	/** Default XWT loader */
	private static IXWTLoader defaultXWTLoader;

	/** Active XWT loader */
	private static IXWTLoader activeXWTLoader;

	/**
	 * Returns the default instance of the XWT loader
	 * 
	 * @return the default instance of the XWT loader
	 */
	public static IXWTLoader getDefault() {
		if(defaultXWTLoader == null) {
			defaultXWTLoader = new XWTLoader();
			XWT.runInitializers(defaultXWTLoader);
		}
		return defaultXWTLoader;
	}

	public static boolean isStarted() {
		return defaultXWTLoader != null;
	}

	/**
	 * Returns the instance of the XWT loader active. If no XWT loader are active, returns the default XWT loader
	 * 
	 * @return the instance of the XWT loader active
	 */
	public static IXWTLoader getActive() {
		IXWTLoader xwtLoader = activeXWTLoader;
		if(xwtLoader == null) {
			xwtLoader = getDefault();
		}
		return xwtLoader;
	}

	/**
	 * Sets the active XWT loader
	 * 
	 * @param xwtLoader
	 *        the XWT loader
	 * @param active
	 *        true if the XWT loader is active, otherwise false
	 */
	public static void setActive(IXWTLoader xwtLoader, boolean active) {
		if(active) {
			activeXWTLoader = xwtLoader;
		} else if(xwtLoader != null && xwtLoader.equals(activeXWTLoader)) {
			activeXWTLoader = null;
		}
	}
}

Back to the top