We provide an API to simplify displaying of Ports on Symbols. Use com.nomagic.magicdraw.uml.symbols.DisplayPorts#displayAllPorts to display all ports or com.nomagic.magicdraw.uml.symbols.DisplayPorts#collectAvailablePorts to get available ports and then com.nomagic.magicdraw.uml.symbols.DisplayPorts#displayPorts(com.nomagic.magicdraw.uml.symbols.PresentationElement, java.util.List<com.nomagic.uml2.ext.magicdraw.compositestructures.mdports.Port>) or com.nomagic.magicdraw.uml.symbols.DisplayPorts#displayPorts(com.nomagic.magicdraw.uml.symbols.PresentationElement, java.util.List<com.nomagic.uml2.ext.magicdraw.compositestructures.mdports.Port>, boolean, boolean, boolean) to display just some of them.
Example: Displaying unnamed ports
Example: Displaying unnamed ports
SessionManager sessionManager = SessionManager.getInstance(); sessionManager.createSession(project, getName()); PresentationElement view = ...; // A symbol for which you want to display ports List<Port> ports = DisplayPorts.collectAvailablePorts(view, false, false); List<Port> unnamedPorts = ports.stream().filter(port -> port.getName().isEmpty()).toList(); DisplayPorts.displayPorts(view, unnamedPorts); sessionManager.closeSession(project);
You can find the code examples in
- <installation_directory>\openapi\examples\displayports