Commit | Line | Data |
---|---|---|
9c0ffa34 BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2013 Ericsson | |
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 BH |
12 | **********************************************************************/ |
13 | package org.eclipse.linuxtools.internal.tracing.rcp.ui; | |
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; |
76fccfb0 MK |
19 | import org.eclipse.linuxtools.internal.tracing.rcp.ui.cli.TracingRCPCliException; |
20 | import org.eclipse.linuxtools.internal.tracing.rcp.ui.cli.CliParser; | |
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 | */ | |
37 | public static final String PLUGIN_ID = "org.eclipse.linuxtools.tracing.rcp.ui"; //$NON-NLS-1$ | |
38 | ||
b42043af BH |
39 | /** |
40 | * The default workspace name | |
41 | */ | |
42 | public static final String WORKSPACE_NAME = ".traceviewer"; //$NON-NLS-1$ | |
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 BH |
73 | /** |
74 | * Gets the tracing workspace root directory | |
75 | * | |
76 | * @return the tracing workspace root directory | |
77 | */ | |
78 | public static String getWorkspaceRoot() { | |
79 | return System.getProperty("user.home"); //$NON-NLS-1$ | |
80 | } | |
81 | ||
9c0ffa34 BH |
82 | // ------------------------------------------------------------------------ |
83 | // Operation | |
84 | // ------------------------------------------------------------------------ | |
85 | @Override | |
86 | public void start(BundleContext context) throws Exception { | |
87 | super.start(context); | |
88 | fPlugin = this; | |
76fccfb0 MK |
89 | String args[] = Platform.getCommandLineArgs(); |
90 | fCli = null; | |
91 | try { | |
92 | fCli = new CliParser(args); | |
93 | } catch (TracingRCPCliException e) { | |
94 | logError(e.getMessage()); | |
9c0ffa34 | 95 | } |
76fccfb0 | 96 | } |
9c0ffa34 BH |
97 | |
98 | @Override | |
99 | public void stop(BundleContext context) throws Exception { | |
100 | fPlugin = null; | |
101 | super.stop(context); | |
76fccfb0 MK |
102 | } |
103 | ||
104 | /** | |
105 | * Gets the command line parser | |
106 | * | |
107 | * @return the command line parser | |
108 | */ | |
109 | public CliParser getCli() { | |
110 | return fCli; | |
111 | } | |
9c0ffa34 BH |
112 | |
113 | /** | |
76fccfb0 MK |
114 | * Returns an image descriptor for the image file at the given plug-in |
115 | * relative path | |
9c0ffa34 | 116 | * |
76fccfb0 MK |
117 | * @param path |
118 | * the path | |
9c0ffa34 BH |
119 | * @return the image descriptor |
120 | */ | |
121 | public static ImageDescriptor getImageDescriptor(String path) { | |
122 | return imageDescriptorFromPlugin(PLUGIN_ID, path); | |
123 | } | |
76fccfb0 MK |
124 | |
125 | /** | |
126 | * Log an error | |
127 | * | |
128 | * @param message | |
129 | * the error message to log | |
130 | */ | |
131 | public void logError(String message) { | |
132 | getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message)); | |
133 | } | |
134 | ||
135 | /** | |
136 | * Log an error | |
137 | * | |
138 | * @param message | |
139 | * the error message to log | |
140 | * @param e | |
141 | * the exception to log | |
142 | */ | |
143 | public void logError(String message, Exception e) { | |
144 | getDefault().getLog().log( | |
145 | new Status(IStatus.ERROR, PLUGIN_ID, message, e)); | |
146 | } | |
147 | ||
148 | /** | |
149 | * Log a warning | |
150 | * | |
151 | * @param message | |
152 | * the warning message to log | |
153 | */ | |
154 | public void logWarning(String message) { | |
155 | getDefault().getLog().log( | |
156 | new Status(IStatus.WARNING, PLUGIN_ID, message)); | |
157 | } | |
158 | ||
9c0ffa34 | 159 | } |