/// <summary> /// This is called during undo or redo to effect state changes to this model. /// </summary> /// <param name="e">an edit describing the change to be performed</param> /// <param name="undo">true if undoing; false if redoing</param> /// <remarks> /// <para> /// This is called by <see cref="ChangeModel"/>. /// You will want to override this method to handle properties that you /// have added to your derived model class. /// </para> /// <para> /// By default this uses reflection to set the <see cref="PropertyChangedEventArgs.PropertyName"/> /// to the <see cref="ModelChangedEventArgs.OldValue"/> or the /// <see cref="ModelChangedEventArgs.NewValue"/>, depending on the value of <paramref name="undo"/>. /// </para> /// <para> /// If you override this method, remember to call the base method for all /// cases that your override method does not handle. /// </para> /// </remarks> protected virtual void ChangeModelValue(ModelChangedEventArgs e, bool undo) { if (e == null) { return; } if (e.PropertyName == "Name") { this.Name = (String)e.GetValue(undo); } else if (e.PropertyName == "DataFormat") { this.DataFormat = (String)e.GetValue(undo); } else if (e.PropertyName == "Modifiable") { this.Modifiable = (bool)e.GetValue(undo); } else if (ModelHelper.SetProperty(e.PropertyName, this, e.GetValue(undo))) { return; // successful set of model property } else { ModelHelper.Error((IDiagramModel)this, "Override ChangeModelValue to handle ModelChangedEventArgs of a model property: " + e.ToString()); } }
/// <summary> /// This method implements the <see cref="IChangeDataValue"/> interface, /// used to perform state changes for undo and redo. /// </summary> /// <param name="e">an edit describing the change to be performed</param> /// <param name="undo">true if undoing; false if redoing</param> /// <remarks> /// Unless you override this method to explicitly handle each property that you define, /// this implementation uses reflection to set the property. /// </remarks> public virtual void ChangeDataValue(ModelChangedEventArgs e, bool undo) { if (e == null) { return; } if (e.PropertyName == "Location") { this.Location = (Point)e.GetValue(undo); } else if (e.PropertyName == "Text") { this.Text = (String)e.GetValue(undo); } else if (e.PropertyName == "Key") { this.Key = (NodeKey)e.GetValue(undo); } else if (e.PropertyName == "IsTreeExpanded") { this.IsTreeExpanded = (bool)e.GetValue(undo); } else if (e.PropertyName == "WasTreeExpanded") { this.WasTreeExpanded = (bool)e.GetValue(undo); } else if (e.PropertyName == "ParentKey") { this.ParentKey = (NodeKey)e.GetValue(undo); } else if (e.PropertyName == "ChildKeys") { this.ChildKeys = (IList <NodeKey>)e.GetValue(undo); } else if (e.PropertyName == "Category") { this.Category = (String)e.GetValue(undo); } else if (e.Change == ModelChange.Property) { if (!ModelHelper.SetProperty(e.PropertyName, e.Data, e.GetValue(undo))) { ModelHelper.Error("ERROR: Unrecognized property name: " + e.PropertyName != null ? e.PropertyName : "(noname)" + " in TreeModelNodeData.ChangeDataValue"); } } }
/// <summary> /// This is called during undo or redo to effect state changes to model data. /// </summary> /// <param name="e">an edit describing the change to be performed</param> /// <param name="undo">true if undoing; false if redoing</param> /// <remarks> /// <para> /// This is called by <see cref="ChangeModel"/>. /// You will want to override this method to handle properties that you /// have added to your model data classes. /// Or you can have your data classes implement <see cref="IChangeDataValue"/> /// to achieve the same effect. /// </para> /// <para> /// By default this just calls <see cref="IChangeDataValue.ChangeDataValue"/> /// if the <see cref="ModelChangedEventArgs.Data"/> implements <see cref="IChangeDataValue"/>. /// Otherwise this uses reflection to set the <see cref="PropertyChangedEventArgs.PropertyName"/> /// to the <see cref="ModelChangedEventArgs.OldValue"/> or the /// <see cref="ModelChangedEventArgs.NewValue"/>, depending on the value of <paramref name="undo"/>. /// </para> /// <para> /// If you override this method, remember to call the base method for all /// cases that your override method does not handle. /// </para> /// </remarks> protected virtual void ChangeDataValue(ModelChangedEventArgs e, bool undo) { if (e == null) { return; } Object data = e.Data; IChangeDataValue changeable = data as IChangeDataValue; if (changeable != null) { changeable.ChangeDataValue(e, undo); } else if (ModelHelper.SetProperty(e.PropertyName, data, e.GetValue(undo))) { return; // successful set of data property } else { ModelHelper.Error((IDiagramModel)this, "Override ChangeDataValue to handle ModelChangedEventArgs.Data, or have data implement IChangeDataValue: " + data.ToString()); } }
/// <summary> /// This is called during undo or redo to effect state changes to model data. /// </summary> /// <param name="e">an edit describing the change to be performed</param> /// <param name="undo">true if undoing; false if redoing</param> /// <remarks> /// <para> /// This is called by <see cref="ChangeModel"/>. /// You will want to override this method to handle properties that you /// have added to your model data classes. /// Or you can have your data classes implement <see cref="IChangeDataValue"/> /// to achieve the same effect. /// </para> /// <para> /// By default this just calls <see cref="IChangeDataValue.ChangeDataValue"/> /// if the <see cref="ModelChangedEventArgs.Data"/> implements <see cref="IChangeDataValue"/>. /// Otherwise this uses reflection to set the <see cref="PropertyChangedEventArgs.PropertyName"/> /// to the <see cref="ModelChangedEventArgs.OldValue"/> or the /// <see cref="ModelChangedEventArgs.NewValue"/>, depending on the value of <paramref name="undo"/>. /// </para> /// <para> /// If you override this method, remember to call the base method for all /// cases that your override method does not handle. /// </para> /// </remarks> protected virtual void ChangeDataValue(ModelChangedEventArgs e, bool undo) { if (e == null) return; Object data = e.Data; IChangeDataValue changeable = data as IChangeDataValue; if (changeable != null) { changeable.ChangeDataValue(e, undo); } else if (ModelHelper.SetProperty(e.PropertyName, data, e.GetValue(undo))) { return; // successful set of data property } else { ModelHelper.Error((IDiagramModel)this, "Override ChangeDataValue to handle ModelChangedEventArgs.Data, or have data implement IChangeDataValue: " + data.ToString()); } }
/// <summary> /// This is called during undo or redo to effect state changes to this model. /// </summary> /// <param name="e">an edit describing the change to be performed</param> /// <param name="undo">true if undoing; false if redoing</param> /// <remarks> /// <para> /// This is called by <see cref="ChangeModel"/>. /// You will want to override this method to handle properties that you /// have added to your derived model class. /// </para> /// <para> /// By default this uses reflection to set the <see cref="PropertyChangedEventArgs.PropertyName"/> /// to the <see cref="ModelChangedEventArgs.OldValue"/> or the /// <see cref="ModelChangedEventArgs.NewValue"/>, depending on the value of <paramref name="undo"/>. /// </para> /// <para> /// If you override this method, remember to call the base method for all /// cases that your override method does not handle. /// </para> /// </remarks> protected virtual void ChangeModelValue(ModelChangedEventArgs e, bool undo) { if (e == null) return; if (e.PropertyName == "Name") { this.Name = (String)e.GetValue(undo); } else if (e.PropertyName == "DataFormat") { this.DataFormat = (String)e.GetValue(undo); } else if (e.PropertyName == "Modifiable") { this.Modifiable = (bool)e.GetValue(undo); } else if (ModelHelper.SetProperty(e.PropertyName, this, e.GetValue(undo))) { return; // successful set of model property } else { ModelHelper.Error((IDiagramModel)this, "Override ChangeModelValue to handle ModelChangedEventArgs of a model property: " + e.ToString()); } }