Tuesday, February 22, 2011

eUML2 Class Diagram including Multiple Packages

It didn't seem straightforward to me how to do this so I'll explain the steps here. I wanted to generate a class diagram from my code using the reverse engineering capability of the plugin. This seems backward but I wanted to use it as a way to show my coworkers how the design of something already written looks visually. I have my code separated into different packages and wanted to make a diagram containing every package and show relations between most of the classes.

The overall concept of the class diagrams generated from the plugin is that each diagram represents one package. So first you must create a class diagram representing one of your packages. Once you have that, you can add your other packages to that diagram.
  1. Open the .ucd file for the existing diagram you have so far in Eclipse.
  2. Make sure you're in "Selection mode" in the toolbar.
  3. Make sure nothing is selected*. Then right-click on empty space in the diagram.
  4. Choose Insert->Package and pick the package you want to add to the diagram.
  5. A box will be added that represents that package. Select it by left-clicking on it.
  6. Then right-click and choose "Package Elements...".
  7. Check the boxes for the classes you want to show explicitly in the diagram.
  8. The classes should now be in the package box.
  9. Then you can select nothing* again, right-click and choose "Show All Associations" or "Show all Inheritances" if you want.
  10. When you have picked all the options you want, select nothing*, right-click and choose "Layout" to make it arrange things nicely. If you don't like the layout it comes up with, you can repeat the same action and it seems to cycle through a few layout options.
  11. You can save it as an image by selecting nothing*, right-clicking and choosing "Export as image" and following the wizard.
*Left-click on empty space in the diagram to "select nothing" i.e. make sure that no items are selected.

    3 comments: