PageRenderTime 15ms CodeModel.GetById 1ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

/eclipse-plugin/plugins/com.google.test.metric.eclipse.ui/src/main/java/com/google/test/metric/eclipse/ui/plugin/Activator.java

http://testability-explorer.googlecode.com/
Java | 101 lines | 48 code | 11 blank | 42 comment | 3 complexity | 4bfd90a5c5bd0b07fd926240aa15676a MD5 | raw file
  1/*
  2 * Copyright 2009 Google Inc.
  3 * 
  4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5 * use this file except in compliance with the License. You may obtain a copy of
  6 * 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, WITHOUT
 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 13 * License for the specific language governing permissions and limitations under
 14 * the License.
 15 */
 16package com.google.test.metric.eclipse.ui.plugin;
 17
 18import org.eclipse.jface.resource.ImageDescriptor;
 19import org.eclipse.swt.graphics.Image;
 20import org.eclipse.ui.plugin.AbstractUIPlugin;
 21import org.osgi.framework.BundleContext;
 22
 23import java.net.MalformedURLException;
 24import java.net.URL;
 25import java.util.HashMap;
 26import java.util.Map;
 27
 28/**
 29 * The activator class controls the plug-in life cycle
 30 */
 31public class Activator extends AbstractUIPlugin {
 32  private Map<String, Image> images = new HashMap<String, Image>();
 33  
 34  // The plug-in ID
 35  public static final String PLUGIN_ID = "com.google.test.metric.eclipse.ui";
 36
 37  // The shared instance
 38  private static Activator plugin;
 39
 40  /**
 41   * The constructor
 42   */
 43  public Activator() {
 44  }
 45
 46  /*
 47   * (non-Javadoc)
 48   * 
 49   * @see
 50   * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
 51   * )
 52   */
 53  @Override
 54  public void start(BundleContext context) throws Exception {
 55    super.start(context);
 56    plugin = this;
 57  }
 58
 59  /*
 60   * (non-Javadoc)
 61   * 
 62   * @see
 63   * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
 64   * )
 65   */
 66  @Override
 67  public void stop(BundleContext context) throws Exception {
 68    plugin = null;
 69    super.stop(context);
 70  }
 71
 72  /**
 73   * Returns the shared instance
 74   * 
 75   * @return the shared instance
 76   */
 77  public static Activator getDefault() {
 78    return plugin;
 79  }
 80
 81  public Image getImage(String path) throws ImageNotFoundException {
 82    Image image = images.get(path);
 83    if (image == null) {
 84      String pluginLocation = Activator.getDefault().getBundle().getLocation();
 85      if (pluginLocation.startsWith("reference:")) {
 86        pluginLocation = pluginLocation.substring(10);
 87      }
 88      URL url;
 89      try {
 90        url = new URL(pluginLocation + path);
 91      } catch (MalformedURLException e) {
 92        throw new ImageNotFoundException("Image : " + path + " not found");
 93      }
 94  
 95      ImageDescriptor projectImageDescriptor = ImageDescriptor.createFromURL(url);
 96      image = projectImageDescriptor.createImage();
 97      images.put(path, image);
 98    }
 99    return image;
100  }
101}