Getting started with the Eclipse Platform: development Environment and examples

Source: Internet
Author: User
Tags contains interface variables version variable versions window version control system
To test the Java development environment, we will create and run a "Hello World" application. Using the Java perspective, right-click the "Hello" Item and select New=>class, as shown in Figure 2. In the dialog box that appears, type "Hello" as the class name. In the "Which method stubs would" and "create?" Next, select the public static void main (string[] args) check box, and then press Finish.
Figure 2. Create a new class in a Java perspective

This creates a. java file in the editor area that contains the Hello class and the empty main () method, as shown in Figure 3. Then add the following code to the method (note that the declaration of which I was intentionally omitted):

Figure 3. The Hello class in the Java editor

You will notice some of the features of the Eclipse editor as you type, including syntax checking and automatic code completion. In version 2.1 (I downloaded the M2 version to try out), when you type open brackets or double quotes, Eclipse automatically provides paired symbols and places the cursor inside a symbol pair. In other cases, you can invoke the code completion function by pressing Ctrl-space. Code completion provides a context-sensitive list of suggestions that you can select from the list by keyboard or mouse. These recommendations can be either a list of methods for a particular object or a snippet of code that is expanded based on different keywords, such as for or while. The syntax check relies on incremental compilation. Whenever you save your code, it accepts compilation and syntax checking in the background. By default, syntax errors are underlined with a red underline, and a red dot with a white "X" appears on the left edge. Other errors are indicated by a lightbulb icon on the left side of the editor, which is the problem that the editor may be able to fix for you-the so-called quick fix feature.

The code example above has a lightbulb icon behind the for statement, because the declaration of I is omitted. Double-clicking the icon will bring up the suggested fix list. In this example, it provides suggestions for creating a class field I, a local variable I, or a method parameter I; clicking each of these suggestions displays the code that will be generated. Figure 4 shows the list of recommendations and the code that is generated after a local variable is created.

Figure 4. Quick Fix recommend

Double-clicking the suggestion inserts the suggested code in the appropriate location in your code. Once the code compiles without errors, you can choose Run from the Eclipse menu to execute the program (note that there is no separate compilation step here, because the compilation is done when you save the code.) If the code has no syntax errors, it can run. A Launch Configurations dialog box appears with the appropriate default settings, and press the Run button in the upper-right corner. A new tabbed pane appears in the following pane (console), showing the output of the program, as shown in Figure 5.

Figure 5. The output of the program

You can also run programs in the Java debugger. First double-click the gray edge of the left side of the editor view to set a breakpoint in main () System.out.println () after the call to System.out.println (). A blue dot will appear there. Then choose Debug from the Run menu. As described above, a Launch Configurations dialog box appears. Please select Run. The perspective will automatically switch to the Debug perspective, which has a number of interesting new views, as shown in Figure 6:

Figure 6. Debug Pivot Chart

First, notice the Debug view in the upper-left corner of the perspective. This view displays the call stack, and there is a toolbar in the title bar that allows you to control the execution of the program, including continuing, suspending or terminating it, tracking the next statement, stepping through the next statement, or returning from the method. The upper-right pane contains a number of tabbed views, including Variables, breakpoints, Expressions, and Display. Here I clicked the Variables view so that we could see the current value of I. You can get more information about these views with context-sensitive Help: Click the title of the view, and then press F1.

Additional Plug-ins In addition to plug-ins such as JDT for editing, compiling, and debugging applications, there are a number of plug-ins available that support the complete development process from modeling, build automation, unit testing, performance testing, versioning to configuration management. The Eclipse standard comes with plug-ins that work with CVS, which is an open source concurrent version system for source control (Concurrent versions system). The team plug-in connects to the CVS server, allowing members of the development teams to manipulate a set of source code files without overwriting other people's changes. There is no further discussion of how to source control from within Eclipse, as this requires the installation of a CVS server, but it is an important and essential feature of Eclipse to support the development team rather than just stand-alone development. Some of the Third-party plug-ins that are available or have been announced for release include: Versioning and Configuration Management CVS Merant PVCS Rational ClearCase UML modeling Omondo eclipseumlrational XDE (instead of Rose) together WebSphere Studio Edition Graphics batik SVG Macromedia Flash Web Development, HTML, XML Macromedia Dreamweaver xmlbuddy Application Server integration Sysdeo Tomcat Launcher to see examples of plug-ins and see how it is integrated with Eclipse, download the popular Omondo eclipseuml, which is free. This plug-in relies on GEF, the graphical Editor Framework, which is another Eclipse plug-in. GEF is part of the Tools sub project. To download GEF, go to the Eclipse Web site, select "Downloads", and then click the "Tools PMC Downloads page" link. Note that you will need to download the GEF version recommended by Omondo (GEF 2.0 for Omondo 1.0.2). After downloading, the installation of the plug-in is usually done by decompressing the download file and copying its contents to the Eclipse plug-in directory. In this case, GEF needs to extract the Eclipse directory (it will automatically enter the plug-in directory from that directory). For security reasons, you might want to unzip it to a temporary directory, and then copy the related directory from there accordingly. If Eclipse is running, you need to stop it and then restart it so that it recognizes the newly installed plug-in. OnceECLIPSEUML (and GEF) Setup completes, you can create a class diagram just as you would create a Java class file. In the Java perspective, right-click the "Hello" item in Package Explorer and choose New=>other from the pop-up menu. There will be a new option for UML in the left pane of the New dialog box. The free version of ECLIPSEUML only supports class diagrams, so the only option on the right is UML class Diagram. Please select UML class Diagram and type a name for the class diagram, such as "Hello":

