src/Misc/EFTools/EntityDesignPackage/CustomCode/MicrosoftDataEntityDesignCommandSet.cs
/// <summary>
///     Event handler to delete shapes (diagram items) and corresponding model items.
/// </summary>
Event handler to delete shapes (diagram items) and corresponding model items.
Event handler to delete shapes ( diagram items ) and corresponding model items .
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
        internal void OnMenuRemoveFromDiagram(object sender, EventArgs e)
        {
            var diagram = GetDiagram();
            if (MonitorSelection != null
                && MonitorSelection.CurrentWindow is MicrosoftDataEntityDesignDocView
                && diagram != null)
            {
                if (SelectedEntityTypeShapes.Count > 0)
                {
                    Debug.Assert(
                        AreAllSelectedItemsTypeof<EntityTypeShape>(),
                        "If an entity type shape is selected in the diagram, no other type should be selected.");
                    if (AreAllSelectedItemsTypeof<EntityTypeShape>())
                    {
                        IList<Command> deleteCommands = new List<Command>();
                        foreach (var ets in SelectedEntityTypeShapes)
                        {
                            Debug.Assert(
                                ets.TypedModelElement != null, "DSL entity type shape (PEL) does not have the corresponding model element");
                            if (ets.TypedModelElement != null)
                            {
                                var viewModelEntityType = ets.TypedModelElement;
                                var modelEntityTypeShape =
                                    viewModelEntityType.EntityDesignerViewModel.ModelXRef.GetExisting(ets) as Model.Designer.EntityTypeShape;
                                Debug.Assert(
                                    modelEntityTypeShape != null,
                                    "Why DslModel-EscherModel XRef does not contain Escher model diagram item for DSL entity-type-shape: "
                                    + viewModelEntityType.Name);
                                if (modelEntityTypeShape != null)
                                {
                                    deleteCommands.Add(modelEntityTypeShape.GetDeleteCommand());
                                }
                            }
                        }
                        if (deleteCommands.Count > 0)
                        {
                            var transactionName = Resources.Tx_DeleteItems;
                            if (deleteCommands.Count == 1)
                            {
                                var ets = SelectedEntityTypeShapes.FirstOrDefault();
                                Debug.Assert(null != ets, "There should be a selected entity type.");
                                if (null != ets)
                                {
                                    transactionName = String.Format(
                                        CultureInfo.CurrentCulture, Resources.Tx_Delete, ets.TypedModelElement.Name);
                                }
                            }
                            var uri = Utils.FileName2Uri(CurrentDocData.FileName);
                            var editingContext = PackageManager.Package.DocumentFrameMgr.EditingContextManager.GetNewOrExistingContext(uri);
                            var cp = new CommandProcessor(
                                editingContext, EfiTransactionOriginator.EntityDesignerOriginatorId, transactionName, deleteCommands);
                            cp.Invoke();
                        }
                    }
                }
            }
        }
[ SuppressMessage ( " " , " " ) ] internal void OnMenuRemoveFromDiagram ( object sender , EventArgs e ) { var diagram = GetDiagram ( ) ; if ( MonitorSelection != null && MonitorSelection . CurrentWindow is MicrosoftDataEntityDesignDocView && diagram != null ) { if ( SelectedEntityTypeShapes . Count > 0 ) { Debug . Assert ( AreAllSelectedItemsTypeof < EntityTypeShape > ( ) , " " ) ; if ( AreAllSelectedItemsTypeof < EntityTypeShape > ( ) ) { IList < Command > deleteCommands = new List < Command > ( ) ; foreach ( var ets in SelectedEntityTypeShapes ) { Debug . Assert ( ets . TypedModelElement != null , " " ) ; if ( ets . TypedModelElement != null ) { var viewModelEntityType = ets . TypedModelElement ; var modelEntityTypeShape = viewModelEntityType . EntityDesignerViewModel . ModelXRef . GetExisting ( ets ) as Model . Designer . EntityTypeShape ; Debug . Assert ( modelEntityTypeShape != null , " " + viewModelEntityType . Name ) ; if ( modelEntityTypeShape != null ) { deleteCommands . Add ( modelEntityTypeShape . GetDeleteCommand ( ) ) ; } } } if ( deleteCommands . Count > 0 ) { var transactionName = Resources . Tx_DeleteItems ; if ( deleteCommands . Count == 1 ) { var ets = SelectedEntityTypeShapes . FirstOrDefault ( ) ; Debug . Assert ( null != ets , " " ) ; if ( null != ets ) { transactionName = String . Format ( CultureInfo . CurrentCulture , Resources . Tx_Delete , ets . TypedModelElement . Name ) ; } } var uri = Utils . FileName2Uri ( CurrentDocData . FileName ) ; var editingContext = PackageManager . Package . DocumentFrameMgr . EditingContextManager . GetNewOrExistingContext ( uri ) ; var cp = new CommandProcessor ( editingContext , EfiTransactionOriginator . EntityDesignerOriginatorId , transactionName , deleteCommands ) ; cp . Invoke ( ) ; } } } } }
Event handler to delete shapes (diagram items) and corresponding model items.
Event handler to delete shapes ( diagram items ) and corresponding model items .
// For entity-type shape we only delete the diagram model items, not the model that the diagram items represent. // Note that this command is only available for Entity-Type-Shape. For any other types it should not be available. // We also update the behavior of what the user can select in the diagram. // The user cannot select Entity-Type-Shapes and other types at the same time. // Please see EntityDesignerDiagramSelectionRules class for more information. // check if the EntityTypeShape model element is not null.
sender
object
e
EventArgs