|
1 /* |
|
2 * Copyright (c) 2009 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 */ |
|
17 package com.nokia.testfw.launch; |
|
18 |
|
19 import org.eclipse.core.resources.IProject; |
|
20 import org.eclipse.core.runtime.CoreException; |
|
21 import org.eclipse.core.runtime.IStatus; |
|
22 import org.eclipse.core.runtime.Status; |
|
23 import org.eclipse.debug.core.DebugPlugin; |
|
24 import org.eclipse.debug.core.ILaunchManager; |
|
25 import org.eclipse.ui.IWorkbench; |
|
26 import org.eclipse.ui.IWorkbenchPage; |
|
27 import org.eclipse.ui.IWorkbenchWindow; |
|
28 import org.eclipse.ui.plugin.AbstractUIPlugin; |
|
29 import org.osgi.framework.BundleContext; |
|
30 |
|
31 import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin; |
|
32 import com.nokia.testfw.launch.monitor.LogMonitor; |
|
33 |
|
34 /** |
|
35 * The activator class controls the plug-in life cycle |
|
36 */ |
|
37 public class TFWLaunchPlugin extends AbstractUIPlugin { |
|
38 |
|
39 // The plug-in ID |
|
40 public static final String PLUGIN_ID = "com.nokia.testfw.launch"; |
|
41 |
|
42 // The shared instance |
|
43 private static TFWLaunchPlugin plugin; |
|
44 |
|
45 private static TFWLaunchListener iLaunchListener; |
|
46 |
|
47 private static LogMonitor iLogMonitor; |
|
48 |
|
49 /** |
|
50 * The constructor |
|
51 */ |
|
52 public TFWLaunchPlugin() { |
|
53 } |
|
54 |
|
55 /* |
|
56 * (non-Javadoc) |
|
57 * |
|
58 * @see |
|
59 * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext |
|
60 * ) |
|
61 */ |
|
62 public void start(BundleContext context) throws Exception { |
|
63 super.start(context); |
|
64 plugin = this; |
|
65 addLaunchListener(); |
|
66 } |
|
67 |
|
68 /* |
|
69 * (non-Javadoc) |
|
70 * |
|
71 * @see |
|
72 * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext |
|
73 * ) |
|
74 */ |
|
75 public void stop(BundleContext context) throws Exception { |
|
76 plugin = null; |
|
77 if (iLogMonitor != null) { |
|
78 iLogMonitor.stopme(); |
|
79 iLogMonitor = null; |
|
80 } |
|
81 super.stop(context); |
|
82 removeLaunchListener(); |
|
83 } |
|
84 |
|
85 /** |
|
86 * Returns the shared instance |
|
87 * |
|
88 * @return the shared instance |
|
89 */ |
|
90 public static TFWLaunchPlugin getDefault() { |
|
91 return plugin; |
|
92 } |
|
93 |
|
94 /** |
|
95 * @return the iLogMonitor |
|
96 */ |
|
97 public static LogMonitor getLogMonitor() { |
|
98 if (iLogMonitor == null) { |
|
99 iLogMonitor = new LogMonitor(); |
|
100 iLogMonitor.start(); |
|
101 } |
|
102 return iLogMonitor; |
|
103 } |
|
104 |
|
105 public static IProject getSelectedProject() { |
|
106 return CarbideBuilderPlugin.getProjectInContext(); |
|
107 } |
|
108 |
|
109 /** |
|
110 * Returns the active workbench window |
|
111 * |
|
112 * @return the active workbench window |
|
113 */ |
|
114 public static IWorkbenchWindow getActiveWorkbenchWindow() { |
|
115 if (plugin == null) |
|
116 return null; |
|
117 IWorkbench workBench = plugin.getWorkbench(); |
|
118 if (workBench == null) |
|
119 return null; |
|
120 return workBench.getActiveWorkbenchWindow(); |
|
121 } |
|
122 |
|
123 public static IWorkbenchPage getActivePage() { |
|
124 IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow(); |
|
125 if (activeWorkbenchWindow == null) |
|
126 return null; |
|
127 return activeWorkbenchWindow.getActivePage(); |
|
128 } |
|
129 |
|
130 public static void addLaunchListener() { |
|
131 ILaunchManager launchManager = DebugPlugin.getDefault() |
|
132 .getLaunchManager(); |
|
133 if (iLaunchListener == null) { |
|
134 iLaunchListener = new TFWLaunchListener(); |
|
135 launchManager.addLaunchListener(iLaunchListener); |
|
136 } |
|
137 } |
|
138 |
|
139 public static void removeLaunchListener() { |
|
140 if (iLaunchListener != null) { |
|
141 ILaunchManager launchManager = DebugPlugin.getDefault() |
|
142 .getLaunchManager(); |
|
143 launchManager.removeLaunchListener(iLaunchListener); |
|
144 iLaunchListener = null; |
|
145 } |
|
146 } |
|
147 |
|
148 public static TFWLaunchListener getLaunchListener() { |
|
149 return iLaunchListener; |
|
150 } |
|
151 |
|
152 public static void log(Throwable e) { |
|
153 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "Error", e)); //$NON-NLS-1$ |
|
154 } |
|
155 |
|
156 public static void log(CoreException e) { |
|
157 log(e.getStatus()); //$NON-NLS-1$ |
|
158 } |
|
159 |
|
160 public static void log(IStatus status) { |
|
161 getDefault().getLog().log(status); |
|
162 } |
|
163 |
|
164 public static void log(int status, String msg) { |
|
165 Status s = new Status(status, PLUGIN_ID, status, msg, null); |
|
166 log(s); |
|
167 } |
|
168 } |