Skip to main content
summaryrefslogtreecommitdiffstats
blob: ec0e9dd297659090961ff93d19333d81f0485e30 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*******************************************************************************
 * Copyright (c) 2006 Sybase, Inc. and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http:// www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Sybase, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.pagedesigner.jsf.ui;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jst.jsf.common.ui.IFileFolderConstants;
import org.eclipse.jst.jsf.common.ui.JSFUICommonPlugin;
import org.eclipse.jst.jsf.common.ui.internal.guiutils.Alerts;
import org.eclipse.jst.jsf.common.ui.internal.logging.Logger;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

/**
 * The main plugin class to be used in the desktop.
 */
public class JSFUIPlugin extends AbstractUIPlugin
{
    //The shared instance.
    private static JSFUIPlugin _plugin;
    //Resource bundle.
    private ResourceBundle     _resourceBundle;
    private URL                _pluginBase;

    private static Logger      _logger;
    private static Alerts      _alerts;

    /**
     * The constructor.
     */
    public JSFUIPlugin()
    {
        super();
        _plugin = this;
        try
        {
            _resourceBundle = ResourceBundle.getBundle("org.eclipse.jst.pagedesigner.jsf.ui.JSFUIPluginResources");
        }
        catch (MissingResourceException x)
        {
            _resourceBundle = null;
        }
    }

    /**
     * This method is called upon plug-in activation
     */
    public void start(BundleContext context) throws Exception
    {
        super.start(context);
        _alerts = new Alerts(this, _resourceBundle);
        _logger = JSFUICommonPlugin.getLogger(JSFUIPlugin.class);
//        _logger.setResourceBundle(_resourceBundle);
        _pluginBase = getBundle().getEntry("/");
    }

    /**
     * get the alerts objects associated with this plugin for alerting the user.
     * @return the alerts
     */
    public static Alerts getAlerts()
    {
        return _alerts;
    }

    /**
     * This method is called when the plug-in is stopped
     */
    public void stop(BundleContext context) throws Exception
    {
        super.stop(context);
    }

    /**
     * Returns the shared instance.
     * @return the default plugin
     */
    public static JSFUIPlugin getDefault()
    {
        return _plugin;
    }

    /**
     * Returns the string from the plugin's resource bundle,
     * or 'key' if not found.
     * @param key 
     * @return the resource string for key or 'key' if not found
     */
    public static String getResourceString(String key)
    {
        ResourceBundle bundle = JSFUIPlugin.getDefault().getResourceBundle();
        try
        {
            return (bundle != null) ? bundle.getString(key) : key;
        }
        catch (MissingResourceException e)
        {
            return key;
        }
    }

    /**
     * Returns the plugin's resource bundle,
     * @return the resource bundle
     */
    public ResourceBundle getResourceBundle()
    {
        return _resourceBundle;
    }

    /**
     * Return an image from the path
     * @param name
     * @return Image
     */
    public Image getImage(String name)
    {
        if (name == null)
        {
            return null;
        }

        ImageRegistry images = getImageRegistry();
        Image image = images.get(name);
        if (image == null)
        {
            try
            {
                ImageDescriptor id = ImageDescriptor.createFromURL(new URL(_pluginBase,
                        IFileFolderConstants.FOLDER_ICONS + "/" + name));
                images.put(name, id);

                image = images.get(name);
            }
            catch (MalformedURLException ee)
            {
                _logger.error("Error.JSFUIPlugin", name, ee); //$NON-NLS-2$
            }
        }
        return image;
    }

    /**
     * Log message and Throwable by severity.
     * 
     * @param severity Severity (use appropriate IStatus constant).
     * @param message Message to be logged.
     * @param exception Throwable instance to be logged.
     */
    public static void log(int severity, String message, Throwable exception) {
    	ILog log = getDefault().getLog();
    	IStatus status = new Status(
    			severity,
    			"org.eclipse.jst.pagedesigner.jsf.ui",
    			message,
    			exception);
    	log.log(status);
    }

    /**
     * Log message by severity.
     * 
     * @param severity Severity (use an IStatus constant).
     * @param message Message to be logged.
     */
    public static void log(int severity, String message) {
    	ILog log = getDefault().getLog();
    	IStatus status = new Status(
    			severity,
    			"org.eclipse.jst.pagedesigner.jsf.ui",
    			message);
    	log.log(status);
    }

}

Back to the top