Exemple #1
0
        /// <summary>
        /// Called during view fixup to ask the parent whether a shape should be created for the given child element.
        /// </summary>
        /// <remarks>
        /// Always return true, since we assume there is only one diagram per model file for DSL scenarios.
        /// </remarks>
        protected override bool ShouldAddShapeForElement(ModelElement element)
        {
            ModelElement parent = null;

            // for attributes and enum values, the we should add the shape if its parent is on the diagram
            if (element is ModelAttribute modelAttribute)
            {
                parent = modelAttribute.ModelClass;
            }

            if (element is ModelEnumValue enumValue)
            {
                parent = enumValue.Enum;
            }

            bool result =
                ForceAddShape || // we've made the decision somewhere else that this shape should be added
                IsDroppingExternal || // we're dropping a file from Solution Explorer or File Explorer
                base.ShouldAddShapeForElement(element) || // the built-in rules say to do this
                DisplayedElements.Contains(element) || // the serialized diagram has this element present (other rules should prevent duplication)
                (parent != null && DisplayedElements.Contains(parent)) || // the element's parent is on this diagram
                (element is ElementLink link && link.LinkedElements.All(linkedElement => DisplayedElements.Contains(linkedElement))); // adding a link and both of the linkk's end nodes are in this diagram

            return(result);
        }
Exemple #2
0
 private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == NotifyCollectionChangedAction.Add)
     {
         DisplayedElements.AddRange(e.NewItems.OfType <DisplayedCell>());
     }
     if (e.Action == NotifyCollectionChangedAction.Remove)
     {
         foreach (DisplayedCell element in e.OldItems)
         {
             DisplayedElements.Remove(element);
         }
     }
     if (e.Action == NotifyCollectionChangedAction.Reset)
     {
         DisplayedElements.Clear();
     }
 }