Editing Diagrams

Now that you have learned to add and edit elements to a diagram, it is time to learn how to refine the appearance of the diagram itself.

Drag and Drop

Some diagrams will be created solely from new elements. But sometimes you will want to use elements that already exist in the model. You just want to present them in a different context and show other specific aspects of its role in the overall architecture.

To do this, you can drag existing elements from the Navigation pane and drop them in the diagram. These elements will appear with all currently known associations to other elements already present in the diagram.

Drag and Drop can also be used to move a class from one package to another. This can be accomplished by selecting a class in the Navigation pane and dragging it to the destination package. Once the class has been moved, the description that shows the origin of the class is immediately updated.

The other possibility is to select elements in a different diagram, copy them by hitting CTRL-C and pasting them into your new diagram by hitting CTRL-V. To cut elements from a diagram, use CTRL-X. Of course, you can also use these features via the Edit menu or the Context menu.

Changing Namespaces

As your model evolves and grows bigger, you might want to restructure your model organization. Drag-and-Drop and Copy/Cut/Paste functions are surely one way of doing this. But there is a deeper concept behind the structure of models that you should be aware of.

UML has the notion of namespaces that define a structure for a model. This structure is not necessarily the same as the structure of your diagrams. Remember that model elements can be represented in several diagrams but can only have one namespace. And since diagrams can be created at very different points in the model structure (that is in different namespaces), model elements do not always share the namespace of that diagram.

A namespace is an abstraction of model elements that can contain further model elements. A typical example for a namespace is a package. Classes as well as diagrams are usually contained in a package, or to put it differently, their namespace is the package they are included in. Any model element that is not directly owned by another model element (like an operation that is owned by a class) has such a namespace.

To find out what namespace a model is in, look at the Properties tab in the Details pane. Any element either has a namespace or an owner. You can change the namespace by clicking on the little button to the right of the text field. This opens a drop-down menu with all namespaces you can move it to. For example, if you decide a class should not belong to the package you created it in, you can simply change its namespace to be a different package from the Properties tab.

In some cases, changing the namespace for one element does not only effect this element but others as well. This is a convenience feature that was intentionally built in, believing that this is what the user intends to do in most cases. But this might not always be the case. If you change the namespace of a diagram, then all model elements in that diagram are assigned the new namespace as well. Also, if you change the namespace of a package, all included elements will likewise be moved to the new namespace.

Since packages are the most important type of namespace, there is another convenience feature for it. You can change a model element's namespace by dragging it with the mouse onto the figure of a package within a diagram.

Layout functions

You already know that you can layout your diagram by using the select tool. But there are a number of other ways to rearrange your diagrams.

Select and Move Elements

A selected class can be moved not only by using the mouse, but also by means of the arrow keys. The elements get nudged in the direction of the selected arrow key. Holding down the SHIFT key while pressing the arrows causes the elements to move in larger increments.

You can easily select several elements by holding down the SHIFT key while you select further elements, or by clicking somewhere in the empty space of the drawing area and dragging the mouse over elements. A blue rectangle appears and all elements that are completely enclosed in it will be selected.

Figure 7-15. Selecting multiple elements with the mouse.

Movements always apply only to the selected elements. If you want to select all elements in a diagram, use the hot key: CTRL-A.

Arrange Elements

Another set of useful options that are accessible from the main menu are the arrangement options. These are a powerful set of tools to assist with the layout of a diagram. They are divided into two groups: align and distribute. The align tools move elements to a specified axis.

The Align Tools include:

The distribute tools adjust the spacing of the elements without regard to their alignment.

The Distribute Tools include:

Both groups of tools may be used alone or in conjunction with another tool of a different type. For example,

The layout process is supported by a grid. It you want a finer or a coarser grid than the default or if you want the grid to be displayed in a different manner, you can change this in the View menu.

Changing the Shape of Relationships

You can also change the layout of the edges. By default, Poseidon for UML always tries to draw a straight line without bends but you can easily add waypoints: Select an edge and move the mouse perpendicular to the edge. At first the edge simply moves, too. But as soon as a straight edge is no longer possible, a waypoint is automatically added. You can add several waypoints by clicking on the edge so that you can wire your diagrams as you prefer. To remove a waypoint, just move it over another waypoint or an endpoint and it disappears.

Figure 7-16. Adding Waypoints.

In Poseidon for UML version 2.0, waypoints have changed from blue boxes to yellow circles. Despite the change in appearance, they function in the same way.

Moving Adornments

You can also move adornments as you can move elements. Simply select the adornment and drag it around. You will notice a little dotted red line that indicates to which association this adornment belongs. Roles and multiplicities are attached to the association ends in the same manner.

Figure 7-17. Moving Adornments.

In version 2.0, the adornments move in a slightly different (and more intelligent) manner. Previously, an adornment might obscure an edge. Adornments now 'hop' over edges, automatically providing a cleaner look to the diagrams.

Removing and Deleting Elements

With drawing tools like Visio or Powerpoint, deleting an element from a diagram simply removes the figure from that single location. With full-blown UML modeling tools this is different. You are always working on a single, consistent model. The different diagrams and the elements contained within them are just components of views rendered from this single model, even if the diagrams are constantly used as a means to change the model. The consequence of this is that modifications to any element within a diagram are applied to the element, not to the diagram. As such, a change made to the element will be seen throughout the entire model.

It then follows that selecting an element and then pressing delete means that the element itself is deleted, meaning that it no longer exists within the model and is removed from all aspects of the model. Note that there is a big difference between deleting an element from a model and removing an element from a diagram.

This leads us to use different terminology with different meanings: You can delete an element from the model, which means that the element is removed entirely and is no longer available in the Navigation pane or in any of the diagrams, or you can just remove its figure from the current diagram you are working with. These are very different things, and different commands are used to achieve them.

To completely remove an element from the model:

To remove an element's representation from the current diagram:

The element, as part of the model, remains untouched in other diagrams and it also remains in the tree in the Navigation pane. For elements that are connected to other elements through, for example, an association or inheritance, removing the first element (e.g. a class) means that the association is no longer valid and therefore the second element (e.g. the association) is also removed from the diagram, but is likewise still accessible from the navigation pane or other diagrams.

If you want to remove an element but not the connections it has to other elements, you can detach it by selecting the connection and dragging the handle at the end of it to another element before you remove the element.