Exemple #1
0
		public FieldAggregator() {
			foreach(FieldType fieldType in FieldType.Values) {
				Field field = new Field(fieldType, GetType());
				AddField(field);
			}
			boundContainers = new List<IDrawableContainer>();
		}
		public virtual void AddField(Field field) {
			if (fieldsByType != null && fieldsByType.ContainsKey(field.FieldType)) {
				if (LOG.IsDebugEnabled) {
					LOG.DebugFormat("A field with of type '{0}' already exists in this {1}, will overwrite.", field.FieldType, GetType());
				}
			} 
			
			fields.Add(field);
			fieldsByType[field.FieldType] = field;
			field.PropertyChanged += delegate { if(fieldChanged != null) fieldChanged(this, new FieldChangedEventArgs(field)); };
		}
		public void TestSerializeField() {
			Field f = new Field(FieldType.ARROWHEADS, GetType());
			f.myValue = ArrowContainer.ArrowHeadCombination.BOTH;
			
			Field clone = (Field) Objects.DeepClone(f);
			Assert.AreEqual(f, clone);
			Assert.AreEqual(f.Value, clone.Value);
			Assert.AreEqual(f.Scope, clone.Scope);
			
			f.Scope = this.GetType().ToString();
			
			clone = (Field) Objects.DeepClone(f);
			Assert.AreEqual(f, clone);
			Assert.AreEqual(f.Value, clone.Value);
			Assert.AreEqual(f.Scope, clone.Scope);
		}
		/// <summary>
		/// This method will be called before a field is changes.
		/// Using this makes it possible to invalidate the object as is before changing.
		/// </summary>
		/// <param name="fieldToBeChanged">The field to be changed</param>
		/// <param name="newValue">The new value</param>
		public virtual void BeforeFieldChange(Field fieldToBeChanged, object newValue) {
			_parent.MakeUndoable(new ChangeFieldHolderMemento(this, fieldToBeChanged), true);
			Invalidate();
		}
Exemple #5
0
		public override void AddField(Field field) {
			base.AddField(field);
			field.PropertyChanged += OwnPropertyChanged;
		}
		public ChangeFieldHolderMemento(IDrawableContainer drawableContainer, Field fieldToBeChanged) {
			this.drawableContainer = drawableContainer;
			this.fieldToBeChanged = fieldToBeChanged;
			oldValue = fieldToBeChanged.Value;
		}
        /// <param name="requestingType">Type of the class for which to create the field</param>
        /// <param name="fieldType">FieldType of the field to construct</param>
        /// <param name="scope">FieldType of the field to construct</param>
        /// <returns>a new Field of the given fieldType, with the scope of it's value being restricted to the Type scope</returns>
        public Field CreateField(Type requestingType, FieldType fieldType, object preferredDefaultValue)
        {
            string requestingTypeName = requestingType.Name;
            string requestedField = requestingTypeName + "." + fieldType.Name;
            object fieldValue = preferredDefaultValue;

            // Check if the configuration exists
            if (LastUsedFieldValues == null)
            {
                LastUsedFieldValues = new Dictionary<string, object>();
            }

            // Check if settings for the requesting type exist, if not create!
            if (LastUsedFieldValues.ContainsKey(requestedField))
            {
                // Check if a value is set (not null)!
                if (LastUsedFieldValues[requestedField] != null)
                {
                    fieldValue = LastUsedFieldValues[requestedField];
                }
                else
                {
                    // Overwrite null value
                    LastUsedFieldValues[requestedField] = fieldValue;
                }
            }
            else
            {
                LastUsedFieldValues.Add(requestedField, fieldValue);
            }
            Field returnField = new Field(fieldType, requestingType);
            returnField.Value = fieldValue;
            return returnField;
        }
 public void UpdateLastFieldValue(Field field)
 {
     string requestedField = field.Scope + "." + field.FieldType.Name;
     // Check if the configuration exists
     if (LastUsedFieldValues == null)
     {
         LastUsedFieldValues = new Dictionary<string, object>();
     }
     // check if settings for the requesting type exist, if not create!
     if (LastUsedFieldValues.ContainsKey(requestedField))
     {
         LastUsedFieldValues[requestedField] = field.myValue;
     }
     else
     {
         LastUsedFieldValues.Add(requestedField, field.myValue);
     }
 }
 public void RemoveField(Field field)
 {
     fields.Remove(field);
     fieldsByType.Remove(field.FieldType);
     field.PropertyChanged -= delegate
     {
         if (fieldChanged != null)
         {
             fieldChanged(this, new FieldChangedEventArgs(field));
         }
     };
 }
 public override void AddField(Field field)
 {
     base.AddField(field);
     field.PropertyChanged += new PropertyChangedEventHandler(OwnPropertyChanged);
 }
 /// <summary>
 /// Creates a flat clone of this Field. The fields value itself is not cloned.
 /// </summary>
 /// <returns></returns>
 public Field Clone()
 {
     Field ret = new Field(FieldType, Scope);
     ret.Value = Value;
     return ret;
 }
 public FieldChangedEventArgs(Field field)
 {
     Field = field;
 }