Skip to main content
summaryrefslogtreecommitdiffstats
blob: 32382b2c9f23828fb5ad8b178b6371d7c3b2b12e (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
/*******************************************************************************
 * 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.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jst.pagedesigner.common.CommonPlugin;
import org.eclipse.jst.pagedesigner.common.IFileFolderConstants;
import org.eclipse.jst.pagedesigner.common.guiutils.Alerts;
import org.eclipse.jst.pagedesigner.common.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 = CommonPlugin.getLogger(JSFUIPlugin.class);
//        _logger.setResourceBundle(_resourceBundle);
        _pluginBase = getBundle().getEntry("/");
    }

    /**
     * get the alerts objects associated with this plugin for alerting the user.
     * @return
     */
    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.
     */
    public static JSFUIPlugin getDefault()
    {
        return _plugin;
    }

    /**
     * Returns the string from the plugin's resource bundle,
     * 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,
     */
    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 = (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;
    }
}

Back to the top