Пример #1
0
        protected virtual IEnumerable<object> assemblyInner(ViewFactory factory, BuildContext context)
        {
            var resultList = new List<object>();

            XElement parentNode = context.CurrentNode;

            foreach (XElement childNode in context.CurrentNode.Elements())
            {
                BaseBuilder childBuilder = factory.GetBuilder(childNode.Name.LocalName);

                if (childBuilder != null)
                {
                    XElement fullChildNode = applyParentParameters(parentNode, childNode);

                    context.CurrentNode = fullChildNode;

                    object childBuildResult = childBuilder.Assembly(factory, context);

                    resultList.AddRange(getFlatResult(childBuildResult));
                }
            }

            context.CurrentNode = parentNode;

            return resultList;
        }
Пример #2
0
        protected override object create(ViewFactory factory, BuildContext context)
        {
            //Rect="left,top,right,bottom"

            var place = (Place)getAttributeValue(context.CurrentNode, typeof(Place), "Rect");

            return Far.Net.CreateDialog(place.Left, place.Top, place.Right, place.Bottom);
        }
Пример #3
0
        public override object Assembly(ViewFactory factory, BuildContext context)
        {
            object control = base.Assembly(factory, context);

            assemblyInner(factory, context);

            return control;
        }
Пример #4
0
        public override object Assembly(ViewFactory factory, BuildContext context)
        {
            var item = (SetItem)base.Assembly(factory, context);

            // save node inner value as FarItem.Data or FarItem.Text
            if (string.IsNullOrEmpty(item.Text))
                item.Text = context.CurrentNode.Value;
            else
                item.Data = context.CurrentNode.Value;

            return item;
        }
Пример #5
0
        protected override object create(ViewFactory factory, BuildContext context)
        {
            //Box

            //Rect="left,top,right,bottom"

            var place = (Place)getAttributeValue(context.CurrentNode, typeof(Place), "Rect");

            if (place.Right < 0) place.Right = place.Left - place.Right;

            object resultControl = context.Dialog.AddBox(place.Left, place.Top, place.Right, place.Bottom, string.Empty);

            return resultControl;
        }
Пример #6
0
        protected virtual void addEventHandler(
            Type typeOfControl,
            object control,
            ViewFactory factory,
            BuildContext context,
            PropertyMap pm)
        {
            var name = pm.Name;
            var eventHandlerName = (string)getAttributeValue(context.CurrentNode, typeof(string), name);

            if (string.IsNullOrEmpty(eventHandlerName) == false)
            {
                var ei = getEvent(typeOfControl, name);
                var mi = getEventHandler(context.TypeOfView, eventHandlerName);

                if (ei != null && mi != null)
                {
                    ei.AddEventHandler(control, Delegate.CreateDelegate(ei.EventHandlerType, context.View, mi));
                }
            }
        }
Пример #7
0
        public virtual object Assembly(ViewFactory factory, BuildContext context)
        {
            object control = create(factory, context);

            var mapping = factory.GetMapping(TypeOfResult);

            //Name="nameOfControl"

            applyMapping(control.GetType(), control, mapping, factory, context);

            if (mapping.HasName)
            {
                string name = (string)getAttributeValue(context.CurrentNode, typeof(string), "Name");

                if (string.IsNullOrEmpty(name) == false)
                {
                    BindingHelper.SetValueIfViewHasProperty(context.TypeOfView, context.View, name, control);
                }
            }

            return control;
        }
Пример #8
0
        public override object Assembly(ViewFactory factory, BuildContext context)
        {
            var dialog = (IDialog)base.Assembly(factory, context);

            var typeOfDlg = dialog.GetType();

            var mapping = factory.GetMapping(TypeOfResult);

            context.Dialog = dialog;

            assemblyInner(factory, context);

            //Cancel="IButton"
            //Default="IControl"
            //Focused="IControl"

            foreach (var pm in mapping.PropertyMaps)
            {
                if (pm.Kind == PropertyMap.EKind.Control) setPropertyIfHasControl(typeOfDlg, dialog, context.CurrentNode, factory, pm.Name);
            }

            return dialog;
        }
        public override object Assembly(ViewFactory factory, BuildContext context)
        {
            object control = base.Assembly(factory, context);

            string controlName = (string)getAttributeValue(context.CurrentNode, typeof(string), "Name");

            if (string.IsNullOrEmpty(controlName) == false)
            {
                factory.AddControl(controlName, (IControl)control);
            }

            // add color wrapper
            if (context.CurrentNode.Attributes().Select(a => a.Name.LocalName).Any(a => a.StartsWith("Background") || a.StartsWith("Foreground")))
            {
                var colorWrapper = new FarControlColorWrapper((IControl)control);

                applyMapping(colorWrapper.GetType(), colorWrapper, factory.GetMapping(typeof(ColorControlMap)), factory, context);
            }

            // save node inner value as IControl.Data
            ((IControl)control).Data = context.CurrentNode.Value;

            return control;
        }
