예제 #1
0
        public void UpdateSelection(OptionValueChangedEventArgs e)
        {
            if (e == null)
            {
                return;
            }
            if (inUpdate)
            {
                return;
            }
//      if (!optionItem.IsAlive) {
//        return;
//      }

//      IOptionItem oi = (IOptionItem)optionItem.Target;
            object value = e.NewValue;

            if (value == OptionItem.VALUE_UNDEFINED)
            {
                //no change
                return;
            }
            try {
                inUpdate = true;
                //lock selection for the duration of our update
                selection.BeginValueUpdate();

                ICollection <IPropertyItemDescriptor <T> > descriptors;
                descriptors = selection.Selection;

                bool hasChanged = false;
                foreach (IPropertyItemDescriptor <T> descriptor in descriptors)
                {
                    //get the propertyItem from the current lookup
                    IPropertyMap map = descriptor.Properties;
                    if (map == null)
                    {
                        continue;
                    }

                    //get value from current selection item
                    IPropertyItem item   = map.GetEntry(virtualPropertyName);
                    IValueSetter  setter = item != null ? item.Setter : null;
                    if (setter == null || !setter.CanSet())
                    {
                        continue;
                    }
                    setter.SetValue(value);
                    hasChanged = true;
                }

                if (hasChanged)
                {
                    selection.UpdateSelectedItems();
                }
            } finally {
                selection.EndValueUpdate();
                inUpdate = false;
            }
        }
            public void SetValue(object value)
            {
                T1 newInstance = parent.parent.CreateCopy(parent, parent.CurrentInstance);

                parent.SetTempInstance(newInstance);
                try {
                    if (setter.CanSet())
                    {
                        setter.SetValue(value);
                    }
                    else
                    {
                        return; // don't commit it.
                    }
                } finally {
                    parent.ResetTempInstance();
                }
                parent.SetNewInstance(newInstance);
            }
        ///<inheritdoc/>
        public virtual OptionItemValidities CheckValidity(ISelectionProvider <T> selection)
        {
            if (selection.Selection.Count == 0)
            {
                return(OptionItemValidities.Invalid);
            }
            OptionItemValidities retval = OptionItemValidities.ReadWrite;

            foreach (IPropertyItemDescriptor <T> descriptor in selection.Selection)
            {
                IPropertyMap map = descriptor.Properties;
                if (map == null)
                {
                    return(OptionItemValidities.Invalid);
                }
                IPropertyItem item = map.GetEntry(virtualPropertyName);
                if (item != null)
                {
                    IValueGetter getter = item.Getter;
                    IValueSetter setter = item.Setter;

                    if (getter != null && getter.CanGet())
                    {
                        if (setter == null || !setter.CanSet())
                        {
                            //readonly item...
                            retval = OptionItemValidities.ReadOnly;
                        }
                    }
                    else
                    {
                        //we can't even get the values :-(
                        return(OptionItemValidities.Invalid);
                    }
                }
                else
                {
                    return(OptionItemValidities.Invalid);
                }
            }
            return(retval);
        }
 public bool CanSet()
 {
     return(setter != null && setter.CanSet());
 }