Eclipse RCP + Spring build fat client Web program

Source: Internet
Author: User

SummaryEclipse's rich client platform (RCP) is quickly becoming the framework choice for building fat client applications. This article will introduce you in detail how to use Eclipse RCP for Spring Web development.

  I. Introduction

Although Web 2.0 and rich Internet applications (RIA) are extremely popular today, building a rich Web Front-end may not really meet your requirements when you really need the functionality of a fat client.

However, if you really want to avoid the so-called RIA craze and choose an actual fat client solution, what should you do? A: You can choose a wide range of client platforms (RCP) to handle most of your work. In essence, this RCP concept provides a new framework for the Java Desktop Application World.

An RCP provides an application framework/Shell and a set of module-based APIs. you can build your own applications based on this shell. This RCP is responsible for implementing all the heavy tasks, such as adding menus, tool bars, and different views. You do not have to repeat the work.

This article will guide you to build a fat client interface in detail to connect to the server built in the previous article. You will build a fat client based on Eclipse's rich client platform, and then integrate Eclipse RCP with Spring.

[Preparations]

· Eclipse 3.1.2

· MyEclipse 4.1.1

· Java SE 5

· A Servlet container or J2EE server (Tomcat 5.5 + is used in this article)

· Spring 1.2 +

  2. Why use Eclipse RCP?

Nowadays, more and more applications are developed based on Eclipse RCP (of course, there is also a thick development background of Eclipse). Therefore, we can safely assume that, compared with any other framework, this framework has been widely tested.

Next, let's start.

(1) Create a New Eclipse plug-in Project

Follow these steps to create a new Eclipse plug-in project for your rich client applications:

1. Create a new plug-in project in Eclipse and name the project "Export setradeclient. Locate the application target of this plug-in Eclipse 3.1, click "Create an OSGi bundle manifest" (see figure 1), and click Next.


Figure 1. Create a New Plug-in Project named setradeclient in Eclipse in the "New Plug-in Project" dialog box.

2. on the "Plug-in Content" screen, keep the default settings, but make sure you select "Yes"-create a rich client application (see figure 2) and click Next.


Figure 2. On the "Plug-in Content" screen, select to create a rich client application.

· For the template, select "RCP application with a view" and click Next.

· Enter the RCP application properties shown in 3 and click Finish. Then, you will be prompted to go to the "Plug-in Development" view and click "Yes.


Figure 3. The final result screen of the RCP plug-in Project Wizard

· Now, you have created your project and opened plugin. xml. You will see the screen snapshot shown in Figure 4.


Figure 4. Overview of Plugin. XML

If you are a beginner in Eclipse plug-in development, you may often need to use the plugin. xml tab at the bottom. As you can see on the Overview tab, you can run/debug your Eclipse rich client applications.

· Expand the export setradeclient/src/export setradeclient package to observe the classes created by the RCP Wizard of Eclipse. In the Eclipse Editor, click the "All Extensions" tab and expand each top-level node, as shown in Figure 5.


Figure 5. classes generated by Eclipse and all extensions

Note the extensions of your Application class, Perspective class, and View class. Since Eclipse's rich client platform includes the plugin. xml file, you can simply Add new components by adding them through the "Add..." button on the "Extensions" tab.

(2) refactor the default View class

As you can see, the Eclipse wizard creates a class named View for you. Not very useful, right? Use the following steps to reconstruct the default view class:

1. rename it-right-click View. java in Package Explorer. Go to Refactor-> Rename, enter the new name "assumerview", and click "Preview. On the panel that will pop up later, you will see that the Perspective class is restructured-use assumerview. ID to replace View. ID (see figure 6 ). Click OK.


Figure 6. Reconstruct the View class for the assumerview

2. Unfortunately, Eclipse's refactoring capabilities are a little weak-especially compared with IntelliJ. For refactoring like this, IntelliJ will not only change the class as expected, but also apply the refactoring to your. xml file! This is a very useful feature, especially when there is a large proportion of Spring/Hibernate/XML configuration operations.

You must manually update the refactoring of plugin. xml. Open plugin. xml and click the plugin. xml tab. Find the extended View and make the following updates:

Name = "assumerview"
Class = "Export setradeclient. assumerview"
Id = "Your setradeclient. assumerview">

Save the settings (see figure 7 ).


Figure 7. Further refactoring-manually update Plugin. XML

3. This is the case for this simple refactoring, right? Yes, but unfortunately, you are not finished yet. Open the assumerview class and change the static variable ID-initialize it as javassetradeclient. assumerview. This corresponds to the ID you just set in plugin. xml.

4. Finally, you can complete the refactoring. Now, let's test whether all the changes are normal. Switch back to plugin. xml in the editor and click the "Overview" tab. Click "Launch an Eclipse application", which should result in 8 results.


Figure 8. Start the Eclipse Trade Client program


5. Now let's change the node name. Open the assumerview class. Find the internal class ViewContentProvider and change the method "Object getElements (Object parent)" to return a String Array ({"Watch List", "Order History "}).

 

3. Add Spring Remoting to your application

Next, we add Spring to your Eclipse rich client so that it sends a request to the StockTradeServer project in the previous article.

First, when developing Eclipse plug-ins/RCP applications, the recommended method to add third-party libraries is to use another plug-in. After this is done, you do not need to add these third-party jars to each project you create. Instead, you only establish a certain dependency between your plug-in/RCP project and third-party library project. First

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.