]> git.argeo.org Git - lgpl/argeo-commons.git/blob - ui/ArgeoUiPlugin.java
Prepare next development cycle
[lgpl/argeo-commons.git] / ui / ArgeoUiPlugin.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 package org.argeo.eclipse.ui;
18
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;
27
28 /**
29 * The activator class controls the plug-in life cycle
30 */
31 public class ArgeoUiPlugin extends AbstractUIPlugin implements ILogListener {
32
33 // The plug-in ID
34 public static final String PLUGIN_ID = "org.argeo.eclipse.ui";
35
36 private final static String SPRING_OSGI_EXTENDER = "org.springframework.osgi.extender";
37
38 private final static Log log = LogFactory.getLog(ArgeoUiPlugin.class);
39
40 // The shared instance
41 private static ArgeoUiPlugin plugin;
42
43 private BundleContext bundleContext;
44
45 /**
46 * The constructor
47 */
48 public ArgeoUiPlugin() {
49 }
50
51 /*
52 * (non-Javadoc)
53 *
54 * @see
55 * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
56 * )
57 */
58 public void start(BundleContext context) throws Exception {
59 super.start(context);
60 plugin = this;
61 bundleContext = context;
62
63 Platform.addLogListener(this);
64 log.debug("Eclipse logging now directed to standard logging");
65
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();
70 else
71 log.error("Spring OSGi Extender not found");
72
73 }
74
75 /*
76 * (non-Javadoc)
77 *
78 * @see
79 * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
80 * )
81 */
82 public void stop(BundleContext context) throws Exception {
83 Platform.removeLogListener(this);
84 log.debug("Eclipse logging not directed anymore to standard logging");
85
86 plugin = null;
87 super.stop(context);
88 }
89
90 /**
91 * Returns the shared instance
92 *
93 * @return the shared instance
94 */
95 public static ArgeoUiPlugin getDefault() {
96 return plugin;
97 }
98
99 public BundleContext getBundleContext() {
100 return bundleContext;
101 }
102
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());
115
116 }
117
118 }