예제 #1
0
        /// <summary>
        /// Converts the property value (in respect to multiple source elements) and returns the converted value.
        /// </summary>
        /// <returns>Converted property value.</returns>
        /// <remarks>
        /// Converter: All equal --> use value. One differs --> empty value.
        /// </remarks>
        public override object GetPropertyValue()
        {
            List <object> values = PropertyGridEditorViewModel.GetPropertyValues(this.Elements, this.PropertyName);

            if (values.Count == 0)
            {
                return("");
            }

            try
            {
                double value = Convert.ToDouble(values[0]);
                foreach (object v in values)
                {
                    if (value != Convert.ToDouble(v))
                    {
                        return("");
                    }
                }

                return(value.ToString());
            }
            catch
            {
                return("");
            }
        }
        /// <summary>
        /// Converts the property value (in respect to multiple source elements) and returns the converted value.
        /// </summary>
        /// <returns>Converted property value.</returns>
        /// <remarks>
        /// Converter: All equal --> use value. One differs --> null value.
        /// </remarks>
        public override object GetPropertyValue()
        {
            List <object> values = PropertyGridEditorViewModel.GetPropertyValues(this.Elements, this.PropertyName);

            if (values.Count == 0)
            {
                return(SentinelItem);
            }

            ModelElement value = values[0] as ModelElement;

            foreach (object v in values)
            {
                if (value != v as ModelElement)
                {
                    value = null;
                    break;
                }
            }

            if (value == null)
            {
                return(SentinelItem);
            }
            else
            {
                return(this.ViewModelStore.Factory.CreateModelElementBaseViewModel(value));
            }
        }
예제 #3
0
        /// <summary>
        /// Converts the property value (in respect to multiple source elements) and returns the converted value.
        /// </summary>
        /// <returns>Converted property value.</returns>
        /// <remarks>
        /// Converter: All equal --> use value. One differs --> null value.
        /// </remarks>
        public override object GetPropertyValue()
        {
            if (this.IsFlags)
            {
                return("");
            }

            List <object> values = PropertyGridEditorViewModel.GetPropertyValues(this.Elements, this.PropertyName);

            if (values.Count == 0)
            {
                return(NullElement);
            }

            Enum value = values[0] as Enum;

            foreach (object v in values)
            {
                if (value != v as Enum)
                {
                    value = null;
                    break;
                }
            }

            if (value == null)
            {
                return(NullElement);
            }
            else
            {
                return(value);
            }
        }
예제 #4
0
        /// <summary>
        /// Assigns the property value to the property of every source element.
        /// </summary>
        /// <param name="value">Property value to be assigned.</param>
        public override void SetPropertyValue(object value)
        {
            Double?valueD = null;

            // empty string values are treated as null...
            if (String.IsNullOrEmpty(value as string))
            {
                value = null;
            }
            if (String.IsNullOrWhiteSpace(value as string))
            {
                value = null;
            }

            try
            {
                if (value != null)
                {
                    valueD = Convert.ToDouble(value);
                }
            }
            catch
            {
                IMessageBoxService messageBox = this.GlobalServiceProvider.Resolve <IMessageBoxService>();
                messageBox.ShowError("Could not set new value: Conversion failed");
                return;
            }

            using (Transaction transaction = this.Store.TransactionManager.BeginTransaction("Update property value - " + this.PropertyName))
            {
                PropertyGridEditorViewModel.SetPropertyValues(this.Elements, this.PropertyName, valueD);
                transaction.Commit();
            }
        }
        /// <summary>
        /// Converts the property value (in respect to multiple source elements) and returns the converted value.
        /// </summary>
        /// <returns>Converted property value.</returns>
        /// <remarks>
        /// Converter: All equal --> use value. One differs --> null value.
        /// </remarks>
        public override object GetPropertyValue()
        {
            List <object> values = PropertyGridEditorViewModel.GetPropertyValues(this.Elements, this.PropertyName);

            if (values.Count == 0)
            {
                return(NullElement);
            }

            bool?value = values[0] as bool?;

            foreach (object v in values)
            {
                if (value != v as bool?)
                {
                    value = null;
                    break;
                }
            }

            if (value == null)
            {
                return(NullElement);
            }
            else if (value == true)
            {
                return(TrueElement);
            }
            else
            {
                return(FalseElement);
            }
        }
        /// <summary>
        /// Edit element executed.
        /// </summary>
        protected virtual void EditElementCommand_Executed()
        {
            // update the default values list first.
            this.UpdateDefaultValuesList();

            using (SelectElementViewModel vm = new SelectElementViewModel(this.ViewModelStore, this.DefaultValues))
            {
                vm.Title = "Select a role player";

                //if (this.Elements.Count == 1)
                //    vm.Title += " of type " + this.ViewModelStore.ElementTypeProvider.GetTypeDisplayName(this.Elements[0] as ModelElement);

                bool?result = this.GlobalServiceProvider.Resolve <IUIVisualizerService>().ShowDialog("SelectElementPopup", vm);
                if (result == true)
                {
                    try
                    {
                        using (Transaction transaction = this.Store.TransactionManager.BeginTransaction("Update role value - " + this.PropertyName))
                        {
                            PropertyGridEditorViewModel.SetPropertyValues(this.Elements, this.PropertyName, vm.SelectedElement);
                            transaction.Commit();
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Windows.MessageBox.Show("Error while adding: " + ex.Message);
                    }
                }
            }
            GC.Collect();
        }
예제 #7
0
 /// <summary>
 /// Subscribe to model element changes
 /// </summary>
 public override void SubscribeToModelChanges()
 {
     // subscribe to <#= domainElement.Name #>.<#= property.Name #> changes
     foreach (ModelElement modelElement in this.Elements)
     {
         Guid?propertyId = PropertyGridEditorViewModel.GetPropertyDomainObjectId(modelElement, this.PropertyName);
         if (propertyId != null)
         {
             this.EventManager.GetEvent <ModelElementPropertyChangedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainProperty(propertyId.Value), modelElement.Id, new System.Action <ElementPropertyChangedEventArgs>(OnPropertyChanged));
         }
     }
 }
