///-------------------------------------------------------------------------------- /// <summary>This method applies objectinstance deletes.</summary> ///-------------------------------------------------------------------------------- public void ProcessDeleteObjectInstancePerformed(ObjectInstanceEventArgs data) { try { bool isItemMatch = false; if (data != null && data.ObjectInstance != null) { foreach (ObjectInstanceViewModel item in ObjectInstances.ToList <ObjectInstanceViewModel>()) { if (item.ObjectInstance.ObjectInstanceID == data.ObjectInstance.ObjectInstanceID) { // remove item from tabs, if present WorkspaceEventArgs message = new WorkspaceEventArgs(); message.ItemID = item.ObjectInstance.ObjectInstanceID; Mediator.NotifyColleagues <WorkspaceEventArgs>(MediatorMessages.Command_CloseItemRequested, message); // delete children for (int i = item.Items.Count - 1; i >= 0; i--) { if (item.Items[i] is PropertyInstanceViewModel) { PropertyInstanceViewModel child = item.Items[i] as PropertyInstanceViewModel; PropertyInstanceEventArgs childMessage = new PropertyInstanceEventArgs(); childMessage.PropertyInstance = child.PropertyInstance; childMessage.ObjectInstanceID = item.ObjectInstance.ObjectInstanceID; childMessage.Solution = Solution; childMessage.WorkspaceID = child.WorkspaceID; item.ProcessDeletePropertyInstancePerformed(childMessage); } } // delete item isItemMatch = true; ObjectInstances.Remove(item); ModelObject.ObjectInstanceList.Remove(item.ObjectInstance); Items.Remove(item); ModelObject.ResetModified(true); OnUpdated(this, null); break; } } if (isItemMatch == false) { ShowIssue(DisplayValues.Issue_DeleteItemNotFound); } } } catch (Exception ex) { ShowIssue(ex.Message + ex.StackTrace); } }
///-------------------------------------------------------------------------------- /// <summary>This method processes the new ObjectInstance command.</summary> ///-------------------------------------------------------------------------------- public void ProcessNewObjectInstanceCommand() { ObjectInstanceEventArgs message = new ObjectInstanceEventArgs(); message.ObjectInstance = new ObjectInstance(); message.ObjectInstance.ObjectInstanceID = Guid.NewGuid(); message.ObjectInstance.ModelObjectID = ModelObjectID; message.ObjectInstance.ModelObject = Solution.ModelObjectList.FindByID(ModelObjectID); message.ObjectInstance.Solution = Solution; message.ModelObjectID = ModelObjectID; message.Solution = Solution; message.WorkspaceID = WorkspaceID; Mediator.NotifyColleagues <ObjectInstanceEventArgs>(MediatorMessages.Command_EditObjectInstanceRequested, message); }
public void ProcessDeleteObjectInstanceRequested(ObjectInstanceEventArgs data) { if (SolutionsFolder != null) { foreach (SolutionViewModel solution in SolutionsFolder.Solutions) { if (solution.Solution.SolutionID == data.Solution.SolutionID) { EditWorkspaceViewModel parentView = solution.FindParentViewModel(data); if (parentView is ModelObjectDataViewModel) { (parentView as ModelObjectDataViewModel).ProcessDeleteObjectInstancePerformed(data); } break; } } } }
///-------------------------------------------------------------------------------- /// <summary>This method applies objectinstance updates.</summary> ///-------------------------------------------------------------------------------- public void ProcessEditObjectInstancePerformed(ObjectInstanceEventArgs data) { try { bool isItemMatch = false; if (data != null && data.ObjectInstance != null) { foreach (ObjectInstanceViewModel item in ObjectInstances) { if (item.ObjectInstance.ObjectInstanceID == data.ObjectInstance.ObjectInstanceID) { isItemMatch = true; item.ObjectInstance.TransformDataFromObject(data.ObjectInstance, null, false); item.OnUpdated(item, null); item.ShowInTreeView(); break; } } if (isItemMatch == false) { // add new ObjectInstance data.ObjectInstance.ModelObject = ModelObject; ObjectInstanceViewModel newItem = new ObjectInstanceViewModel(data.ObjectInstance, Solution); newItem.Updated += new EventHandler(Children_Updated); ObjectInstances.Add(newItem); ModelObject.ObjectInstanceList.Add(newItem.ObjectInstance); Solution.ObjectInstanceList.Add(newItem.ObjectInstance); Items.Add(newItem); OnUpdated(this, null); newItem.ShowInTreeView(); } } } catch (Exception ex) { ShowIssue(ex.Message + ex.StackTrace); } }