Ejemplo n.º 1
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method is used to copy/paste a new item.</summary>
        ///
        /// <param name="copyItem">The item to copy/paste.</param>
        /// <param name="savePaste">Flag to determine whether to save the results of the paste.</param>
        ///--------------------------------------------------------------------------------
        public ModelObjectViewModel PasteModelObject(ModelObjectViewModel copyItem, bool savePaste = true)
        {
            ModelObject newItem = new ModelObject();

            newItem.ReverseInstance = new ModelObject();
            newItem.TransformDataFromObject(copyItem.ModelObject, null, false);
            newItem.ModelObjectID = Guid.NewGuid();
            newItem.IsAutoUpdated = false;

            // try to find referenced ModelObject by existing id first, second by old id, finally by name
            newItem.ParentModelObject = Solution.ModelObjectList.FindByID((Guid)copyItem.ModelObject.ParentModelObjectID);
            if (newItem.ParentModelObject == null && Solution.PasteNewGuids[copyItem.ModelObject.ParentModelObjectID.ToString()] is Guid)
            {
                newItem.ParentModelObject = Solution.ModelObjectList.FindByID((Guid)Solution.PasteNewGuids[copyItem.ModelObject.ParentModelObjectID.ToString()]);
            }
            if (newItem.ParentModelObject == null)
            {
                newItem.ParentModelObject = Solution.ModelObjectList.Find("Name", copyItem.ModelObject.Name);
            }
            if (newItem.ParentModelObject == null)
            {
                newItem.OldParentModelObjectID = newItem.ParentModelObjectID;
                newItem.ParentModelObjectID    = Guid.Empty;
            }
            newItem.Model    = Model;
            newItem.Solution = Solution;
            ModelObjectViewModel newView = new ModelObjectViewModel(newItem, Solution);

            newView.ResetModified(true);
            AddModelObject(newView);

            // paste children
            foreach (ModelPropertyViewModel childView in copyItem.ModelProperties)
            {
                newView.PasteModelProperty(childView, savePaste);
            }
            if (savePaste == true)
            {
                Solution.ModelObjectList.Add(newItem);
                Model.ModelObjectList.Add(newItem);
                newView.OnUpdated(this, null);
                Solution.ResetModified(true);
            }
            return(newView);
        }
Ejemplo n.º 2
0
 ///--------------------------------------------------------------------------------
 /// <summary>This method loads ModelObjects into the view model.</summary>
 ///
 /// <param name="model">The model to load.</param>
 /// <param name="solution">The associated solution.</param>
 /// <param name="loadChildren">Flag indicating whether to perform a deeper load.</param>
 ///--------------------------------------------------------------------------------
 public void LoadModelObjects(Model model, Solution solution, bool loadChildren = true)
 {
     // attach the items
     Items.Clear();
     if (ModelObjects == null)
     {
         ModelObjects = new EnterpriseDataObjectList <ModelObjectViewModel>();
     }
     if (loadChildren == true)
     {
         foreach (ModelObject item in model.ModelObjectList)
         {
             ModelObjectViewModel itemView = new ModelObjectViewModel(item, solution);
             itemView.Updated += new EventHandler(Children_Updated);
             ModelObjects.Add(itemView);
             Items.Add(itemView);
         }
     }
 }
