internal void SetUpAssociationDisplay() { var association = GetAssociationFromLastPrimarySelection(); if (association != null) { // reset our view model XRef Context.Items.SetValue(new ModelToMappingModelXRef()); // set our mode to None since we aren't mapping entities _currentMappingDetailsInfo.EntityMappingMode = EntityMappingModes.None; _currentMappingDetailsInfo.ViewModel = MappingViewModelHelper.CreateViewModel(Context, association); // show the view model in the tool window 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); } // update the toolbar buttons MappingDetailsWindowContainer.UpdateToolbar(); MappingDetailsWindowContainer.SetHintColor(Color.Transparent); } }
// <summary> // Calls a validation method to check if this entity's MSL is editable by the designer // </summary> private bool CanEditMappingsForEntityType(ConceptualEntityType entityType) { var errorMessage = string.Empty; if (MappingViewModelHelper.CanEditMappingsForEntityType(entityType, ref errorMessage)) { return(true); } else { SetWatermarkInfo(string.Format(CultureInfo.CurrentCulture, Resources.MappingDetails_ErrMslGeneral, errorMessage)); return(false); } }
// <summary> // Calls a validation method to check if this association's MSL is editable by the designer // </summary> private bool CanEditMappingsForFunctionImport(FunctionImport fi) { var errorMessage = string.Empty; // check whether we should lit up the function import mapping. if (EdmFeatureManager.GetFunctionImportMappingFeatureState(fi.Artifact.SchemaVersion).IsEnabled() == false) { SetWatermarkInfo(Resources.MappingDetails_ErrMappingNotSupported); return(false); } else if (MappingViewModelHelper.CanEditMappingsForFunctionImport(fi, ref errorMessage)) { return(true); } else { SetWatermarkInfo(string.Format(CultureInfo.CurrentCulture, Resources.MappingDetails_ErrMslGeneral, errorMessage)); return(false); } }
// <summary> // Calls a validation method to check if this association's MSL is editable by the designer // </summary> internal bool CanEditMappingsForAssociation(Association association, bool allowAssociationMappingEditWithFKs) { if (association == null) { throw new ArgumentNullException("association"); } TreeGridDesignerWatermarkInfo watermarkInfo = null; if (MappingViewModelHelper.CanEditMappingsForAssociation( association, MappingDetailsWindowContainer, ref watermarkInfo, allowAssociationMappingEditWithFKs)) { return(true); } else { Debug.Assert(watermarkInfo != null, "watermark should not be null"); if (watermarkInfo != null) { SetWatermarkInfo(watermarkInfo); } return(false); } }
private void ProcessSelectionFromOtherWindows(Selection selection) { _lastPrimarySelection = selection.PrimarySelection; // we might be called before we are fully initialized 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) { // same item we are showing, don't do anything 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)) ) { // we are selecting a child for the parent we are showing (like property and entity), don't do anything return; } else if (_currentMappingDetailsInfo.ViewModel != null && entityTypeShape != null && entityTypeShape.EntityType != null && _currentMappingDetailsInfo.ViewModel.RootNode.ModelItem == entityTypeShape.EntityType.Target) { // 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). return; } // reset the watermark to the default (it may have been set to an error message about hand-edited MSL) SetWatermarkInfo(_defaultWatermarkInfo); // 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. 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)) { // reset our view model XRef Context.Items.SetValue(new ModelToMappingModelXRef()); // if our last view was not an entity or the entity is abstract, start out in Tables mode if (_currentMappingDetailsInfo.EntityMappingMode == EntityMappingModes.None || entityType.Abstract.Value) { _currentMappingDetailsInfo.EntityMappingMode = EntityMappingModes.Tables; } // create the view model _currentMappingDetailsInfo.ViewModel = MappingViewModelHelper.CreateViewModel(Context, entityType); // show the view model in the tool window 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); } // update the toolbar buttons MappingDetailsWindowContainer.UpdateToolbar(); return; } // see if user selected a navigation property, and treat the mapping view as if the user selected an association var association = GetAssociationFromLastPrimarySelection(); if (association != null && association.EntityModel.IsCSDL && CanEditMappingsForAssociation(association, false)) { SetUpAssociationDisplay(); return; } // set the screen if the user selected a FunctionImport var fi = selection.PrimarySelection as FunctionImport; if (fi != null && fi.FunctionImportMapping != null) { // only show mappings for FunctionImports that ReturnType is either EntityType or ComplexType var isReturnTypeEntityOrComplexType = fi.IsReturnTypeEntityType || fi.IsReturnTypeComplexType; if (isReturnTypeEntityOrComplexType && CanEditMappingsForFunctionImport(fi)) { // reset our view model XRef Context.Items.SetValue(new ModelToMappingModelXRef()); // set our mode to None since we aren't mapping entities _currentMappingDetailsInfo.EntityMappingMode = EntityMappingModes.None; _currentMappingDetailsInfo.ViewModel = MappingViewModelHelper.CreateViewModel(Context, fi.FunctionImportMapping); // show the view model in the tool window 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); } // update the toolbar buttons MappingDetailsWindowContainer.UpdateToolbar(); return; } } } // the user clicked on something other than an entity or association ClearToolWindowContents(false); // clear out our selection source _currentMappingDetailsInfo.SelectionSource = EntityMappingSelectionSource.None; }