|
1 /** |
|
2 * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "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 * Symbian Foundation - initial contribution. |
|
11 * Contributors: |
|
12 * Description: |
|
13 * Overview: |
|
14 * Details: |
|
15 * Platforms/Drives/Compatibility: |
|
16 * Assumptions/Requirement/Pre-requisites: |
|
17 * Failures and causes: |
|
18 */ |
|
19 package org.symbian.tools.wrttools.sdt.utils; |
|
20 |
|
21 import java.util.MissingResourceException; |
|
22 import java.util.ResourceBundle; |
|
23 |
|
24 import org.eclipse.core.runtime.IStatus; |
|
25 import org.eclipse.core.runtime.Plugin; |
|
26 import org.osgi.framework.BundleContext; |
|
27 |
|
28 /** |
|
29 * The main plugin class to be used in the desktop. |
|
30 */ |
|
31 public class UtilsPlugin extends Plugin { |
|
32 //The shared instance. |
|
33 private static UtilsPlugin plugin; |
|
34 //Resource bundle. |
|
35 private ResourceBundle resourceBundle; |
|
36 |
|
37 /** |
|
38 * The constructor. |
|
39 */ |
|
40 public UtilsPlugin() { |
|
41 super(); |
|
42 plugin = this; |
|
43 } |
|
44 |
|
45 /** |
|
46 * This method is called upon plug-in activation |
|
47 */ |
|
48 public void start(BundleContext context) throws Exception { |
|
49 super.start(context); |
|
50 } |
|
51 |
|
52 /** |
|
53 * This method is called when the plug-in is stopped |
|
54 */ |
|
55 public void stop(BundleContext context) throws Exception { |
|
56 super.stop(context); |
|
57 plugin = null; |
|
58 resourceBundle = null; |
|
59 } |
|
60 |
|
61 /** |
|
62 * Returns the shared instance. |
|
63 */ |
|
64 public static UtilsPlugin getDefault() { |
|
65 return plugin; |
|
66 } |
|
67 |
|
68 /** |
|
69 * Returns the string from the plugin's resource bundle, |
|
70 * or 'key' if not found. |
|
71 */ |
|
72 public static String getResourceString(String key) { |
|
73 ResourceBundle bundle = UtilsPlugin.getDefault().getResourceBundle(); |
|
74 try { |
|
75 return (bundle != null) ? bundle.getString(key) : key; |
|
76 } catch (MissingResourceException e) { |
|
77 return key; |
|
78 } |
|
79 } |
|
80 |
|
81 /** |
|
82 * Returns the plugin's resource bundle, |
|
83 */ |
|
84 public ResourceBundle getResourceBundle() { |
|
85 try { |
|
86 if (resourceBundle == null) |
|
87 resourceBundle = ResourceBundle.getBundle("com.nokia.sdt.utils.UtilsPluginResources"); //$NON-NLS-1$ |
|
88 } catch (MissingResourceException x) { |
|
89 resourceBundle = null; |
|
90 } |
|
91 return resourceBundle; |
|
92 } |
|
93 |
|
94 static public void log(IStatus status) { |
|
95 Logging.log(plugin, status); |
|
96 } |
|
97 |
|
98 static public void log(Throwable thr) { |
|
99 Logging.log(plugin, Logging.newStatus(plugin, thr)); |
|
100 } |
|
101 |
|
102 static public void log(Throwable thr, String msg) { |
|
103 Logging.log(plugin, Logging.newStatus(plugin, IStatus.ERROR, msg, thr)); |
|
104 } |
|
105 |
|
106 } |