src/Misc/EFTools/EntityDesign/UI/Views/MappingDetails/MappingDetailsWindow.cs
// <summary>
//     This will work with an item selected in either the Designer or the Explorer.
// </summary>
This will work with an item selected in either the Designer or the Explorer.
This will work with an item selected in either the Designer or the Explorer .
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
        private void ProcessSelectionFromOtherWindows(Selection selection)
        {
            _lastPrimarySelection = selection.PrimarySelection;
            if (_currentMappingDetailsInfo == null)
            {
                return;
            }
            if (selection.PrimarySelection != null)
            {
                var property = selection.PrimarySelection as Property;
                var navProp = selection.PrimarySelection as NavigationProperty;
                var entityTypeShape = selection.PrimarySelection as EntityTypeShape;
                MappingDetailsWindowContainer.SetHintColor(Color.Transparent);
                if (entityTypeShape != null)
                {
                    MappingDetailsWindowContainer.SetHintColor(entityTypeShape.FillColor.Value);
                }
                if (_currentMappingDetailsInfo.ViewModel != null
                    &&
                    _currentMappingDetailsInfo.ViewModel.RootNode.ModelItem.Identity == selection.PrimarySelection.Identity)
                {
                    return;
                }
                else if (_currentMappingDetailsInfo.ViewModel != null
                         && selection.PrimarySelection.Parent != null
                         && ((property != null && property.Parent == _currentMappingDetailsInfo.ViewModel.RootNode.ModelItem) ||
                             (navProp != null && navProp.Relationship.Target == _currentMappingDetailsInfo.ViewModel.RootNode.ModelItem))
                    )
                {
                    return;
                }
                else if (_currentMappingDetailsInfo.ViewModel != null
                         && entityTypeShape != null
                         && entityTypeShape.EntityType != null
                         && _currentMappingDetailsInfo.ViewModel.RootNode.ModelItem == entityTypeShape.EntityType.Target)
                {
                    return;
                }
                SetWatermarkInfo(_defaultWatermarkInfo);
                ConceptualEntityType entityType = null;
                if (property != null
                    && property.EntityType != null
                    && property.EntityType.EntityModel.IsCSDL)
                {
                    entityType = property.EntityType as ConceptualEntityType;
                    Debug.Assert(property.EntityType != null ? entityType != null : true, "EntityType is not ConceptualEntityType");
                }
                else if (entityTypeShape != null
                         && entityTypeShape.EntityType != null
                         && entityTypeShape.EntityType.Target != null)
                {
                    entityType = entityTypeShape.EntityType.Target as ConceptualEntityType;
                    Debug.Assert(entityType != null, "Why does EntityTypeShape's EntityType is not ConceptualEntityType");
                }
                else
                {
                    entityType = selection.PrimarySelection as ConceptualEntityType;
                }
                if (entityType != null
                    && CanEditMappingsForEntityType(entityType))
                {
                    Context.Items.SetValue(new ModelToMappingModelXRef());
                    if (_currentMappingDetailsInfo.EntityMappingMode == EntityMappingModes.None
                        || entityType.Abstract.Value)
                    {
                        _currentMappingDetailsInfo.EntityMappingMode = EntityMappingModes.Tables;
                    }
                    _currentMappingDetailsInfo.ViewModel = MappingViewModelHelper.CreateViewModel(Context, entityType);
                    Debug.Assert(
                        _currentMappingDetailsInfo.ViewModel != null && _currentMappingDetailsInfo.ViewModel.RootNode != null,
                        "Failed to correctly create the mapping details ViewModel for the selected entity");
                    if (_currentMappingDetailsInfo.ViewModel != null
                        && _currentMappingDetailsInfo.ViewModel.RootNode != null)
                    {
                        DoShowMappingDetailsForElement(_currentMappingDetailsInfo.ViewModel.RootNode.ModelItem);
                    }
                    MappingDetailsWindowContainer.UpdateToolbar();
                    return;
                }
                var association = GetAssociationFromLastPrimarySelection();
                if (association != null
                    && association.EntityModel.IsCSDL
                    && CanEditMappingsForAssociation(association, false))
                {
                    SetUpAssociationDisplay();
                    return;
                }
                var fi = selection.PrimarySelection as FunctionImport;
                if (fi != null
                    && fi.FunctionImportMapping != null)
                {
                    var isReturnTypeEntityOrComplexType = fi.IsReturnTypeEntityType || fi.IsReturnTypeComplexType;
                    if (isReturnTypeEntityOrComplexType && CanEditMappingsForFunctionImport(fi))
                    {
                        Context.Items.SetValue(new ModelToMappingModelXRef());
                        _currentMappingDetailsInfo.EntityMappingMode = EntityMappingModes.None;
                        _currentMappingDetailsInfo.ViewModel = MappingViewModelHelper.CreateViewModel(Context, fi.FunctionImportMapping);
                        Debug.Assert(
                            _currentMappingDetailsInfo.ViewModel != null && _currentMappingDetailsInfo.ViewModel.RootNode != null,
                            "Failed to correctly create the mapping details ViewModel for the selected association");
                        if (_currentMappingDetailsInfo.ViewModel != null
                            &&
                            _currentMappingDetailsInfo.ViewModel.RootNode != null)
                        {
                            DoShowMappingDetailsForElement(_currentMappingDetailsInfo.ViewModel.RootNode.ModelItem);
                        }
                        MappingDetailsWindowContainer.UpdateToolbar();
                        return;
                    }
                }
            }
            ClearToolWindowContents(false);
            _currentMappingDetailsInfo.SelectionSource = EntityMappingSelectionSource.None;
        }