예제 #8
0
        /// <summary>
        /// Unregister from events although they are weak.
        /// </summary>
        protected override void OnDispose()
        {
            foreach (ModelElement modelElement in this.Elements)
            {
                Guid?propertyId = PropertyGridEditorViewModel.GetPropertyDomainObjectId(modelElement, this.PropertyName);
                if (propertyId != null)
                {
                    this.EventManager.GetEvent <ModelElementPropertyChangedEvent>().Unsubscribe(this.Store.DomainDataDirectory.GetDomainProperty(propertyId.Value), modelElement.Id, new System.Action <ElementPropertyChangedEventArgs>(OnPropertyChanged));
                }
            }

            base.OnDispose();
        }
예제 #9
0
        /// <summary>
        /// Returns the default value for the current enumeration.
        /// </summary>
        /// <returns>List of default values.</returns>
        protected override List <object> GetDefaultValues()
        {
            Array array = Enum.GetValues(enumType);

            defaultValuesList = new List <object>();

            if (this.IsFlags)
            {
                if (this.Elements.Count == 1)
                {
                    Enum val = PropertyGridEditorViewModel.GetPropertyValue(this.Elements[0], this.PropertyName) as Enum;
                    if (val != null)
                    {
                        foreach (object obj in array)
                        {
                            if (!(obj is Enum))
                            {
                                continue;
                            }

                            bool bContains = false;
                            if (val.HasFlag((Enum)obj))
                            {
                                bContains = true;
                            }

                            Item item = new Item(this, obj, bContains);
                            defaultValuesList.Add(item);
                        }
                    }
                    else
                    {
                        foreach (object obj in array)
                        {
                            Item item = new Item(this, obj, false);
                            defaultValuesList.Add(item);
                        }
                    }
                }
            }
            else
            {
                foreach (object obj in array)
                {
                    defaultValuesList.Add(obj);
                }
            }

            return(defaultValuesList);
        }
