예제 #1
0
        internal static void SelectDiagramItems(
            this EntityDesignerView.EntityDesignerDiagram entityDesignerDiagram, ShapeElement[] shapeElements)
        {
            var diagramItemCollection = new DiagramItemCollection();

            foreach (var shapeElement in shapeElements)
            {
                diagramItemCollection.Add(new DiagramItem(shapeElement));
            }

            if (entityDesignerDiagram.ActiveDiagramView != null)
            {
                entityDesignerDiagram.ActiveDiagramView.Focus();
                entityDesignerDiagram.ActiveDiagramView.Selection.Set(diagramItemCollection);
                entityDesignerDiagram.EnsureSelectionVisible();
            }
            else
            {
                // if no active diagram view is available, set the selection in any client view.
                if (entityDesignerDiagram.ClientViews != null &&
                    entityDesignerDiagram.ClientViews.Count > 0)
                {
                    foreach (DiagramClientView clientView in entityDesignerDiagram.ClientViews)
                    {
                        clientView.Selection.Set(diagramItemCollection);
                        clientView.Selection.EnsureVisible(DiagramClientView.EnsureVisiblePreferences.ScrollIntoViewCenter);
                        break;
                    }
                }
                else
                {
                    throw new InvalidOperationException("There is no active client views in the diagram.");
                }
            }
        }
 internal override EntityDesignerDiagram CreateDiagramHelper(Partition diagramPartition, ModelElement modelRoot)
 {
     var evm = modelRoot as EntityDesignerViewModel;
     var diagram = new EntityDesignerDiagram(diagramPartition);
     diagram.ModelElement = evm;
     return diagram;
 }
예제 #3
0
 internal static EntityDesignerView.EntityTypeShape GetShape(
     this EntityDesignerView.EntityDesignerDiagram entityDesignerDiagram, string name)
 {
     return(entityDesignerDiagram
            .NestedChildShapes
            .OfType <EntityDesignerView.EntityTypeShape>()
            .SingleOrDefault(ets => ((EntityDesignerViewModel.EntityType)ets.ModelElement).Name == name));
 }
        internal static void StaticInvoke(CommandProcessorContext cpc, EntityDesignerDiagram diagram)
        {
            var viewModel = diagram.ModelElement;
            Debug.Assert(viewModel != null, "Why Diagram's Model Element is null?");

            if (viewModel != null)
            {
                var artifact = cpc.Artifact;
                Debug.Assert(artifact != null && artifact.DesignerInfo() != null && artifact.DesignerInfo().Diagrams != null);
                if (artifact != null
                    && artifact.DesignerInfo() != null
                    && artifact.DesignerInfo().Diagrams != null)
                {
                    var modelDiagram = CreateDiagramCommand.CreateDiagramWithDefaultName(cpc);
                    Debug.Assert(modelDiagram != null);
                    using (var t = diagram.Store.TransactionManager.BeginTransaction("Set Diagram Id", false))
                    {
                        diagram.DiagramId = modelDiagram.Id.Value;
                        t.Commit();
                    }
                    viewModel.ModelXRef.Add(modelDiagram, diagram, viewModel.EditingContext);
                }
            }
        }
