]> git.argeo.org Git - lgpl/argeo-commons.git/blob - base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ArgeoUiPlugin.java
fix bug 145 ( https://www.argeo.org/bugzilla/show_bug.cgi?id=145 ).
[lgpl/argeo-commons.git] / base / runtime / org.argeo.eclipse.ui / src / main / java / org / argeo / eclipse / ui / ArgeoUiPlugin.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
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 package org.argeo.eclipse.ui;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20 import org.eclipse.core.runtime.ILogListener;
21 import org.eclipse.core.runtime.IStatus;
22 import org.eclipse.core.runtime.Platform;
23 import org.eclipse.ui.plugin.AbstractUIPlugin;
24 import org.osgi.framework.BundleContext;
25
26 /**
27 * The activator class controls the plug-in life cycle
28 */
29 public class ArgeoUiPlugin extends AbstractUIPlugin implements ILogListener {
30 public static final String PLUGIN_ID = "org.argeo.eclipse.ui";
31 private final static Log log = LogFactory.getLog(ArgeoUiPlugin.class);
32 // The shared instance
33 private static ArgeoUiPlugin plugin;
34
35 public void start(BundleContext context) throws Exception {
36 super.start(context);
37 // weirdly, the start method is called twice...
38 if (plugin == null) {
39 plugin = this;
40 Platform.addLogListener(this);
41 log.debug("Eclipse logging now directed to standard logging");
42 }
43 }
44
45 public void stop(BundleContext context) throws Exception {
46 try {
47 // weirdly, the stop method is called twice...
48 if (plugin != null) {
49 Platform.removeLogListener(this);
50 log.debug("Eclipse logging not directed anymore to standard logging");
51 plugin = null;
52 }
53 } finally {
54 super.stop(context);
55 }
56 }
57
58 /** Returns the shared instance */
59 public static ArgeoUiPlugin getDefault() {
60 return plugin;
61 }
62
63 public void logging(IStatus status, String plugin) {
64 Log pluginLog = LogFactory.getLog(plugin);
65 Integer severity = status.getSeverity();
66 if (severity == IStatus.ERROR)
67 pluginLog.error(status.getMessage(), status.getException());
68 else if (severity == IStatus.WARNING)
69 pluginLog.warn(status.getMessage(), status.getException());
70 else if (severity == IStatus.INFO)
71 pluginLog.info(status.getMessage(), status.getException());
72 else if (severity == IStatus.CANCEL)
73 if (pluginLog.isDebugEnabled())
74 pluginLog.debug(status.getMessage(), status.getException());
75
76 }
77
78 }