///--------------------------------------------------------------------------------
        /// <summary>This method removes an entity from the view model.</summary>
        ///
        /// <param name="diagramEntity">The diagram entity to remove.</param>
        ///--------------------------------------------------------------------------------
        public void RemoveEntity(DiagramEntityViewModel diagramEntity, bool isDeleted = false)
        {
            // remove diagram entity
            DiagramEntities.Remove(diagramEntity);
            Items.Remove(diagramEntity);
            //diagramEntity.Dispose();
            ClearSelectedItems();
            if (isDeleted == false)
            {
                EntityViewModel entity = EntitiesRemoved.Find("EntityID", diagramEntity.EntityViewModel.EntityID);
                if (entity != null)
                {
                    EntitiesRemoved.Remove(entity);
                    Entities.Add(entity);
                    Entities.Sort("DisplayName", SortDirection.Ascending);
                }
            }
            IList <DiagramRelationshipViewModel> relationshipsToRemove = new List <DiagramRelationshipViewModel>();

            foreach (DiagramRelationshipViewModel diagramRelationship in DiagramRelationships)
            {
                if (diagramRelationship.SinkDiagramEntityViewModel.EntityID == diagramEntity.EntityID || diagramRelationship.SourceDiagramEntityViewModel.EntityID == diagramEntity.EntityID)
                {
                    relationshipsToRemove.Add(diagramRelationship);
                }
            }
            foreach (DiagramRelationshipViewModel diagramRelationship in relationshipsToRemove)
            {
                DiagramRelationships.Remove(diagramRelationship);
                Items.Remove(diagramRelationship);
            }
            Refresh(false);
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This method adds a relationship to the view model.</summary>
        ///
        /// <param name="sourceEntity">The source entity of the relationship to add.</param>
        /// <param name="sinkEntity">The sink entity of the relationship to add.</param>
        /// <param name="entityRelationship">The associated entity relationship.</param>
        ///--------------------------------------------------------------------------------
        public void AddRelationship(DiagramEntityViewModel sourceEntity, DiagramEntityViewModel sinkEntity, RelationshipViewModel entityRelationship)
        {
            // add diagram relationship to solution diagram
            DiagramRelationshipViewModel relationship = new DiagramRelationshipViewModel(sourceEntity, sinkEntity, sourceEntity.Diagram, entityRelationship);

            DiagramRelationships.Add(relationship);
            Items.Add(relationship);
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This method adds relationships for an entity to the view model.</summary>
        ///
        /// <param name="entity">The entity to add.</param>
        ///--------------------------------------------------------------------------------
        public void AddRelationships(DiagramEntityViewModel diagramEntity)
        {
            NameObjectCollection relationshipsAdded = new NameObjectCollection();

            // add relationships this entity is the source of
            foreach (Relationship relationship in diagramEntity.EntityViewModel.Entity.RelationshipList)
            {
                bool isDeletedRelationship = false;
                foreach (DiagramRelationshipViewModel diagramRelationship in ItemsToDelete.OfType <DiagramRelationshipViewModel>())
                {
                    if (diagramRelationship.RelationshipViewModel.Relationship.RelationshipID == relationship.RelationshipID)
                    {
                        isDeletedRelationship = true;
                        break;
                    }
                }
                if (isDeletedRelationship == false && relationshipsAdded[relationship.RelationshipID.ToString()] == null)
                {
                    foreach (DiagramEntityViewModel loopEntity in DiagramEntities)
                    {
                        if (relationship.ReferencedEntityID == loopEntity.EntityViewModel.Entity.EntityID)
                        {
                            RelationshipViewModel relationshipViewModel = new RelationshipViewModel(relationship, Solution);
                            AddRelationship(diagramEntity, loopEntity, relationshipViewModel);
                            relationshipsAdded[relationship.RelationshipID.ToString()] = true;
                        }
                    }
                }
            }

            // add relationships this entity is the sink of
            foreach (DiagramEntityViewModel loopEntity in DiagramEntities)
            {
                foreach (Relationship relationship in loopEntity.EntityViewModel.Entity.RelationshipList)
                {
                    if (relationship.ReferencedEntityID == diagramEntity.EntityViewModel.Entity.EntityID)
                    {
                        bool isDeletedRelationship = false;
                        foreach (DiagramRelationshipViewModel diagramRelationship in ItemsToDelete.OfType <DiagramRelationshipViewModel>())
                        {
                            if (diagramRelationship.RelationshipViewModel.Relationship.RelationshipID == relationship.RelationshipID)
                            {
                                isDeletedRelationship = true;
                                break;
                            }
                        }
                        if (isDeletedRelationship == false && relationshipsAdded[relationship.RelationshipID.ToString()] == null)
                        {
                            RelationshipViewModel relationshipViewModel = new RelationshipViewModel(relationship, Solution);
                            AddRelationship(loopEntity, diagramEntity, relationshipViewModel);
                            relationshipsAdded[relationship.RelationshipID.ToString()] = true;
                        }
                    }
                }
            }

            Refresh(false);
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This method deletes an entity from the view model and solution.</summary>
        ///
        /// <param name="entity">The entity to remove.</param>
        ///--------------------------------------------------------------------------------
        public void DeleteEntity(DiagramEntityViewModel entity)
        {
            // remove diagram entity
            RemoveEntity(entity, true);

            // add to deleted entity list
            ItemsToDelete.Add(entity);
            Refresh(false);
        }
Exemple #5
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method applies diagram deletes.</summary>
        ///--------------------------------------------------------------------------------
        public void ProcessDeleteDiagramPerformed(DiagramEventArgs data)
        {
            try
            {
                bool isItemMatch = false;
                if (data != null && data.Diagram != null)
                {
                    foreach (DiagramViewModel item in Diagrams.ToList <DiagramViewModel>())
                    {
                        if (item.Diagram.DiagramID == data.Diagram.DiagramID)
                        {
                            // remove item from tabs, if present
                            WorkspaceEventArgs message = new WorkspaceEventArgs();
                            message.ItemID = item.Diagram.DiagramID;
                            Mediator.NotifyColleagues <WorkspaceEventArgs>(MediatorMessages.Command_CloseItemRequested, message);

                            // delete children
                            for (int i = item.Items.Count - 1; i >= 0; i--)
                            {
                                if (item.Items[i] is DiagramEntityViewModel)
                                {
                                    DiagramEntityViewModel child        = item.Items[i] as DiagramEntityViewModel;
                                    DiagramEntityEventArgs childMessage = new DiagramEntityEventArgs();
                                    childMessage.DiagramEntity = child.DiagramEntity;
                                    childMessage.DiagramID     = item.Diagram.DiagramID;
                                    childMessage.Solution      = Solution;
                                    childMessage.WorkspaceID   = child.WorkspaceID;
                                    item.ProcessDeleteDiagramEntityPerformed(childMessage);
                                }
                            }

                            // delete item
                            isItemMatch = true;
                            Diagrams.Remove(item);
                            Solution.DiagramList.Remove(item.Diagram);
                            Items.Remove(item);
                            Solution.ResetModified(true);
                            OnUpdated(this, null);
                            break;
                        }
                    }
                    if (isItemMatch == false)
                    {
                        ShowIssue(DisplayValues.Issue_DeleteItemNotFound);
                    }
                }
            }
            catch (Exception ex)
            {
                ShowIssue(ex.Message + ex.StackTrace);
            }
        }
Exemple #6
0
 ///--------------------------------------------------------------------------------
 /// <summary>This method loads a diagram entity into the view model.</summary>
 ///
 /// <param name="sourceDiagramEntityViewModel">The associated source entity view model.</param>
 /// <param name="sinkDiagramEntityViewModel">The associated sink entity view model.</param>
 /// <param name="entityRelationship">The associated entity relationship.</param>
 ///--------------------------------------------------------------------------------
 public void LoadDiagramRelationship(DiagramEntityViewModel sourceDiagramEntityViewModel, DiagramEntityViewModel sinkDiagramEntityViewModel, RelationshipViewModel entityRelationship)
 {
     try
     {
         // attach the entities
         SourceDiagramEntityViewModel = sourceDiagramEntityViewModel;
         SinkDiagramEntityViewModel   = sinkDiagramEntityViewModel;
         RelationshipViewModel        = entityRelationship;
         HasCustomizations            = true;
         IsSelected = true;
     }
     catch (ApplicationException ex)
     {
         ShowException(ex);
     }
     catch (Exception ex)
     {
         ShowException(ex);
     }
 }
        ///--------------------------------------------------------------------------------
        /// <summary>This method creates an entity and adds to the view model.</summary>
        ///
        /// <param name="entity">The entity to add.</param>
        /// <param name="position">The desired position to place the entity.</param>
        ///--------------------------------------------------------------------------------
        public DiagramEntityViewModel CreateEntity(EntityViewModel entity, Point position)
        {
            // create diagram entity and add to solution diagram
            DiagramEntity dropDiagram = new DiagramEntity();

            dropDiagram.DiagramEntityID = Guid.NewGuid();
            DiagramEntityViewModel diagramEntity = new DiagramEntityViewModel(dropDiagram, entity, this);

            diagramEntity.X      = Math.Max(0, position.X);
            diagramEntity.Y      = Math.Max(0, position.Y);
            diagramEntity.Width  = Double.NaN;
            diagramEntity.Height = Double.NaN;
            DiagramEntities.Add(diagramEntity);
            Items.Add(diagramEntity);
            ClearSelectedItems();
            diagramEntity.IsSelected = true;
            diagramEntity.ZIndex     = ++ZIndex;

            // add to diagram entites to add list
            ItemsToAdd.Add(diagramEntity);
            Refresh(false);
            return(diagramEntity);
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This method adds an entity to the view model.</summary>
        ///
        /// <param name="entity">The entity to add.</param>
        /// <param name="position">The desired position to place the entity.</param>
        ///--------------------------------------------------------------------------------
        public DiagramEntityViewModel AddEntity(EntityViewModel entity, Point position, bool isNewEntity = false)
        {
            DiagramEntity dropDiagram = new DiagramEntity();

            dropDiagram.DiagramID       = DiagramID;
            dropDiagram.DiagramEntityID = Guid.NewGuid();
            EntityViewModel        entityView    = entity;
            DiagramEntityViewModel diagramEntity = new DiagramEntityViewModel(dropDiagram, entityView, this);

            diagramEntity.X        = Math.Max(0, position.X);
            diagramEntity.Y        = Math.Max(0, position.Y);
            diagramEntity.Width    = Double.NaN;
            diagramEntity.Height   = Double.NaN;
            diagramEntity.Updated += new EventHandler(Children_Updated);
            diagramEntity.DiagramEntity.Entity = diagramEntity.EntityViewModel.Entity;
            diagramEntity.ResetModified(false);
            diagramEntity.EditDiagramEntity.ResetModified(false);
            if (isNewEntity == true)
            {
                AddDiagramEntity(diagramEntity);
            }
            else
            {
                DiagramEntities.Add(diagramEntity);
                Items.Add(diagramEntity);
            }
            ClearSelectedItems();
            diagramEntity.IsSelected = true;
            diagramEntity.ZIndex     = ++ZIndex;
            Entities.Remove(entity);
            EntitiesRemoved.Add(entity);
            diagramEntity.PositionChanged += new EventHandler(diagramEntity_PositionChanged);

            AddRelationships(diagramEntity);

            return(diagramEntity);
        }
Exemple #9
0
 ///--------------------------------------------------------------------------------
 /// <summary>Create the instance with the designer view and other data.</summary>
 ///
 /// <param name="sourceDiagramEntityViewModel">The associated source entity view model.</param>
 /// <param name="sinkDiagramEntityViewModel">The associated sink entity view model.</param>
 /// <param name="solutionDiagram">The associated solution diagram.</param>
 /// <param name="entityRelationship">The associated entity relationship.</param>
 ///--------------------------------------------------------------------------------
 public DiagramRelationshipViewModel(DiagramEntityViewModel sourceDiagramEntityViewModel, DiagramEntityViewModel sinkDiagramEntityViewModel, DiagramViewModel solutionDiagram, RelationshipViewModel entityRelationship)
 {
     LoadDiagramRelationship(sourceDiagramEntityViewModel, sinkDiagramEntityViewModel, entityRelationship);
     WorkspaceID = Guid.NewGuid();
     Diagram     = solutionDiagram;
 }