internal override DslModeling.ModelElement SynchronizeSingleDslModelElement( DslModeling.ModelElement parentViewModel, EFObject modelElement) { var t = modelElement.GetType(); if (t == typeof(ConceptualEntityType)) { return(TranslateEntityType(parentViewModel as EntityDesignerViewModel, modelElement as ConceptualEntityType)); } else if (t == typeof(EntityTypeBaseType)) { return(TranslateBaseType(parentViewModel as EntityDesignerViewModel, (modelElement).Parent as ConceptualEntityType)); } else if (t == typeof(ModelNavigationProperty)) { return(TranslateNavigationProperty(parentViewModel as ViewModelEntityType, modelElement as ModelNavigationProperty)); } else if (t == typeof(ComplexConceptualProperty) || t == typeof(ConceptualProperty)) { return(TranslateProperty(parentViewModel as ViewModelEntityType, modelElement as ModelProperty)); } else if (t == typeof(ModelAssociation)) { return(TranslateAssociation(parentViewModel as EntityDesignerViewModel, modelElement as ModelAssociation)); } else if (t == typeof(DesignerModel.Diagram)) { return(TranslateDiagramValues(parentViewModel as EntityDesignerViewModel, modelElement as DesignerModel.Diagram)); } Debug.Assert(false, "modelElement with type= " + t.Name + " is not supported"); return(null); }
private static ModelElement CreateModelElementForEFObjectType(EFObject obj, Partition partition) { ModelElement modelElement = null; var t = obj.GetType(); if (t == typeof(ConceptualEntityModel)) { modelElement = new EntityDesignerViewModel(partition); } else if (t == typeof(ConceptualEntityType)) { modelElement = new EntityType(partition); } else if (t == typeof(ConceptualProperty)) { modelElement = new ScalarProperty(partition); } else if (t == typeof(ComplexConceptualProperty)) { modelElement = new ComplexProperty(partition); } else if (t == typeof(Association)) { modelElement = new ViewModel.Association(partition); } else if (t == typeof(EntityTypeBaseType)) { modelElement = new Inheritance(partition); } else if (t == typeof(NavigationProperty)) { modelElement = new ViewModel.NavigationProperty(partition); } return modelElement; }
internal static ModelElement CreateConnectorModelElementForEFObjectType(EFObject obj, ModelElement end1, ModelElement end2) { ModelElement modelElement = null; var t = obj.GetType(); var et1 = end1 as EntityType; var et2 = end2 as EntityType; if (t == typeof(Association)) { Debug.Assert(et1 != null && et2 != null, "Unexpected end type for Association model element"); modelElement = new ViewModel.Association(et1, et2); } else if (t == typeof(EntityTypeBaseType)) { Debug.Assert(et1 != null && et2 != null, "Unexpected end type for Inheritance model element"); modelElement = new Inheritance(et1, et2); } return modelElement; }
internal static ModelElement CreateConnectorModelElementForEFObjectType(EFObject obj, ModelElement end1, ModelElement end2) { ModelElement modelElement = null; var t = obj.GetType(); var et1 = end1 as EntityType; var et2 = end2 as EntityType; if (t == typeof(Association)) { Debug.Assert(et1 != null && et2 != null, "Unexpected end type for Association model element"); modelElement = new ViewModel.Association(et1, et2); } else if (t == typeof(EntityTypeBaseType)) { Debug.Assert(et1 != null && et2 != null, "Unexpected end type for Inheritance model element"); modelElement = new Inheritance(et1, et2); } return(modelElement); }
private static ModelElement CreateModelElementForEFObjectType(EFObject obj, Partition partition) { ModelElement modelElement = null; var t = obj.GetType(); if (t == typeof(ConceptualEntityModel)) { modelElement = new EntityDesignerViewModel(partition); } else if (t == typeof(ConceptualEntityType)) { modelElement = new EntityType(partition); } else if (t == typeof(ConceptualProperty)) { modelElement = new ScalarProperty(partition); } else if (t == typeof(ComplexConceptualProperty)) { modelElement = new ComplexProperty(partition); } else if (t == typeof(Association)) { modelElement = new ViewModel.Association(partition); } else if (t == typeof(EntityTypeBaseType)) { modelElement = new Inheritance(partition); } else if (t == typeof(NavigationProperty)) { modelElement = new ViewModel.NavigationProperty(partition); } return(modelElement); }
// <summary> // Returns a wrapper for the specified EFObject. The wrapper is the type descriptor // that describes the properties that should be displayed for the EFObject. // The returned wrapper should be handed to a property window control // </summary> public static ObjectDescriptor GetObjectDescriptor(EFObject obj, EditingContext editingContext, bool runningInVS) { if (obj != null) { Type objectDescriptorType; if (ObjectDescriptorTypes.TryGetValue(obj.GetType(), out objectDescriptorType)) { // create the descriptor wrapper for the EFObject object var descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, objectDescriptorType, null, null); descriptor.Initialize(obj, editingContext, runningInVS); return descriptor; } else { // special case for Property var property = obj as Property; if (property != null) { ObjectDescriptor descriptor = null; if (property is ComplexConceptualProperty) { descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFComplexPropertyDescriptor), null, null); } else if (property.EntityModel.IsCSDL) { descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFPropertyDescriptor), null, null); } else { descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFSPropertyDescriptor), null, null); } descriptor.Initialize(obj, editingContext, runningInVS); return descriptor; } // special case for Parameter var parameter = obj as Parameter; if (parameter != null) { ObjectDescriptor descriptor = null; if (parameter.Parent is FunctionImport) { descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFParameterDescriptor), null, null); descriptor.Initialize(obj, editingContext, runningInVS); return descriptor; } else if (parameter.Parent is Function) { //Stored procedure parameter descriptor (EFSParameterDescriptor) descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFSParameterDescriptor), null, null); descriptor.Initialize(obj, editingContext, runningInVS); return descriptor; } } } } return null; }
private static ExplorerTreeViewItem GetTreeViewItemForEFObject(EFObject efobject, ExplorerFrame explorerFrame) { var treeViewItem = explorerFrame.ExplorerTreeRoot; if (null != efobject && !(efobject is EFArtifact)) { var entityDesignArtifact = efobject.Artifact.ArtifactSet.GetEntityDesignArtifact(); var editingContext = PackageManager.Package.DocumentFrameMgr.EditingContextManager.GetNewOrExistingContext(entityDesignArtifact.Uri); var element = explorerFrame.ExplorerViewModelHelper.GetExplorerEFElementForEFObject(editingContext, efobject); Debug.Assert(element != null, "Unable to find ExplorerEFElement for efobject of type " + efobject.GetType()); if (element != null) { treeViewItem = explorerFrame.GetTreeViewItem(element, true); } } return(treeViewItem); }
// <summary> // Returns a wrapper for the specified EFObject. The wrapper is the type descriptor // that describes the properties that should be displayed for the EFObject. // The returned wrapper should be handed to a property window control // </summary> public static ObjectDescriptor GetObjectDescriptor(EFObject obj, EditingContext editingContext, bool runningInVS) { if (obj != null) { Type objectDescriptorType; if (ObjectDescriptorTypes.TryGetValue(obj.GetType(), out objectDescriptorType)) { // create the descriptor wrapper for the EFObject object var descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, objectDescriptorType, null, null); descriptor.Initialize(obj, editingContext, runningInVS); return(descriptor); } else { // special case for Property var property = obj as Property; if (property != null) { ObjectDescriptor descriptor = null; if (property is ComplexConceptualProperty) { descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFComplexPropertyDescriptor), null, null); } else if (property.EntityModel.IsCSDL) { descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFPropertyDescriptor), null, null); } else { descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFSPropertyDescriptor), null, null); } descriptor.Initialize(obj, editingContext, runningInVS); return(descriptor); } // special case for Parameter var parameter = obj as Parameter; if (parameter != null) { ObjectDescriptor descriptor = null; if (parameter.Parent is FunctionImport) { descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFParameterDescriptor), null, null); descriptor.Initialize(obj, editingContext, runningInVS); return(descriptor); } else if (parameter.Parent is Function) { //Stored procedure parameter descriptor (EFSParameterDescriptor) descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFSParameterDescriptor), null, null); descriptor.Initialize(obj, editingContext, runningInVS); return(descriptor); } } } } return(null); }
private static void RetrieveDiagramItemCollectionForEFObject( EntityDesignerDiagram diagram, EFObject efobject, DiagramItemCollection diagramItemCollection) { if (efobject == null) { return; } var cModel = efobject.RuntimeModelRoot() as ConceptualEntityModel; if (cModel == null) { // this either isn't a c-space object, or it is the ConceptualEntityModel node, so just return null return; } // if this is a child element of the association, return the diagram item for the association if (!(efobject is Association)) { var association = efobject.GetParentOfType(typeof(Association)) as Association; if (association != null) { RetrieveDiagramItemCollectionForEFObject(diagram, association, diagramItemCollection); return; } } if (efobject is Association) { var shapeElement = GetDesignerShapeElementForEFObject(diagram, efobject); if (shapeElement != null) { diagramItemCollection.Add(new DiagramItem(shapeElement)); return; } } else if (efobject is NavigationProperty) { var np = efobject as NavigationProperty; var shapeElement = GetDesignerShapeElementForEFObject(diagram, np.Parent); var entityTypeShape = shapeElement as EntityTypeShape; if (entityTypeShape != null) { // get the view model navigation property var vmNavProp = diagram.ModelElement.ModelXRef.GetExisting(np) as ViewModel.NavigationProperty; // try to create the DiagramItem from this if (vmNavProp != null) { var index = entityTypeShape.NavigationCompartment.Items.IndexOf(vmNavProp); if (index >= 0) { diagramItemCollection.Add( new DiagramItem( entityTypeShape.NavigationCompartment, entityTypeShape.NavigationCompartment.ListField, new ListItemSubField(index))); return; } } } } else if (efobject is Property) { var prop = efobject as Property; if (prop.IsComplexTypeProperty) { // complex type properties are not supported in the designer return; } var shapeElement = GetDesignerShapeElementForEFObject(diagram, prop.Parent); var entityTypeShape = shapeElement as EntityTypeShape; if (entityTypeShape != null) { // get the view model property var vmProp = diagram.ModelElement.ModelXRef.GetExisting(prop) as ViewModel.Property; if (vmProp != null) { var index = entityTypeShape.PropertiesCompartment.Items.IndexOf(vmProp); if (index >= 0) { diagramItemCollection.Add( new DiagramItem( entityTypeShape.PropertiesCompartment, entityTypeShape.PropertiesCompartment.ListField, new ListItemSubField(index))); return; } } } } else if (efobject is EntityType) { var shapeElement = GetDesignerShapeElementForEFObject(diagram, efobject); if (shapeElement != null) { diagramItemCollection.Add(new DiagramItem(shapeElement)); return; } } else if (efobject is EntitySet) { var es = efobject as EntitySet; foreach (var entityType in es.GetEntityTypesInTheSet()) { if (entityType != null) { RetrieveDiagramItemCollectionForEFObject(diagram, entityType, diagramItemCollection); } } return; } else if (efobject is AssociationSet) { // return a diagram item for the association var associationSet = efobject as AssociationSet; var association = associationSet.Association.Target; if (association != null) { RetrieveDiagramItemCollectionForEFObject(diagram, association, diagramItemCollection); return; } } else if (efobject is AssociationSetEnd) { var associationSetEnd = efobject as AssociationSetEnd; var end = associationSetEnd.Role.Target; if (end != null) { RetrieveDiagramItemCollectionForEFObject(diagram, end, diagramItemCollection); return; } else { var es = associationSetEnd.EntitySet.Target; if (es != null) { RetrieveDiagramItemCollectionForEFObject(diagram, es, diagramItemCollection); return; } } } else if (efobject is PropertyRef) { var pref = efobject as PropertyRef; if (pref.Name.Target != null) { RetrieveDiagramItemCollectionForEFObject(diagram, pref.Name.Target, diagramItemCollection); return; } } else if (efobject is PropertyRefContainer) { var prefContainer = efobject as PropertyRefContainer; // just use the first entry in the list. foreach (var pref in prefContainer.PropertyRefs) { RetrieveDiagramItemCollectionForEFObject(diagram, pref, diagramItemCollection); return; } } else if (efobject is EFAttribute) { // this is an EFAttribute node, so get the DiagramItem for the parent RetrieveDiagramItemCollectionForEFObject(diagram, efobject.Parent, diagramItemCollection); return; } else if (efobject is ConceptualEntityModel) { // nothing in the DSL surface to map to, so return null return; } else if (efobject is ConceptualEntityContainer) { // nothing in the DSL surface to map to, so return null return; } else if (efobject is FunctionImport) { // nothing in the DSL surface to map to, so return null return; } else { Debug.Fail("unexpected type of efobject. type = " + efobject.GetType()); if (efobject.Parent != null) { RetrieveDiagramItemCollectionForEFObject(diagram, efobject.Parent, diagramItemCollection); } } }
internal override DslModeling.ModelElement SynchronizeSingleDslModelElement( DslModeling.ModelElement parentViewModel, EFObject modelElement) { var t = modelElement.GetType(); if (t == typeof(ConceptualEntityType)) { return TranslateEntityType(parentViewModel as EntityDesignerViewModel, modelElement as ConceptualEntityType); } else if (t == typeof(EntityTypeBaseType)) { return TranslateBaseType(parentViewModel as EntityDesignerViewModel, (modelElement).Parent as ConceptualEntityType); } else if (t == typeof(ModelNavigationProperty)) { return TranslateNavigationProperty(parentViewModel as ViewModelEntityType, modelElement as ModelNavigationProperty); } else if (t == typeof(ComplexConceptualProperty) || t == typeof(ConceptualProperty)) { return TranslateProperty(parentViewModel as ViewModelEntityType, modelElement as ModelProperty); } else if (t == typeof(ModelAssociation)) { return TranslateAssociation(parentViewModel as EntityDesignerViewModel, modelElement as ModelAssociation); } else if (t == typeof(DesignerModel.Diagram)) { return TranslateDiagramValues(parentViewModel as EntityDesignerViewModel, modelElement as DesignerModel.Diagram); } Debug.Assert(false, "modelElement with type= " + t.Name + " is not supported"); return null; }
private static ExplorerTreeViewItem GetTreeViewItemForEFObject(EFObject efobject, ExplorerFrame explorerFrame) { var treeViewItem = explorerFrame.ExplorerTreeRoot; if (null != efobject && !(efobject is EFArtifact)) { var entityDesignArtifact = efobject.Artifact.ArtifactSet.GetEntityDesignArtifact(); var editingContext = PackageManager.Package.DocumentFrameMgr.EditingContextManager.GetNewOrExistingContext(entityDesignArtifact.Uri); var element = explorerFrame.ExplorerViewModelHelper.GetExplorerEFElementForEFObject(editingContext, efobject); Debug.Assert(element != null, "Unable to find ExplorerEFElement for efobject of type " + efobject.GetType()); if (element != null) { treeViewItem = explorerFrame.GetTreeViewItem(element, true); } } return treeViewItem; }