Eclipse rcp developing desktop programs

Source: Internet
Author: User

The so-called RCP, the rich-client platform, the client platform, is the product of Eclipse Evolution (since version 3.0), is the Eclipse organization to provide users with a powerful open development platform, can Enough to make it easy for users to create their own eclipse-based applications, and these applications can get the underlying support of Eclipse. More importantly, we can use Java to create a desktop program as beautiful as Eclipse.

I believe that RCP will become very popular in the next few years. With RCP, we can develop interfaces such as beautiful desktop programs like Eclipse, hospital management Systems, CAD software, and so on. Unfortunately, at present in the country basically cannot find the Chinese information about RCP, we can only through their own exploration to our program to add the functionality we want.

Here's a step-by-step way to build an Eclipse RCP program, which can be said to search a lot of Google, some people will feel boring, but it doesn't matter, this is just a quick start.

Select New-Project and select Plug-in Project:




Click Next, enter the project name, choose Eclipse Version, I choose 3.2 here:


Click Next, the plugin identity and plug-in name can be changed, other content can remain the default, make sure to remember to select Rich client application support:


Click Next, select a template, here to choose the simplest one, the time to see the source code when easy to understand:


Click Next to change the application title:


Click Finish, we can right-click on the item, choose to run by Eclipse program, you can see the effect:




In this program, the window shows a perspective, the perspective contains an editor area, later, we can gradually add to the Program menu, toolbar and for this perspective to add a view, editor, and so on.

Now, this program can only run in the Eclipse environment, and RCP's goal is to create an application that can run independently, and we're not done yet. Next, right-click on the project to create the product configuration file:


Enter product profile file name:



The resulting product configuration file opens in the editor, which should look like this:


At the beginning, the above text boxes are empty, click the New button, pop up the following dialog box, enter the product name, after the point of completion on the line.



Click on the "Launcher" in the configuration file and we can try to start our RCP program. As a result, there will be mistakes. The reason is simple because we have not checked the plug-ins it relies on for our program.

Select the Configuration tab of the profile, add the following dependencies, and remember, be sure to add ourselves, or Com.blogjava.youxia.rcp_start, to the dependencies, or you will get an error. At the very beginning, it was such a small problem that I wasted a few days.


Then click Add the necessary plug-ins to automatically add additional dependencies.

Next, set the build path for the project, as shown in the following figure:


Next, export our programs:




Next, enter the directory we exported to the program, as shown in the following figure:


Click to complete the button, our program is exported to our designated directory, open this directory, you can see an eclipse-like program icon, double-click to run, the effect of the following figure:

Finally, two points need to be explained: First, if you want the generated program to have its own icon, you can set it in the last two profiles in the product configuration file, and second, the resulting program should have no menu bar, because my eclipse installs MyEclipse, so the exported program has two more menus.

OK, here's the quick start, and then we'll look at the generated code and add functionality to our program.
=========================================================================
Using Eclipse RCP for Desktop program development (i): Fast start, we have built up an RCP application through the Eclipse Plug-in Development wizard, but this program has no function, it is difficult to arouse our interest in learning. In this section, we'll explore how to add menus and toolbars to your programs. First look at the results:

Figure I, figure II: RCP programs with menus and toolbars


Figure three: Prompt text for buttons on the toolbar

Figure Four: Click on the menu item or toolbar button to pop up a simple dialog box.

Here's a little bit of explaining why you talk about the dialog box together when you're talking about menus and toolbars, this is because the dialog box is the simplest and most direct user interaction we can think of, and you can add a variety of controls to the dialog box to achieve complex functionality, so that we can see the effect when we click on the menu item. A simple dialog box is used here. Of course, when we later touch on concepts such as views, editors, and perspectives, the user interaction we can use is more than just a dialog box.

To open the project we built using the wizard in the previous section, you can find that the following files are automatically generated under the project:
Application.java
Applicationworkbenchadvisor.java
Applicationworkbenchwindowadvisor.java
Applicationactionbaradvisor.java
Perspective.java
Plugin.xml
The Application.java here is the entry point for our entire program, and when our program runs, it executes the application run method, the code for the Run method is as follows: 1 public object Run (object args) throws E xception {
2 Display display = Platformui.createdisplay ();
3 try {
4 int returncode = Platformui.createandrunworkbench (display, New Applicationworkbenchadvisor ());
5 if (ReturnCode = = Platformui.return_restart) {
6 return Iplatformrunnable.exit_restart;
7}
8 return IPLATFORMRUNNABLE.EXIT_OK;
9} finally {
Ten Display.dispose ();
11}
12}

On line 4th we can see that the portal function gives the Applicationworkbenchadvisor class the job of creating the user interface. Next, we open the Applicationworkbenchadvisor.java code as follows:  1 public   class  ApplicationWorkbenchAdvisor  Extends  WorkbenchAdvisor  {
 2
 3      private   static   Final  String PERSPECTIVE_ID  =   "Cn.blogjava.youxia.rcp_start.perspective";
 4
 5      public  WorkbenchWindowAdvisor  Createworkbenchwindowadvisor (iworkbenchwindowconfigurer configurer)   {
 6           return   New  applicationworkbenchwindowadvisor (Configurer);
 7     }
 8
 9      public  string getinitialwindowperspectiveid ()   {
Ten          return  PERSPECTIVE_ID;
One     }
[}

You can see that the job of this class is to specify the default perspective for our program, and then give the work of creating the window to the Applicationworkbenchwindowadvisor class. Next, we open the Applicationworkbenchwindowadvisor.java file and see the code as follows:  1 public   class   applicationworkbenchwindowadvisor  extends  WorkbenchWindowAdvisor 

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.