Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1a9fa293488991fb3efae69ba9dcf490ffe92368 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package org.eclipse.e4.internal.tools;

import java.net.URL;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

public class ToolsPlugin extends AbstractUIPlugin {
	// The plug-in ID
	public static final String PLUGIN_ID = "org.eclipse.e4.tools"; //$NON-NLS-1$
 
	private static ToolsPlugin plugin;
	
	private ResourceLocator resourceLocator;
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
	 * )
	 */
	public void start(BundleContext context) throws Exception {
		super.start(context);
		plugin = this;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
	 * )
	 */
	public void stop(BundleContext context) throws Exception {
		plugin = null;
		super.stop(context);
	}

	/**
	 * Returns the shared instance
	 * 
	 * @return the shared instance
	 */
	public static ToolsPlugin getDefault() {
		return plugin;
	}
	
	public ResourceLocator getResourceLocator() {
		if (resourceLocator == null) {
			resourceLocator = new ResourceLocator() {
				
				public String getString(String key, Object[] substitutions,
						boolean translate) {
					return null;
				}
				
				public String getString(String key, Object[] substitutions) {
					return null;
				}
				
				public String getString(String key, boolean translate) {
					return null;
				}
				
				public String getString(String key) {
					return null;
				}
				
				public Object getImage(String key) {
					return null;
				}
				
				public URL getBaseURL() {
					return null;
				}
			};
		}
		return resourceLocator;
	}
	
	public static void log(IStatus status, int nesting, boolean appendLogger) {
		getDefault().getLog().log(status);
	}
	
	/**
	 * Log Throwable Error
	 */
	public static void logError(Throwable t) {
		logError(t, 0, true);
	}

	public static void logError(Throwable t, boolean appendLogger) {
		logError(t, 0, appendLogger);
	}

	public static void logError(Throwable t, int nesting) {
		logError(t, nesting, true);
	}

	public static void logError(Throwable t, int nesting, boolean appendLogger) {
		log(newStatus(IStatus.ERROR, t.getMessage(), t), nesting, appendLogger);
	}
	
	/**
	 * Create an IStatus
	 * 
	 * @return a new IStatus
	 */
	public static IStatus newStatus(int severity, String message,
			Throwable exception) {
		return new Status(severity, PLUGIN_ID, 0, message, exception);
	}
}

Back to the top