Initial version from the webtools project; sligthly modified for phpeclipse
[phpeclipse.git] / net.sourceforge.phpeclipse.webbrowser / src / org / eclipse / webbrowser / internal / WebBrowserUIPlugin.java
1 /**
2  * Copyright (c) 2003 IBM Corporation and others.
3  * All rights reserved.   This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *    IBM - Initial API and implementation
10  */
11 package org.eclipse.webbrowser.internal;
12
13 import java.text.MessageFormat;
14
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.ui.plugin.AbstractUIPlugin;
17 import org.osgi.framework.BundleContext;
18 /**
19  * The main web browser plugin class.
20  */
21 public class WebBrowserUIPlugin extends AbstractUIPlugin {
22         // Web browser plugin id
23         public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.webbrowser";
24
25         // singleton instance of this class
26         private static WebBrowserUIPlugin singleton;
27
28         /**
29          * Create the WebBrowserUIPlugin
30          */
31         public WebBrowserUIPlugin() {
32                 super();
33                 singleton = this;
34         }
35
36         /**
37          * Returns the singleton instance of this plugin.
38          *
39          * @return org.eclipse.webbrowser.WebBrowserPlugin
40          */
41         public static WebBrowserUIPlugin getInstance() {
42                 return singleton;
43         }
44
45         /**
46          * Returns the translated String found with the given key.
47          *
48          * @param key java.lang.String
49          * @return java.lang.String
50          */
51         public static String getResource(String key) {
52                 try {
53                         return Platform.getResourceString(getInstance().getBundle(), key);
54                 } catch (Exception e) {
55                         return key;
56                 }
57         }
58
59         /**
60          * Returns the translated String found with the given key,
61          * and formatted with the given arguments using java.text.MessageFormat.
62          *
63          * @param key java.lang.String
64          * @param arg java.lang.String
65          * @return java.lang.String
66          */
67         public static String getResource(String key, String arg) {
68                 try {
69                         String text = getResource(key);
70                         return MessageFormat.format(text, new String[] { arg });
71                 } catch (Exception e) {
72                         return key;
73                 }
74         }
75
76         public void start(BundleContext context) throws Exception {
77                 super.start(context);
78                 WebBrowserPreference.initializeDefaultPreferences();
79         }
80
81         /**
82          * Shuts down this plug-in and saves all plug-in state.
83          *
84          * @exception Exception
85          */
86         public void stop(BundleContext context) throws Exception {
87                 super.stop(context);
88                 BrowserManager.getInstance().dispose();
89         }
90 }