Figure 7. Class Diagram Editor

A graphical editor appears in the editor area with a canvas for drawing class diagrams. You can create class diagrams in two ways: reverse-engineer existing code by dragging Java files from Package Explorer onto class diagrams, or by using the drawing tools available on the toolbar above the blank class diagram. To experiment with the first method, create a new class named person (using File=>new=>class) and give it the two private properties listed below:

/** Person.java * @author David */public class Person {private String name;private address address;/** * Returns the Addre SS. * @return Address */public address getaddress () {return address;} /** * Returns the name. * @return String */public string GetName () {return name;} /** * Sets the address. * @param address "address" to set */public void Setaddress (address) {this.address = address;} /** * Sets the name. * @param name the name to set */public void SetName (String name) {this.name = name;}}

(Admittedly, I just typed the line for name and address.) Getter and setter methods are generated automatically through Eclipse, that is, right-click the source code and select the Source=>generate Getter and setter from the pop-up menu. ) Please save and close Person.java HELLO.UCD.

Figure 8. Person class diagram

To create a Java class from UML, click the New Class button on the toolbar at the top of the class Diagram window, the third button on the left, and then click the class Diagram. When the New Class Wizard opens, type adress as the class name, and then click Finish.

You can add properties to a class by right-clicking the class name and selecting New=>attribute. In the New Properties dialog box, enter the property name, type, and visibility. Then right-click the class name and select New=>method to add the method. When you change a class diagram, the Source Editor window below the figure reflects the changes you made. Finally, you can draw a diagram of the two classes by clicking the association button (fifth from the left) and drawing a line segment from the person class to the address class. This will bring up another dialog box where you can enter the associated attributes (refer to ECLIPSEUML Help for more on the required information). The completed diagram should resemble the following:

Figure 9. Association

This UML plug-in demonstrates several typical features of the Eclipse plug-in. First, it shows the tight integration between tools. There is absolutely no way to see how many components are working; integration with the Eclipse platform and JDT is seamless. For example, when the person class is created, it displays a syntax error because one of its property address is not defined. Once the address class is created in a UML diagram, the components are displayed separately. Another feature is the ability of ECLIPSEUML to leverage the functionality provided by other Plug-ins--in this case, the GEF plug-in, which provides tools for developing visual editors. Another feature relates to the way eclipseuml Plug-ins use multi-level functionality for distribution. The basic plug-ins that support the class diagram are free, but more mature versions are paid to be used. Eclipse Platform Architecture Eclipse Platform is a framework for a powerful set of services that support plug-ins such as the JDT and plug-in development environments (PDE). It consists of several major components: platform runtime, Workspace, Workbench, Team support, and help.

Figure 10. Eclipse Platform Architecture

The Platform platform runtime is the kernel that checks which plug-ins are installed at startup and creates registry information about them. To reduce startup time and resource usage, it loads the plug-in when it actually requires any plug-ins. In addition to the kernel, everything else is implemented as a plugin. A workspace workspace is a plug-in that is responsible for managing user resources. This includes user-created projects, files in those projects, and file changes and other resources. The workspace is also responsible for notifying other plug-ins of information about resource changes, such as file creation, deletion, or change. The Workbench table provides the user interface for Eclipse. It is built using standard window Toolkit (SWT) and a more advanced API (JFace); SWT is a non-standard substitute for the Java swing/awt GUI API, and JFace is based on SWT and provides user interface components. SWT has proved to be the most controversial part of Eclipse. SWT maps more closely to the native graphics features of the underlying operating system than Swing or SWT, which not only makes SWT faster, but also makes Java programs look and feel more like native applications. Using this new GUI API may limit the portability of the Eclipse Workbench, but the SWT porting version for most popular operating systems is already available. Eclipse's use of SWT only affects the portability of eclipse itself--any Java applications built with eclipse will not be affected unless they use SWT instead of using SWING/AWT. The team support Team support component is responsible for providing version control and configuration management support. It adds views as needed to allow the user to interact with any version control system (if any) that is used. Most plug-ins do not need to interact with the team support components unless they provide version control services. The Help help component has the scalability capabilities that are equivalent to the Eclipse platform itself. As with Plug-ins adding functionality to Eclipse, it helps provide an additional navigation structure that allows tools to add documents as HTML files. The prospects for eclipse are at a critical stage around the development of Eclipse. Major software tool providers are involved, and the number of open source Eclipse plug-in projects is increasing. A portable, extensible, open source framework is not a new idea (you'll recall Emacs), but Eclipse brings a whole new impetus to its mature, robust, and elegant design. IBM's $40 million worth of world-class software in the open source area of the release, the industry has brought a long absence of shock.


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.