Commit | Line | Data |
---|---|---|
9c0ffa34 | 1 | /********************************************************************** |
60ae41e1 | 2 | * Copyright (c) 2013, 2014 Ericsson |
9c0ffa34 BH |
3 | * |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Bernd Hufmann - Initial API and implementation | |
76fccfb0 | 11 | * Matthew Khouzam - Implementation of File->Open |
9c0ffa34 | 12 | **********************************************************************/ |
9d26aebf | 13 | package org.eclipse.tracecompass.internal.tracing.rcp.ui; |
9c0ffa34 | 14 | |
76fccfb0 MK |
15 | import org.eclipse.core.runtime.IStatus; |
16 | import org.eclipse.core.runtime.Platform; | |
17 | import org.eclipse.core.runtime.Status; | |
9c0ffa34 | 18 | import org.eclipse.jface.resource.ImageDescriptor; |
9d26aebf AM |
19 | import org.eclipse.tracecompass.internal.tracing.rcp.ui.cli.CliParser; |
20 | import org.eclipse.tracecompass.internal.tracing.rcp.ui.cli.TracingRCPCliException; | |
9c0ffa34 BH |
21 | import org.eclipse.ui.plugin.AbstractUIPlugin; |
22 | import org.osgi.framework.BundleContext; | |
23 | ||
24 | /** | |
25 | * The activator class controls the plug-in life cycle. | |
26 | * | |
27 | * @author Bernd Hufmann | |
28 | */ | |
29 | public class TracingRcpPlugin extends AbstractUIPlugin { | |
30 | ||
31 | // ------------------------------------------------------------------------ | |
32 | // Constants | |
33 | // ------------------------------------------------------------------------ | |
34 | /** | |
35 | * The plug-in ID | |
36 | */ | |
1814c020 | 37 | public static final String PLUGIN_ID = "org.eclipse.tracecompass.rcp.ui"; //$NON-NLS-1$ |
9c0ffa34 | 38 | |
b42043af BH |
39 | /** |
40 | * The default workspace name | |
41 | */ | |
1814c020 | 42 | public static final String WORKSPACE_NAME = ".tracecompass"; //$NON-NLS-1$ |
b42043af | 43 | |
9c0ffa34 BH |
44 | // ------------------------------------------------------------------------ |
45 | // Attributes | |
46 | // ------------------------------------------------------------------------ | |
47 | ||
48 | // The shared instance | |
49 | private static TracingRcpPlugin fPlugin; | |
76fccfb0 | 50 | private static CliParser fCli; |
9c0ffa34 BH |
51 | |
52 | // ------------------------------------------------------------------------ | |
53 | // Constructor(s) | |
54 | // ------------------------------------------------------------------------ | |
55 | /** | |
56 | * The default constructor | |
57 | */ | |
58 | public TracingRcpPlugin() { | |
59 | } | |
60 | ||
61 | // ------------------------------------------------------------------------ | |
62 | // Accessors | |
63 | // ------------------------------------------------------------------------ | |
64 | /** | |
65 | * Returns the shared instance | |
66 | * | |
67 | * @return the shared instance | |
68 | */ | |
69 | public static TracingRcpPlugin getDefault() { | |
70 | return fPlugin; | |
71 | } | |
72 | ||
b42043af | 73 | /** |
9f0e5ca9 GB |
74 | * Gets the tracing workspace root directory. By default it uses the user's |
75 | * home directory. This value can be overwritten by using the global | |
76 | * TRACING_RCP_ROOT environment variable. | |
b42043af BH |
77 | * |
78 | * @return the tracing workspace root directory | |
79 | */ | |
80 | public static String getWorkspaceRoot() { | |
9f0e5ca9 GB |
81 | /* Look for the environment variable in the global environment variables */ |
82 | String workspaceRoot = System.getenv().get("TRACING_RCP_ROOT"); //$NON-NLS-1$ | |
83 | if (workspaceRoot == null) { | |
84 | /* Use the user's home directory */ | |
85 | workspaceRoot = System.getProperty("user.home"); //$NON-NLS-1$ | |
86 | } | |
87 | return workspaceRoot; | |
b42043af BH |
88 | } |
89 | ||
9c0ffa34 BH |
90 | // ------------------------------------------------------------------------ |
91 | // Operation | |
92 | // ------------------------------------------------------------------------ | |
93 | @Override | |
94 | public void start(BundleContext context) throws Exception { | |
95 | super.start(context); | |
96 | fPlugin = this; | |
76fccfb0 MK |
97 | String args[] = Platform.getCommandLineArgs(); |
98 | fCli = null; | |
99 | try { | |
100 | fCli = new CliParser(args); | |
101 | } catch (TracingRCPCliException e) { | |
102 | logError(e.getMessage()); | |
9c0ffa34 | 103 | } |
76fccfb0 | 104 | } |
9c0ffa34 BH |
105 | |
106 | @Override | |
107 | public void stop(BundleContext context) throws Exception { | |
108 | fPlugin = null; | |
109 | super.stop(context); | |
76fccfb0 MK |
110 | } |
111 | ||
112 | /** | |
113 | * Gets the command line parser | |
114 | * | |
115 | * @return the command line parser | |
116 | */ | |
117 | public CliParser getCli() { | |
118 | return fCli; | |
119 | } | |
9c0ffa34 BH |
120 | |
121 | /** | |
76fccfb0 MK |
122 | * Returns an image descriptor for the image file at the given plug-in |
123 | * relative path | |
9c0ffa34 | 124 | * |
76fccfb0 MK |
125 | * @param path |
126 | * the path | |
9c0ffa34 BH |
127 | * @return the image descriptor |
128 | */ | |
129 | public static ImageDescriptor getImageDescriptor(String path) { | |
130 | return imageDescriptorFromPlugin(PLUGIN_ID, path); | |
131 | } | |
76fccfb0 MK |
132 | |
133 | /** | |
134 | * Log an error | |
135 | * | |
136 | * @param message | |
137 | * the error message to log | |
138 | */ | |
139 | public void logError(String message) { | |
140 | getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message)); | |
141 | } | |
142 | ||
143 | /** | |
144 | * Log an error | |
145 | * | |
146 | * @param message | |
147 | * the error message to log | |
148 | * @param e | |
149 | * the exception to log | |
150 | */ | |
151 | public void logError(String message, Exception e) { | |
152 | getDefault().getLog().log( | |
153 | new Status(IStatus.ERROR, PLUGIN_ID, message, e)); | |
154 | } | |
155 | ||
156 | /** | |
157 | * Log a warning | |
158 | * | |
159 | * @param message | |
160 | * the warning message to log | |
161 | */ | |
162 | public void logWarning(String message) { | |
163 | getDefault().getLog().log( | |
164 | new Status(IStatus.WARNING, PLUGIN_ID, message)); | |
165 | } | |
166 | ||
9c0ffa34 | 167 | } |