Class AnyToAnyModelTransformation
- java.lang.Object
-
- com.nomagic.magicdraw.modeltransformations.impl.any_to_any.AnyToAnyModelTransformation
-
- All Implemented Interfaces:
ModelTransformation
@OpenApiAll public class AnyToAnyModelTransformation extends java.lang.Object implements ModelTransformation
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
AnyToAnyModelTransformation.ConnectionAwareElementsRule
private class
AnyToAnyModelTransformation.RelationsSearchRule
-
Field Summary
Fields Modifier and Type Field Description private java.util.Collection<Element>
mAlreadyVisitedElements
private java.util.Collection<Element>
mCopiedElements
private boolean
mCopy
private java.util.Map<Element,java.util.List<Element>>
mCustomMappedElements
private Package
mDestinationPackage
private java.util.List<? extends java.lang.Class>
mDoNotCopyTypes
private java.util.List<? extends java.lang.Class>
mDoNotReconnect
private ModelTransformationInfo
mInfo
private java.util.List<? extends java.lang.Class>
mMappedTypes
private java.util.List<java.lang.String>
mNotSettableProperties
private java.util.List<Element>
mObjectsToTransform
private java.util.Map<BaseElement,BaseElement>
mOldToNewCopiedElements
private PropertyManager
mPropertyManager
private java.util.Collection<Element>
mRemovedByCustomTransformation
private java.util.Collection<Element>
mRemoveElements
private boolean
mSyncDestination
private Task
mTask
protected java.util.Map<Element,java.util.Collection<Element>>
mTransformationMap
private Package
mTransformationsPackage
private TypeMapProfile
mTypeMap
private com.nomagic.magicdraw.modeltransformations.impl.any_to_any.TypeMapper
mTypeMapper
private java.util.Collection<Element>
skippedElements
-
Constructor Summary
Constructors Constructor Description AnyToAnyModelTransformation()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addClonedElement(PresentationElement originalPE, Diagram targetDiagram, java.util.Map<BaseElement,BaseElement> cloned)
Adds cloned end to cloned mapprivate java.util.Map<BaseElement,BaseElement>
addClonedElements(java.lang.Iterable<PresentationElement> originalVisiblePresentationElements)
If originalVisiblePresentationElementsprotected void
afterTransformation()
Method invoked after all custom transformations.protected void
changeDiagramType(DiagramPresentationElement dpe, DiagramType createDiagramType)
private com.nomagic.magicdraw.commands.Command
changeType(Element me, com.nomagic.magicdraw.modeltransformations.impl.any_to_any.TypeMapper typeMapper)
private void
cleanOutputPackage(com.nomagic.magicdraw.commands.MacroCommand macro, java.util.Collection<Element> objectsList)
private java.util.List<Diagram>
collectDiagrams(java.util.Collection<Element> objects, boolean collectMapped)
protected java.util.List<Element>
collectInnerElements(java.util.Collection<Element> objects, boolean update)
private java.util.List<Element>
collectRelatedElements(java.util.Collection<Element> objects, boolean update)
private com.nomagic.magicdraw.commands.MacroCommand
copyDiagrams(java.util.Collection<Diagram> diagrams)
Copies diagramsprotected Element
copyElementInto(Element source, Element parent)
Copies and pastes given element.protected com.nomagic.magicdraw.commands.MacroCommand
copyElements(java.util.List<Element> objects)
Copies elementsprotected java.util.List<? extends java.lang.Class>
createDefaultDoNotCopyTypes()
protected java.util.List<? extends java.lang.Class>
createDefaultDoNotReconnectTypes()
protected java.util.List<java.lang.String>
createDefaultDoNotSettableProperties()
protected java.util.List<java.lang.Class>
createDefaultMappedTypes()
protected com.nomagic.magicdraw.modeltransformations.impl.any_to_any.ElementUpdater
createElementUpdater()
private java.util.Map<BaseElement,BaseElement>
createExternalMapForCopyPasteManager()
private void
createPathElement(java.util.Collection<PresentationElement> symbolsInDiagram, Element link, com.nomagic.magicdraw.commands.MacroCommand macro)
protected void
customTransformationForElement(Element original, java.util.Collection<Element> mapped)
Custom transformations should override this method to add additional functionality.protected void
customTransformations()
private void
disposeRemovedElementsFromCustomTransformations(com.nomagic.magicdraw.commands.MacroCommand macro)
private java.util.Collection<Element>
getAllMappedElements()
java.util.Collection<Element>
getMappedElements(Element original)
Returns transformed elements for given original element.private java.util.List<PresentationElement>
getNewlyAddedElements(java.util.Collection<PresentationElement> elements)
Returns list of presentation elements from original diagram, that are newly added.java.util.List
getNotSettableProperties()
protected java.util.Map<BaseElement,BaseElement>
getOneToOneMap()
protected java.util.Collection<Element>
getOriginalElement(Element mapped)
Returns original elements which are mapped to given mapped element.<T extends Element>
java.util.Collection<T>getOriginalElement(Element mapped, java.lang.Class<T> type)
Returns original elements which are mapped to given mapped element.protected java.util.Collection<Element>
getOriginalElements()
protected ProgressStatus
getProgressStatus()
PropertyManager
getPropertyManager()
protected java.util.Collection<Element>
getRemovedByCustomTransformation()
<T extends Element>
TgetTarget(Element original, java.lang.Class<T> type)
Returns transformed element that's transformation source is 'original' element and it's type is specified in 'type'Package
getTransformationsPackage()
protected com.nomagic.magicdraw.modeltransformations.impl.any_to_any.TypeMapper
getTypeMapper()
void
invokeCustomTransformation(Element original)
Invokes custom transformation for element.void
invokeCustomTransformation(java.util.Collection<? extends Element> original)
Invokes custom transformation for collection.protected boolean
isAlreadyVisited(Element element)
private boolean
isContainedBy(Element element, java.util.Collection<Element> owners)
Checks if given element is contained by some given owner (directly or indirectly)private boolean
isCopyableValueOfMetaProperty(Element element)
protected boolean
isElementCopied(Element element)
protected boolean
isMappableElement(Element element)
private boolean
isNewlyAdded(Element element)
Checks if specified element is newly added element in diagramprotected boolean
isSkipElement(Element element)
Check if element should be skippedboolean
isTransformationInPlace()
boolean
isTypeMapSet()
private boolean
loadElements()
protected void
markAsAlreadyVisited(Element element)
private boolean
needToUpdate()
protected void
processMappedElements(Element original, java.util.Collection<Element> mappedElements, java.util.Collection<Element> originalMappedElements)
protected void
processMappingResult(Element original, java.util.Collection<Element> mappedElements, java.util.Collection<Element> originalMappedElements)
private void
reconnectMappedSymbol(com.nomagic.magicdraw.commands.MacroCommand macro, PresentationElement oldPE, Element newElement, boolean force, java.util.Collection<PresentationElement> symbolsInDiagram, boolean onlyDeleteSymbol)
private void
removeUnCreatable(java.util.Collection<PresentationElement> elements)
(package private) void
reportROElement(Element me)
private void
setDescription(java.lang.String string)
void
setTask(Task task)
Sets task for transformation.protected void
setTransformationMapValue(Element original, java.util.Collection<Element> mappedElements)
private static void
showNotLoadedElementWarning(java.lang.String key, Element element)
protected void
sortOriginalElements(java.util.List<Element> objects)
Sorts elements before invoking custom transformationPackage
transform(java.util.Collection selectedObjects, ModelTransformationInfo info, TypeMapProfile typeMap, PropertyManager propertyManager, Package destination)
Performs transformation on specific set of objectsprivate void
transformTypes(com.nomagic.magicdraw.commands.MacroCommand macro)
protected com.nomagic.magicdraw.commands.MacroCommand
updateDiagrams()
Updates diagram with newly added elements during transformation update phase.private void
updateDiagrams(com.nomagic.magicdraw.commands.MacroCommand macro)
private void
updateMap()
void
updateTransform(Package transformationPackage, TypeMapProfile typeMap, PropertyManager propertyManager, boolean syncDestination)
Updates transformation on specific set of objectsprivate void
updateTransformationState()
-
-
-
Field Detail
-
mMappedTypes
private final java.util.List<? extends java.lang.Class> mMappedTypes
-
mNotSettableProperties
private final java.util.List<java.lang.String> mNotSettableProperties
-
mDoNotReconnect
private final java.util.List<? extends java.lang.Class> mDoNotReconnect
-
mDoNotCopyTypes
private final java.util.List<? extends java.lang.Class> mDoNotCopyTypes
-
mTransformationMap
protected java.util.Map<Element,java.util.Collection<Element>> mTransformationMap
-
mTransformationsPackage
private Package mTransformationsPackage
-
mDestinationPackage
private Package mDestinationPackage
-
mInfo
private ModelTransformationInfo mInfo
-
mRemoveElements
private java.util.Collection<Element> mRemoveElements
-
mAlreadyVisitedElements
private java.util.Collection<Element> mAlreadyVisitedElements
-
mCopy
private boolean mCopy
-
mObjectsToTransform
private java.util.List<Element> mObjectsToTransform
-
mPropertyManager
private PropertyManager mPropertyManager
-
mTypeMapper
private com.nomagic.magicdraw.modeltransformations.impl.any_to_any.TypeMapper mTypeMapper
-
mRemovedByCustomTransformation
private java.util.Collection<Element> mRemovedByCustomTransformation
-
mSyncDestination
private boolean mSyncDestination
-
skippedElements
private java.util.Collection<Element> skippedElements
-
mTypeMap
private TypeMapProfile mTypeMap
-
mTask
private Task mTask
-
mCopiedElements
private final java.util.Collection<Element> mCopiedElements
-
mOldToNewCopiedElements
private java.util.Map<BaseElement,BaseElement> mOldToNewCopiedElements
-
-
Method Detail
-
createDefaultDoNotCopyTypes
protected java.util.List<? extends java.lang.Class> createDefaultDoNotCopyTypes()
-
createDefaultDoNotReconnectTypes
protected java.util.List<? extends java.lang.Class> createDefaultDoNotReconnectTypes()
-
createDefaultDoNotSettableProperties
protected java.util.List<java.lang.String> createDefaultDoNotSettableProperties()
-
createDefaultMappedTypes
protected java.util.List<java.lang.Class> createDefaultMappedTypes()
-
transform
@CheckForNull public Package transform(@CheckForNull java.util.Collection selectedObjects, @CheckForNull ModelTransformationInfo info, TypeMapProfile typeMap, PropertyManager propertyManager, Package destination) throws ReadOnlyElementException
Description copied from interface:ModelTransformation
Performs transformation on specific set of objects- Specified by:
transform
in interfaceModelTransformation
- Parameters:
selectedObjects
- set of objects to transforminfo
- model transformation infotypeMap
- type map profile to use for transformation, null for nonepropertyManager
- transformation propertiesdestination
- destination model packages, null for transformation in place- Returns:
- transformation model package (where transformation links are stored)
- Throws:
ReadOnlyElementException
- in case target model elements are read-only
-
setDescription
private void setDescription(java.lang.String string)
-
needToUpdate
private boolean needToUpdate()
- Returns:
- true if model should be updated from source. In other case only new elements are added to model.
-
afterTransformation
protected void afterTransformation() throws ReadOnlyElementException
Method invoked after all custom transformations.- Throws:
ReadOnlyElementException
- in case of error
-
customTransformations
protected void customTransformations()
-
isSkipElement
protected boolean isSkipElement(Element element)
Check if element should be skipped- Parameters:
element
- element- Returns:
- true if element can not be processed by custom transformation
-
disposeRemovedElementsFromCustomTransformations
private void disposeRemovedElementsFromCustomTransformations(com.nomagic.magicdraw.commands.MacroCommand macro)
-
invokeCustomTransformation
public void invokeCustomTransformation(java.util.Collection<? extends Element> original)
Invokes custom transformation for collection.- Parameters:
original
- original elements- See Also:
invokeCustomTransformation(Element)
-
invokeCustomTransformation
public void invokeCustomTransformation(Element original)
Invokes custom transformation for element. If custom transformation was already invoked, this method does nothing.- Parameters:
original
- original element for which custom transformation is invoked.
-
processMappingResult
protected void processMappingResult(Element original, java.util.Collection<Element> mappedElements, java.util.Collection<Element> originalMappedElements)
-
processMappedElements
protected void processMappedElements(Element original, java.util.Collection<Element> mappedElements, java.util.Collection<Element> originalMappedElements)
-
setTransformationMapValue
protected void setTransformationMapValue(Element original, java.util.Collection<Element> mappedElements)
-
customTransformationForElement
protected void customTransformationForElement(Element original, java.util.Collection<Element> mapped) throws ReadOnlyElementException
Custom transformations should override this method to add additional functionality.- Parameters:
original
- original element.mapped
- collection of current mapped elements. Custom transformation can modify this collection. In case custom transformation needs to remove current mapping, it should remove element from this collection. In case it needs to map more elements it should add new elements to this collection.- Throws:
ReadOnlyElementException
- in case of error
-
getMappedElements
public java.util.Collection<Element> getMappedElements(Element original)
Returns transformed elements for given original element.- Parameters:
original
- original element.- Returns:
- mapped elements if original was mapped; empty collection if original was mapped to nothing;
-
cleanOutputPackage
private void cleanOutputPackage(com.nomagic.magicdraw.commands.MacroCommand macro, java.util.Collection<Element> objectsList) throws ReadOnlyElementException
- Throws:
ReadOnlyElementException
-
updateTransformationState
private void updateTransformationState() throws ReadOnlyElementException
- Throws:
ReadOnlyElementException
-
updateTransform
public void updateTransform(Package transformationPackage, TypeMapProfile typeMap, PropertyManager propertyManager, boolean syncDestination) throws ReadOnlyElementException
Description copied from interface:ModelTransformation
Updates transformation on specific set of objects- Specified by:
updateTransform
in interfaceModelTransformation
- Parameters:
transformationPackage
- package containing transformation linkstypeMap
- type map profile to use for transformation, null for nonepropertyManager
- transformation propertiessyncDestination
- true for destination overwrite- Throws:
ReadOnlyElementException
- in case target model elements are read-only
-
getAllMappedElements
private java.util.Collection<Element> getAllMappedElements()
-
transformTypes
private void transformTypes(com.nomagic.magicdraw.commands.MacroCommand macro)
-
updateDiagrams
private void updateDiagrams(com.nomagic.magicdraw.commands.MacroCommand macro) throws ReadOnlyElementException
- Throws:
ReadOnlyElementException
-
reconnectMappedSymbol
private void reconnectMappedSymbol(com.nomagic.magicdraw.commands.MacroCommand macro, PresentationElement oldPE, Element newElement, boolean force, java.util.Collection<PresentationElement> symbolsInDiagram, boolean onlyDeleteSymbol) throws ReadOnlyElementException
- Throws:
ReadOnlyElementException
-
createPathElement
private void createPathElement(java.util.Collection<PresentationElement> symbolsInDiagram, Element link, com.nomagic.magicdraw.commands.MacroCommand macro) throws ReadOnlyElementException
- Throws:
ReadOnlyElementException
-
getOriginalElements
protected java.util.Collection<Element> getOriginalElements()
- Returns:
- all original elements.
-
getOriginalElement
public <T extends Element> java.util.Collection<T> getOriginalElement(Element mapped, java.lang.Class<T> type)
Returns original elements which are mapped to given mapped element.- Parameters:
mapped
- original elements that are mapped to this element will be returnedtype
- only this type of elements will be returned.- Returns:
- collection of original elements. If there is no original elements returns empty list.
-
getOriginalElement
protected java.util.Collection<Element> getOriginalElement(Element mapped)
Returns original elements which are mapped to given mapped element.- Parameters:
mapped
- mapped element- Returns:
- collection of original elements. If there is no original elements returns empty list.
-
updateMap
private void updateMap() throws ReadOnlyElementException
- Throws:
ReadOnlyElementException
-
changeType
@CheckForNull private com.nomagic.magicdraw.commands.Command changeType(Element me, com.nomagic.magicdraw.modeltransformations.impl.any_to_any.TypeMapper typeMapper)
-
reportROElement
void reportROElement(Element me)
-
collectDiagrams
private java.util.List<Diagram> collectDiagrams(java.util.Collection<Element> objects, boolean collectMapped)
-
isContainedBy
private boolean isContainedBy(Element element, java.util.Collection<Element> owners)
Checks if given element is contained by some given owner (directly or indirectly)- Parameters:
element
- elementowners
- owners- Returns:
- true if is contained
-
copyElements
protected com.nomagic.magicdraw.commands.MacroCommand copyElements(java.util.List<Element> objects)
Copies elements- Parameters:
objects
- objects- Returns:
- command for copying
-
createExternalMapForCopyPasteManager
private java.util.Map<BaseElement,BaseElement> createExternalMapForCopyPasteManager()
-
createElementUpdater
protected com.nomagic.magicdraw.modeltransformations.impl.any_to_any.ElementUpdater createElementUpdater()
- Returns:
- element updater.
-
getOneToOneMap
protected java.util.Map<BaseElement,BaseElement> getOneToOneMap()
- Returns:
- map where one key is mapped only to one element
-
getTypeMapper
protected com.nomagic.magicdraw.modeltransformations.impl.any_to_any.TypeMapper getTypeMapper()
- Returns:
- type mapper.
-
getTarget
@CheckForNull public <T extends Element> T getTarget(Element original, java.lang.Class<T> type)
Returns transformed element that's transformation source is 'original' element and it's type is specified in 'type'- Parameters:
original
- source model element.type
- type of returned element.- Returns:
- transformed element. If no element found - null is returned.
-
updateDiagrams
protected com.nomagic.magicdraw.commands.MacroCommand updateDiagrams()
Updates diagram with newly added elements during transformation update phase.- Returns:
- update macro command
-
addClonedElements
private java.util.Map<BaseElement,BaseElement> addClonedElements(java.lang.Iterable<PresentationElement> originalVisiblePresentationElements)
If originalVisiblePresentationElements- Parameters:
originalVisiblePresentationElements
- contains path elements, that cloned ends will be returned.- Returns:
- map of path elements cloned ends.
-
addClonedElement
private void addClonedElement(PresentationElement originalPE, Diagram targetDiagram, java.util.Map<BaseElement,BaseElement> cloned)
Adds cloned end to cloned map- Parameters:
originalPE
- presentation element, that's clone will be added into maptargetDiagram
- diagram containing cloned endcloned
- map where cloned end will be stored
-
getNewlyAddedElements
private java.util.List<PresentationElement> getNewlyAddedElements(java.util.Collection<PresentationElement> elements)
Returns list of presentation elements from original diagram, that are newly added.- Parameters:
elements
- list of presentation elements to filter- Returns:
- list of newly added presentation elements.
-
isNewlyAdded
private boolean isNewlyAdded(@CheckForNull Element element)
Checks if specified element is newly added element in diagram- Parameters:
element
- to be checked- Returns:
- true if element is newly added into diagram
-
copyDiagrams
private com.nomagic.magicdraw.commands.MacroCommand copyDiagrams(java.util.Collection<Diagram> diagrams)
Copies diagrams- Parameters:
diagrams
- diagrams- Returns:
- command for copying diagram
-
removeUnCreatable
private void removeUnCreatable(java.util.Collection<PresentationElement> elements)
-
sortOriginalElements
protected void sortOriginalElements(java.util.List<Element> objects)
Sorts elements before invoking custom transformation- Parameters:
objects
- objects
-
collectInnerElements
protected java.util.List<Element> collectInnerElements(java.util.Collection<Element> objects, boolean update)
-
isCopyableValueOfMetaProperty
private boolean isCopyableValueOfMetaProperty(Element element)
-
collectRelatedElements
private java.util.List<Element> collectRelatedElements(java.util.Collection<Element> objects, boolean update)
-
isMappableElement
protected boolean isMappableElement(Element element)
- Parameters:
element
- element to check.- Returns:
- true if transformation can be applied for this element.
-
getTransformationsPackage
public Package getTransformationsPackage()
- Returns:
- package where transformation information is stored
-
isTransformationInPlace
public boolean isTransformationInPlace()
- Returns:
- true if transformation is in place (not copying)
-
getPropertyManager
public PropertyManager getPropertyManager()
- Returns:
- property manager for additional transformation properties
-
copyElementInto
protected Element copyElementInto(Element source, Element parent)
Copies and pastes given element.- Parameters:
source
- element to copy.parent
- parent where place copied element.- Returns:
- copied element.
-
setTask
public void setTask(Task task)
Description copied from interface:ModelTransformation
Sets task for transformation. Transformation can use Task for accesing progress status and etc.- Specified by:
setTask
in interfaceModelTransformation
- Parameters:
task
- transformation task
-
getProgressStatus
protected ProgressStatus getProgressStatus()
-
isElementCopied
protected boolean isElementCopied(Element element)
-
isTypeMapSet
public boolean isTypeMapSet()
-
getNotSettableProperties
public java.util.List getNotSettableProperties()
-
loadElements
private boolean loadElements()
-
changeDiagramType
protected void changeDiagramType(DiagramPresentationElement dpe, DiagramType createDiagramType)
-
showNotLoadedElementWarning
private static void showNotLoadedElementWarning(java.lang.String key, Element element)
-
getRemovedByCustomTransformation
protected java.util.Collection<Element> getRemovedByCustomTransformation()
-
markAsAlreadyVisited
protected void markAsAlreadyVisited(Element element)
-
isAlreadyVisited
protected boolean isAlreadyVisited(Element element)
-
-