Managing compartments
Some elements display information in their symbol compartments. For example, a UML Class symbol can contain compartments for attributes, operations, and ports.
Compartments do not have to display all available information. Instead, they can show a subset, while the remaining entries remain hidden. For example, you may choose to display only a few specific operations on a Class symbol in a diagram.
To manage the visibility of compartment entries, use the com.nomagic.magicdraw.uml.symbols.CompartmentManager API.
Additional details are available in the JavaDoc.
CompartmentManager
package com.nomagic.magicdraw.uml.symbols;
@OpenApiAll
public class CompartmentManager
Utility methods for showing and hiding elements in compartments.
This class provides helper APIs for showing and hiding:
- Model elements within diagram compartments (for example, attributes or slots)
- Element properties rendered on diagram symbols
Examples
All diagram modifications must be executed inside a modeling session using SessionManager.
Example 1: Display a Property in a Compartment
Property property = ...; // Property model element
ClassView classView = ...; // Class symbol
SessionManager.getInstance().executeInsideSession(
Project.getProject(property),
"Show Property",
() -> CompartmentManager.showCompartmentElement(
classView,
CompartmentID.ATTRIBUTES,
property
)
);
Example 2: Hide a Slot on a Class Shape
Slot slot = ...; // Slot model element
ClassView classView = ...; // Class symbol
SessionManager.getInstance().executeInsideSession(
Project.getProject(slot),
"Hide Slot",
() -> CompartmentManager.hideCompartmentElement(
classView,
CompartmentID.TAGGED_VALUES_ON_SHAPE,
slot
)
);
Example 3: Show Element Properties on a Class Shape
ClassView classView = ...; // Class symbol
SessionManager.getInstance().executeInsideSession(
Project.getProject(classView),
"Show Properties",
() -> CompartmentManager.showCompartmentElementProperties(
classView,
Arrays.asList(
PropertyNames.OWNER,
PropertyNames.VISIBILITY,
PropertyNames.APPLIED_STEREOTYPE
)
)
);
Example 4: Hide an Element Property from a Class Shape
ClassView classView = ...; // Class symbol
SessionManager.getInstance().executeInsideSession(
Project.getProject(classView),
"Hide Property",
() -> CompartmentManager.hideCompartmentElementProperty(
classView,
PropertyNames.IS_ABSTRACT
)
);
Code Examples Location
Additional examples demonstrating compartment manipulation can be found in the modeling tool's OpenAPI distribution:
<installation_directory>\openapi\examples\compartmentedit