COMP 310 |
Using UML Lab |
UML Lab is a commercial UML diagramming tool produced by Yatta Solutions in Germany. UML Lab supports round-trip engineering, i.e. creating diagrams from code as well as creating code from diagrams.
Quick links:
As of 8/29/21, UML Lab Modeling IDE v. 1.24.0: UML Lab is unable to properly parse interfaces that contain static methods. UML Lab will display error messages saying that it cannot parse the files and its code auto-generator will attempt to either remove the methods completely or replace them with invalid Java code.
At the moment, the only work-arounds are:
- Remove the interface from any diagrams and remove the interface from UML LAb model as per the instructions in Cleaning Up the UML Lab model.
- Note that subsequent diagram editing operations may re-introduce the offending interface back into the UML Lab model and the removal process will need to be repeated.
- Temporarily comment out the offending methods, export an image of the diagram and then uncomment the methods.
- This is only useful if one is ready to create a final version of the diagram.
- Be careful not to commit the vesion of the interface with the commented-out methods!
To prevent UML Lab from attempting to process classes/interfaces that are not part of a diagram and in particular, classes/interfaces that it is unable to parse, a highly recommended practice is to prevent UML Lab from reading the entire codebase when first creating a UML Lab model (
.uml
file). This occurs when such one is first starting off and one has selectedNew/UML Model and Class Diagram
from the right-click menu in Eclipse's Package Explorer tab.By default, UML Lab selects the entire source folder to parse into the model file. Unchecking all the boxes when presented with the
Populate model and diagram
dialog window will prevent UML Lab from reading in unwanted files into the model.Now, only the classes and interfaces dragged onto a diagram will be parsed into the UML Lab model.
In Eclipse: Go to Help/Help Contents/UML Lab User Guide
UML Lab Home page: http://www.uml-lab.com/en/uml-lab/
Unfortunately, most of the discussion postings are in German, so if you cannot read German, you can use the built-in translation capabilities of your browser to get a pretty usable translation of the postings:
UML Lab runs slightly differently than many other diagramming tools. UML Lab creates a "model" which holds all of the relevant relational information about the Java classes and interfaces needed to create UML diagrams. This is the ".uml" file that is created. This model is NOT a UML diagram however. Separately, UML Lab creates a UML class diagram from the model. There may be many class diagrams created from a single model. The class diagrams are the ".umlcd" files.
To create a UML diagram using UML Lab, you must have BOTH a model and a class diagram file! However, only one model file may be needed for multiple class diagrams.
Important Note: UML Lab does not instantaneously create code when the elements of a diagram are changed. Changes to code are not created until the diagram is saved.
The UML Lab preferences can be found in the Eclipse preferences, under the main Eclipse menu: Window/Preferences/UML Lab
It is highly recommended that you make the following changes to the default settings:
Apply and Close
" button to save the changes.
(Click the image for a larger version)
Tip: If you are having trouble selecting entities in UML Lab, be sure that you have selected the "arrow" pointer at the top of the palette. The "universal tool", whose icon looks like a little blue gear, can also be used. This tool uses shortcuts to bypass keystrokes for common tasks. See the description under Concepts/Class Diagram Editor/Palette/Universal Tool in the UML Lab help topics in Eclipse.
We need to create both the model file and the class diagram file in this situation:
We only need to create the diagram file in this situation because the model file was already made:
When you first save a diagram, UML Lab will ask you if wish to automatically generate the associated code for the diagram. Check the option to always generate code upon saving.
When UML Lab generates code, existing code in .java files will be modified and new files created if necessary.
You can manually generate code without saving by right-clicking the diagram and selecting "Generate Code".
Any changes to code will automatically be reflected in a diagram when the diagram when the diagram is first opened. However, sometimes the UML Lab model engine gets confused as to whether to code in the Java file is newer or older than the code in the model and will erroneously try to overwrite the code you just wrote directly into the Java file.
However, you must be a bit careful if you edit the code while the diagram is while UML Lab's automatic code generator is running. You may get the following warning message:
or you may get the following:
You may get a warning dialog like the above that says that the code is open in the diagram editor and asks if you want to overwrite the opened code and to discard your changes. Select No or Cancel! This will cause the code you just edited to be reflected in the diagram. Otherwise, your code edits will be lost.
Often, you will get the above warnings every time you save your Java code file, even if the UML Lab diagram is not open. The reason is because the underlying UML Lab model engine is still running, trying to synchronize the code. If you know you will not be using the class diagram for a while, you should shut down the UML Lab model engine:
If you accidentally do the wrong thing and UML Lab overwrites/deletes your code, you can almost always get your code back by pressing "Ctrl-Z" (Undo).
Simply drag and drop the items from the Package Explorer to the diagram.
Sometimes the UML Lab component palette is hidden from view because it is collapsed. If you do not see it, click the small arrowhead at the upper right corner of the diagram to expand the palette. (The arrowhead can be hard to see if Eclipse is running in a "dark theme" mode.)
Inheritance ("Generalization/Realization") relationships are available on the UML Lab palette. Simply highlight the "Generalization/Realization" relationship, and drag-and-drop (you need to do a click at the end) a line from the sub-class to the superclass, i.e. in the direction of the inheritance arrow.
Association or compositional relationships (collectively, "association", "aggregation", "reference" and "composition") and dependency lines are all available on the UML Lab palette. Simply highlight the desired relationship, and drag-and-drop (you need to do a click at the end) a line in the direction of the arrow for that sort of relationship, i.e. from the the class with a field that references the other class to that other class in an aggregation line.
Technically, all association relationships in Java are aggregations. In other languages, such as C++, there is a distinct difference.
Use the "Reference" line in the Palette as this will cause the least problems with extraneous code being generated.
Fixing UML Labs defaults:
Unfortunately, the default properties for association type lines are not what we generally want, so we have to fix them up a bit. The following applies ONLY if the relationship refers to a fixed number of associated objects, i.e. 1 or 2, not a collection of objects.
To add a field to a class, click on a class in the diagram to select, but not highlight it. Then simply type the desired name of the field, followed by a colon, ":", and then the type of the field: fieldName: FieldType
For example: -count: int or position: Point
The visibility of the field can be modified by clicking the light blue rectangle icon to the left of the field name, which will bring the field up in the Property Editor below. Click the UML tab and select the desired visibility.
SAVE THE DIAGRAM AND LET IT GENERATE THE NEW CODE BEFORE ATTEMPTING TO DISPLAY ASSOCIATION LINES AND/OR REMOVING GETTERS/SETTERS
Bad practice by UML Lab:
Unfortunately, UML Lab auto-generates "gettor" and "settor" functions for any fields that are created. These methods only show up in the generated code, not on the diagram itself. This means that UML Lab defaults to breaking the encapsulation of classes, a practice common in "object-based programming" where objects are treated as dumb data containers. For our purposes, unless there is a clear need for the gettor or settor, one should always delete those auto-generated methods.
Before you delete the getter and/or setter, set the stereotype of the association line belonging to the field (if there is one) to "Reference", otherwise UML Lab won't show the association line for that field.
If the aggregation line is not displaying or not displaying in the desired manner, see the Tips and Traps section below.
Adding methods is similar to adding fields: select the class and type the name of the method followed by a set of parentheses, "()" -- input parameters will be added later --, followed by a colon and the return type: methodName(): ReturnType
For example: run(): boolean or makeFrame(): JFrame or -setState(): void
The visibility of the method can be modified by clicking the light blue "gear" icon to the left of the method name, which will bring the method up in the Property Editor below. Click the UML tab and select the desired visibility.
Adding input parameters:
To add input parameters to a method, select the entire method by clicking the light blue "gear" icon to the left of the method name in the class. The properties of that method will appear in the Property Editor below.
Click the "Parameters" tab to show the input parameters for the method:
Creating a constructor is very similar to making a method, with one extra step:
Properties
pane, under the UML
tab, enter "create
" (no quotes) in the Keywords
input box.
Sometimes you need to force UML Lab to rebuild its model and resynchronize its model with the actual code.
To reparse a single class in the diagram, simply
right-click the class and select "Update from classpath
".
Be sure to save all your work before asking UML Lab to reparse the file(s).
Editing the model file is risky! You can easily damage your code if something is done incorrectly. Always commit your project BEFORE attempting to edit the model file! Do not generate code if there are large errors occurring!
Open the UML Lab Model file (XXX.uml
) from inside of Eclipse. The default system editor for this sort of file should display something like this (you may need to expand some sections):
UML Lab will constantly try to process all classes and interfaces that it knows about even if they don't appear in any diagrams. Once a class or interface appears in a diagram, it is known to the UML LAb model even if it subsequently removed from the diagram.
Sometimes one needs to remove a class or interface from the UML Lab model file to keep UML Lab from processing that entity. This could be due to a number of reasons, such as the file containing code that UML Lab does not recognize, UML Lab's auto-generated code isn't correct or desired, a bug in the UML Lab processing, etc.
REMOVE THE OFFENDING CLASS/INTERFACE FROM ANY DIAGRAMS FIRST!
- Open the model file and fully expand the first section, which should be labelled: "
platform/resource/...
"- Expand the desired
<Package>
heading- Right-click and delete the desired entries.
- Save the model file.
Sometimes information gets orphaned in the UML Lab model file and removing those orphaned items can sometimes alleviate model errors.
- Open the model file and fully expand the first section, which should be labelled: "platform/resource/..." Right-click and delete the following items:
- "
<<UnresolvedElement>> ...
" -- these give the error "This element is not resolved and no code will be generated for it "dangling-refs
- Delete any sub-entries EXCEPT for the ones labelled "Change Description"
- "
<<Association>>
" where there is no additonal information associated with the tag.- Save the model file.
- Reload the model
A class diagram does not reflect the underlying code
A class diagram won't always immediately reflect the changes to the underlying code.
Make sure that you have saved all your changes! UML Lab will not pick up any changes until the source code file has been saved.
Once the files have been saved, force UML Lab to reparse all or part of the classes in its model.
UML Lab generates fields in both classes when drawing an aggregation (or similar) line
The following settings will make a a proper aggregation line with the open arrowhead pointing at the referenced class and an unfilled diamond at the class with the field. If your association line does not look right, compare it to the settings below.
Unfortunately, this is the default behavior of UML Lab -- by default it assumes that all aggregations are two-way navigations, that is each class can reference the other. Things to do to get rid of the unwanted field in the referenced class: Highlight the association line, then
Missing getters and setters in the UML Diagram and seemingly incorrect field visibility
Fields with no gettor or settor methods do not show up as lines on the diagram.
This is sometimes caused by the diagram not updating to display the new code or its diagram properties are not properly set. Try the following:
Show
associated
" icon that appears on the upper left corner of the class (the 3rd
icon from the left, a white box linked to a green box)Refactor/Convert
to Reference
".
Associations that represent collections do not show up properly
The best way to make an association that represents a collection, e.g. a List<Something>, Something[], Set<Something> or the like, is
Certain types of fields do not show up as association lines
UML Labs only recognizes certain types of fields, a restriction that is particularly apparent when working with generic collections, such as ArrayLists. For instance, suppose you made a field like such, in perfectly legal Java syntax:
private ArrayList<MyData> data = new ArrayList<MyData>();
If you had a UML diagram that already had the MyData class on it, an association line pointing at MyData would not appear.
The problem is that UML Lab does not recognize the ArrayList as a generic collection type. The type that UML Lab understands is the top-level interface for array-type collections, List. Thus the following code works and shows the association line in the UML diagram:
private List<MyData> data = new ArrayList<MyData>();
Ref: http://forum.yatta.de/discussion/28/reverse-engineering-generics
Error: "The association "" is defect: At least two member endsa re required"
This error seems to arise when association lines are somehow "orphaned" in UML Lab's model.
A technique that seems to have some success in getting rid of those errors is to open the model (XXX.uml) file and search through it looking for and deleting Association definitions that don't have any information associated with them. After you are done, follow the directions above to reload the model. See the above instructions on cleaning up the model.
A more drastic measure is to delete the model and class diagram and recreate it.
"Error: "This element is not resolved and no code will be generated for it (depends on the chosen templates). Substitute occurrences with the correct element."
This error seems to come from orphaned fields, etc in the model.
Either remake the model and diagram or see the above instructions on cleaning up the model.
"Not enough free memory available to reverse engineer the source code. Increase the available memory or reverse engineer fewer elements."
Try increasing the amount of memory allocated to Eclipse.
When creating a new diagram and model from scratch, no classes populate either the model or the diagram
This may also manifest itself as an apparent "rejection" of a class from being placed on the diagram where UML Lab refuses, without an error message, to allow the class to be dropped onto the diagram.
This may be due to a corrupted UML Lab installation, so try re-installing it.
© 2017 by Stephen Wong