Package com.nomagic.magicdraw.utils
Class StateChangeHandler
- java.lang.Object
 - 
- com.nomagic.magicdraw.utils.StateChangeHandler
 
 
- 
@OpenApi public class StateChangeHandler extends java.lang.ObjectClass handling state changes in model and symbols. 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classcom.nomagic.magicdraw.utils.StateChangeHandler.ConcurrentModificationDetectingSet<E>A set which helps to detect concurrent modifications from different threadsstatic classStateChangeHandler.DirtyTypeDefines how much dirty is project.static classcom.nomagic.magicdraw.utils.StateChangeHandler.ResourceChangeTrackingAdapterprivate classcom.nomagic.magicdraw.utils.StateChangeHandler.StateChangeNonMaskedPropertyChangeListener 
- 
Field Summary
Fields Modifier and Type Field Description private com.nomagic.ci.persistence.local.partitioning.DirtyResourceSupportServicedirtyFlagServiceprivate static org.apache.log4j.LoggerLOGGERprivate booleanmAutoSaveDirtyprivate com.nomagic.magicdraw.utils.StateChangeHandler.ConcurrentModificationDetectingSet<java.lang.String>mChangedElementsIDSprivate java.util.Map<IProject,StateChangeHandler.DirtyType>mDirtyProjectsprivate booleanmEnableprivate booleanmEventDeliveryStoppedprivate java.util.List<com.nomagic.magicdraw.utils.StatusChangeHandlerListener>mListenersprivate java.util.Collection<java.lang.String>mLoadedChangedElementsIDSprivate ProjectmProjectprivate com.nomagic.magicdraw.utils.StateChangeHandler.ResourceChangeTrackingAdaptermResourceChangeTrackingAdapterprivate java.lang.RunnablemUIUpdater 
- 
Constructor Summary
Constructors Constructor Description StateChangeHandler(Project project) 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(com.nomagic.magicdraw.utils.StatusChangeHandlerListener listener)Adds specified listener.voidaddToLoadedChangedElementsIDS(java.util.Collection<java.lang.String> ids)private voidappendInternalProfilingElementsOwners(java.util.Collection<java.lang.String> applyTo, java.util.Collection<java.lang.String> ids)private booleanareElementsDirty(IAttachedProject project)voidclearDirty()Clear dirty state of this handlervoidclearDirty(IProject part)Marks all elements as non dirty.private voidclearDirtyInternal(IProject part)java.util.Collection<java.lang.String>getAllChangedElementsIDS()java.util.Collection<java.lang.String>getChangedElementsIDS()StateChangeHandler.DirtyTypegetDirtyType(IProject project)private static ElementgetInternalProfilingElementOwner(BaseElement element)voidhandleViewChange(PresentationElement view)Marks object diagram as dirty.booleanisAutoSaveDirty()booleanisDirty(IProject project)booleanisDirty(BaseElement element)Returns true if given element has been modified and is not yet saved.booleanisDirty(org.eclipse.emf.ecore.resource.Resource resource)Check if given resource is dirty in the given project context.private booleanisDirtyWithoutLoaded(BaseElement element)private booleanisIgnored(BaseElement source, java.lang.String propertyName)private voidnotify(java.util.function.Consumer<com.nomagic.magicdraw.utils.StatusChangeHandlerListener> action)private voidonChange(BaseElement source, java.lang.String propertyName)private voidremoveIfFromModule(IAttachedProject md, java.util.Iterator<java.lang.String> iterator)private voidremoveIfNotFromModule(java.util.Iterator<java.lang.String> iterator)voidremoveListener(com.nomagic.magicdraw.utils.StatusChangeHandlerListener listener)Removes the specified listener.voidreSetDirty(IProject project, boolean dirty, StateChangeHandler.DirtyType dirtyType)private voidreSetDirtyInternal(IProject project, boolean dirty, StateChangeHandler.DirtyType dirtyType)voidsetAutoSaveDirty(boolean autoSaveDirty)voidsetChangedElementsIDS(java.util.Collection<java.lang.String> ids)voidsetDirty(boolean dirty, BaseElement element)Marks element as changed/unchanged.voidsetDirty(com.nomagic.ci.persistence.features.FeatureDataSet fd, boolean dirty)Marks given resource dirtyvoidsetDirty(IProject project, boolean dirty)voidsetDirty(IProject project, boolean dirty, StateChangeHandler.DirtyType dirtyType)voidsetDirty(org.eclipse.emf.ecore.resource.Resource resource, boolean dirty)Marks given resource dirtyprivate voidsetDirtyInternal(boolean dirty, BaseElement element)Marks element as changed/unchanged.private voidsetDirtyInternal(IProject project, boolean dirty, StateChangeHandler.DirtyType dirtyType)booleansetEnable(boolean enable)Enables or disabled handlervoidtrackModificationForResource(org.eclipse.emf.ecore.resource.Resource resource)Registers URI for which default dirty resource tracking will be enabled.private voidupdateUI() 
 - 
 