Ejemplo n.º 3
0
 ///--------------------------------------------------------------------------------
 /// <summary>This method applies modelobject updates.</summary>
 ///--------------------------------------------------------------------------------
 public void ProcessEditModelObjectPerformed(ModelObjectEventArgs data)
 {
     try
     {
         bool isItemMatch = false;
         if (data != null && data.ModelObject != null)
         {
             foreach (ModelObjectViewModel item in ModelObjects)
             {
                 if (item.ModelObject.ModelObjectID == data.ModelObject.ModelObjectID)
                 {
                     isItemMatch = true;
                     item.ModelObject.TransformDataFromObject(data.ModelObject, null, false);
                     item.OnUpdated(item, null);
                     item.ShowInTreeView();
                     break;
                 }
             }
             if (isItemMatch == false)
             {
                 // add new ModelObject
                 data.ModelObject.Model = Model;
                 ModelObjectViewModel newItem = new ModelObjectViewModel(data.ModelObject, Solution);
                 newItem.Updated += new EventHandler(Children_Updated);
                 ModelObjects.Add(newItem);
                 Model.ModelObjectList.Add(newItem.ModelObject);
                 Solution.ModelObjectList.Add(newItem.ModelObject);
                 Items.Add(newItem);
                 OnUpdated(this, null);
                 newItem.ShowInTreeView();
             }
         }
     }
     catch (Exception ex)
     {
         ShowIssue(ex.Message + ex.StackTrace);
     }
 }
Ejemplo n.º 4
0
 ///--------------------------------------------------------------------------------
 /// <summary>This method deletes an instance of ModelObject from the view model.</summary>
 ///
 /// <param name="itemView">The ModelObject to delete.</param>
 ///--------------------------------------------------------------------------------
 public void DeleteModelObject(ModelObjectViewModel itemView)
 {
     itemView.Updated -= Children_Updated;
     ModelObjects.Remove(itemView);
     Delete(itemView);
 }
Ejemplo n.º 5
0
 ///--------------------------------------------------------------------------------
 /// <summary>This method adds an instance of ModelObject to the view model.</summary>
 ///
 /// <param name="itemView">The ModelObject to add.</param>
 ///--------------------------------------------------------------------------------
 public void AddModelObject(ModelObjectViewModel itemView)
 {
     itemView.Updated += new EventHandler(Children_Updated);
     ModelObjects.Add(itemView);
     Add(itemView);
 }
        ///--------------------------------------------------------------------------------
        /// <summary>This method applies model deletes.</summary>
        ///--------------------------------------------------------------------------------
        public void ProcessDeleteModelPerformed(ModelEventArgs data)
        {
            try
            {
                bool isItemMatch = false;
                if (data != null && data.Model != null)
                {
                    foreach (ModelViewModel item in Models.ToList <ModelViewModel>())
                    {
                        if (item.Model.ModelID == data.Model.ModelID)
                        {
                            // remove item from tabs, if present
                            WorkspaceEventArgs message = new WorkspaceEventArgs();
                            message.ItemID = item.Model.ModelID;
                            Mediator.NotifyColleagues <WorkspaceEventArgs>(MediatorMessages.Command_CloseItemRequested, message);

                            // delete children
                            for (int i = item.Items.Count - 1; i >= 0; i--)
                            {
                                if (item.Items[i] is EnumerationViewModel)
                                {
                                    EnumerationViewModel child        = item.Items[i] as EnumerationViewModel;
                                    EnumerationEventArgs childMessage = new EnumerationEventArgs();
                                    childMessage.Enumeration = child.Enumeration;
                                    childMessage.ModelID     = item.Model.ModelID;
                                    childMessage.Solution    = Solution;
                                    childMessage.WorkspaceID = child.WorkspaceID;
                                    item.EnumerationsFolder.ProcessDeleteEnumerationPerformed(childMessage);
                                }
                                if (item.Items[i] is ModelObjectViewModel)
                                {
                                    ModelObjectViewModel child        = item.Items[i] as ModelObjectViewModel;
                                    ModelObjectEventArgs childMessage = new ModelObjectEventArgs();
                                    childMessage.ModelObject = child.ModelObject;
                                    childMessage.ModelID     = item.Model.ModelID;
                                    childMessage.Solution    = Solution;
                                    childMessage.WorkspaceID = child.WorkspaceID;
                                    item.ModelObjectsFolder.ProcessDeleteModelObjectPerformed(childMessage);
                                }
                            }

                            // delete item
                            isItemMatch = true;
                            Models.Remove(item);
                            Solution.ModelList.Remove(item.Model);
                            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);
            }
        }