| /******************************************************************************* |
| |
| * Copyright (c) 2010 BSI Business Systems Integration AG. |
| * 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: |
| * BSI Business Systems Integration AG - initial API and implementation |
| ******************************************************************************/ |
| package org.eclipse.scout.sdk.debug.internal; |
| |
| import org.eclipse.jface.resource.ImageDescriptor; |
| import org.eclipse.scout.sdk.debug.view.JdtEventLoggerView; |
| import org.eclipse.scout.sdk.util.log.SdkLogManager; |
| import org.eclipse.swt.graphics.Image; |
| import org.eclipse.ui.plugin.AbstractUIPlugin; |
| import org.osgi.framework.BundleContext; |
| |
| /** |
| * <h3>{@link Activator}</h3> |
| * |
| * @author Andreas Hoegger |
| * @since 1.0.8 11.02.2011 |
| */ |
| public class Activator extends AbstractUIPlugin { |
| |
| // The plug-in ID |
| public static final String PLUGIN_ID = "org.eclipse.scout.sdk.debug"; |
| |
| public static final String VIEW_JDT_EVENT_LOGGER = JdtEventLoggerView.VIEW_ID; |
| |
| private static final String IMAGE_PATH = "resources/icons/"; |
| |
| // The shared instance |
| private static Activator plugin; |
| private static SdkLogManager logManager; |
| |
| /** |
| * The constructor |
| */ |
| public Activator() { |
| } |
| |
| /* |
| * (non-Javadoc) |
| * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) |
| */ |
| @Override |
| public void start(BundleContext context) throws Exception { |
| super.start(context); |
| logManager = new SdkLogManager(this); |
| plugin = this; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) |
| */ |
| @Override |
| public void stop(BundleContext context) throws Exception { |
| plugin = null; |
| logManager = null; |
| super.stop(context); |
| } |
| |
| /** |
| * Returns the shared instance |
| * |
| * @return the shared instance |
| */ |
| public static Activator getDefault() { |
| return plugin; |
| } |
| |
| public static void logInfo(Throwable t) { |
| logManager.logInfo(t); |
| } |
| |
| public static void logInfo(String message) { |
| logManager.logInfo(message); |
| } |
| |
| public static void logInfo(String message, Throwable t) { |
| logManager.logInfo(message, t); |
| } |
| |
| public static void logWarning(String message) { |
| logManager.logWarning(message); |
| } |
| |
| public static void logWarning(Throwable t) { |
| logManager.logWarning(t); |
| } |
| |
| public static void logWarning(String message, Throwable t) { |
| logManager.logWarning(message, t); |
| } |
| |
| public static void logError(Throwable t) { |
| logManager.logError(t); |
| } |
| |
| public static void logError(String message) { |
| logManager.logError(message); |
| } |
| |
| public static void logError(String message, Throwable t) { |
| logManager.logError(message, t); |
| } |
| |
| /** |
| * Returns the image for the given composite descriptor. |
| */ |
| // public static Image getImage(CompositeImageDescriptor imageDescriptor) { |
| // return getDefault().getImageImpl(imageDescriptor); |
| // } |
| // |
| // private Image getImageImpl(CompositeImageDescriptor imageDescriptor) { |
| // return getImageRegistry().get(imageDescriptor); |
| // } |
| |
| /** |
| * To get a cached image with one of the extensions [gif | png | jpg] |
| * |
| * @param name |
| * the name without extension located under resources/icons e.g. "person" |
| * @return the cached image |
| */ |
| public static Image getImage(String name) { |
| return getDefault().getImageImpl(name); |
| } |
| |
| private Image getImageImpl(String name) { |
| Image image = getImageRegistry().get(name); |
| if (image == null) { |
| loadImage(name); |
| image = getImageRegistry().get(name); |
| } |
| return image; |
| } |
| |
| /** |
| * To get a cached image with one of the extensions [gif | png | jpg] |
| * |
| * @param name |
| * the name without extension located under resources/icons e.g. "person" |
| * @return the cached image |
| */ |
| public static ImageDescriptor getImageDescriptor(String name) { |
| return getDefault().getImageDescriptorImpl(name); |
| } |
| |
| private ImageDescriptor getImageDescriptorImpl(String name) { |
| ImageDescriptor imageDesc = getImageRegistry().getDescriptor(name); |
| if (imageDesc == null) { |
| loadImage(name); |
| imageDesc = getImageRegistry().getDescriptor(name); |
| } |
| return imageDesc; |
| } |
| |
| private void loadImage(String name) { |
| ImageDescriptor desc = null; |
| if (name.startsWith(IMAGE_PATH)) { |
| desc = AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, name); |
| } |
| if (desc == null) { |
| // try already extension |
| desc = AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, IMAGE_PATH + name); |
| } |
| // gif |
| if (desc == null) { |
| desc = AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, IMAGE_PATH + name + ".gif"); |
| } |
| // png |
| if (desc == null) { |
| desc = AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, IMAGE_PATH + name + ".png"); |
| } |
| // jpg |
| if (desc == null) { |
| desc = AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, IMAGE_PATH + name + ".jpg"); |
| } |
| if (desc == null) { |
| logWarning("could not find image for plugin: '" + PLUGIN_ID + "' under: '" + IMAGE_PATH + name + "'."); |
| } |
| else { |
| getImageRegistry().put(name, desc); |
| } |
| } |
| } |