Eclipse Plugin try to do

Source: Internet
Author: User

Brief Description:

Test how to make a plugin for eclipse


Reference:

"In-depth understanding of Java virtual machines"

April 2012 1th Edition, 6th time printing

Page 116


Project Download Address

Http://pan.baidu.com/s/1mg8yi1a


steps:

1. Create a new plug-in project

Launchinfo


Project structure:




2. Interface

Launchplugin.java

Package com.anialy.launch_plugin;

Public interface Launchplugin {public
	void Showonlaunch ();
}


3. Implement

Launchpluginimpl

Package Com.anialy.launch_plugin.impl;

Import Org.eclipse.jface.dialogs.MessageDialog;
Import Org.eclipse.swt.widgets.Display;
Import Org.eclipse.swt.widgets.Shell;

Import Com.anialy.launch_plugin. Launchplugin;

public class Launchpluginimpl implements launchplugin{public

	void Showonlaunch () {
		display.getdefault (). Syncexec (New Runnable () {

			@Override public
			void Run () {
				Long eclipselaunchtime = Long.parselong (
						System.getproperty ("Eclipse.starttime"));
				Long costtime = System.currenttimemillis ()-eclipselaunchtime;
				Shell shell = Display.getdefault (). Getactiveshell ();
				String message = "Eclipse startup time:" + costtime + "MS"; 
				Messagedialog.openinformation (Shell, "Info", Message);}}
		);
	}
	
}



4. Configuration

Plugin.xml

<?xml version= "1.0" encoding= "UTF-8"?> <?eclipse
version= "3.4"?>
<plugin>

   < Extension
         point= "Org.eclipse.ui.startup" >
         <startup class= "Com.anialy.launch_plugin. Launchplugin "/>
   </extension>

</plugin>

Activator.java

Package com.anialy.launch_plugin.startup;
Import Org.eclipse.jface.resource.ImageDescriptor;
Import Org.eclipse.ui.plugin.AbstractUIPlugin;

Import Org.osgi.framework.BundleContext; /** * The Activator class controls the plug-in life cycle */public class Activator extends Abstractuiplugin {//the Plug-in ID public static final String plugin_id = "Lauchinfo";
	
	$NON-nls-1$//The shared instance private static Activator plugin; /** * The constructor * */Public Activator () {}/* * (non-javadoc) * @see Org.eclipse.ui.plugin.AbstractUIPlug In#start (org.osgi.framework.BundleContext) */public void Start (Bundlecontext context) throws Exception {Super.start
		(context);
	plugin = this; }/* * (non-javadoc) * @see org.eclipse.ui.plugin.abstractuiplugin#stop (org.osgi.framework.BundleContext) */Publ
		IC 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; }/** * 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 image
	Descriptorfromplugin (plugin_id, path);
 }
}


5. Export as jar (default to Workspce folder)



6. Right-click Project, run





7. Start the test, after the effect








Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.