[ SuppressMessage ( " " , " " ) ] private void ProcessSelectionFromOtherWindows ( Selection selection ) { _lastPrimarySelection = selection . PrimarySelection ; if ( _currentMappingDetailsInfo == null ) { return ; } if ( selection . PrimarySelection != null ) { var property = selection . PrimarySelection as Property ; var navProp = selection . PrimarySelection as NavigationProperty ; var entityTypeShape = selection . PrimarySelection as EntityTypeShape ; MappingDetailsWindowContainer . SetHintColor ( Color . Transparent ) ; if ( entityTypeShape != null ) { MappingDetailsWindowContainer . SetHintColor ( entityTypeShape . FillColor . Value ) ; } if ( _currentMappingDetailsInfo . ViewModel != null && _currentMappingDetailsInfo . ViewModel . RootNode . ModelItem . Identity == selection . PrimarySelection . Identity ) { return ; } else if ( _currentMappingDetailsInfo . ViewModel != null && selection . PrimarySelection . Parent != null && ( ( property != null && property . Parent == _currentMappingDetailsInfo . ViewModel . RootNode . ModelItem ) || ( navProp != null && navProp . Relationship . Target == _currentMappingDetailsInfo . ViewModel . RootNode . ModelItem ) ) ) { return ; } else if ( _currentMappingDetailsInfo . ViewModel != null && entityTypeShape != null && entityTypeShape . EntityType != null && _currentMappingDetailsInfo . ViewModel . RootNode . ModelItem == entityTypeShape . EntityType . Target ) { return ; } SetWatermarkInfo ( _defaultWatermarkInfo ) ; ConceptualEntityType entityType = null ; if ( property != null && property . EntityType != null && property . EntityType . EntityModel . IsCSDL ) { entityType = property . EntityType as ConceptualEntityType ; Debug . Assert ( property . EntityType != null ? entityType != null : true , " " ) ; } else if ( entityTypeShape != null && entityTypeShape . EntityType != null && entityTypeShape . EntityType . Target != null ) { entityType = entityTypeShape . EntityType . Target as ConceptualEntityType ; Debug . Assert ( entityType != null , " " ) ; } else { entityType = selection . PrimarySelection as ConceptualEntityType ; } if ( entityType != null && CanEditMappingsForEntityType ( entityType ) ) { Context . Items . SetValue ( new ModelToMappingModelXRef ( ) ) ; if ( _currentMappingDetailsInfo . EntityMappingMode == EntityMappingModes . None || entityType . Abstract . Value ) { _currentMappingDetailsInfo . EntityMappingMode = EntityMappingModes . Tables ; } _currentMappingDetailsInfo . ViewModel = MappingViewModelHelper . CreateViewModel ( Context , entityType ) ; Debug . Assert ( _currentMappingDetailsInfo . ViewModel != null && _currentMappingDetailsInfo . ViewModel . RootNode != null , " " ) ; if ( _currentMappingDetailsInfo . ViewModel != null && _currentMappingDetailsInfo . ViewModel . RootNode != null ) { DoShowMappingDetailsForElement ( _currentMappingDetailsInfo . ViewModel . RootNode . ModelItem ) ; } MappingDetailsWindowContainer . UpdateToolbar ( ) ; return ; } var association = GetAssociationFromLastPrimarySelection ( ) ; if ( association != null && association . EntityModel . IsCSDL && CanEditMappingsForAssociation ( association , false ) ) { SetUpAssociationDisplay ( ) ; return ; } var fi = selection . PrimarySelection as FunctionImport ; if ( fi != null && fi . FunctionImportMapping != null ) { var isReturnTypeEntityOrComplexType = fi . IsReturnTypeEntityType || fi . IsReturnTypeComplexType ; if ( isReturnTypeEntityOrComplexType && CanEditMappingsForFunctionImport ( fi ) ) { Context . Items . SetValue ( new ModelToMappingModelXRef ( ) ) ; _currentMappingDetailsInfo . EntityMappingMode = EntityMappingModes . None ; _currentMappingDetailsInfo . ViewModel = MappingViewModelHelper . CreateViewModel ( Context , fi . FunctionImportMapping ) ; Debug . Assert ( _currentMappingDetailsInfo . ViewModel != null && _currentMappingDetailsInfo . ViewModel . RootNode != null , " " ) ; if ( _currentMappingDetailsInfo . ViewModel != null && _currentMappingDetailsInfo . ViewModel . RootNode != null ) { DoShowMappingDetailsForElement ( _currentMappingDetailsInfo . ViewModel . RootNode . ModelItem ) ; } MappingDetailsWindowContainer . UpdateToolbar ( ) ; return ; } } } ClearToolWindowContents ( false ) ; _currentMappingDetailsInfo . SelectionSource = EntityMappingSelectionSource . None ; }
This will work with an item selected in either the Designer or the Explorer.
This will work with an item selected in either the Designer or the Explorer .
// we might be called before we are fully initialized // same item we are showing, don't do anything // we are selecting a child for the parent we are showing (like property and entity), don't do anything // if the current entity type that we are showing is as same as what the shape refers, do nothing (we try to show the same thing). // reset the watermark to the default (it may have been set to an error message about hand-edited MSL) // set the screen if the user selects an entity or property // if they select a property, then resolve up to parent entity // if they select an EntityTypeShape, then resolve up the referred entity. // reset our view model XRef // if our last view was not an entity or the entity is abstract, start out in Tables mode // create the view model // show the view model in the tool window // update the toolbar buttons // see if user selected a navigation property, and treat the mapping view as if the user selected an association // set the screen if the user selected a FunctionImport // only show mappings for FuntionImports that ReturnType is either EntityType or ComplexType // reset our view model XRef // set our mode to None since we aren't mapping entities // show the view model in the tool window // update the toolbar buttons // the user clicked on something other than an entity or association // clear out our selection source
selection
Selection