src/Misc/EFTools/EntityDesignEntityDesigner/CustomCode/Diagram/EntityDesignerDiagram.cs
/// <summary>
///     Called by the design surface to allow selection filtering
/// </summary>
/// <param name="currentSelection">[in] The current selection before any ShapeElements are added or removed.</param>
/// <param name="proposedItemsToAdd">[in/out] The proposed DiagramItems to be added to the selection.</param>
/// <param name="proposedItemsToRemove">[in/out] The proposed DiagramItems to be removed from the selection.</param>
/// <param name="primaryItem">
///     [in/out] The proposed DiagramItem to become the primary DiagramItem of the selection.
///     A null value signifies that the last DiagramItem in the resultant selection should be assumed as the
///     primary DiagramItem.
/// </param>
/// <returns>
///     true if some or all of the selection was accepted; false if the entire selection proposal
///     was rejected. If false, appropriate feedback will be given to the user to indicate that the
///     selection was rejected.
/// </returns>
Called by the design surface to allow selection filtering
Called by the design surface to allow selection filtering
public override bool GetCompliantSelection(
                SelectedShapesCollection currentSelection, DiagramItemCollection proposedItemsToAdd,
                DiagramItemCollection proposedItemsToRemove, DiagramItem primaryItem)
            {
                base.GetCompliantSelection(currentSelection, proposedItemsToAdd, proposedItemsToRemove, primaryItem);
                var originalProposedItemsToAdd = new DiagramItem[proposedItemsToAdd.Count];
                proposedItemsToAdd.CopyTo(originalProposedItemsToAdd, 0);
                if (currentSelection.FocusedItem != null
                    && currentSelection.FocusedItem.Shape == _diagram)
                {
                    foreach (var item in originalProposedItemsToAdd)
                    {
                        if (item.Shape != null
                            && item.Shape is ElementListCompartment)
                        {
                            var elListCompartment = item.Shape as ElementListCompartment;
                            if (elListCompartment.DefaultCreationDomainClass.Id == ViewModelProperty.DomainClassId
                                || elListCompartment.DefaultCreationDomainClass.Id == ViewModelNavigationProperty.DomainClassId)
                            {
                                var representedShapeElements = item.RepresentedElements.OfType<ShapeElement>();
                                if (representedShapeElements.Count() == 1
                                    && representedShapeElements.Contains(item.Shape))
                                {
                                    var entityTypeShape = elListCompartment.ParentShape as EntityTypeShape;
                                    Debug.Assert(
                                        entityTypeShape != null, "Why isn't the parent of the list compartment an EntityTypeShape?");
                                    var entityTypeShapeDiagramItem = new DiagramItem(entityTypeShape);
                                    if (!currentSelection.Contains(entityTypeShapeDiagramItem)
                                        && proposedItemsToAdd.Contains(entityTypeShapeDiagramItem) == false)
                                    {
                                        proposedItemsToAdd.Add(entityTypeShapeDiagramItem);
                                    }
                                    proposedItemsToAdd.Remove(item);
                                }
                            }
                        }
                    }
                }
                var firstDiagramItem = FirstSelectionItem(currentSelection, proposedItemsToAdd, proposedItemsToRemove);
                if (firstDiagramItem != null
                    && proposedItemsToAdd.Count > 0)
                {
                    var isFirstDiagramItemEntityTypeShape = firstDiagramItem.Shape is EntityTypeShape;
                    foreach (var item in proposedItemsToAdd.ToList())
                    {
                        if (isFirstDiagramItemEntityTypeShape && ((item.Shape is EntityTypeShape) == false))
                        {
                            RemoveSelectedDiagramItem(item, currentSelection, proposedItemsToAdd, proposedItemsToRemove);
                        }
                        else if (isFirstDiagramItemEntityTypeShape == false
                                 && (item.Shape is EntityTypeShape))
                        {
                            RemoveSelectedDiagramItem(item, currentSelection, proposedItemsToAdd, proposedItemsToRemove);
                        }
                    }
                }
                return true;
            }
