blob: 926c0a9d8bbc1b45ab32bc56d4f25b667bfc251a [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2011-2012 EclipseSource Muenchen GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eugen Neufeld - initial API and implementation
*
*******************************************************************************/
package org.eclipse.emf.ecp.emfstore.internal.ui;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle.
*/
public class Activator extends Plugin {
/** The plug-in ID. **/
public static final String PLUGIN_ID = "org.eclipse.emf.ecp.emfstore.ui"; //$NON-NLS-1$
private static Activator instance;
/**
* The constructor.
*/
public Activator() {
}
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
instance = this;
}
@Override
public void stop(BundleContext context) throws Exception {
instance = null;
super.stop(context);
}
/**
* Returns the shared instance.
*
* @return the shared instance
*/
public static Activator getInstance() {
return instance;
}
private static void log(IStatus status) {
instance.getLog().log(status);
}
/**
* Logs a message with a specific status.
*
* @param status the {@link IStatus} value
* @param message the message to log
*/
public static void log(int status, String message) {
instance.getLog().log(new Status(status, PLUGIN_ID, message));
}
/**
* Logs a {@link Throwable}.
*
* @param t the {@link Throwable}
* @return the message of the {@link Throwable}
*/
public static String log(Throwable t) {
final IStatus status = getStatus(t);
log(status);
return status.getMessage();
}
private static IStatus getStatus(Throwable t) {
if (t instanceof CoreException) {
final CoreException coreException = (CoreException) t;
return coreException.getStatus();
}
String msg = t.getLocalizedMessage();
if (msg == null || msg.length() == 0) {
msg = t.getClass().getName();
}
return new Status(IStatus.ERROR, PLUGIN_ID, msg, t);
}
}