]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - WorkbenchUiPlugin.java
6fd8e5d3b995488294c00d4e84f8349c1197bf7d
2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.eclipse
.ui
.workbench
;
18 import java
.util
.ResourceBundle
;
20 import org
.apache
.commons
.logging
.Log
;
21 import org
.apache
.commons
.logging
.LogFactory
;
22 import org
.eclipse
.core
.runtime
.ILogListener
;
23 import org
.eclipse
.core
.runtime
.IStatus
;
24 import org
.eclipse
.core
.runtime
.Platform
;
25 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
26 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
27 import org
.osgi
.framework
.BundleContext
;
30 * The activator class controls the plug-in life cycle
32 public class WorkbenchUiPlugin
extends AbstractUIPlugin
implements ILogListener
{
33 private final static Log log
= LogFactory
.getLog(WorkbenchUiPlugin
.class);
34 private ResourceBundle messages
;
37 public static final String ID
= "org.argeo.eclipse.ui.workbench"; //$NON-NLS-1$
39 // The shared instance
40 private static WorkbenchUiPlugin plugin
;
45 public WorkbenchUiPlugin() {
48 public void start(BundleContext context
) throws Exception
{
51 messages
= ResourceBundle
.getBundle(ID
+ ".messages");
52 Platform
.addLogListener(this);
53 if (log
.isTraceEnabled())
54 log
.trace("Eclipse logging now directed to standard logging");
57 public void stop(BundleContext context
) throws Exception
{
59 Platform
.removeLogListener(this);
60 if (log
.isTraceEnabled())
61 log
.trace("Eclipse logging not directed anymore to standard logging");
69 * Returns the shared instance
71 * @return the shared instance
73 public static WorkbenchUiPlugin
getDefault() {
77 public static ImageDescriptor
getImageDescriptor(String path
) {
78 return imageDescriptorFromPlugin(ID
, path
);
81 /** Returns the internationalized label for the given key */
82 public static String
getMessage(String key
) {
84 return getDefault().messages
.getString(key
);
85 } catch (NullPointerException npe
) {
86 log
.warn(key
+ " not found.");
92 * Gives access to the internationalization message bundle. Returns null in
93 * case this UiPlugin is not started (for JUnit tests, by instance)
95 public static ResourceBundle
getMessagesBundle() {
96 if (getDefault() != null)
98 return getDefault().messages
;
103 public void logging(IStatus status
, String plugin
) {
104 Log pluginLog
= LogFactory
.getLog(plugin
);
105 Integer severity
= status
.getSeverity();
106 if (severity
== IStatus
.ERROR
)
107 pluginLog
.error(status
.getMessage(), status
.getException());
108 else if (severity
== IStatus
.WARNING
)
109 pluginLog
.warn(status
.getMessage(), status
.getException());
110 else if (severity
== IStatus
.INFO
)
111 pluginLog
.info(status
.getMessage(), status
.getException());
112 else if (severity
== IStatus
.CANCEL
)
113 if (pluginLog
.isDebugEnabled())
114 pluginLog
.debug(status
.getMessage(), status
.getException());