2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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.
17 package org
.argeo
.eclipse
.ui
;
19 import org
.apache
.commons
.logging
.Log
;
20 import org
.apache
.commons
.logging
.LogFactory
;
21 import org
.eclipse
.core
.runtime
.ILogListener
;
22 import org
.eclipse
.core
.runtime
.IStatus
;
23 import org
.eclipse
.core
.runtime
.Platform
;
24 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
25 import org
.osgi
.framework
.Bundle
;
26 import org
.osgi
.framework
.BundleContext
;
29 * The activator class controls the plug-in life cycle
31 public class ArgeoUiPlugin
extends AbstractUIPlugin
implements ILogListener
{
34 public static final String PLUGIN_ID
= "org.argeo.eclipse.ui";
36 private final static String SPRING_OSGI_EXTENDER
= "org.springframework.osgi.extender";
38 private final static Log log
= LogFactory
.getLog(ArgeoUiPlugin
.class);
40 // The shared instance
41 private static ArgeoUiPlugin plugin
;
43 private BundleContext bundleContext
;
48 public ArgeoUiPlugin() {
55 * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
58 public void start(BundleContext context
) throws Exception
{
61 bundleContext
= context
;
63 Platform
.addLogListener(this);
64 log
.debug("Eclipse logging now directed to standard logging");
66 // Make sure that the Spring OSGi extender is started
67 Bundle osgiExtBundle
= Platform
.getBundle(SPRING_OSGI_EXTENDER
);
68 if (osgiExtBundle
!= null)
69 osgiExtBundle
.start();
71 log
.error("Spring OSGi Extender not found");
79 * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
82 public void stop(BundleContext context
) throws Exception
{
83 Platform
.removeLogListener(this);
84 log
.debug("Eclipse logging not directed anymore to standard logging");
91 * Returns the shared instance
93 * @return the shared instance
95 public static ArgeoUiPlugin
getDefault() {
99 public BundleContext
getBundleContext() {
100 return bundleContext
;
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());