Beispiel #1
0
 /// <summary>
 /// Raises the Bubbled Change event for the given collection change
 /// </summary>
 /// <param name="propertyName">The name of the property that has changed</param>
 /// <param name="e">The event data</param>
 protected void OnCollectionChanged(string propertyName, NotifyCollectionChangedEventArgs e, Lazy <ITypedElement> feature = null)
 {
     if (!IsFlagSet(ModelElementFlag.Deleting))
     {
         OnBubbledChange(BubbledChangeEventArgs.CollectionChanged(this, propertyName, e, IsFlagSet(ModelElementFlag.RequireUris), feature));
     }
 }
Beispiel #2
0
        internal void OnUriChanged(Uri oldUri)
        {
            var e = new UriChangedEventArgs(oldUri);

            UriChanged?.Invoke(this, e);
            OnBubbledChange(BubbledChangeEventArgs.UriChanged(this, e));
        }
Beispiel #3
0
 /// <summary>
 /// Raises the Bubbled Change event for the given upcoming collection change
 /// </summary>
 /// <param name="propertyName">The name of the property that has changed</param>
 /// <param name="e">The event data</param>
 protected void OnCollectionChanging(string propertyName, NotifyCollectionChangingEventArgs e)
 {
     if (!IsFlagSet(ModelElementFlag.Deleting))
     {
         OnBubbledChange(BubbledChangeEventArgs.CollectionChanging(this, propertyName, e, IsFlagSet(ModelElementFlag.RequireUris)));
     }
 }
Beispiel #4
0
 /// <summary>
 /// Gets called when a new model element is added as a child of the current model element
 /// </summary>
 /// <param name="child">The child element</param>
 /// <remarks>This method is not called if an existing model element is moved in the composition hierarchy</remarks>
 protected virtual void OnChildCreated(IModelElement child)
 {
     if (bubbledChange != null || IsFlagSet(ModelElementFlag.RaiseBubbledChanges))
     {
         OnBubbledChange(BubbledChangeEventArgs.ElementCreated(child, new UriChangedEventArgs(null)));
     }
 }
Beispiel #5
0
 /// <summary>
 /// Gets called when the PropertyChanging event is fired
 /// </summary>
 /// <param name="propertyName">The name of the changed property</param>
 protected virtual void OnPropertyChanging(string propertyName, ValueChangedEventArgs e = null)
 {
     PropertyChanging?.Invoke(this, new PropertyChangingEventArgs(propertyName));
     if (!IsFlagSet(ModelElementFlag.Deleting))
     {
         OnBubbledChange(BubbledChangeEventArgs.PropertyChanging(this, propertyName, e, IsFlagSet(ModelElementFlag.RequireUris)));
     }
 }
Beispiel #6
0
 protected override void OnBubbledChange(BubbledChangeEventArgs e)
 {
     base.OnBubbledChange(e);
     if (e.ChangeType == ChangeType.UnlockRequest)
     {
         UnlockRequested?.Invoke(this, e.OriginalEventArgs as UnlockEventArgs);
     }
 }
Beispiel #7
0
 /// <summary>
 /// Gets called when the PropertyChanged event is fired
 /// </summary>
 /// <param name="propertyName">The name of the changed property</param>
 /// <param name="valueChangedEvent">The original event data</param>
 protected virtual void OnPropertyChanged(string propertyName, ValueChangedEventArgs valueChangedEvent, Lazy <ITypedElement> feature = null)
 {
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
     if (!IsFlagSet(ModelElementFlag.Deleting))
     {
         OnBubbledChange(BubbledChangeEventArgs.PropertyChanged(this, propertyName, valueChangedEvent, IsFlagSet(ModelElementFlag.RequireUris), feature));
     }
 }
Beispiel #8
0
 /// <summary>
 /// Fires the BubbledChange event
 /// </summary>
 /// <param name="e">The event data</param>
 protected virtual void OnBubbledChange(BubbledChangeEventArgs e)
 {
     bubbledChange?.Invoke(this, e);
     if (IsFlagSet(ModelElementFlag.RaiseBubbledChanges) || e.ChangeType == ChangeType.UnlockRequest)
     {
         var parent = Parent as ModelElement;
         if (parent != null)
         {
             parent.OnBubbledChange(e);
         }
     }
 }
Beispiel #9
0
 /// <summary>
 /// Deletes the current model element
 /// </summary>
 public virtual void Delete()
 {
     if (!IsFlagSet(ModelElementFlag.Deleting))
     {
         SetFlag(ModelElementFlag.Deleting);
         // do not create event args when nobody listens
         if (IsFlagSet(ModelElementFlag.RaiseBubbledChanges) || Deleted != null || Deleting != null)
         {
             Uri originalAbsoluteUri = null;
             if (IsFlagSet(ModelElementFlag.RequireUris))
             {
                 originalAbsoluteUri = AbsoluteUri;
             }
             var e = new UriChangedEventArgs(originalAbsoluteUri);
             OnDeleting(e);
             OnDeleted(e);
             // only bubble deletion for deleted root
             OnBubbledChange(BubbledChangeEventArgs.ElementDeleted(this, e));
         }
         SetParent(null);
     }
 }