- 
- 
Field Detail
- 
LOGGER
private static final org.apache.log4j.Logger LOGGER
 
- 
mChangedElementsIDS
private final com.nomagic.magicdraw.utils.StateChangeHandler.ConcurrentModificationDetectingSet<java.lang.String> mChangedElementsIDS
 
- 
mLoadedChangedElementsIDS
private final java.util.Collection<java.lang.String> mLoadedChangedElementsIDS
 
- 
mProject
private final Project mProject
 
- 
mUIUpdater
@CheckForNull private java.lang.Runnable mUIUpdater
 
- 
mEnable
private volatile boolean mEnable
 
- 
mEventDeliveryStopped
private volatile boolean mEventDeliveryStopped
 
- 
mDirtyProjects
private final java.util.Map<IProject,StateChangeHandler.DirtyType> mDirtyProjects
 
- 
mListeners
private final java.util.List<com.nomagic.magicdraw.utils.StatusChangeHandlerListener> mListeners
 
- 
mAutoSaveDirty
private boolean mAutoSaveDirty
 
- 
mResourceChangeTrackingAdapter
private final com.nomagic.magicdraw.utils.StateChangeHandler.ResourceChangeTrackingAdapter mResourceChangeTrackingAdapter
 
- 
dirtyFlagService
private final com.nomagic.ci.persistence.local.partitioning.DirtyResourceSupportService dirtyFlagService
 
 - 
 
- 
Constructor Detail
- 
StateChangeHandler
public StateChangeHandler(Project project)
 
 - 
 
- 
Method Detail
- 
addListener
public void addListener(com.nomagic.magicdraw.utils.StatusChangeHandlerListener listener)
Adds specified listener.- Parameters:
 listener- a new listener.
 
- 
removeListener
public void removeListener(com.nomagic.magicdraw.utils.StatusChangeHandlerListener listener)
Removes the specified listener.- Parameters:
 listener- the listener which should be removed.
 
- 
notify
private void notify(java.util.function.Consumer<com.nomagic.magicdraw.utils.StatusChangeHandlerListener> action)
 
- 
areElementsDirty
private boolean areElementsDirty(IAttachedProject project)
- Parameters:
 project- module- Returns:
 - true if module is editable and was not saved after edit.
 
 
- 
setEnable
public boolean setEnable(boolean enable)
Enables or disabled handler- Parameters:
 enable- true if changes should be registered, false otherwise- Returns:
 - previous state
 
 
- 
handleViewChange
public void handleViewChange(PresentationElement view)
Marks object diagram as dirty.- Parameters:
 view- symbol to mark as dirty
 
- 
clearDirty
public void clearDirty()
Clear dirty state of this handler 
- 
clearDirty
public void clearDirty(@CheckForNull IProject part)Marks all elements as non dirty.- Parameters:
 part- part part to clear. Can be null. If null clears everything. In other case clears only module, or project.
 
- 
clearDirtyInternal
private void clearDirtyInternal(@CheckForNull IProject part) 
- 
removeIfFromModule
private void removeIfFromModule(IAttachedProject md, java.util.Iterator<java.lang.String> iterator)
 
