Modeling an Application with UML1
UML1 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 Model Repository
MyEclipse UML stores all UML diagrams and model elements in a file known as a UML Model Repository (UMR). A UMR has a file extension of .umr and is depicted with the icon in the Package Explorer and Navigation views. You can create any number of UMR files in any type of MyEclipse project.
- Select File>New>Other, expand MyEclipse>UML, and select UML1 Model. Or, from the MyEclipse UML perspective select FiIe>New>UML1 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. The MyEclipse UML Diagram editor opens a new, empty class diagram.
2. Creating and Editing UML Diagrams
A model repository can contain any number of diagrams of any type. To add a new diagram to a model repository, open the UML repository file in the editor, click the New Diagram drop-down arrow on the Diagram Editor toolbar, and select the appropriate new UML Diagram action from the menu.
New Diagram icon menu from Editor toolbar
Diagrams can also be created from the UML Outline view.
New Diagram drop-down menu in the Outline view
To edit or view a UML diagram, select it from either the drop-down diagram list on the Diagram Editors toolbar or from the MyEclipse UML Outline view.
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, double-click the type of element you want to add to your diagram, and then begin clicking the diagram canvas.
Mass-add mode
To exit mass-add mode, click the Selction Tool icon (black arrow) on the toolbar, and continue editing the diagram.
Adding Model Elements to Diagrams
Model elements can be added to the current diagram from the UML editor toolbar by clicking the appropriate element button, and then selecting the location on the diagram where the new element should reside. The toolbar is diagram-specific, so its contents changes 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.
Adding a new class to a Class diagram
Editing Diagram Elements
The UML Diagram editor enables you to directly modify nodes and connections through a concept known as a hot-zone. There are two type of hot-zones: text and connection.
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
Quick Connects are a type of hot-zone that provides fly-over short-cut association and generalization connections on a node. You can quickly choose the connection type, e.g., association, generalization, self association, and drag the connection to another node to complete the connection.
Quick connects
Properties editing allows you to change an element in the Properties view. The Properties view has several pages for easy entry or edit of attributes associated with an element. Some of the fields overlap with changes that can be made in a hot-zone, and others are available only in the Properties view.
Editing properties
3. Forward Engineering – UML Class Diagrams to Java Code
MyEclipse UML enables you to generate Java code directly from the class diagrams of your UML model.
- Open the UML repository with the class diagrams you want to generate Java code.
- Select UML>Generate Java.
- Select the source folder of the MyEclipse 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.
Generated classes
4. Reverse Engineering – Java Code to UML 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.
- Open the UMR file.
- Select UML>Reverse Engineer UML from Java.
- Navigate to, and select the Java source files to reverse-engineer. Click Next.
- Specify your processing preferences, and click Finish.
Drag-and-Drop Reverse-Engineering
You can seamlessly add Java classes and interfaces to any UML class diagram using drag-and-drop operations.
- From the Explorer view, select one or more classes or interfaces.
- Drag and drop the selected classes onto the UML class diagram in the UML Diagram editor.
- Customize the generated content, and click Finish. The default settings are highly recommended.
Upon completion, the class diagram reflects the new additions, including associations between them, if any. The following example is a reverse-engineered diagram containing associations between elements.
Reverse-engineered diagram with associations
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.
- Open the MyEclipse UML perspective by selecting Window>Open Perspective>Other from the menu, and selecting MyEclipse UML.
- Create a new UMR file by selecting File>New>Other from the menu, expanding MyEclipse>UML, and selecting UML1 Model. This creates a UMR file and opens the UML Diagram editor.
Is MyEclipse UML 1 compatible with Arg 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.