BBSBrowerPlugin.java :  » SSH » brick-leeon » leeon » bbsbrower » Java Open Source

Java Open Source » SSH » brick leeon 
brick leeon » leeon » bbsbrower » BBSBrowerPlugin.java
package leeon.bbsbrower;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Map;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

/**
 * The main plugin class to be used in the desktop.
 */
public class BBSBrowerPlugin extends AbstractUIPlugin {

  //The shared instance.
  private static BBSBrowerPlugin plugin;
  
  /**
   * The constructor.
   */
  public BBSBrowerPlugin() {
    plugin = this;
  }

  /**
   * This method is called upon plug-in activation
   */
  public void start(BundleContext context) throws Exception {
    super.start(context);
  }

  /**
   * This method is called when the plug-in is stopped
   */
  public void stop(BundleContext context) throws Exception {
    super.stop(context);
    plugin = null;
  }

  /**
   * Returns the shared instance.
   */
  public static BBSBrowerPlugin getDefault() {
    return plugin;
  }

  /**
   * Returns an image descriptor for the image file at the given
   * plug-in relative path.
   *
   * @param path the path
   * @return the image descriptor
   */
  public static ImageDescriptor getImageDescriptor(String path) {
    return AbstractUIPlugin.imageDescriptorFromPlugin("bbsbrower", path);
  }
  
  /**
   * file
   * @param path
   * @return
   * @throws IOException
   */
  public static File getRealFile(String path) throws IOException {
    //URL url = getDefault().find(new Path(path));
    //String filePath = Platform.asLocalURL(url).getFile();
    
    URL url = FileLocator.find(getDefault().getBundle(), new Path(path), (Map<?, ?>)null);
    String filePath = FileLocator.toFileURL(url).getFile();
    File file = new File(filePath);
    return file;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.