- 
removeIfNotFromModule
private void removeIfNotFromModule(java.util.Iterator<java.lang.String> iterator)
 
- 
updateUI
private void updateUI()
 
- 
setDirty
public void setDirty(boolean dirty, BaseElement element)Marks element as changed/unchanged.- Parameters:
 dirty- dirty flagelement- element
 
- 
setDirtyInternal
private void setDirtyInternal(boolean dirty, BaseElement element)Marks element as changed/unchanged.- Parameters:
 dirty- dirty flagelement- element
 
- 
getInternalProfilingElementOwner
@CheckForNull private static Element getInternalProfilingElementOwner(BaseElement element)
 
- 
setDirty
public void setDirty(@Nonnull org.eclipse.emf.ecore.resource.Resource resource, boolean dirty)Marks given resource dirty- Parameters:
 resource- target element which will become dirty
 
- 
setDirty
public void setDirty(@Nonnull com.nomagic.ci.persistence.features.FeatureDataSet fd, boolean dirty)Marks given resource dirty- Parameters:
 fd- target element which will become dirty
 
- 
isDirty
public boolean isDirty(@Nonnull org.eclipse.emf.ecore.resource.Resource resource)Check if given resource is dirty in the given project context. Even ifResource.isModified()==false, this method can returntrue- Returns:
 - true if resource is dirty
 
 
- 
isDirty
@OpenApi public boolean isDirty(BaseElement element)
Returns true if given element has been modified and is not yet saved.- Parameters:
 element- element- Returns:
 - true if element is dirty
 
 
- 
isDirtyWithoutLoaded
private boolean isDirtyWithoutLoaded(BaseElement element)
 
- 
setChangedElementsIDS
public void setChangedElementsIDS(java.util.Collection<java.lang.String> ids)
 
- 
getAllChangedElementsIDS
public java.util.Collection<java.lang.String> getAllChangedElementsIDS()
- Returns:
 - changed during this session + loaded changed ids.
 
 
- 
getChangedElementsIDS
public java.util.Collection<java.lang.String> getChangedElementsIDS()
 
- 
onChange
private void onChange(BaseElement source, java.lang.String propertyName)
 
- 
isIgnored
private boolean isIgnored(BaseElement source, java.lang.String propertyName)
 
- 
addToLoadedChangedElementsIDS
public void addToLoadedChangedElementsIDS(java.util.Collection<java.lang.String> ids)
 
- 
appendInternalProfilingElementsOwners
private void appendInternalProfilingElementsOwners(java.util.Collection<java.lang.String> applyTo, java.util.Collection<java.lang.String> ids) 
- 
setDirty
public void setDirty(IProject project, boolean dirty)
 
- 
setDirty
public void setDirty(IProject project, boolean dirty, @CheckForNull StateChangeHandler.DirtyType dirtyType)
 
- 
setDirtyInternal
private void setDirtyInternal(IProject project, boolean dirty, @CheckForNull StateChangeHandler.DirtyType dirtyType)
 
- 
isDirty
public boolean isDirty(IProject project)
 
- 
getDirtyType
@CheckForNull public StateChangeHandler.DirtyType getDirtyType(IProject project)
 
- 
reSetDirty
public void reSetDirty(IProject project, boolean dirty, @CheckForNull StateChangeHandler.DirtyType dirtyType)
 
- 
reSetDirtyInternal
private void reSetDirtyInternal(IProject project, boolean dirty, @CheckForNull StateChangeHandler.DirtyType dirtyType)
 
- 
isAutoSaveDirty
public boolean isAutoSaveDirty()
 
- 
setAutoSaveDirty
public void setAutoSaveDirty(boolean autoSaveDirty)
 
- 
trackModificationForResource
public void trackModificationForResource(@Nonnull org.eclipse.emf.ecore.resource.Resource resource)Registers URI for which default dirty resource tracking will be enabled.Note, this mechanism is based on EMF track changes
- Parameters:
 resource- resource to track changes
 
 - 
 
 -