public override bool GetCompliantSelection ( SelectedShapesCollection currentSelection , DiagramItemCollection proposedItemsToAdd , DiagramItemCollection proposedItemsToRemove , DiagramItem primaryItem ) { base . GetCompliantSelection ( currentSelection , proposedItemsToAdd , proposedItemsToRemove , primaryItem ) ; var originalProposedItemsToAdd = new DiagramItem [ proposedItemsToAdd . Count ] ; proposedItemsToAdd . CopyTo ( originalProposedItemsToAdd , 0 ) ; if ( currentSelection . FocusedItem != null && currentSelection . FocusedItem . Shape == _diagram ) { foreach ( var item in originalProposedItemsToAdd ) { if ( item . Shape != null && item . Shape is ElementListCompartment ) { var elListCompartment = item . Shape as ElementListCompartment ; if ( elListCompartment . DefaultCreationDomainClass . Id == ViewModelProperty . DomainClassId || elListCompartment . DefaultCreationDomainClass . Id == ViewModelNavigationProperty . DomainClassId ) { var representedShapeElements = item . RepresentedElements . OfType < ShapeElement > ( ) ; if ( representedShapeElements . Count ( ) == 1 && representedShapeElements . Contains ( item . Shape ) ) { var entityTypeShape = elListCompartment . ParentShape as EntityTypeShape ; Debug . Assert ( entityTypeShape != null , " " ) ; var entityTypeShapeDiagramItem = new DiagramItem ( entityTypeShape ) ; if ( ! currentSelection . Contains ( entityTypeShapeDiagramItem ) && proposedItemsToAdd . Contains ( entityTypeShapeDiagramItem ) == false ) { proposedItemsToAdd . Add ( entityTypeShapeDiagramItem ) ; } proposedItemsToAdd . Remove ( item ) ; } } } } } var firstDiagramItem = FirstSelectionItem ( currentSelection , proposedItemsToAdd , proposedItemsToRemove ) ; if ( firstDiagramItem != null && proposedItemsToAdd . Count > 0 ) { var isFirstDiagramItemEntityTypeShape = firstDiagramItem . Shape is EntityTypeShape ; foreach ( var item in proposedItemsToAdd . ToList ( ) ) { if ( isFirstDiagramItemEntityTypeShape && ( ( item . Shape is EntityTypeShape ) == false ) ) { RemoveSelectedDiagramItem ( item , currentSelection , proposedItemsToAdd , proposedItemsToRemove ) ; } else if ( isFirstDiagramItemEntityTypeShape == false && ( item . Shape is EntityTypeShape ) ) { RemoveSelectedDiagramItem ( item , currentSelection , proposedItemsToAdd , proposedItemsToRemove ) ; } } } return true ; }
Called by the design surface to allow selection filtering
Called by the design surface to allow selection filtering
// we only perform this with selection rectangles, in which case the focused item will be the diagram  // and the user clicks on the "Properties" or "Navigation Properties" compartment on an entity // only perform this if we have selected the "Scalar Properties" ListCompartment or // the "Navigation Properties" ListCompartment // we don't perform this if a Property or NavigationProperty was selected // find the parent EntityTypeShape that houses this ListCompartment // add the parent EntityTypeShape if it doesn't already exist in the collection // The code below is responsible to enforce the following diagram items selection rule. (see Multiple Diagram spec). // - if an entity-type-shape is selected, no diagram-item can be selected in the diagram. // - if diagram-item that is not an entity-type-shape is selected, no entity-type-shape can be selected. // For Multi selection rules, we can only select EntityTypeShapes or else but not both.
true if some or all of the selection was accepted; false if the entire selection proposal
was rejected. If false, appropriate feedback will be given to the user to indicate that the
selection was rejected.
true if some or all of the selection was accepted ; false if the entire selection proposal was rejected . If false appropriate feedback will be given to the user to indicate that the selection was rejected .
currentSelection
SelectedShapesCollection
[in] The current selection before any ShapeElements are added or removed.
[ in ] The current selection before any ShapeElements are added or removed .
proposedItemsToAdd
DiagramItemCollection
[in/out] The proposed DiagramItems to be added to the selection.
[ in / out ] The proposed DiagramItems to be added to the selection .
proposedItemsToRemove
DiagramItemCollection
[in/out] The proposed DiagramItems to be removed from the selection.
[ in / out ] The proposed DiagramItems to be removed from the selection .
primaryItem
DiagramItem
[in/out] The proposed DiagramItem to become the primary DiagramItem of the selection.
A null value signifies that the last DiagramItem in the resultant selection should be assumed as the
primary DiagramItem.
[ in / out ] The proposed DiagramItem to become the primary DiagramItem of the selection . A null value signifies that the last DiagramItem in the resultant selection should be assumed as the primary DiagramItem .