internal void NavigateToElementAndPutInRenameMode(EFElement element) { Debug.Assert(element != null, "element must not be null"); if (element != null) { // first select the element ExplorerNavigationHelper.NavigateTo(element); // Invoke deferred request to put the selected item in rename mode. // This is necessary because the selected explorer item might not have been fully initialized yet. _putSelectedExplorerItemInRenameModeRequest.Request(); } }
public void ExecuteActivate() { var viewModelHelper = ExplorerViewModelHelper as EntityDesignExplorerViewModelHelper; Debug.Assert(viewModelHelper != null, "ExplorerViewModelHelper is null or is not type of EntityDesignExplorerViewModelHelper"); // Function-Import/Function double-click behavior. var selectedExplorerEFElement = GetSelectedExplorerEFElement(); var explorerFunctionImport = selectedExplorerEFElement as ExplorerFunctionImport; var explorerFunction = selectedExplorerEFElement as ExplorerFunction; var explorerDiagram = selectedExplorerEFElement as ExplorerDiagram; var explorerConceptualProperty = selectedExplorerEFElement as ExplorerConceptualProperty; var explorerEnumType = selectedExplorerEFElement as ExplorerEnumType; var diagramManagercontextItem = EditingContext.Items.GetValue <DiagramManagerContextItem>(); Debug.Assert(diagramManagercontextItem != null, "Could not find instance of: DiagramManagerContextItem in editing context."); if (viewModelHelper != null && explorerFunctionImport != null) { viewModelHelper.EditFunctionImport(explorerFunctionImport.ModelItem as FunctionImport); } // if the user double-clicks on the function in the model browser. else if (viewModelHelper != null && explorerFunction != null) { var function = explorerFunction.ModelItem as Function; Debug.Assert(function != null, "ExplorerFunction.ModelItem value is expected to be typeof Function and not null."); if (function != null) { var schemaVersion = (function.Artifact == null ? null : function.Artifact.SchemaVersion); if (function.IsComposable != null && function.IsComposable.Value && !EdmFeatureManager.GetComposableFunctionImportFeatureState(schemaVersion).IsEnabled()) { // Composable Function Import for Version <= V2 - give warning message VsUtils.ShowMessageBox( PackageManager.Package, string.Format( CultureInfo.CurrentCulture, Design.Resources.FunctionImport_CannotCreateFromComposableFunction, EntityFrameworkVersion.Version2), OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_WARNING); } else { // first we detect whether there are existing FunctionImport(s) with the underlying function. var itemBindings = function.GetDependentBindings(); var matchFunctionImportList = new List <FunctionImport>(); foreach (var itemBinding in itemBindings) { var functionImportMapping = itemBinding.GetParentOfType(typeof(FunctionImportMapping)) as FunctionImportMapping; if (functionImportMapping != null && functionImportMapping.FunctionImportName != null && functionImportMapping.FunctionImportName.Target != null) { matchFunctionImportList.Add(functionImportMapping.FunctionImportName.Target); } } // if we found function imports for the underlying function, navigate to the first function import in alphabetical sorted list if (matchFunctionImportList.Count > 0) { matchFunctionImportList.Sort(EFElement.EFElementDisplayNameComparison); ExplorerNavigationHelper.NavigateTo(matchFunctionImportList[0]); } else { // We could not find any function import for the underlying function, show new function import dialog viewModelHelper.CreateFunctionImport(explorerFunction.ModelItem as Function); } } } } else if (explorerEnumType != null) { var enumType = explorerEnumType.ModelItem as EnumType; Debug.Assert(enumType != null, "ExplorerEnumType's model item is null or is not type of EnumType."); EntityDesignViewModelHelper.EditEnumType( Context, EfiTransactionOriginator.ExplorerWindowOriginatorId, new EnumTypeViewModel(enumType)); } // if the selected Explorer is type of ExplorerDiagram. else if (explorerDiagram != null && diagramManagercontextItem != null) { diagramManagercontextItem.DiagramManager.OpenDiagram(explorerDiagram.DiagramMoniker, true); } else if (explorerConceptualProperty != null) { Debug.Assert( explorerConceptualProperty.Parent is ExplorerConceptualEntityType, "Only properties that belong to Entity type are supported."); if (explorerConceptualProperty.Parent is ExplorerConceptualEntityType) { diagramManagercontextItem.DiagramManager.ActiveDiagram.AddOrShowEFElementInDiagram(explorerConceptualProperty.ModelItem); } } // if the selected Explorer is type of ExplorerConceptualEntityType, ExplorerConceptualAssociation, ExplorerNavigationProperty, ExplorerAssociationSet or ExplorerEntitySet else if (diagramManagercontextItem != null && diagramManagercontextItem.DiagramManager != null && diagramManagercontextItem.DiagramManager.ActiveDiagram != null) { Debug.Assert( selectedExplorerEFElement is ExplorerConceptualEntityType || selectedExplorerEFElement is ExplorerConceptualAssociation || selectedExplorerEFElement is ExplorerNavigationProperty || selectedExplorerEFElement is ExplorerAssociationSet || selectedExplorerEFElement is ExplorerEntitySet || selectedExplorerEFElement is ExplorerEntityTypeShape, "The selected explorer type:" + selectedExplorerEFElement.GetType().Name + " is not supported."); if (selectedExplorerEFElement is ExplorerConceptualEntityType || selectedExplorerEFElement is ExplorerConceptualAssociation || selectedExplorerEFElement is ExplorerNavigationProperty || selectedExplorerEFElement is ExplorerAssociationSet || selectedExplorerEFElement is ExplorerEntitySet) { diagramManagercontextItem.DiagramManager.ActiveDiagram.AddOrShowEFElementInDiagram(selectedExplorerEFElement.ModelItem); } else if (selectedExplorerEFElement is ExplorerEntityTypeShape) { var entityTypeShape = selectedExplorerEFElement.ModelItem as EntityTypeShape; Debug.Assert(entityTypeShape != null, "ExplorerEntityTypeShape does not contain instance of EntityTypeShape"); if (entityTypeShape != null) { diagramManagercontextItem.DiagramManager.OpenDiagram(entityTypeShape.Diagram.Id, true); diagramManagercontextItem.DiagramManager.ActiveDiagram.AddOrShowEFElementInDiagram( entityTypeShape.EntityType.Target); } } } }