Visual Paradigm:10.0与Eclipse3.7集成

来源:互联网 发布:优化神马pc关键词排名 编辑:程序博客网 时间:2024/06/05 06:29

Installing Visual Paradigm in Eclipse

  1. In Visual Paradigm, select Tools > IDE Integration... from the main menu.
  2. In the Visual Paradigm IDE Integration window, check Eclipse Integration.
    select ec integration
  3. Click Next.
  4. Enter the path of Eclipse and click Next.
    enter ec path
  5. This begins file copying. When finish, close Visual Paradigm and move on to the next section to see how to create a Java application along with a UML model.

Creating a Java Project

  1. Start Eclipse.
  2. Select File > New > Java Project from the main menu to open theNew Java Project window.
  3. In the New Java Project window, enter My Project in theProject name field.
    new java project
  4. Click Finish.

Creating a UML Model for the Java Project

Now, you have an empty Java project. Let's create a UML model for it. To create a UML model:

  1. Right click on the Java project node in Package Explorer and selectOpen Visual Paradigm from the popup menu.
    open Visual Paradigm
  2. When you are prompted to configure the eclipse.ini file to achieve an increase in memory, keepStart anyway select and click OK.
  3. When you are prompted to enter the path of project file, keep Create in default path selected and clickOK. This will create the file under the Java project folder.

UML Modeling in Eclipse

Let's draw a simple class diagram. We will generate Java code from it in the next section.

  1. Right click on the Class Diagram node in the Diagram Navigator pane and selectNew Class Diagram from the popup menu.
    new class diagram
  2. This creates an empty class diagram. Double click on <default package> at the top left of diagram to enter the name of package header. The class diagram along with the classes to be created in the diagram will automatically be put in a package with the entered name. Enter myapp as package header.
    enter package header
  3. Create a class. Select Class from the diagram toolbar. Drag it out and put it onto the diagram.
    create class
  4. Release the mouse button to create the class. Enter User as name and pressEnter to confirm.
    class created
  5. A user has two attributes: name and phone number. Let's add them. Right click on theUser class and select Add > Attribute from the popup menu.
    create att
  6. Enter name : String to create the name attribute in String type. Then pressEnter to confirm.
  7. Similarly, enter phoneNum : int to create the phoneNum attribute in integer type. Then pressEnter to confirm it and press Esc to cancel the next attribute.
    attrs created
  8. We want Visual Paradigm to generate getter and setter for the attributes during code generation. Select them both (Multiple selection can be made by pressing theShift/Ctrl button). Right click on them and select Model Element Properties > Setter from the popup menu.
    set setter
  9. Repeat the previous step to enable Getter.

Generate Java Code from UML Class

Let's produce Java source code from the UML class. There are several ways to achieve this. Here let's try the one that generate code for the entire UML model. Click on theUpdate Code button at the top of Diagram Navigator.


update code

In the Package Explorer, expand the project node and the src folder node. The packagemyapp and User class are there. Open User.java. You can see theUser class filled with attributes and its getter and setter.


user class

Perform Coding

In this section, you are going to build an executable application with the User class.

  1. Create a Main class. In the Package Explorer, right click on the package myapp and selectNew > Class from the popup menu.
  2. In the New Java Class window, enter Main as class name and clickFinish.
    new main class
  3. Create a static main method in the Main class that create and instantiate twoUser objects. Set the name and phone number through the setter.
    main content
  4. It would be nice to add into the User class a method to print out its name and phone number. Add a public methodprintInfo() in the User class.
    print info
  5. Call printInfo() from the Main class to display the information of created users.
    call print info

Running the Application

Let's run the application. Keep the Main class opened. Select Run > Run As > Java Application from the main menu. You should see the Console view appear with users' information printed in it.


console

Updating the UML Model from Java Code

You have made some changes in source code, such as the creation of Main class andprintInfo() in User class. In order to keep the design consistent with your source code, you need to update the UML model from code. Let's do it now.

  1. In the Eclipse toolbar, click on the Update UML Model button.
    update uml model
  2. Open the class diagram. The printInfo() method is presented in the User class.
    class updated
  3. For the Main class, you can find it under the Model Explorer. Drag it out and put it below theUser class.
    main visualized

 

 

Begin UML Modeling in Eclipse
http://www.visual-paradigm.com/tutorials/eclipseuml.jsp

0 0