///--------------------------------------------------------------------------------
 /// <summary>Create the instance with the designer view and other data.</summary>
 ///
 /// <param name="PropertyInstanceViewModel">The PropertyInstance to load.</param>
 ///
 /// <param name="modelProperty">The model property.</param>
 /// <param name="solution">The associated solution.</param>
 ///--------------------------------------------------------------------------------
 public PropertyItemViewModel(PropertyInstanceViewModel propertyInstanceViewModel, ModelProperty modelProperty, Solution solution)
 {
     WorkspaceID = Guid.NewGuid();
     Solution    = solution;
     PropertyInstanceViewModel = propertyInstanceViewModel;
     ModelProperty             = modelProperty;
 }
Ejemplo n.º 2
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method updates an item of PropertyInstance.</summary>
        ///
        /// <param name="propertyInstance">The PropertyInstance to update.</param>
        ///--------------------------------------------------------------------------------
        public void UpdateEditPropertyInstance(PropertyInstance propertyInstance)
        {
            bool isItemMatch = false;

            foreach (PropertyInstanceViewModel item in PropertyInstances)
            {
                if (item.PropertyInstance.PropertyInstanceID == propertyInstance.PropertyInstanceID)
                {
                    isItemMatch = true;
                    item.PropertyInstance.TransformDataFromObject(propertyInstance, null, false);
                    if (!item.PropertyInstance.ModelPropertyID.IsNullOrEmpty())
                    {
                        item.PropertyInstance.ModelProperty = Solution.ModelPropertyList.FindByID((Guid)item.PropertyInstance.ModelPropertyID);
                    }
                    item.OnUpdated(item, null);
                    break;
                }
            }
            if (isItemMatch == false)
            {
                // add new PropertyInstance
                propertyInstance.ObjectInstance = ObjectInstance;
                PropertyInstanceViewModel newItem = new PropertyInstanceViewModel(propertyInstance, Solution);
                if (!newItem.PropertyInstance.ModelPropertyID.IsNullOrEmpty())
                {
                    newItem.PropertyInstance.ModelProperty = Solution.ModelPropertyList.FindByID((Guid)newItem.PropertyInstance.ModelPropertyID);
                }
                newItem.Updated += new EventHandler(Children_Updated);
                PropertyInstances.Add(newItem);
                ObjectInstance.PropertyInstanceList.Add(propertyInstance);
                Solution.PropertyInstanceList.Add(newItem.PropertyInstance);
                Items.Add(newItem);
                OnUpdated(this, null);
            }
        }
        ///--------------------------------------------------------------------------------
        /// <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 adds to PropertyInstance adds.</summary>
        ///--------------------------------------------------------------------------------
        public void AddNewPropertyInstance()
        {
            PropertyInstanceViewModel item = new PropertyInstanceViewModel();

            item.PropertyInstance = new PropertyInstance();
            item.PropertyInstance.PropertyInstanceID = Guid.NewGuid();
            item.PropertyInstance.ObjectInstance     = ObjectInstanceViewModel.EditObjectInstance;
            item.PropertyInstance.ObjectInstanceID   = ObjectInstanceViewModel.EditObjectInstance.ObjectInstanceID;
            item.PropertyInstance.ModelPropertyID    = ModelProperty.ModelPropertyID;
            item.PropertyInstance.Solution           = Solution;
            item.Solution = Solution;

            ObjectInstanceViewModel.ItemsToAdd.Add(item);
            PropertyInstances.Add(item);
        }
Ejemplo n.º 5
0
        ///--------------------------------------------------------------------------------
        /// <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="modelProperty">The ModelProperty 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 LoadModelPropertyData(Model model, ModelObject modelObject, ModelProperty modelProperty, ObjectInstance objectInstance, Solution solution, bool loadChildren = true)
        {
            // attach the ModelObject
            Model          = model;
            ModelObject    = modelObject;
            ModelProperty  = modelProperty;
            ObjectInstance = objectInstance;
            Solution       = solution;
            ItemID         = ModelProperty.ModelPropertyID;
            Items.Clear();
            if (loadChildren == true)
            {
                // attach PropertyInstances
                if (PropertyInstances == null)
                {
                    PropertyInstances = new EnterpriseDataObjectList <PropertyInstanceViewModel>();
                    foreach (PropertyInstance item in objectInstance.PropertyInstanceList)
                    {
                        if (item.Solution == null)
                        {
                            // TODO: this is a hack
                            item.Solution = solution;
                        }
                        if (objectInstance == null || item.ModelPropertyID == modelProperty.ModelPropertyID)
                        {
                            PropertyInstanceViewModel itemView = new PropertyInstanceViewModel(item, solution);
                            itemView.Updated += new EventHandler(Children_Updated);
                            PropertyInstances.Add(itemView);
                            Items.Add(itemView);
                        }
                    }
                }
                #region protected
                #endregion protected

                Refresh(false);
            }
        }
 ///--------------------------------------------------------------------------------
 /// <summary>This method adds to PropertyInstance deletes.</summary>
 ///--------------------------------------------------------------------------------
 public void AddToDeletedPropertyInstances(PropertyInstanceViewModel item)
 {
     ObjectInstanceViewModel.ItemsToDelete.Add(item);
     PropertyInstances.Remove(item);
 }
Ejemplo n.º 7
0
 ///--------------------------------------------------------------------------------
 /// <summary>This method adds to PropertyInstance deletes.</summary>
 ///--------------------------------------------------------------------------------
 public void AddToDeletedPropertyInstances(PropertyInstanceViewModel item)
 {
     ItemsToDelete.Add(item);
     Items.Remove(item);
 }