///--------------------------------------------------------------------------------
 /// <summary>Create the instance with the designer view and other data.</summary>
 ///
 /// <param name="propertyInstances">The PropertyInstance items to load.</param>
 /// <param name="modelProperty">The model property.</param>
 /// <param name="objectInstanceViewModel">The associated object instance view model.</param>
 /// <param name="solution">The associated solution.</param>
 ///--------------------------------------------------------------------------------
 public PropertyCollectionItemViewModel(EnterpriseDataObjectList <PropertyInstanceViewModel> propertyInstances, ModelProperty modelProperty, ObjectInstanceViewModel objectInstanceViewModel, Solution solution)
 {
     WorkspaceID             = Guid.NewGuid();
     Solution                = solution;
     PropertyInstances       = propertyInstances;
     ObjectInstanceViewModel = objectInstanceViewModel;
     ModelProperty           = modelProperty;
 }
 ///--------------------------------------------------------------------------------
 /// <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);
     }
 }
        ///--------------------------------------------------------------------------------
        /// <summary>This method loads an item of ModelObjectData into the view model.</summary>
        ///
        /// <param name="model">The Model to load.</param>
        /// <param name="modelObject">The ModelObject to load.</param>
        /// <param name="objectInstance">The ObjectInstance to load.</param>
        /// <param name="solution">The Solution to load.</param>
        /// <param name="loadChildren">Flag indicating whether to perform a deeper load.</param>
        ///--------------------------------------------------------------------------------
        public void LoadModelObjectData(Model model, ModelObject modelObject, ObjectInstance objectInstance, Solution solution, bool loadChildren = true)
        {
            // attach the ModelObject
            Model          = model;
            ModelObject    = modelObject;
            ObjectInstance = objectInstance;
            Solution       = solution;
            ItemID         = ModelObject.ModelID;
            Items.Clear();
            if (loadChildren == true)
            {
                // attach ObjectInstances
                if (ObjectInstances == null)
                {
                    ObjectInstances = new EnterpriseDataObjectList <ObjectInstanceViewModel>();
                    foreach (ObjectInstance item in modelObject.ObjectInstanceList)
                    {
                        if (item.Solution == null)
                        {
                            // TODO: this is a hack
                            item.Solution = solution;
                        }
                        if (objectInstance == null || item.ParentObjectInstanceID == objectInstance.ObjectInstanceID)
                        {
                            ObjectInstanceViewModel itemView = new ObjectInstanceViewModel(item, solution);
                            itemView.Updated += new EventHandler(Children_Updated);
                            ObjectInstances.Add(itemView);
                            Items.Add(itemView);
                        }
                    }
                }
                #region protected
                #endregion protected

                Refresh(false);
            }
        }