Search code examples
packageumlclass-diagramstaruml

How can you put a whole class diagram inside a package on StarUML?


I've been using StarUML for a while and always have had this problem that, if you don't create a package first and then everything create everything inside, and you actually design the class diagram first and then want to put it inside a package you can't do so by moving everything inside as the package will cover the class diagram as in this image:

enter image description here

You can move every single class and association one by one and it gets on top of the package, but that's super tedious, specially if you had already organized everything as you will need to do it again. Is there anything that I could do to do this quick?

Btw, everything is moved already inside the package in the Model Explorer.

Thanks in advance!


Solution

  • The answer is that moving several classes to a package probably already assigned the classes to the package, but that visually, the package symbol is just no enclosing them.

    Here a demo with version 4.1.6. THe version 5.0.1 has the same behavior. I have created 3 classes (note the automatic names Class 1, Class 2, Class 3, the next would be Class 4) and then a package. Here the result; look especially at the model explorer that shows the classes and the package at the same level:

    StarUML screenshot with 3 classes and a pacakge

    Now I can select the 3 classes and drag and drop them into the package. But caution: it is not sufficient to move the classes around until some overlap the package: you really have to drag the mouse into the package, so that StarUML gives you a visual feedback with the package element surrounded by a highlighting frame (in blue in my screenshot):

    StarUML screenshot with drag and drop in progress

    When you release the mouse for the drop, the classes will move by translation, but the package symbol remains unchanged, giving the impression of a failed operation. But don't be disappointed; look at the model explorer and you'll see that the classes now are under the package:

    StarUML screenshot, showing the model explorer surroundedn, with classes under the package

    This means that StarUML now considers the classes to be part of the package. And if you move the package symbol, the classes will follow the movement. In fact they are positioned relatively to the package symbol. The only thing you need to do is to resize the package symbol to enclose all the classes that you've dropped into it.

    Btw, there must be some kind of bug, because if you change the format of the package to Auto Resize, it becomes very tiny again, ignoring the included elements in the size determination.

    If you're still not convinced, you may also rightclick on one of those classes, and choose in the menu Format > Show namespace:Screenshot of the contextual format menu

    You'll then have the package indicated clearly in plaintext in the diagram:

    Zoom on a class with package indication

    Now if you add a new class outside the package, you'll see that by default the numbering restarts at 1 as there are no other classes left at this level. If you move the package, all the previously selected classes move with the package, but the newly created one stays where it is.

    StarUML screenshot

    Note that this discrepancy between visualisation and modeling semantic can also happen in the other direction. You may create a package and resiez it, and then add classes clicking into the package. Visually, the class seems to be in the package. But if you move the package the class stays where it is, and in the model explorer, you'll see the class at the same level as the package. This can be very misleading.