Package com.nomagic.magicdraw.annotation
Class AnnotationManager
- java.lang.Object
-
- com.nomagic.uml2.project.service.ElementProjectService<Project>
-
- com.nomagic.magicdraw.core.project.service.AbstractProjectService
-
- com.nomagic.magicdraw.annotation.AnnotationManager
-
- All Implemented Interfaces:
ProjectProvider
,com.nomagic.uml2.project.service.DisposableService
@OpenApiAll public final class AnnotationManager extends com.nomagic.magicdraw.core.project.service.AbstractProjectService implements ProjectProvider
Handles annotations visualization on diagrams and other UI components. It takes care of drawing decorations around symbols with annotations and provides annotation actions for manipulators. Users are responsible for adding annotations and removing added annotations afterwards. Users is responsible to call update() method when some annotation is added or removed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
AnnotationManager.DefaultAnnotatableChildrenConfigurator
private static class
AnnotationManager.DefaultAnnotatableChildrenInspector
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Collection<com.nomagic.magicdraw.annotation.AnnotatableChildrenConfigurator>
annotatableChildrenConfigurators
private java.util.Map<AnnotationSubset,java.util.Collection<BaseElement>>
annotatedElements
private com.nomagic.magicdraw.annotation.OwnersHandler
annotationOwnerHandler
private java.util.Map<java.lang.Object,com.nomagic.magicdraw.annotation.AnnotationCache>
annotations
private java.util.Collection<AnnotationSubset>
cachedAnnotationSubsets
private java.util.List<AnnotationManagerListener>
listeners
private com.nomagic.magicdraw.annotation.AnnotationManipulatorConfigurator
manipulatorConfigurator
private static java.util.Collection<AnnotationTargetParentProvider>
parentTargetProviders
private com.nomagic.magicdraw.annotation.SymbolHighlightAdornment
symbolHighlighter
Annotation highlighter for symbols.
-
Constructor Summary
Constructors Modifier Constructor Description private
AnnotationManager(Project project)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(Annotation annotation)
Add single annotation.boolean
add(Annotation annotation, AnnotationCategory category)
Add single annotation.static void
addAnnotationParentTargetProvider(AnnotationTargetParentProvider provider)
void
addListener(AnnotationManagerListener listener)
void
disposeService()
private void
fireAdded(Annotation annotation)
private void
fireRemoved(Annotation annotation)
private void
fireUpdated()
private static java.util.List<com.nomagic.magicdraw.annotation.AnnotatableChildrenInspector>
getAnnotatableChildrenInspectors(BaseElement baseElement, AnnotationSubset subset)
java.util.Collection<BaseElement>
getAnnotatedElements()
Returns a collection of annotated elementsjava.util.Collection<BaseElement>
getAnnotatedElements(AnnotationSubset subset)
Returns a collection of annotated elementsjava.util.Set<java.lang.Object>
getAnnotatedTargets(AnnotationSubset subset)
Returns targets of the registered annotations.private java.util.stream.Stream<java.lang.Object>
getAnnotatedTargetsStream(AnnotationSubset subset)
java.util.List<Annotation>
getAnnotations(BaseElement element)
Get all annotations for particular element.java.util.List<Annotation>
getAnnotations(BaseElement element, AnnotationSubset subset)
java.util.List<Annotation>
getAnnotations(java.lang.Object target)
java.util.List<Annotation>
getAnnotations(java.lang.Object target, AnnotationSubset subset)
java.util.List<Annotation>
getAnnotationsOfChildren(BaseElement element)
java.util.List<Annotation>
getAnnotationsOfChildren(BaseElement element, AnnotationSubset subset)
Get all annotations of children of given element.private java.util.List<Annotation>
getAnnotationsOfChildren(BaseElement element, AnnotationSubset subset, java.util.function.Predicate<Annotation> predicate)
java.util.List<Annotation>
getAnnotationsOfHiddenChildren(PresentationElement view)
Get all annotations of closest hidden children(recursively) of given symbol.java.util.List<Annotation>
getAnnotationsOfHiddenChildren(PresentationElement view, AnnotationSubset subset)
Get all annotations of closest hidden children(recursively) of given symbol.private java.lang.Iterable<AnnotationManagerListener>
getClonedListeners()
static AnnotationManager
getInstance(Project project)
static AnnotationManager
getInstance(BaseElement element)
java.util.Iterator<BaseElement>
getIteratorOfAnnotatedElements(BaseElement owner)
Returns a collection of annotated elementsjava.util.Iterator<Annotation>
getIteratorOfAnnotationsOfChildren(BaseElement element)
java.util.Iterator<Annotation>
getIteratorOfAnnotationsOfChildren(BaseElement element, AnnotationSubset subset)
private static AnnotationManager
getManager(Project project)
private static java.lang.Object
getParentTarget(java.lang.Object annotationTarget)
Project
getProject()
static Project
getProject(java.lang.Object annotationTarget)
Used to retrieve project from element or parent target providers if given object is not element.private static Project
getProjectFromParentTargetProviders(java.lang.Object annotationTarget)
boolean
hasAnnotatedChildren(BaseElement element)
Test if given element has children (recursively) with some annotations.boolean
hasAnnotatedChildren(BaseElement element, AnnotationSubset subset)
Test if given element has children (recursively) with some annotations.boolean
hasAnnotations()
boolean
hasAnnotations(BaseElement element, AnnotationSubset subset)
boolean
hasAnnotations(java.lang.Object target, AnnotationSubset subset)
private static boolean
hasChild(java.util.Collection<com.nomagic.magicdraw.annotation.AnnotatableChildrenInspector> inspectors, BaseElement element)
private boolean
hasCustomChildren(java.util.Collection<com.nomagic.magicdraw.annotation.AnnotatableChildrenInspector> inspectors, AnnotationSubset subset)
(package private) static boolean
isAncestor(BaseElement ancestor, BaseElement child)
private void
lazyInitAnnotationConfigurators()
void
registerSubset(AnnotationSubset subset)
Register subset (part) of annotations.boolean
remove(Annotation annotation)
Remove single annotation.static void
removeAnnotationParentTargetProvider(AnnotationTargetParentProvider provider)
void
removeListener(AnnotationManagerListener listener)
private static void
repaintBrowserTree(Project project)
void
unregisterSubset(AnnotationSubset subset)
void
update()
Repaint only opened diagrams for projectvoid
update(java.util.Collection<? extends Annotation> removed, java.util.Collection<Annotation> added)
Updates annotation manager using specified data.void
update(java.util.Collection<? extends Annotation> removed, java.util.Collection<Annotation> added, AnnotationCategory category)
Updates annotation manager using specified data.
-
-
-
Field Detail
-
symbolHighlighter
private com.nomagic.magicdraw.annotation.SymbolHighlightAdornment symbolHighlighter
Annotation highlighter for symbols.
-
manipulatorConfigurator
private com.nomagic.magicdraw.annotation.AnnotationManipulatorConfigurator manipulatorConfigurator
-
cachedAnnotationSubsets
private final java.util.Collection<AnnotationSubset> cachedAnnotationSubsets
-
annotations
private final java.util.Map<java.lang.Object,com.nomagic.magicdraw.annotation.AnnotationCache> annotations
-
annotatedElements
private final java.util.Map<AnnotationSubset,java.util.Collection<BaseElement>> annotatedElements
-
annotationOwnerHandler
private com.nomagic.magicdraw.annotation.OwnersHandler annotationOwnerHandler
-
listeners
private final java.util.List<AnnotationManagerListener> listeners
-
annotatableChildrenConfigurators
private static final java.util.Collection<com.nomagic.magicdraw.annotation.AnnotatableChildrenConfigurator> annotatableChildrenConfigurators
-
parentTargetProviders
private static final java.util.Collection<AnnotationTargetParentProvider> parentTargetProviders
-
-
Constructor Detail
-
AnnotationManager
private AnnotationManager(Project project)
-
-
Method Detail
-
addAnnotationParentTargetProvider
public static void addAnnotationParentTargetProvider(AnnotationTargetParentProvider provider)
-
removeAnnotationParentTargetProvider
public static void removeAnnotationParentTargetProvider(AnnotationTargetParentProvider provider)
-
getInstance
public static AnnotationManager getInstance(BaseElement element)
-
getInstance
public static AnnotationManager getInstance(Project project)
-
getManager
private static AnnotationManager getManager(Project project)
-
add
public boolean add(Annotation annotation)
Add single annotation. Annotation may not be visible until theupdate()
method has been called.- Parameters:
annotation
- annotation to add- Returns:
- true if annotation was added, false if such annotation already exists
-
add
public boolean add(Annotation annotation, AnnotationCategory category)
Add single annotation. Annotation may not be visible until theupdate()
method has been called.- Parameters:
annotation
- annotation to addcategory
- category to which this annotation belongs. Each category can be part of various AnnotationSubsets- Returns:
- true if annotation was added, false if such annotation already exists
-
remove
public boolean remove(Annotation annotation)
Remove single annotation. Changes may not be visible until theupdate()
method has been called.- Parameters:
annotation
- annotation to remove- Returns:
- true if annotation was removed, false if such annotation was not added before
-
hasAnnotatedChildren
public boolean hasAnnotatedChildren(@CheckForNull BaseElement element)
Test if given element has children (recursively) with some annotations.- Parameters:
element
- given element- Returns:
- true if there are at least one annotated child of given element
-
hasAnnotatedChildren
public boolean hasAnnotatedChildren(@CheckForNull BaseElement element, AnnotationSubset subset)
Test if given element has children (recursively) with some annotations.- Parameters:
element
- given elementsubset
- subset (part) of all currently registered annotations to check.- Returns:
- true if there are at least one annotated child of given element
-
getAnnotationsOfChildren
public java.util.List<Annotation> getAnnotationsOfChildren(BaseElement element)
-
getAnnotationsOfChildren
public java.util.List<Annotation> getAnnotationsOfChildren(BaseElement element, AnnotationSubset subset)
Get all annotations of children of given element. Also includes informationFlows for given element.- Parameters:
element
- given elementsubset
- subset (part) of all currently registered children annotations to retrieve- Returns:
- list of annotations sorted by severity.
-
getAnnotationsOfHiddenChildren
public java.util.List<Annotation> getAnnotationsOfHiddenChildren(PresentationElement view)
Get all annotations of closest hidden children(recursively) of given symbol. Also includes InformationFlows of given element, that has conveyed Info.- Parameters:
view
- symbol of starting PE. dedicated to find closest hidden elements for diagrams.- Returns:
- list of annotations sorted by severity.
-
getAnnotationsOfHiddenChildren
public java.util.List<Annotation> getAnnotationsOfHiddenChildren(PresentationElement view, AnnotationSubset subset)
Get all annotations of closest hidden children(recursively) of given symbol. Also includes InformationFlows of given element, that has conveyed Info.- Parameters:
view
- symbol of starting PE. dedicated to find closest hidden elements for diagrams.subset
- subset (part) of all currently registered hidden children annotations to check.- Returns:
- list of annotations sorted by severity.
-
getAnnotations
public java.util.List<Annotation> getAnnotations(BaseElement element)
Get all annotations for particular element.- Parameters:
element
- element to get annotations for- Returns:
- unmodifiable list of annotations
-
getAnnotations
public java.util.List<Annotation> getAnnotations(BaseElement element, AnnotationSubset subset)
- Parameters:
element
- element to get annotations forsubset
- subset (part) of all currently registered annotations to retrieve.- Returns:
- unmodifiable subset of element's annotations
-
getAnnotations
public java.util.List<Annotation> getAnnotations(java.lang.Object target)
-
getAnnotations
public java.util.List<Annotation> getAnnotations(java.lang.Object target, AnnotationSubset subset)
-
hasAnnotations
public boolean hasAnnotations(BaseElement element, AnnotationSubset subset)
- Returns:
- true if there is one or more annotation added for the given element
-
hasAnnotations
public boolean hasAnnotations(java.lang.Object target, AnnotationSubset subset)
-
getParentTarget
@CheckForNull private static java.lang.Object getParentTarget(java.lang.Object annotationTarget)
-
update
public void update()
Repaint only opened diagrams for project
-
lazyInitAnnotationConfigurators
private void lazyInitAnnotationConfigurators()
-
repaintBrowserTree
private static void repaintBrowserTree(Project project)
-
disposeService
public void disposeService()
- Specified by:
disposeService
in interfacecom.nomagic.uml2.project.service.DisposableService
- Overrides:
disposeService
in classcom.nomagic.uml2.project.service.ElementProjectService<Project>
-
getProject
public static Project getProject(java.lang.Object annotationTarget)
Used to retrieve project from element or parent target providers if given object is not element.- Parameters:
annotationTarget
- annotation target- Returns:
- project which annotation target exists in
-
getProjectFromParentTargetProviders
@CheckForNull private static Project getProjectFromParentTargetProviders(java.lang.Object annotationTarget)
-
getAnnotatedElements
public java.util.Collection<BaseElement> getAnnotatedElements()
Returns a collection of annotated elements- Returns:
- all annotated elements
-
getAnnotatedElements
public java.util.Collection<BaseElement> getAnnotatedElements(AnnotationSubset subset)
Returns a collection of annotated elements- Parameters:
subset
- subset (part) of all currently registered annotations to take into account.- Returns:
- elements that have registered annotations belonging to the given subset
-
getAnnotatedTargets
public java.util.Set<java.lang.Object> getAnnotatedTargets(AnnotationSubset subset)
Returns targets of the registered annotations.- Parameters:
subset
- subset (part) of all currently registered annotations to take into account.- Returns:
- all targets that have registered annotations belonging to the given subset
-
getAnnotatedTargetsStream
private java.util.stream.Stream<java.lang.Object> getAnnotatedTargetsStream(AnnotationSubset subset)
-
getIteratorOfAnnotatedElements
public java.util.Iterator<BaseElement> getIteratorOfAnnotatedElements(@CheckForNull BaseElement owner)
Returns a collection of annotated elements- Returns:
- all annotated elements
-
update
public void update(java.util.Collection<? extends Annotation> removed, java.util.Collection<Annotation> added)
Updates annotation manager using specified data. No need to call update() method.- Parameters:
removed
- collection of removed annotations.added
- collection of added annotations.
-
update
public void update(java.util.Collection<? extends Annotation> removed, java.util.Collection<Annotation> added, AnnotationCategory category)
Updates annotation manager using specified data. No need to call update() method.- Parameters:
removed
- collection of removed annotations.added
- collection of added annotations.category
- category to which annotations belongs
-
addListener
public void addListener(AnnotationManagerListener listener)
-
removeListener
public void removeListener(AnnotationManagerListener listener)
-
fireAdded
private void fireAdded(Annotation annotation)
-
fireRemoved
private void fireRemoved(Annotation annotation)
-
fireUpdated
private void fireUpdated()
-
getClonedListeners
private java.lang.Iterable<AnnotationManagerListener> getClonedListeners()
-
hasAnnotations
public boolean hasAnnotations()
-
getIteratorOfAnnotationsOfChildren
public java.util.Iterator<Annotation> getIteratorOfAnnotationsOfChildren(BaseElement element)
-
getIteratorOfAnnotationsOfChildren
public java.util.Iterator<Annotation> getIteratorOfAnnotationsOfChildren(BaseElement element, AnnotationSubset subset)
-
hasCustomChildren
private boolean hasCustomChildren(java.util.Collection<com.nomagic.magicdraw.annotation.AnnotatableChildrenInspector> inspectors, AnnotationSubset subset)
-
registerSubset
public void registerSubset(AnnotationSubset subset)
Register subset (part) of annotations. This enables caching annotations by all the containing subsets. Only subsets, registered using this method, should be be used when retrieving annotations from the manager.
-
unregisterSubset
public void unregisterSubset(AnnotationSubset subset)
-
isAncestor
static boolean isAncestor(BaseElement ancestor, BaseElement child)
-
getAnnotationsOfChildren
private java.util.List<Annotation> getAnnotationsOfChildren(BaseElement element, AnnotationSubset subset, java.util.function.Predicate<Annotation> predicate)
-
getAnnotatableChildrenInspectors
private static java.util.List<com.nomagic.magicdraw.annotation.AnnotatableChildrenInspector> getAnnotatableChildrenInspectors(BaseElement baseElement, AnnotationSubset subset)
-
hasChild
private static boolean hasChild(java.util.Collection<com.nomagic.magicdraw.annotation.AnnotatableChildrenInspector> inspectors, BaseElement element)
-
getProject
public Project getProject()
- Specified by:
getProject
in interfaceProjectProvider
-
-