facebook

Modeling an Application with UML2

UML2 modeling files are stored in a modeling repository, and the modeling can be used to generate Java code, or a model can be generated from code. This tutorial shows you how to perform tasks related to a modeling repository. You will learn how to:

  • Create a UML model repository
  • Create and edit UML diagrams
  • Forward engineer a diagram to generate Java code
  • Reverse engineer Java code into a diagram
This feature is available in MyEclipse.


1. Create a UML 2 Modeling File

MyEclipse UML2 stores UML2 modeling information in a modeling (.uml) file. Diagrams and model elements are stored in a UML model diagram (.umldi) file. You can create any number of UML2 files in any type of MyEclipse project. 

  1. Select File>New>Other, expand MyEclipse>UML, and select UML2 Model. Or, from the MyEclipse UML perspective select FiIe>New>UML2 Model.
  2. Navigate to the workspace folder in which you want to place the UMR file, and specify the name of the UML model repository.

    Creating a new UMR
  3. Click Finish to open a new, empty class diagram.

    Editing model using the Diagram editor


2. Creating and Editing UML 2 Diagrams

A model can contain any number of diagrams of any type. To add a new diagram to a model, open a .umldi file in the editor, click the drop-down arrow, and select a new UML2 Diagram.


New Diagram icon menu from the toolbar

To edit or view a UML2 diagram in a model, select it from the diagram drop-down list on the toolbar.


View/edit UML diagrams

While editing UML diagrams, you can enter “mass-add” mode, which allows you to continually click in the diagram area adding the same type of element, click after click. To enter mass-add mode, press the CTRL key as you click the diagram canvas once. From then on, you can add multiple items of the same type. To exit mass-add mode, click the Selction tool (white arrow), and continue editing the diagram.


Press CTRL and click the canvas to add multiple elements

Adding Model Elements to Diagrams

Model elements can be added to the current diagram from the UML editor tools by clicking the appropriate element in the toolbar, and then clicking the location on the diagram where the new element should reside. The tools list is diagram-specific, so its contents change based on the type of diagram. Below is a sequence of screenshots that show how a class can be added to a class diagram. Any element can be added to other diagrams in a similar way.


Click the element in the toolbar you want to add


Click a location on the diagram to place the element


Click the header to change the element name. Right-click to add properties and operations.

Editing Diagram Elements

The UML2 Diagram editor enables you to directly modify nodes and connections through a concept known as a hot-zone. The text hot-zone is region within a node or at the center and end-points of a connection, e.g., association, that is activated by double-clicking within its region. When activated, a hot-zone presents a rectangular field in which you can type. The type-in field accepts direct text entry and delete/cut/copy/paste operations. To commit the changes of a text hot-zone, select anywhere outside the hot-zone edit region. The type-in region disappears and is replaced with its content.


Text hot-zone

Properties editing allows you to change an element using the Properties view. As you select an element and its components, the appropriate properties appear in the Properties view.


Editing properties of a selected element


3. Forward Engineering a UML 2 Class Diagram to Java Code

MyEclipse UML enables you to generate Java code directly from the class diagrams of your UML model. 

  1. Open the UML2 model file containing the class diagrams for which you want to generate Java code. Click the diagram to place focus on it.
  2. Select UML2>Generate Java.
  3. Select the source folder of the Java project into which the new UML Java classes will be created. 
  4. Select one or more UML classes to translate to Java code, and click Finish.
    UML Forward Select
    UML Forward-engineering

After generation is complete, the newly generated Java classes appear in the specified source folder.


Generated package and class


4. Reverse Engineering Java Code to UML 2 Class Diagrams

Reverse engineering from Java code to UML can be done in two different ways, either through batch processing or drag-and-drop.

Batch Mode – Reverse-Engineering

The MyEclipse UML Reverse-Engineering tools enable you to import the Java classes and interfaces from any Java project, source folder, Java package, or source file. 

  1. Right-click the projet you want to reverse engineer, and select MyEclipse>Generate UML2 Class Diagram.
  2. Select the project parent folder, and enter a name for the model file. Click Next.

    Reverse engineering to create a UML2 model
  3. Select the Java source files you want to diagram, and click Finish. 

    Selecting packages and classes to reverse engineer

Drag-and-Drop Reverse-Engineering

You can seamlessly add Java classes and interfaces to any UML class diagram using drag-and-drop operations. 

  1. From the Explorer, select one or more classes or interfaces.
  2. Drag and drop the selected classes onto the UML class diagram in the UML Diagram editor.
    UML Drag Start
    Drag and drop reverse engineering

Upon completion, the class diagram reflects the new additions.


Reverse-engineered diagram

5. FAQ

When I open the MyEclipse workbench, I don’t see how to get started using UML features.
You need to create a UMR file and open it in the UML Diagram editor.

  1. Open the MyEclipse UML perspective by selecting Window>Open Perspective>Other, and selecting MyEclipse UML.
  2. Create a new UMR file by selecting File>New>Other, expanding MyEclipse>UML, and selecting UML1 Model. This creates a UMR file and opens the UML Diagram editor.

Is MyEclipse UML2 compatible with Argo UML?
MyEclipse UML is backward compatible with the .zargo file format of Argo UML (ver. 0.17 or earlier). To use an existing Argo model file with MyEclipse UML do the following:

  1. Copy the Argo file into an Eclipse project.
  2. Open the .zargo file in the Diagram editor to begin browsing and editing diagrams.


6. Resources

UML Resource Center