Пример #10
0
        public override object Assembly(ViewFactory factory, BuildContext context)
        {
            var ic = (ItemCollection)base.Assembly(factory, context);

            BaseMap mapping = factory.GetMapping(TypeOfResult);

            //applyMapping(ic.GetType(), ic, mapping, factory, context);

            if (ic.Items == null || !ic.Items.Cast<object>().Any()) return null;

            BaseBuilder childBuilder = factory.GetBuilder(ic.TypeOfItem);

            if (childBuilder == null) return null;

            if (childBuilder.TypeOfResult == ic.Items.Cast<object>().First().GetType())
            {
                return ic.Items;
            }

            // build new xml

            XElement etalonNode = new XElement(context.CurrentNode);

            foreach (PropertyMap pm in mapping.PropertyMaps)
            {
                var attr = etalonNode.Attribute(pm.Name);

                if (attr != null) attr.Remove();
            }

            bool isFirstItem = true;

            foreach (object childItem in ic.Items)
            {
                var childNode = new XElement(ic.TypeOfItem);

                // calc Rect
                var rect = new Place();

                if (ic.Orientation == 0)
                {
                    // in one line
                    if (isFirstItem)
                    {
                        rect = ic.StartPlace;

                        isFirstItem = false;
                    }
                }
                else if (ic.Orientation == 1)
                {
                    // line by line
                    rect = ic.StartPlace;
                }

                // add rect
                childNode.Add(new XAttribute("Rect", string.Empty));

                childNode.Attribute("Rect").Value = string.Format("{0},{1},{2},{3}", rect.Left, rect.Top, rect.Right, rect.Bottom);

                // add text
                childNode.Add(new XAttribute("Text", string.Empty));

                childNode.Attribute("Text").Value = childItem.ToString();

                etalonNode.Add(childNode);
            }

            XElement currentNode = context.CurrentNode;

            context.CurrentNode = etalonNode;

            var buildResult = assemblyInner(factory, context);

            int index = 0;

            foreach (object result in buildResult)
            {
                if (result is IControl) ((IControl)result).Data = index++;
            }

            context.CurrentNode = currentNode;

            return buildResult;
        }
Пример #11
0
        protected virtual void applyMapping(
            Type controlType,
            object control,
            BaseMap mapping,
            ViewFactory factory,
            BuildContext context)
        {
            foreach (var pm in mapping.PropertyMaps)
            {
                if (tryParseComplexValue(controlType, control, factory, context, pm)) continue;

                switch (pm.Kind)
                {
                    case PropertyMap.EKind.Value:
                        setControlProperty(controlType, control, factory, context, pm);
                        break;
                    case PropertyMap.EKind.Event:
                        addEventHandler(controlType, control, factory, context, pm);
                        break;
                }
            }
        }
Пример #12
0
 protected override object create(ViewFactory factory, BuildContext context)
 {
     return new SetItem();
 }
Пример #13
0
 protected override object create(ViewFactory factory, BuildContext context)
 {
     return new ItemCollection();
 }
Пример #14
0
 protected override bool tryParseComplexValue(Type typeOfControl, object control, ViewFactory factory, BuildContext context, PropertyMap pm)
 {
     return base.tryParseComplexValue(typeOfControl, control, factory, context, pm);
 }
Пример #15
0
        public virtual IDialog Create(object view, IModuleManager mm, XElement rootNode)
        {
            _moduleManager = mm;

            _controlHash.Clear();

            var context = new BuildContext();

            context.RootNode = rootNode;
            context.View = view;
            context.TypeOfView = view.GetType();
            context.CurrentNode = context.RootNode;

            var resultDlg = (IDialog)GetBuilder("Dialog").Assembly(this, context);

            resultDlg.Initialized += onDialogInitialized;
            resultDlg.Closing += onDialogClosing;

            _bindingEngine.Prepare();

            _garbageList = new List<IDisposable>();

            _garbageList.Add(_bindingEngine);

            return resultDlg;
        }
Пример #16
0
 protected abstract object create(
     ViewFactory factory,
     BuildContext context);
Пример #17
0
        protected virtual void setControlProperty(
            Type typeOfControl,
            object control,
            ViewFactory factory,
            BuildContext context,
            PropertyMap pm)
        {
            var name = pm.Name;

            PropertyInfo property = getProperty(typeOfControl, name);

            if (property == null || property.CanWrite == false) return;

            object value = getAttributeValue(context.CurrentNode, property.PropertyType, name);

            if (value != null) property.SetValue(control, value, null);
        }
Пример #18
0
        protected virtual bool tryParseComplexValue(
            Type typeOfControl,
            object control,
            ViewFactory factory,
            BuildContext context,
            PropertyMap pm)
        {
            var name = pm.Name;

            var binding = ComplexParser.GetValue(
                getAttributeValue(context.CurrentNode, typeof(string), name),
                "Binding",
                "Path");

            if (binding != null)
            {
                object source = null;
                PropertyInfo sourceProperty = null;

                // будет работать только если контрол, на который биндимся уже создали (пока что и так хватит)
                if (binding.ContainsKey("SourceControl"))
                {
                    source = factory.GetControl(binding["SourceControl"]);
                    sourceProperty = getProperty(source.GetType(), binding["Path"]);
                }
                else
                {
                    source = context.View;
                    sourceProperty = getProperty(context.TypeOfView, binding["Path"]);
                }

                object target = control;
                PropertyInfo targetProperty = getProperty(typeOfControl, name);

                // тут targetProperty или sourceProperty могут быть фиктивными и потому не надо делать жосткой проверки
                // базовый BindingExpression сам выбросить исключение если надо

                if (source != null &&
                    target != null)
                {
                    EBingingMode mode = EBingingMode.OneTime;

                    if (binding.ContainsKey("Mode")) mode = (EBingingMode)ValueParser.GetValue(typeof(EBingingMode), binding["Mode"]);

                    BindingExpression be = createBindingExpression(
                        mode,
                        source,
                        sourceProperty,
                        target,
                        targetProperty);

                    applyBindingExpression(
                        be,
                        factory,
                        binding);
                }

                return true;
            }

            var resource = ComplexParser.GetValue(
                getAttributeValue(context.CurrentNode, typeof(string), name),
                "Resource",
                "Key");

            if (resource != null)
            {
                var property = getProperty(typeOfControl, name);
                var value = factory.GetLocalString(resource["Key"]);

                if (property != null && property.CanWrite)
                {
                    property.SetValue(control, value, null);
                }

                return true;
            }

            return false;
        }