/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.utils;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Version;
import de.innovationgate.wga.model.VersionCompliance;
import de.innovationgate.wga.model.WGADesignConfigurationModel;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
public static final VersionCompliance DEFAULT_VERSION_COMPLIANCE = WGADesignConfigurationModel.VERSIONCOMPLIANCES.get(VersionCompliance.VERSIONCOMPLIANCE_WGA54);
public static final Version SUPPORTED_WGA_VERSION_MIN = new Version(3, 3, 0);
public static final Version SUPPORTED_WGA_VERSION_MAX = new Version(5, 4, 0);
// The plug-in ID
public static final String PLUGIN_ID = "de.innovationgate.eclipse.plugins.WGAEclipseUtils";
// The shared instance
private static Activator plugin;
public static final String IMAGE_REFRESH = "IMAGE_REFRESH";
public static final String IMAGE_FLAG_RED = "IMAGE_FLAG_RED";
public static final String IMAGE_FLAG_YELLOW = "IMAGE_FLAG_YELLOW";
public static final String IMAGE_FLAG_GREEN = "IMAGE_FLAG_GREEN";
public static final String IMAGE_FLAG_GRAY = "IMAGE_FLAG_GRAY";
/**
* The constructor
*/
public Activator() {
}
/*
* (non-Javadoc)
* @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
/*
* (non-Javadoc)
* @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
*/
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;
}
public void logError(String message, Throwable e) {
if (e != null)
getLog().log(new Status(Status.ERROR, PLUGIN_ID, message, e));
else
getLog().log(new Status(Status.ERROR, PLUGIN_ID, message));
}
public void logError(Throwable e) {
if (e != null)
getLog().log(new Status(Status.ERROR, PLUGIN_ID, e.getMessage(), e));
else
getLog().log(new Status(Status.ERROR, PLUGIN_ID, "Unknown error occured."));
}
public void logInfo(String message, Throwable e) {
if (e != null)
getLog().log(new Status(Status.INFO, PLUGIN_ID, message, e));
else
getLog().log(new Status(Status.INFO, PLUGIN_ID, message));
}
public void logWarning(String message, Throwable e) {
if (e != null)
getLog().log(new Status(Status.WARNING, PLUGIN_ID, message, e));
else
getLog().log(new Status(Status.WARNING, PLUGIN_ID, message));
}
public void logError(String message) {
logError(message, null);
}
public void logInfo(String message) {
logInfo(message, null);
}
public void logWarning(String message) {
logWarning(message, null);
}
@Override
protected void initializeImageRegistry(ImageRegistry reg) {
super.initializeImageRegistry(reg);
try {
reg.put(IMAGE_FLAG_GRAY, createImage("resources/icons/flag_gray.png"));
reg.put(IMAGE_FLAG_GREEN, createImage("resources/icons/flag_green.png"));
reg.put(IMAGE_FLAG_YELLOW, createImage("resources/icons/flag_yellow.png"));
reg.put(IMAGE_FLAG_RED, createImage("resources/icons/flag_red.png"));
reg.put(IMAGE_REFRESH, createImage("resources/icons/arrow_refresh.png"));
}
catch (IOException e) {
logError("Unable to initialize image registry for plugin '" + PLUGIN_ID + "'.");
}
}
private Image createImage(String resourcePath) throws IOException {
InputStream in = null;
try {
in = getResourceAsStream(resourcePath);
return new Image(Display.getCurrent(),in);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
}
private InputStream getResourceAsStream(String relativePath) throws IOException {
if (relativePath.startsWith("resources/")) {
return FileLocator.toFileURL(FileLocator.find(Platform.getBundle(PLUGIN_ID), new Path(relativePath), null)).openStream();
} else {
return new FileInputStream(relativePath);
}
}
}