Beispiel #10
0
        /// <summary>
        /// Tries to unlock the current model element in order to make changes possible
        /// </summary>
        /// <returns>True, if unlocking the model element succeeds, otherwise False</returns>
        public bool TryUnlock()
        {
            if (IsFlagSet(ModelElementFlag.Locked))
            {
                if (IsFlagSet(ModelElementFlag.Frozen))
                {
                    return(false);
                }

                var unlockEventArgs = new UnlockEventArgs(this);
                OnBubbledChange(BubbledChangeEventArgs.Unlock(this, unlockEventArgs));

                if (unlockEventArgs.MayUnlock)
                {
                    UnlockInternal();
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #11
0
 /// <summary>
 /// Gets called when the model element gets deleted
 /// </summary>
 /// <param name="e">The event data</param>
 protected virtual void OnDeleted(UriChangedEventArgs e)
 {
     foreach (var child in Children.Reverse())
     {
         var childME = child as ModelElement;
         if (childME != null)
         {
             Uri oldChildUri = null;
             if (e.OldUri != null)
             {
                 var uriBuilder = new UriBuilder(e.OldUri);
                 uriBuilder.Fragment = uriBuilder.Fragment.Substring(1) + '/' + childME.CreateUriWithFragment(null, false, this).OriginalString;
                 oldChildUri         = uriBuilder.Uri;
             }
             var args = new UriChangedEventArgs(oldChildUri);
             childME.OnDeleting(args);
             childME.OnDeleted(args);
         }
     }
     Deleted?.Invoke(this, e);
     OnBubbledChange(BubbledChangeEventArgs.ElementDeleted(this, e));
     UnsetFlag(ModelElementFlag.Deleting);
 }
Beispiel #12
0
 public override void PropagateBubbledChange(BubbledChangeEventArgs e)
 {
     BubbledChange?.Invoke(this, e);
 }
Beispiel #13
0
        /// <summary>
        /// Sets the parent for the current model element to the given element
        /// </summary>
        /// <param name="newParent">The new parent for the given element</param>
        private void SetParent(IModelElement newParent)
        {
            Unlock();
            var newParentME = newParent as ModelElement;

            if (newParentME != parent)
            {
                var oldParent = parent;
                if (newParentME != null)
                {
                    OnParentChanging(newParentME, parent);
                    Uri oldUri = null;
                    if (IsFlagSet(ModelElementFlag.RequireUris))
                    {
                        oldUri = AbsoluteUri;
                    }
                    parent = newParentME;
                    var newModel = newParentME.Model;
                    var oldModel = oldParent != null ? oldParent.Model : null;
                    if (oldParent != null)
                    {
                        if (EnforceModels && oldModel != null && newModel == null)
                        {
                            oldModel.RootElements.Add(newParentME);
                        }
                    }
                    if (oldParent != null && oldParent.IsFlagSet(ModelElementFlag.RequireUris) && oldUri != null)
                    {
                        oldParent.OnBubbledChange(BubbledChangeEventArgs.UriChanged(this, new UriChangedEventArgs(oldUri)));
                    }
                    else if (bubbledChange == null)
                    {
                        UnregisterBubbledChangeRequest();
                    }
                    if (newParentME.IsFlagSet(ModelElementFlag.RaiseBubbledChanges) || newParentME.bubbledChange != null)
                    {
                        RequestBubbledChanges();
                    }
                    if (newParentME.IsFlagSet(ModelElementFlag.RequireUris))
                    {
                        RequestUris();
                        OnUriChanged(oldUri);
                    }
                    newParentME.OnChildCreated(this);
                    if (newModel != oldModel)
                    {
                        PropagateNewModel(newModel, oldModel, this);
                    }
                    OnParentChanged(newParentME, oldParent);
                }
                else
                {
                    parent = null;
                    var oldModel = oldParent.Model;
                    if (bubbledChange == null)
                    {
                        UnregisterBubbledChangeRequest();
                    }
                    if (oldModel != null)
                    {
                        PropagateNewModel(null, oldModel, this);
                    }
                    OnParentChanged(null, oldParent);
                }
            }
        }
Beispiel #14
0
 /// <summary>
 /// Gets called when the model element gets deleted
 /// </summary>
 /// <param name="e">The event data</param>
 protected virtual void OnDeleted(EventArgs e, Uri originalAbsoluteUri)
 {
     Deleted?.Invoke(this, e);
     OnBubbledChange(BubbledChangeEventArgs.ElementDeleted(this, originalAbsoluteUri));
 }
Beispiel #15
0
 /// <summary>
 /// Gets called when a new model element is added as a child of the current model element
 /// </summary>
 /// <param name="child">The child element</param>
 /// <remarks>This method is not called if an existing model element is moved in the composition hierarchy</remarks>
 protected virtual void OnChildCreated(IModelElement child)
 {
     OnBubbledChange(BubbledChangeEventArgs.ElementCreated(child, new UriChangedEventArgs(null)));
 }
Beispiel #16
0
 public virtual void PropagateBubbledChange(BubbledChangeEventArgs e)
 {
     Parent.PropagateBubbledChange(e);
 }
Beispiel #17
0
 private void Element_BubbledChange(object sender, BubbledChangeEventArgs e)
 {
     PropagateBubbledChange(e);
 }
Beispiel #18
0
 private void Repository_BubbledChange(object sender, BubbledChangeEventArgs e)
 {
     Parent.PropagateBubbledChange(e);
 }
Beispiel #19
0
 /// <summary>
 /// Gets called when a new model element is added as a child of the current model element
 /// </summary>
 /// <param name="child">The child element</param>
 /// <remarks>This method is not called if an existing model element is moved in the composition hierarchy</remarks>
 protected virtual void OnChildCreated(IModelElement child)
 {
     OnBubbledChange(BubbledChangeEventArgs.ElementCreated(child, IsFlagSet(ModelElementFlag.RequireUris)));
 }