SDE for Eclipse UML CASE Tool Tutorial - Introduction to Eclipse UML Tool

Chapter 1  Introduction

 

In this chapter, you will learn how to work with the SDE environment in Eclipse/IBM WebSphere Studio Application Developer®, and you will have a first taste of the powerful functionalities of SDE including code reverse engineering, code generation and code/model synchronization.

 

 

In this chapter:

*      Working with SDE for Eclipse/IBM WSAD®

*      Code Reverse Engineering

*      Code Generation

*      Code Synchronization



Working with SDE for Eclipse/IBM WSAD®

1.        Start Eclipse/IBM WSAD®, then select File menu > Import... to import the sample project.

2.        Select Existing Project into Workspace, then click Next > to continue.


3.        Click Browse... to select the "School" sample project folder. After that, click Finish to import the project.

4.        Select the Window menu > Open Perspective > Java to open the Java perspective.


5.        Right-click on the School project node inside the Package Explorer and select Open UML Model from the popup menu to start SDE.

6.        SDE is started. Let's have a glance at the SDE environment.

SDE Toolbars

Provide quick access to SDE's frequently used functionalities

Diagram Tree

Displays diagrams in the project categorized by diagram types

Model Tree

Displays model elements in the model repository

Class Repository Tree

Displays packages/classes in the model repository

Property Pane

Displays context-sensitive properties of selected elements

Preview Pane

Displays the overview of the active diagram

Documentation Pane

Displays the documentation associated with the selected element

Element Viewer

Displays detailed information about specific kind of elements (such as attributes/operations of a class)

Message Pane

Displays SDE information/warning/error messages

 


7.        All the SDE panes behave like standard Eclipse/IBM WSAD® panes, can be dragged and docked to any positions.

8.        You can save your favorite UI perspective by selecting the Window menu > Save Perspective As..., or select the Window menu > Open Perspective to select an existing perspective to apply.

 

To see the interactive tutorial of this section, please click here.

 

Code Reverse Engineering

1.        Start Eclipse/IBM WSAD®, then select the File menu > Import... to import the sample project.

2.        Select Existing Project into Workspace, then click Next > to continue.

3.        Click Browse... to select the "School" sample project folder, then click Finish to import the project.

4.        Select the Window menu > Open Perspective > Java to open the Java perspective.

5.        Right-click on the School project node inside the Package Explorer and select Update UML Model from the popup menu.


6.        Activate the Model Tree and you will see the reversed classes.

7.        Right-click on the package "sch" and select the Form Diagram menu > Customize....

8.        When the Form Diagram dialog box appears, enter "School Class Diagram" in Diagram Name, and select the option Show all levels in single diagram. After that, click OK to generate the diagram.


9.        A class diagram will be generated as shown below.

 

To see the interactive tutorial of this section, please click here.

 

Code Generation

1.        Start Eclipse/IBM WSAD®, then select the File menu > Import... to import the sample project.

2.        Select Existing Project into Workspace, then click Next > to continue.

3.        Click Browse... to select the "SchoolForCodeGen" sample project folder, then click Finish to import the project.

4.        Select the Window menu > Open Perspective > Java to open the Java perspective.

5.        Right-click on the SchoolForCodeGen project node inside the Package Explorer and select Open UML Model from the popup menu to start SDE.

6.        Activate the diagram "School Class Diagram", resize the package "sch" to make room for new classes.


7.        Create a class named "Student" and place it inside the package "sch".

8.        Right-click on the new class and select New Attribute from the popup menu.

9.        Enter "-name : String" to add a private attribute ("-" is UML notation for private visibility) named "name" with type "String". After that, press the Enter key to confirm.

10.     With the attribute "name" still selected, press the Insert key to add another attribute. Enter "-studentID : String" to add a private attribute named "studentID" with type "String".

11.     Right-click on the class "Student" and select New Operation from the popup menu.

12.     Enter "+setName(name: String) : void" to add a public operation ("+" is UML notation for public visibility) named "setName", it accepts a parameter "name" of type "String", and its return type is "void".

13.     Follow the previous steps to add a getter method for "name", this time we enter "+getName() : String" to add a public operation named "getName" whose return type is "String".

14.     Right-click on the project node SchoolForCodeGen inside the Model Tree and select Update Project to Code from the popup menu.

15.     Activate the Package Explorer and expand the package "sch", you will see the source file "Student.java" is generated for the new class.

16.     Double-click on this source file to open it. You can see the source code matches with the class design in the class diagram.

 

To see the interactive tutorial of this section, please click here.

 

Code Synchronization

1.        Start Eclipse/IBM WSAD®, then select the File menu > Import... to import the sample project.

2.        Select Existing Project into Workspace, then click Next > to continue.

3.        Click Browse... to select the "SchoolForCodeSync" sample project folder, then click Finish to import the project.

4.        Select the Window menu > Open Perspective > Java to open the Java perspective.

5.        Right-click on the SchoolForCodeSync project node inside the Package Explorer and select Open UML Model from the popup menu to start SDE.

6.        Activate the diagram "School Class Diagram", right-click on the class "Teacher" and select Select in Code from the popup menu to open its source file.

7.        Drag the text editor Teacher.java and dock it below the class diagram.

8.        Double-click on the class "Teacher" and rename it to "Instructor".                              

9.        Click once on the tab of "Teacher.java" to deactivate the class diagram. Auto synchronization is triggered on deactivation of the class diagram.


10.     You will see the change in the class diagram is now reflected in the source code.

11.     Edit the class "Instructor" in the text editor to change the visibility of the attribute "name" to "protected", and change its initial value from "null" to "unnamed".

12.     Edit the method body of "setName" so that it checks the value of the "name" parameter before assigning the new value to the attribute (as shown in the figure below).

 


13.     Press the hot key Ctrl + S to save the changes in the source code. Auto synchronization is triggered upon the saving of the source file.

14.     The change that you have just made to the class "Instructor" is reflected in the class diagram (except the change of the "setName" method body, which is not displayed in the class diagram).

15.     Select the "setName" operation of the class "Instructor" in the class diagram, press F2 to edit it.

16.     Replace the "+" sign to "-" sign to make this operation private, and change the return type from "String" to "boolean". After that, press Enter to confirm.

17.     Click once on the tab of "Instructor.java" to deactivate the class diagram.

18.     With the help of SDE's incremental code synchronization, the method declaration of "setName" is updated, while the method body remains unchanged.

 

To see the interactive tutorial of this section, please click here.

 

Patents pending. All rights reserved.