| 1 | /********************************************************************** |
| 2 | * Copyright (c) 2013, 2014 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 |
| 11 | * Matthew Khouzam - Implementation of File->Open |
| 12 | **********************************************************************/ |
| 13 | package org.eclipse.linuxtools.internal.tracing.rcp.ui; |
| 14 | |
| 15 | import org.eclipse.core.runtime.IStatus; |
| 16 | import org.eclipse.core.runtime.Platform; |
| 17 | import org.eclipse.core.runtime.Status; |
| 18 | import org.eclipse.jface.resource.ImageDescriptor; |
| 19 | import org.eclipse.linuxtools.internal.tracing.rcp.ui.cli.TracingRCPCliException; |
| 20 | import org.eclipse.linuxtools.internal.tracing.rcp.ui.cli.CliParser; |
| 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 | |
| 39 | /** |
| 40 | * The default workspace name |
| 41 | */ |
| 42 | public static final String WORKSPACE_NAME = ".traceviewer"; //$NON-NLS-1$ |
| 43 | |
| 44 | // ------------------------------------------------------------------------ |
| 45 | // Attributes |
| 46 | // ------------------------------------------------------------------------ |
| 47 | |
| 48 | // The shared instance |
| 49 | private static TracingRcpPlugin fPlugin; |
| 50 | private static CliParser fCli; |
| 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 | |
| 73 | /** |
| 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. |
| 77 | * |
| 78 | * @return the tracing workspace root directory |
| 79 | */ |
| 80 | public static String getWorkspaceRoot() { |
| 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; |
| 88 | } |
| 89 | |
| 90 | // ------------------------------------------------------------------------ |
| 91 | // Operation |
| 92 | // ------------------------------------------------------------------------ |
| 93 | @Override |
| 94 | public void start(BundleContext context) throws Exception { |
| 95 | super.start(context); |
| 96 | fPlugin = this; |
| 97 | String args[] = Platform.getCommandLineArgs(); |
| 98 | fCli = null; |
| 99 | try { |
| 100 | fCli = new CliParser(args); |
| 101 | } catch (TracingRCPCliException e) { |
| 102 | logError(e.getMessage()); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public void stop(BundleContext context) throws Exception { |
| 108 | fPlugin = null; |
| 109 | super.stop(context); |
| 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 | } |
| 120 | |
| 121 | /** |
| 122 | * Returns an image descriptor for the image file at the given plug-in |
| 123 | * relative path |
| 124 | * |
| 125 | * @param path |
| 126 | * the path |
| 127 | * @return the image descriptor |
| 128 | */ |
| 129 | public static ImageDescriptor getImageDescriptor(String path) { |
| 130 | return imageDescriptorFromPlugin(PLUGIN_ID, path); |
| 131 | } |
| 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 | |
| 167 | } |