예제 #5
0
        public void TransactionCommit(EntityDesignerDiagram diagram)
        {
            //If this is a Drag & Drop from the SE transaction, then arrange the new elements
            if (_autoArrangeInfo.Tracking)
            {
                if (_autoArrangeInfo.Objects.Count > 0
                    || _autoArrangeInfo.HiddenObjects.Count > 0)
                {
                    //Arrange the new elemenst before the transaction finishes:
                    using (var t = diagram.Store.TransactionManager.BeginTransaction(Resources.Tx_LayoutDiagram))
                    {
                        //Place single object where the user dropped, and multiple get autoarranged
                        if (_autoArrangeInfo.Objects.Count > 0)
                        {
                            //Place the first entity-type-shape to where the user released the mouse and auto layout the rest.
                            var haveDropPoint = (!_autoArrangeDropPoint.IsEmpty);
                            var shapesToAutoLayout = new List<ShapeElement>();

                            var hasSetUserDefinedPosition = false;

                            foreach (var shape in _autoArrangeInfo.Objects)
                            {
                                var firstShape = shape as EntityTypeShape;
                                if (haveDropPoint
                                    && firstShape != null
                                    && !hasSetUserDefinedPosition)
                                {
                                    firstShape.Location = _autoArrangeDropPoint;
                                    hasSetUserDefinedPosition = true;
                                }
                                else
                                {
                                    shapesToAutoLayout.Add(shape);
                                }
                            }

                            if (shapesToAutoLayout.Count > 0)
                            {
                                diagram.AutoLayoutDiagram(shapesToAutoLayout);
                            }

                            t.Commit();
                        }

                        _autoArrangeInfo.Objects.Clear();
                    }

                    //Add hidden objects to 0,0
                    if (_autoArrangeInfo.HiddenObjects.Count > 0)
                    {
                        foreach (var se in _autoArrangeInfo.HiddenObjects)
                        {
                            var cs = se as EntityTypeShape;
                            cs.Location = new PointD(0, 0);
                        }

                        _autoArrangeInfo.HiddenObjects.Clear();
                    }
                }
            }
        }
        internal override void SaveModelAndDiagram(
            SerializationResult serializationResult, EntityDesignerViewModel modelRoot, string modelFileName, EntityDesignerDiagram diagram,
            string diagramFileName, Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
        {
            // only save the model
            base.SaveModel(serializationResult, modelRoot, modelFileName, encoding, writeOptionalPropertiesWithDefaultValue);

            if (!serializationResult.Failed)
            {
                // flip our dirty bit (as long as we aren't trying to save the auto-recovery backup file)
                var artifact = EditingContextManager.GetArtifact(modelRoot.EditingContext);
                Debug.Assert(artifact != null, "Failed to get a valid EFArtifact from the context");

                IEntityDesignDocData docData = null;
                var fileName = String.Empty;
                if (artifact != null)
                {
                    fileName = artifact.Uri.LocalPath;
                }

                docData = VSHelpers.GetDocData(PackageManager.Package, fileName) as IEntityDesignDocData;
                Debug.Assert(docData != null, "Couldn't locate our DocData");
                if (artifact != null
                    && docData != null
                    && !string.Equals(docData.BackupFileName, modelFileName, StringComparison.OrdinalIgnoreCase))
                {
                    artifact.IsDirty = false;
                }

                // SaveDiagram file if the file exists
                // TODO: What happened if saving diagram file failed? Should we rollback the model file?
                var diagramDocData =
                    VSHelpers.GetDocData(PackageManager.Package, fileName + EntityDesignArtifact.ExtensionDiagram) as XmlModelDocData;
                if (diagramDocData != null)
                {
                    int saveIsCancelled;
                    diagramDocData.SaveDocData(VSSAVEFLAGS.VSSAVE_SilentSave, out diagramFileName, out saveIsCancelled);
                }
            }
        }
 internal override void SaveDiagram(
     SerializationResult serializationResult, EntityDesignerDiagram diagram, string diagramFileName, Encoding encoding,
     bool writeOptionalPropertiesWithDefaultValue)
 {
     // don't save the .diagram file
     return;
 }
        internal static void CreateDefaultDiagram(EditingContext context, EntityDesignerDiagram diagram)
        {
            var service = context.GetEFArtifactService();
            var artifact = service.Artifact;
            Debug.Assert(artifact != null, "Artifact is null");

            var cpc = new CommandProcessorContext(
                context, EfiTransactionOriginator.EntityDesignerOriginatorId, EntityDesignerResources.Tx_CreateDiagram);
            var cmd = new DelegateCommand(
                () =>
                    {
                        EntityDesignerDiagramAdd.StaticInvoke(cpc, diagram);

                        foreach (var shapeElement in diagram.NestedChildShapes)
                        {
                            var entityShape = shapeElement as EntityTypeShape;
                            if (entityShape != null)
                            {
                                EntityTypeShapeAdd.StaticInvoke(cpc, entityShape);
                                EntityTypeShapeChange.StaticInvoke(
                                    cpc, entityShape, ViewModelDiagram.NodeShape.AbsoluteBoundsDomainPropertyId);
                                EntityTypeShapeChange.StaticInvoke(cpc, entityShape, ViewModelDiagram.NodeShape.IsExpandedDomainPropertyId);
                                continue;
                            }

                            var associationConnector = shapeElement as AssociationConnector;
                            if (associationConnector != null)
                            {
                                AssociationConnectorAdd.StaticInvoke(cpc, associationConnector);
                                AssociationConnectorChange.StaticInvoke(
                                    cpc, associationConnector, ViewModelDiagram.LinkShape.EdgePointsDomainPropertyId);
                                AssociationConnectorChange.StaticInvoke(
                                    cpc, associationConnector, ViewModelDiagram.LinkShape.ManuallyRoutedDomainPropertyId);
                                continue;
                            }

                            var inheritanceConnector = shapeElement as InheritanceConnector;
                            if (inheritanceConnector != null)
                            {
                                InheritanceConnectorAdd.StaticInvoke(cpc, inheritanceConnector);
                                InheritanceConnectorChange.StaticInvoke(
                                    cpc, inheritanceConnector, ViewModelDiagram.LinkShape.EdgePointsDomainPropertyId);
                                InheritanceConnectorChange.StaticInvoke(
                                    cpc, inheritanceConnector, ViewModelDiagram.LinkShape.ManuallyRoutedDomainPropertyId);
                                continue;
                            }
                        }
                    });
            CommandProcessor.InvokeSingleCommand(cpc, cmd);
        }
        internal static void TranslateDiagram(EntityDesignerDiagram diagram, DesignerModel.Diagram modelDiagram)
        {
            var viewModel = diagram.ModelElement;
            viewModel.ModelXRef.Add(modelDiagram, diagram, viewModel.EditingContext);

            using (var t = diagram.Store.TransactionManager.BeginTransaction("Translate diagram", true))
            {
                // list of shapes that don't have corresponding element in model and require auto-layout
                var shapesToAutoLayout = new List<ViewModelDiagram.ShapeElement>();

                // try to find object in model for each shape on a diagram
                foreach (var shapeElement in diagram.NestedChildShapes)
                {
                    var entityShape = shapeElement as EntityTypeShape;
                    if (entityShape != null
                        && entityShape.ModelElement != null)
                    {
                        var modelEntity = viewModel.ModelXRef.GetExisting(entityShape.ModelElement) as ModelEntityType;
                        if (modelEntity != null)
                        {
                            var modelEntityTypeShape =
                                modelDiagram.EntityTypeShapes.FirstOrDefault(ets => ets.EntityType.Target == modelEntity);
                            if (modelEntityTypeShape != null)
                            {
                                viewModel.ModelXRef.Add(modelEntityTypeShape, entityShape, viewModel.EditingContext);
                                var rectangle = new ViewModelDiagram.RectangleD(
                                    modelEntityTypeShape.PointX.Value, modelEntityTypeShape.PointY.Value
                                    , modelEntityTypeShape.Width.Value, 0.0);
                                entityShape.AbsoluteBounds = rectangle;
                                entityShape.IsExpanded = modelEntityTypeShape.IsExpanded.Value;
                                entityShape.FillColor = modelEntityTypeShape.FillColor.Value;
                            }
                        }
                        if (viewModel.ModelXRef.GetExisting(entityShape) == null)
                        {
                            shapesToAutoLayout.Add(entityShape);
                        }
                        continue;
                    }

                    var associationConnector = shapeElement as AssociationConnector;
                    if (associationConnector != null
                        && associationConnector.ModelElement != null)
                    {
                        var modelAssociation = viewModel.ModelXRef.GetExisting(associationConnector.ModelElement) as ModelAssociation;
                        if (modelAssociation != null)
                        {
                            var modelAssociationConnector =
                                modelDiagram.AssociationConnectors.FirstOrDefault(ac => ac.Association.Target == modelAssociation);
                            if (modelAssociationConnector != null)
                            {
                                viewModel.ModelXRef.Add(modelAssociationConnector, associationConnector, viewModel.EditingContext);
                                TranslateAssociationConnectors(associationConnector, modelAssociationConnector, shapesToAutoLayout);
                            }
                        }
                        continue;
                    }

                    var inheritanceConnector = shapeElement as InheritanceConnector;
                    if (inheritanceConnector != null
                        && inheritanceConnector.ModelElement != null)
                    {
                        var entityTypeBase = viewModel.ModelXRef.GetExisting(inheritanceConnector.ModelElement) as EntityTypeBaseType;
                        var modelEntity = entityTypeBase.Parent as ModelEntityType;
                        if (modelEntity != null)
                        {
                            var modelInheritanceConnector =
                                modelDiagram.InheritanceConnectors.FirstOrDefault(ic => ic.EntityType.Target == modelEntity);
                            if (modelInheritanceConnector != null)
                            {
                                viewModel.ModelXRef.Add(modelInheritanceConnector, inheritanceConnector, viewModel.EditingContext);
                                TranslateInheritanceConnectors(inheritanceConnector, modelInheritanceConnector, shapesToAutoLayout);
                            }
                        }
                        continue;
                    }
                }

                diagram.AutoLayoutDiagram(shapesToAutoLayout);

                // initiate zoom level, grid and scalar property options
                diagram.ZoomLevel = modelDiagram.ZoomLevel.Value;
                diagram.ShowGrid = modelDiagram.ShowGrid.Value;
                diagram.SnapToGrid = modelDiagram.SnapToGrid.Value;
                diagram.DisplayNameAndType = modelDiagram.DisplayType.Value;
                diagram.DiagramId = modelDiagram.Id.Value;
                diagram.Title = modelDiagram.Name.Value;

                t.Commit();
            }
        }
 protected EntityDesignerDiagramModelChange(EntityDesignerDiagram diagram)
 {
     _diagram = diagram;
 }
 internal EntityDesignerDiagramAdd(EntityDesignerDiagram diagram)
     : base(diagram)
 {
 }
예제 #12
0
        internal static void ExportAsImage(EntityDesignerDiagram diagram)
        {
            if (diagram != null)
            {
                using (var dlg = new SaveFileDialog())
                {
                    dlg.Title = Resources.ExportAsImageTitle;
                    dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                    dlg.Filter = Resources.ImageFormatBmp + "|*.bmp|" +
                                 Resources.ImageFormatJpeg + "|*.jpg|" +
                                 Resources.ImageFormatGif + "|*.gif|" +
                                 Resources.ImageFormatPng + "|*.png|" +
                                 Resources.ImageFormatTiff + "|*.tif";
                    dlg.FileName = Resources.ExportImage_DefaultFileName;
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        var childShapes = diagram.NestedChildShapes;
                        Debug.Assert(childShapes != null && childShapes.Count > 0, "Diagram '" + diagram.Title + "' is empty");

                        if (childShapes != null
                            && childShapes.Count > 0)
                        {
                            Bitmap bmp = null;
                            try
                            {
                                // image has a white background - so force the AssociationConnector text to take that into account
                                AssociationConnector.ForceDrawOnWhiteBackground = true;
                                AssociationConnector.IsColorThemeSet = false;
                                bmp = diagram.CreateBitmap(childShapes, Diagram.CreateBitmapPreference.FavorSmallSizeOverClarity);
                            }
                            finally
                            {
                                AssociationConnector.ForceDrawOnWhiteBackground = false;
                                AssociationConnector.IsColorThemeSet = false;
                            }

                            var imageFormat = ImageFormat.Bmp;
                            var fi = new FileInfo(dlg.FileName);
                            if (fi.Extension.Equals(".jpg", StringComparison.OrdinalIgnoreCase))
                            {
                                imageFormat = ImageFormat.Jpeg;
                            }
                            else if (fi.Extension.Equals(".gif", StringComparison.OrdinalIgnoreCase))
                            {
                                imageFormat = ImageFormat.Gif;
                            }
                            else if (fi.Extension.Equals(".png", StringComparison.OrdinalIgnoreCase))
                            {
                                imageFormat = ImageFormat.Png;
                            }
                            else if (fi.Extension.Equals(".tif", StringComparison.OrdinalIgnoreCase))
                            {
                                imageFormat = ImageFormat.Tiff;
                            }

                            using (var fs = new FileStream(dlg.FileName, FileMode.Create, FileAccess.ReadWrite))
                            {
                                bmp.Save(fs, imageFormat);
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 ///     Returns true if this is an empty diagram, false otherwise
 /// </summary>
 /// <param name="diagram"></param>
 /// <returns></returns>
 internal static bool IsEmptyDiagram(EntityDesignerDiagram diagram)
 {
     return (diagram != null) && (diagram.NestedChildShapes.Count == 0);
 }
 public EntityDesignerDiagramSelectionRules(EntityDesignerDiagram diagram)
 {
     _diagram = diagram;
 }
        /// <summary>
        ///     This class will set the focus on the "most-appropriate" DSL node for the given EFObject and DSL Diagram.  It is assumed that the
        ///     EFObject is either a C-Space node, or an M-space node.
        /// </summary>
        internal static bool NavigateToDSLNodeInDiagram(EntityDesignerDiagram diagram, EFObject efobject)
        {
            var foundDSLElementMatchInDiagram = false;
            var context = PackageManager.Package.DocumentFrameMgr.EditingContextManager.GetNewOrExistingContext(efobject.Artifact.Uri);

            // find the model parent (if this is a c-space object)
            var cModel = efobject.GetParentOfType(typeof(ConceptualEntityModel)) as ConceptualEntityModel;

            // by default, we assume that this our c-space object
            var cspaceEFObject = efobject;
            EFObject mspaceEFObject = null;
            if (cModel == null)
            {
                var mModel = efobject.GetParentOfType(typeof(MappingModel)) as MappingModel;
                Debug.Assert(mModel != null, "efobject is neither in c-space or s-space");

                // if this is a mapping node, then we want to find the closest corresponding c-space node
                // to which this mapping node is mapped, and set the focus on that.
                cspaceEFObject = GetCSpaceEFObjectForMSpaceEFObject(efobject);
                mspaceEFObject = efobject;
            }

            // navigate to the shape in the DSL designer
            var diagramItemCollection = new DiagramItemCollection();
            RetrieveDiagramItemCollectionForEFObject(diagram, cspaceEFObject, diagramItemCollection);
            if (diagram != null
                && diagramItemCollection.Count > 0)
            {
                diagram.Show();

                if (diagram.ActiveDiagramView != null)
                {
                    diagram.ActiveDiagramView.Focus();
                    diagram.ActiveDiagramView.Selection.Set(diagramItemCollection);
                    diagram.EnsureSelectionVisible();
                }
                else
                {
                    // If no active view exists, do the following:
                    // - Set the selection on the first associated views (if any).
                    // - Set InitialSelectionDIagramItemSelectionProperty to prevent the first EntityTypeShape to be selected (default behavior)
                    //   This case can happen when the diagram is not initialized or is not fully rendered.
                    diagram.InitialDiagramItemSelection = diagramItemCollection;
                    if (diagram.ClientViews != null
                        && diagram.ClientViews.Count > 0)
                    {
                        foreach (DiagramClientView clientView in diagram.ClientViews)
                        {
                            clientView.Selection.Set(diagramItemCollection);
                            clientView.Selection.EnsureVisible(DiagramClientView.EnsureVisiblePreferences.ScrollIntoViewCenter);
                            break;
                        }
                    }
                }
                foundDSLElementMatchInDiagram = true;
            }

            if (mspaceEFObject != null) // navigate to the item in the mapping screen (if we are doing MSL items)
            {
                var mappingDetailsInfo = context.Items.GetValue<MappingDetailsInfo>();
                if (mappingDetailsInfo.MappingDetailsWindow != null)
                {
                    mappingDetailsInfo.MappingDetailsWindow.NavigateTo(mspaceEFObject);
                }
            }

            return foundDSLElementMatchInDiagram;
        }
        /// <summary>
        ///     This method will return a DSL ShapeElement for the given efobject.  If the given efobject doesn't map to a designer shape,
        ///     then this will look for a designer shape for the object's parent.
        ///     If no designer shape can be found, this will return null.
        /// </summary>
        /// <param name="efobject"></param>
        /// <returns></returns>
        private static ShapeElement GetDesignerShapeElementForEFObject(EntityDesignerDiagram diagram, EFObject efobject)
        {
            ShapeElement shapeElement = null;
            while (shapeElement == null
                   && efobject != null
                   && ((efobject is ConceptualEntityModel) == false))
            {
                var dslElement = diagram.ModelElement.ModelXRef.GetExisting(efobject);
                shapeElement = dslElement as ShapeElement;

                if (shapeElement == null
                    && dslElement != null)
                {
                    var shapes = PresentationViewsSubject.GetPresentation(dslElement);

                    // just select the first shape for this item
                    if (shapes != null
                        && shapes.Count > 0)
                    {
                        shapeElement = shapes[0] as ShapeElement;
                    }
                }

                // walk up the EFObject tree until we find a node that has a ShapeElement.
                if (shapeElement == null)
                {
                    efobject = efobject.Parent;
                }
            }
            return shapeElement;
        }
        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);
                }
            }
        }