/// <summary> /// Helper method to update the DefaultableValue if and only if the value has changed /// </summary> /// <param name="existingValue"> /// existing value of attribute (StringOrNone.NoneValue indicates attribute /// currently does not exist) /// </param> /// <param name="newValue"> /// new value of attribute passed into setter (null indicates user did not select /// anything on the drop-down and so no setting should take place, StringOrNone.NoneValue indicates user /// selected '(None)' on the drop-down and so attribute should be removed if present) /// </param> /// <param name="defaultableValueToUpdate"></param> internal static void UpdateDefaultableValueIfValuesDiffer( StringOrNone existingValue, StringOrNone newValue, DefaultableValue <StringOrNone> defaultableValueToUpdate) { if (null == newValue) { // user exited drop-down without selecting anything return; } if (existingValue.Equals(newValue)) { // no change in value - so just return return; } else { // existingValue and valueToSet are different - so update the DefaultableValue // if newValue is NoneValue then set valueToSet to null which will remove the attribute // otherwise use newValue as is var valueToSet = (StringOrNone.NoneValue.Equals(newValue) ? null : newValue); var cmd = new UpdateDefaultableValueCommand <StringOrNone>(defaultableValueToUpdate, valueToSet); var cpc = PropertyWindowViewModelHelper.GetCommandProcessorContext(); CommandProcessor.InvokeSingleCommand(cpc, cmd); } }
private static void SetEndNavigationProperty(NavigationProperty navProp, string value) { var cpc = PropertyWindowViewModelHelper.GetCommandProcessorContext(); Command c = new EntityDesignRenameCommand(navProp, value, true); var cp = new CommandProcessor(cpc, c); cp.Invoke(); }
private static void SetEndRole(AssociationEnd end, string value) { var cpc = PropertyWindowViewModelHelper.GetCommandProcessorContext(); Command c = new ChangeAssociationEndCommand(end, null, value); var cp = new CommandProcessor(cpc, c); cp.Invoke(); }
/// <summary> /// Update the property value within a transaction context /// </summary> /// <param name="updateCallback"></param> private void UpdatePropertyValue(UpdatePropertyValueCallback updatePropertyValueCallback, string txName) { try { PropertyWindowViewModelHelper.CreateCommandProcessorContext(_editingContext, txName); updatePropertyValueCallback(); } finally { PropertyWindowViewModelHelper.RemoveCommandProcessorContext(); } }
internal void BeginPropertyValueUpdate(EditingContext editingContext, string transactionName) { if (_cpc == null) { Debug.Assert(_counter == 0, "CommandProcessorContext is null when counter value is not 0?"); if (_counter == 0) { _cpc = PropertyWindowViewModelHelper.CreateCommandProcessorContext(editingContext, transactionName); _cpc.EditingContext.ParentUndoUnitStarted = true; _cpc.Artifact.XmlModelProvider.BeginUndoScope(transactionName); } } }
protected virtual void PopulateMapping(ITypeDescriptorContext context) { if (context != null) { _context = context; } Debug.Assert(_context != null, "Should have a context for the PopulateMapping call."); foreach (var selectedObj in PropertyWindowViewModelHelper.GetObjectsFromSelection <TSelectedObj>(_context.Instance)) { PopulateMappingForSelectedObject(selectedObj); break; } }
public virtual PropertyDescriptorCollection GetProperties(Attribute[] attributes) { if (_properties == null) { _properties = new PropertyDescriptorCollection(null); // get list of properties through reflection PropertyWindowViewModelHelper.AddReflectedProperties(_properties, this, attributes, _editingContext); // add properties from extender objects PropertyWindowViewModelHelper.AddExtendedProperties(this, _properties, attributes, _editingContext); } return(PropertyWindowViewModelHelper.GetBrowsableProperties(_properties)); }
private static void SetEndOnDelete(AssociationEnd end, string value) { var cpc = PropertyWindowViewModelHelper.GetCommandProcessorContext(); if (end.OnDeleteAction != null && value == ModelConstants.OnDeleteAction_None) { DeleteEFElementCommand.DeleteInTransaction(cpc, end.OnDeleteAction); } else if (end.OnDeleteAction == null && value == ModelConstants.OnDeleteAction_Cascade) { CommandProcessor.InvokeSingleCommand(cpc, new CreateOnDeleteActionCommand(end, value)); } }
public LinkedPropertyDescriptor(CustomPropertyDescriptor propertyDescriptor, LinkedDescriptorContextItem contextItem) : base(propertyDescriptor.EditingContext, propertyDescriptor.Component, propertyDescriptor.Name , PropertyWindowViewModelHelper.GetArrayFromCollection <Attribute>(propertyDescriptor.Attributes)) { _wrappedCustomPropertyDescriptor = propertyDescriptor; _contextItem = contextItem; // Since we need to call the protected methods but we still want the methods to be remained protected in other cases, use the reflector to do so. _setEFElementValueMethod = typeof(CustomPropertyDescriptor).GetMethod( "SetEFElementValue", BindingFlags.Instance | BindingFlags.NonPublic); Debug.Assert(_setEFElementValueMethod != null, "Type CustomPropertyDescriptor does not have 'SetEFElementValue' method."); _resetEFElementValue = typeof(CustomPropertyDescriptor).GetMethod( "ResetEFElementValue", BindingFlags.Instance | BindingFlags.NonPublic); Debug.Assert(_resetEFElementValue != null, "Type CustomPropertyDescriptor does not have 'ResetEFElementValue' method."); }
public ReflectedPropertyDescriptor(EditingContext editingContext, PropertyDescriptor reflectedPropDescriptor, object component) : base( editingContext, component, reflectedPropDescriptor.Name, PropertyWindowViewModelHelper.GetArrayFromCollection <Attribute>(reflectedPropDescriptor.Attributes)) { _reflectedPropDescriptor = reflectedPropDescriptor; var propertyName = reflectedPropDescriptor.Name; _descriptionMethod = FindMethod( _reflectedPropDescriptor.ComponentType, "Description" + propertyName, Type.EmptyTypes, typeof(string), false); _isReadOnlyMethod = FindMethod( _reflectedPropDescriptor.ComponentType, "IsReadOnly" + propertyName, Type.EmptyTypes, typeof(bool), false); _isBrowsableMethod = FindMethod( _reflectedPropDescriptor.ComponentType, "IsBrowsable" + propertyName, Type.EmptyTypes, typeof(bool), false); _canResetMethod = FindMethod( _reflectedPropDescriptor.ComponentType, "CanReset" + propertyName, Type.EmptyTypes, typeof(bool), false); }
private void Reset() { Debug.Assert(_cpc != null, "CommandProcessorContext should have been created."); if (_cpc != null) { try { _cpc.Artifact.XmlModelProvider.EndUndoScope(); _cpc.EditingContext.ParentUndoUnitStarted = false; } finally { PropertyWindowViewModelHelper.RemoveCommandProcessorContext(); _cpc = null; _counter = 0; } } }
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attributes) { if (_lastComponent != component) { // one single instance of the type converter may be used for querying the // properties of different component instances, but the list of properties is // specific to each component, so invalidate the cached list of properties if // the component is not the same as the last queried one. // TODO: verify if this can be solved by deriving from IResettableConverter _properties = null; _lastComponent = component; } if (_properties == null) { EditingContext editingContext = null; foreach (var typeDescriptor in PropertyWindowViewModelHelper.GetObjectsFromSelection <ObjectDescriptor>(context.Instance)) { editingContext = typeDescriptor.EditingContext; break; } Debug.Assert(editingContext != null); if (editingContext != null) { _properties = new PropertyDescriptorCollection(null); // get list of properties through reflection PropertyWindowViewModelHelper.AddReflectedProperties(_properties, component, attributes, editingContext); // add properties from extender objects PropertyWindowViewModelHelper.AddExtendedProperties( component as IHavePropertyExtenders, _properties, attributes, editingContext); } } return(PropertyWindowViewModelHelper.GetBrowsableProperties(_properties)); }