Adding Types to Class Diagrams
There are several ways to add types to a class diagram.
Adding Types by Dragging
Types (ie classes, interfaces, enums) may be added to a diagram by dragging them in from the Package Explorer, Project Explorer, Type Hierarchy or the Navigator in the Resource Perspective.
It is best to deselect the Link with Editor button while dragging types onto a diagram to avoid Eclipse assuming you want to edit the code and opening source editors.
As a type is dragged over a diagram the mouse cursor will indicate if it is suitable for dropping. The reasons why a drop would be disallowed are:
- The type has already been added to the diagram
- The type is an inner type
- The diagram file is read-only
- You do not have a valid license
A multiple selection of types can be added to a diagram, or a parent (for example a package) of types can be added. The cursor will indicate a valid drop state if there is at least one suitable type among the selection. Groups of newly added classes are laid out automatically.
Adding Types by Context Menu
Right clicking on a node in the Eclipse Package Explorer tree reveals a menu option Add to current class diagram situated off the AgileJ menu. This action works in exactly the same way as a drag, adding types to the active diagram.
Adding Related Classes
A right click on a type in a diagram reveals options to add related types. Selecting any of these options scans the Java model for qualifying types and adds them to the diagram.
- Supertypes: to add all immediate (non-recursive) superclasses/superinterfaces of the type you clicked on.
- Subtypes: to add all immediate (non-recursive) subclasses/subinterfaces of the type you clicked on.
- Dependencies (Outward): to add all types upon which the type you clicked on depends. This includes supertypes and field types. This option is only available for classes for which the source code is available.
- Dependencies (Inward): to add all types which depend up on the type you clicked on. This includes subtypes and types which contain references (fields) to this type.
- Field Types: to add the types of all fields.
A right-click on the type label of a field reveals the option to add the field's type to the diagram.
A right-click on the return type label of a method (String in this case) reveals the option to add the type String to the diagram.
There are many ways to add types to a diagram, for example: dragging from the package explorer or using the Add Supertypes context menu. Since it is often difficult to anticipate how many types will be added there are thresholds which control AgileJ's response. If you attempt to add a large number (200 or more) of types to a diagram in one go, the addition will be aborted. This prevents accidental addition of a large number of types which would take a long time to process and probably not result in a meaningful class diagram.
For type additions below the large threshold the dialog below offers you an opportunity to apply a filter to thin down the number of types before you add them.
If you want to check the number of types contained beneath a node in the package explorer use the Count Classes action which shows a total of all types which exist beneath that node.
Select any collection of types on a diagram then press the delete key to remove them. You can also right click on the diagram and select Remove selected Types.
- Removing a type from a diagram does not delete the type from the source code.
- Any selection of top-level types can be removed. You cannot delete inner types, fields, methods or initializers.
Copyright © AgileJ Ltd. All rights reserved.