blob: 365f3a1a3f001ab010c43dc8707a3e9d7867c451 [file] [log] [blame]
/*******************************************************************************
* Copyright (C) 2015, Max Hohenegger <eclipse@hohenegger.eu>
*
* 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
*******************************************************************************/
package org.eclipse.egit.gitflow.ui;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.ui.statushandlers.StatusManager;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The shared instance
private static Activator plugin;
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
/**
* @param message
* @param throwable
* @return Status constructed from parameters.
*/
public static IStatus error(String message, Throwable throwable) {
return new Status(IStatus.ERROR, getPluginId(), 0, message, throwable);
}
/**
* @param message
* @return Status constructed from parameters.
*/
public static IStatus error(String message) {
return new Status(IStatus.ERROR, getPluginId(), message);
}
/**
* @param message
* @return Warning status for given message.
*/
public static IStatus warning(String message) {
return new Status(IStatus.WARNING, getPluginId(), message);
}
/**
* @return the id of the egit ui plugin
*/
public static String getPluginId() {
return getDefault().getBundle().getSymbolicName();
}
/**
* Handle an error. The error is logged. If <code>show</code> is
* <code>true</code> the error is shown to the user.
*
* @param message a localized message
* @param throwable
* @param show
*/
public static void handleError(String message, Throwable throwable,
boolean show) {
handleIssue(IStatus.ERROR, message, throwable, show);
}
/**
* Handle an issue. The issue is logged. If <code>show</code> is
* <code>true</code> the issue is shown to the user.
*
* @param severity
* status severity, use constants defined in {@link IStatus}
* @param message
* a localized message
* @param throwable
* @param show
*/
public static void handleIssue(int severity, String message, Throwable throwable,
boolean show) {
IStatus status = new Status(severity, getPluginId(), message,
throwable);
int style = StatusManager.LOG;
if (show) {
style |= StatusManager.SHOW;
}
StatusManager.getManager().handle(status, style);
}
/**
* @param message
* @param e
*/
public static void logError(String message, Throwable e) {
handleError(message, e, false);
}
}