///-------------------------------------------------------------------------------- /// <summary>This method updates the view model data and sends update command back /// to the solution builder.</summary> ///-------------------------------------------------------------------------------- protected override void OnUpdate() { // send update for any updated children foreach (ModelObjectViewModel item in ModelObjects) { if (item.IsEdited == true) { item.Update(); } } // send update for any new children foreach (ModelObjectViewModel item in ItemsToAdd.OfType <ModelObjectViewModel>()) { item.Update(); ModelObjects.Add(item); } ItemsToAdd.Clear(); // send delete for any deleted children foreach (ModelObjectViewModel item in ItemsToDelete.OfType <ModelObjectViewModel>()) { item.Delete(); ModelObjects.Remove(item); } ItemsToDelete.Clear(); // reset modified for children foreach (ModelObjectViewModel item in ModelObjects) { item.ResetModified(false); } }
///-------------------------------------------------------------------------------- /// <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); } } }
///-------------------------------------------------------------------------------- /// <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); } }
///-------------------------------------------------------------------------------- /// <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); }