Home » geronimo-eclipse-plugin-2.2-source-release » org.apache.geronimo.st.ui » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *    http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.geronimo.st.ui;
   18   
   19   import java.io.IOException;
   20   import java.net.URL;
   21   import java.util.HashMap;
   22   import java.util.Map;
   23   
   24   import org.apache.geronimo.st.ui.internal.Trace;
   25   import org.eclipse.core.runtime.FileLocator;
   26   import org.eclipse.core.runtime.Status;
   27   import org.eclipse.jface.resource.ImageDescriptor;
   28   import org.eclipse.jface.resource.ImageRegistry;
   29   import org.eclipse.swt.graphics.Image;
   30   import org.eclipse.ui.plugin.AbstractUIPlugin;
   31   import org.osgi.framework.BundleContext;
   32   
   33   /**
   34    * The activator class controls the plug-in life cycle
   35    *
   36    * @version $Rev: 817996 $ $Date: 2009-09-23 16:04:12 +0800 (Wed, 23 Sep 2009) $
   37    */
   38   public class Activator extends AbstractUIPlugin {
   39   
   40   	// The plug-in ID
   41   	public static final String PLUGIN_ID = "org.apache.geronimo.st.ui";
   42   
   43   	// The shared instance
   44   	private static Activator plugin;
   45   
   46   	private static String iconLocation;
   47   
   48   	private Map imageDescriptors = new HashMap();
   49   
   50   	public static final String ICONS_DIRECTORY = "icons/";
   51   	public static final String IMG_WIZ_GERONIMO = "gServer";
   52   	public static final String IMG_PORT = "port";
   53   
   54   	/**
   55   	 * The constructor
   56   	 */
   57   	public Activator() {
   58   		plugin = this;
   59   	}
   60   
   61   	/*
   62   	 * (non-Javadoc)
   63   	 * 
   64   	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
   65   	 */
   66   	public void start(BundleContext context) throws Exception {
   67   		super.start(context);	
   68   		this.setDebugging(true);
   69   		this.setDebugging(true);
   70   	}
   71   
   72   	/*
   73   	 * (non-Javadoc)
   74   	 * 
   75   	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
   76   	 */
   77   	public void stop(BundleContext context) throws Exception {
   78   		plugin = null;
   79   		super.stop(context);
   80   	}
   81   
   82   	/**
   83   	 * Returns the shared instance
   84   	 * 
   85   	 * @return the shared instance
   86   	 */
   87   	public static Activator getDefault() {
   88   		return plugin;
   89   	}
   90   
   91   	public static String getIconLocation() {
   92   		if (iconLocation == null) {
   93   			try {
   94   				iconLocation = FileLocator.resolve(plugin.getBundle().getEntry("/")).getPath()
   95   						+ ICONS_DIRECTORY;
   96   			} catch (IOException e) {
   97   				e.printStackTrace();
   98   			}
   99   		}
  100   		return iconLocation;
  101   	}
  102   
  103   	/**
  104   	 * Return the image with the given key from the image registry.
  105   	 * 
  106   	 * @param key
  107   	 *            java.lang.String
  108   	 * @return org.eclipse.jface.parts.IImage
  109   	 */
  110   	public static Image getImage(String key) {
  111   		return plugin.getImageRegistry().get(key);
  112   	}
  113   
  114   	/**
  115   	 * Return the image with the given key from the image registry.
  116   	 * 
  117   	 * @param key
  118   	 *            java.lang.String
  119   	 * @return org.eclipse.jface.parts.IImage
  120   	 */
  121   	public static ImageDescriptor getImageDescriptor(String key) {
  122   		try {
  123   			plugin.getImageRegistry();
  124   			return (ImageDescriptor) plugin.imageDescriptors.get(key);
  125   		} catch (Exception e) {
  126   			return null;
  127   		}
  128   	}
  129   
  130   	/*
  131   	 * (non-Javadoc)
  132   	 * 
  133   	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse.jface.resource.ImageRegistry)
  134   	 */
  135   	protected void initializeImageRegistry(ImageRegistry reg) {
  136   		registerImage(reg, IMG_WIZ_GERONIMO, "g_server.gif");
  137   		registerImage(reg, IMG_PORT, "obj16/port.gif");
  138   	}
  139   
  140   	private void registerImage(ImageRegistry registry, String key,
  141   			String partialURL) {
  142   
  143   		URL iconsURL = plugin.getBundle().getEntry(ICONS_DIRECTORY);
  144   
  145   		try { 
  146   			ImageDescriptor id = ImageDescriptor.createFromURL(new URL(iconsURL, partialURL));
  147   			registry.put(key, id);
  148   			imageDescriptors.put(key, id);
  149   		} catch (Exception e) {
  150   			Trace.trace(Trace.WARNING, "Error registering image", e);
  151   		}
  152   	}
  153   
  154   	public static void log(int statusLevel, String s, Throwable t) {
  155   		plugin.getLog().log(new Status(statusLevel, PLUGIN_ID, 0, s, t));
  156   	}
  157   
  158   }

Home » geronimo-eclipse-plugin-2.2-source-release » org.apache.geronimo.st.ui » [javadoc | source]