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
Duration Time: 20 Minutes
Don't have MyEclipse? Download Now
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.
- Select File>New>Other, expand MyEclipse>UML, and select UML2 Model. Or, from the MyEclipse UML perspective select FiIe>New>UML2 Model.
- Navigate to the workspace folder in which you want to place the UMR file, and specify the name of the UML model repository.
- Click Finish to open a new, empty class diagram.
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.
To edit or view a UML2 diagram in a model, select it from the diagram drop-down list on the toolbar.
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.
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.
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.
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.
MyEclipse UML enables you to generate Java code directly from the class diagrams of your UML model.
- 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.
- Select UML2>Generate Java.
- Select the source folder of the Java project into which the new UML Java classes will be created.
- Select one or more UML classes to translate to Java code, and click Finish.
After generation is complete, the newly generated Java classes appear in the specified source folder.
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.
- Right-click the projet you want to reverse engineer, and select MyEclipse>Generate UML2 Class Diagram.
- Select the project parent folder, and enter a name for the model file. Click Next.
- Select the Java source files you want to diagram, and click Finish.
You can seamlessly add Java classes and interfaces to any UML class diagram using drag-and-drop operations.
- From the Explorer, select one or more classes or interfaces.
- Drag and drop the selected classes onto the UML class diagram in the UML Diagram editor.
Upon completion, the class diagram reflects the new additions.
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.
- Open the MyEclipse UML perspective by selecting Window>Open Perspective>Other, and selecting MyEclipse UML.
- 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:
- Copy the Argo file into an Eclipse project.
- Open the .zargo file in the Diagram editor to begin browsing and editing diagrams.