[Java] eclipse plug-in development

Source: Internet
Author: User

Recently, I am engaged in android development. It is very troublesome to write the View variable associated with the id in the activity after the layout interface file is designed, why not automatically create variables after setting a view object in vc ++? So let me get an eclipse plug-in! Haha

1. Install the plug-in development environment: Eclipse plug-in development environment.

2. Create a Plug-in Project: File-> new-> Plug-in Development. After you select the Plug-in Project, you can select a template type. I will select Hello, world.

In the Overview of the MANIFEST. MF file, select Launch an Eclipse application under Testing to start the new eclipse. This eclipse is loaded with my plug-in.

To read the xml file of layout, you must find the path of the current file for easy reading.

Then, I want to retrieve the id and the corresponding type. For example, there is a Button whose ID is btSave. Why? I just need to display it in the terminal

Button btSave;

BtSave = (Button) findViewById (R. id. btSave );

You can.

Dependencies in the MANIFEST. MF file adds some plug-in support packages. Otherwise, some eclipse classes cannot be called.

Resource usage: org. eclipse. core. resources

Console: org. eclipse. ui. console

I also added org. eclipse. ui. ide

Now, let's start writing programs.

I want to get the address of the currently edited xml file.

> Get the currently edited object

IEditorPart activeEditor = PlatformUI. getWorkbench ()
. GetActiveWorkbenchWindow (). getActivePage (). getActiveEditor ();

If (activeEditor! = Null ){

IEditorInput editorInput = activeEditor. getEditorInput ();
If (editorInput instanceof org. eclipse. ui. part. FileEditorInput ){
Org. eclipse. ui. part. FileEditorInput input = (org. eclipse. ui. part. FileEditorInput) editorInput;
IPath path = input. getPath (); // This path is the currently edited xml file.

/** The next step is to parse the xml file and display the function in the eclipse console **/

}

For more information about how to display on the console: I will not do this.

Finally, you can package and release it. The Overview of MANIFEST. MF has an Export in the upper right corner. Export it as a jar file and put it in the eclipse plug-in directory. It is possible to start it.

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.