Beispiel #1
0
        /// <summary>
        /// Factory method to create concrete part.
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        protected virtual StandardPart <T> CreatePart()
        {
            var part = new StandardPart <T>(_builderFactory, _controlFactory);

            part.Paths = new BindingList <IFieldPath>(_paths);
            return(part);
        }
Beispiel #2
0
 public void RemovePart(StandardPart <T> part)
 {
     Parts.Remove(part);
     part.PropertyChanged -= Part_PropertyChanged;
     part.RemoveRequested -= OnRemoveRequested;
     part.Search          -= OnSearch;
     part.Dispose();
 }
Beispiel #3
0
 protected virtual StandardPart <T> AddPart(StandardPart <T> part)
 {
     Parts.Add(part);
     part.PropertyChanged += Part_PropertyChanged;
     part.RemoveRequested += OnRemoveRequested;
     part.Search          += OnSearch;
     return(part);
 }
Beispiel #4
0
        /// <summary>
        /// Add as many parts as required that we can validly represent in the current setup.  This will leave other parts in place.
        /// </summary>
        /// <param name="parts"></param>
        /// <exception cref="System.ApplicationException">Thrown if some parts couldn't be represented in this view.</exception>
        public void SetParts(IPartViewJunction parts)
        {
            // only adding parts, so leave existing Parts alone
            // for each p in parts
            //   can we copy from p?  if so, do it, otherwise try the next part
            //   if we get to the end and the last part we added couldn't be populated, remove it

            int total             = 0;
            var skipped           = new List <IPartView>();
            StandardPart <T> part = null;

            foreach (var p in parts)
            {
                total++;
                if (part == null)
                {
                    part = AddPart();
                }
                if (part.CanCopyFrom(p))
                {
                    part.CopyFrom(p);
                    part = null;
                }
                else
                {
                    skipped.Add(p);
                }
            }

            if (part != null)
            {
                this.RemovePart(part);
            }

            // if skipped contains values, we should throw an exception here with the remaining parts
            if (skipped.Count > 0)
            {
                var message = new StringBuilder();
                message.AppendLine(String.Format("Could not load {0} of {1} parameters:", skipped.Count, total));
                foreach (var p in skipped)
                {
                    message.AppendLine(String.Concat("- ", p.ToString()));
                }

                throw new ApplicationException(message.ToString());
            }
        }
Beispiel #5
0
 protected virtual void OnPartChanged(StandardPart <T> part, PropertyChangedEventArgs e)
 {
     // nothing to see here
 }