예제 #10
0
        /// <summary>
        /// Assigns the property value to the property of every source element.
        /// </summary>
        /// <param name="value">Property value to be assigned.</param>
        public override void SetPropertyValue(object value)
        {
            if (!this.IsFlags)
            {
                Enum eValue = value as Enum;
                if (value as string == NullElement)
                {
                    eValue = null;
                }

                using (Transaction transaction = this.Store.TransactionManager.BeginTransaction("Update property value - " + this.PropertyName))
                {
                    PropertyGridEditorViewModel.SetPropertyValues(this.Elements, this.PropertyName, eValue);
                    transaction.Commit();
                }
            }
            else
            {
                Enum eValue;

                string v = value as String;
                if (String.IsNullOrEmpty(v))
                {
                    eValue = null;
                }
                else
                {
                    string[] vals       = v.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
                    string   parsedVals = "";

                    foreach (string literal in vals)
                    {
                        if (parsedVals != "")
                        {
                            parsedVals += ",";
                        }
                        parsedVals += literal.Trim();
                    }

                    eValue = (Enum)Enum.Parse(this.enumType, parsedVals);
                }

                using (Transaction transaction = this.Store.TransactionManager.BeginTransaction("Update property value - " + this.PropertyName))
                {
                    PropertyGridEditorViewModel.SetPropertyValues(this.Elements, this.PropertyName, eValue);
                    transaction.Commit();
                }
            }
        }
 /// <summary>
 /// Delete element executed.
 /// </summary>
 protected virtual void DeleteElementCommand_Executed()
 {
     try
     {
         using (Transaction transaction = this.Store.TransactionManager.BeginTransaction("Update role value - " + this.PropertyName))
         {
             PropertyGridEditorViewModel.SetPropertyValues(this.Elements, this.PropertyName, null);
             transaction.Commit();
         }
     }
     catch (Exception ex)
     {
         System.Windows.MessageBox.Show("Error while deleting: " + ex.Message);
     }
 }
예제 #12
0
        /// <summary>
        /// Converts the property value (in respect to multiple source elements) and returns the converted value.
        /// </summary>
        /// <returns>Converted property value.</returns>
        /// <remarks>
        /// Converter: All equal --> use value. One differs --> null value.
        /// </remarks>
        public override object GetPropertyValue()
        {
            object value = PropertyGridEditorViewModel.GetPropertyValue(this.Elements[0], this.PropertyName);

            if (value is IEnumerable)
            {
                List <BaseModelElementViewModel> models = new List <BaseModelElementViewModel>();
                foreach (ModelElement m in (IEnumerable)value)
                {
                    models.Add(this.ViewModelStore.Factory.CreateModelElementBaseViewModel(m));
                }
                return(models);
            }
            else
            {
                return(null);
            }
        }
예제 #13
0
        /// <summary>
        /// Assigns the property value to the property of every source element.
        /// </summary>
        /// <param name="value">Property value to be assigned.</param>
        public override void SetPropertyValue(object value)
        {
            // empty string values are treated as null...
            if (String.IsNullOrEmpty(value as string))
            {
                value = null;
            }
            if (String.IsNullOrWhiteSpace(value as string))
            {
                value = null;
            }

            using (Transaction transaction = this.Store.TransactionManager.BeginTransaction("Update property value - " + this.PropertyName))
            {
                PropertyGridEditorViewModel.SetPropertyValues(this.Elements, this.PropertyName, value);
                transaction.Commit();
            }
        }
예제 #14
0
        /// <summary>
        /// Assigns the property value to the property of every source element.
        /// </summary>
        /// <param name="value">Property value to be assigned.</param>
        public override void SetPropertyValue(object value)
        {
            bool?bValue = null;

            if (value as string == TrueElement)
            {
                bValue = true;
            }
            else if (value as string == FalseElement)
            {
                bValue = false;
            }

            using (Transaction transaction = this.Store.TransactionManager.BeginTransaction("Update property value - " + this.PropertyName))
            {
                PropertyGridEditorViewModel.SetPropertyValues(this.Elements, this.PropertyName, bValue);
                transaction.Commit();
            }
        }
예제 #15
0
        /// <summary>
        /// Converts the property value (in respect to multiple source elements) and returns the converted value.
        /// </summary>
        /// <returns>Converted property value.</returns>
        /// <remarks>
        /// Converter: All equal --> use value. One differs --> empty value.
        /// </remarks>
        public override object GetPropertyValue()
        {
            List <object> values = PropertyGridEditorViewModel.GetPropertyValues(this.Elements, this.PropertyName);

            if (values.Count == 0)
            {
                return("");
            }

            string value = values[0] as string;

            foreach (object v in values)
            {
                if (value != v as string)
                {
                    value = "";
                    break;
                }
            }

            return(value);
        }
 /// <summary>
 /// Compares two view models by comparing their property display names.
 /// </summary>
 /// <param name="x">IPropertyGridEditorViewModel to be compared.</param>
 /// <param name="y">IPropertyGridEditorViewModel to be compared.</param>
 /// <returns>Int from Compare.To</returns>
 private static int CompareViewModels(PropertyGridEditorViewModel x, PropertyGridEditorViewModel y)
 {
     return x.PropertyDisplayName.CompareTo(y.PropertyDisplayName);
 }
 /// <summary>
 /// Called whenever the selected editor is changed.
 /// </summary>
 public virtual void SelectedEditorChanged(PropertyGridEditorViewModel selectedEditor)
 {
 }