trace/traceviewer/com.nokia.traceviewer/src/com/nokia/traceviewer/TraceViewerPlugin.java
changeset 11 5b9d4d8641ce
equal deleted inserted replaced
10:ed1c9f64298a 11:5b9d4d8641ce
       
     1 /*
       
     2  * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). 
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:
       
    15  *
       
    16  * TraceViewer Plugin
       
    17  *
       
    18  */
       
    19 package com.nokia.traceviewer;
       
    20 
       
    21 import java.util.ArrayList;
       
    22 
       
    23 import org.eclipse.core.runtime.IConfigurationElement;
       
    24 import org.eclipse.core.runtime.Platform;
       
    25 import org.eclipse.ui.plugin.AbstractUIPlugin;
       
    26 import org.osgi.framework.BundleContext;
       
    27 
       
    28 import com.nokia.traceviewer.engine.DecodeProvider;
       
    29 import com.nokia.traceviewer.engine.TraceProvider;
       
    30 import com.nokia.traceviewer.engine.TraceViewerGlobals;
       
    31 import com.nokia.traceviewer.engine.TrimProvider;
       
    32 import com.nokia.traceviewer.engine.preferences.PreferenceConstants;
       
    33 
       
    34 /**
       
    35  * The activator class controls the plug-in life cycle
       
    36  * 
       
    37  */
       
    38 public class TraceViewerPlugin extends AbstractUIPlugin {
       
    39 
       
    40 	/**
       
    41 	 * The plug-in ID
       
    42 	 */
       
    43 	public static final String PLUGIN_ID = "com.nokia.traceviewer"; //$NON-NLS-1$
       
    44 
       
    45 	/**
       
    46 	 * Trim Provider extension point ID
       
    47 	 */
       
    48 	private static final String TRIMPROVIDER_EXTENSION_POINT_ID = "com.nokia.traceviewer.trimprovider"; //$NON-NLS-1$
       
    49 
       
    50 	/**
       
    51 	 * Decode Provider extension point ID
       
    52 	 */
       
    53 	private static final String DECODEPROVIDER_EXTENSION_POINT_ID = "com.nokia.traceviewer.decodeprovider"; //$NON-NLS-1$
       
    54 
       
    55 	/**
       
    56 	 * Trace Provider extension point ID
       
    57 	 */
       
    58 	private static final String TRACEPROVIDER_EXTENSION_POINT_ID = "com.nokia.traceviewer.traceprovider"; //$NON-NLS-1$
       
    59 
       
    60 	/**
       
    61 	 * The shared instance
       
    62 	 */
       
    63 	private static TraceViewerPlugin plugin;
       
    64 
       
    65 	/**
       
    66 	 * The constructor
       
    67 	 */
       
    68 	public TraceViewerPlugin() {
       
    69 		// Set this as a plugin
       
    70 		plugin = this;
       
    71 	}
       
    72 
       
    73 	/*
       
    74 	 * (non-Javadoc)
       
    75 	 * 
       
    76 	 * @see
       
    77 	 * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
       
    78 	 * )
       
    79 	 */
       
    80 	@Override
       
    81 	public void start(BundleContext context) throws Exception {
       
    82 		super.start(context);
       
    83 
       
    84 		TraceViewerGlobals.start();
       
    85 
       
    86 		// Insert providers
       
    87 		insertProviders();
       
    88 	}
       
    89 
       
    90 	/*
       
    91 	 * (non-Javadoc)
       
    92 	 * 
       
    93 	 * @see
       
    94 	 * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
       
    95 	 * )
       
    96 	 */
       
    97 	@Override
       
    98 	public void stop(BundleContext context) throws Exception {
       
    99 		// Run shutdown
       
   100 		TraceViewerGlobals.getTraceViewer().shutdown();
       
   101 
       
   102 		plugin = null;
       
   103 		super.stop(context);
       
   104 	}
       
   105 
       
   106 	/**
       
   107 	 * Returns the shared instance
       
   108 	 * 
       
   109 	 * @return the shared instance
       
   110 	 */
       
   111 	public static TraceViewerPlugin getDefault() {
       
   112 		// Returns this plugin
       
   113 		return plugin;
       
   114 	}
       
   115 
       
   116 	/**
       
   117 	 * Inserts trace and decode providers to the main engine
       
   118 	 */
       
   119 	private void insertProviders() {
       
   120 		try {
       
   121 			// Trim provider
       
   122 			IConfigurationElement[] config = Platform.getExtensionRegistry()
       
   123 					.getConfigurationElementsFor(
       
   124 							TRIMPROVIDER_EXTENSION_POINT_ID);
       
   125 			for (IConfigurationElement e : config) {
       
   126 				Object o = e.createExecutableExtension("class"); //$NON-NLS-1$
       
   127 				if (o instanceof TrimProvider) {
       
   128 					TraceViewerGlobals.setTrimProvider((TrimProvider) o);
       
   129 				}
       
   130 			}
       
   131 
       
   132 			// Decode provider
       
   133 			config = Platform.getExtensionRegistry()
       
   134 					.getConfigurationElementsFor(
       
   135 							DECODEPROVIDER_EXTENSION_POINT_ID);
       
   136 			for (IConfigurationElement e : config) {
       
   137 				Object o = e.createExecutableExtension("class"); //$NON-NLS-1$
       
   138 				if (o instanceof DecodeProvider) {
       
   139 					TraceViewerGlobals.setDecodeProvider((DecodeProvider) o);
       
   140 				}
       
   141 			}
       
   142 
       
   143 			// Trace providers
       
   144 			config = Platform.getExtensionRegistry()
       
   145 					.getConfigurationElementsFor(
       
   146 							TRACEPROVIDER_EXTENSION_POINT_ID);
       
   147 
       
   148 			// Put providers to ArrayList
       
   149 			ArrayList<TraceProvider> providers = new ArrayList<TraceProvider>();
       
   150 			for (int i = 0; i < config.length; i++) {
       
   151 				Object o = config[i].createExecutableExtension("class"); //$NON-NLS-1$
       
   152 				if (o instanceof TraceProvider) {
       
   153 					providers.add((TraceProvider) o);
       
   154 				}
       
   155 			}
       
   156 
       
   157 			// First check if selected is found and select that
       
   158 			String selectedDataFormat = plugin.getPreferenceStore().getString(
       
   159 					PreferenceConstants.DATA_FORMAT);
       
   160 			for (int j = 0; j < providers.size(); j++) {
       
   161 				TraceProvider provider = providers.get(j);
       
   162 				if (provider.getName().equals(selectedDataFormat)) {
       
   163 					TraceViewerGlobals.setTraceProvider(provider, true);
       
   164 					providers.remove(j);
       
   165 					break;
       
   166 				}
       
   167 			}
       
   168 
       
   169 			// Then set rest of the providers
       
   170 			for (int j = 0; j < providers.size(); j++) {
       
   171 				TraceViewerGlobals.setTraceProvider(providers.get(j), true);
       
   172 			}
       
   173 		} catch (Exception ex) {
       
   174 			System.out.println(ex.getMessage());
       
   175 		}
       
   176 	}
       
   177 
       
   178 }