예제 #1
0
        private void CreateFieldElement(DataViewBuilderContext context, DataViewTemplateEntry templateEntry)
        {
            context.CurrentFieldNode = (DocumentCompositeNode)templateEntry.FieldNode.Clone(context.DocumentContext);
            DocumentCompositeNode documentCompositeNode = (DocumentCompositeNode)context.CurrentFieldNode.Properties[(IPropertyId)templateEntry.FieldValueProperty];
            string path = context.CurrentSchemaPath.Path;

            if (context.CurrentSchemaPath.Schema is XmlSchema)
            {
                string str = path ?? string.Empty;
                documentCompositeNode.Properties[BindingSceneNode.XPathProperty] = (DocumentNode)context.DocumentContext.CreateNode(str);
            }
            else if (!string.IsNullOrEmpty(path))
            {
                object obj = this.Platform.Metadata.MakePropertyPath(path);
                documentCompositeNode.Properties[BindingSceneNode.PathProperty] = context.DocumentContext.CreateNode(obj.GetType(), obj);
            }
            BindingModeInfo defaultBindingMode = BindingPropertyHelper.GetDefaultBindingMode((DocumentNode)templateEntry.FieldNode, (IPropertyId)templateEntry.FieldValueProperty, context.CurrentSchemaPath);

            if (defaultBindingMode.IsOptional)
            {
                return;
            }
            DocumentPrimitiveNode node = context.DocumentContext.CreateNode(PlatformTypes.BindingMode, (IDocumentNodeValue) new DocumentNodeStringValue(defaultBindingMode.Mode.ToString()));

            documentCompositeNode.Properties[BindingSceneNode.ModeProperty] = (DocumentNode)node;
        }
예제 #2
0
        private void ApplyRulesInternal(DataBindingDragDropModel model, DataBindingDragDropFlags filteredDragFlags)
        {
            if ((filteredDragFlags & DataBindingDragDropFlags.SetBinding) == DataBindingDragDropFlags.SetBinding)
            {
                if (model.InsertionPoint.Property != null)
                {
                    model.DropFlags &= ~DataBindingDragDropFlags.SetBinding;
                    IType type = model.RelativeDropSchemaPath.Type;
                    if (type != null && BindingPropertyHelper.GetPropertyCompatibility(model.InsertionPoint.Property, type, (ITypeResolver)model.TargetNode.ProjectContext) != BindingPropertyCompatibility.None)
                    {
                        model.TargetProperty = model.InsertionPoint.Property;
                        model.DropFlags     |= DataBindingDragDropFlags.SetBinding;
                    }
                }
                else if ((filteredDragFlags & DataBindingDragDropFlags.AutoPickProperty) == DataBindingDragDropFlags.AutoPickProperty)
                {
                    model.TargetProperty = this.GetSpecialDefaultBindingProperty(filteredDragFlags);
                    if (model.TargetProperty == null)
                    {
                        model.TargetProperty = this.GetDefaultBindingProperty(filteredDragFlags, model.RelativeDropSchemaPath);
                    }
                    if (model.TargetProperty != null)
                    {
                        model.DropFlags |= DataBindingDragDropFlags.SetBinding;
                    }
                }
            }
            if ((filteredDragFlags & DataBindingDragDropFlags.CreateElement) != DataBindingDragDropFlags.CreateElement || !PlatformTypes.Panel.IsAssignableFrom((ITypeId)model.TargetNode.Type))
            {
                return;
            }
            if (DataBindingModeModel.Instance.NormalizedMode == DataBindingMode.Default && model.RelativeDropSchemaPath.IsCollection)
            {
                model.NewElementType     = !model.RelativeDropSchemaPath.IsHierarchicalCollection ? DataBindingDragDropDefaultHandler.ItemsControlType : DataBindingDragDropDefaultHandler.TreeControlType;
                model.NewElementProperty = (IPropertyId)model.NewElementType.GetMember(MemberType.LocalProperty, "ItemsSource", MemberAccessTypes.Public);
                model.DropFlags         |= DataBindingDragDropFlags.CreateElement;
            }
            List <DataSchemaNode> toCreateElements = this.GetNodesToCreateElements();

            if (toCreateElements.Count < model.DataSource.Count)
            {
                return;
            }
            model.DropFlags            |= DataBindingDragDropFlags.CreateElement;
            model.NodesToCreateElements = (IList <DataSchemaNode>)toCreateElements;
            if (model.NewElementType != null)
            {
                return;
            }
            IType dataType = toCreateElements[0].ResolveType(model.TargetNode.DocumentNode.TypeResolver);
            DataViewTemplateEntry viewTemplateEntry = DataViewFactory.GetDataViewTemplateEntry(model.Platform, dataType, DataViewCategory.Master);

            model.NewElementType     = (ITypeId)viewTemplateEntry.FieldNode.Type;
            model.NewElementProperty = (IPropertyId)viewTemplateEntry.FieldValueProperty;
        }
예제 #3
0
        private void CreateLabelElement(DataViewBuilderContext context, DataViewTemplateEntry templateEntry)
        {
            if (templateEntry.LabelNode == null)
            {
                return;
            }
            context.CurrentLabelNode = (DocumentCompositeNode)templateEntry.LabelNode.Clone(context.DocumentContext);
            string str = context.CurrentSchemaPath.Node.PathName.TrimStart('@', '/');

            context.CurrentLabelNode.Properties[(IPropertyId)templateEntry.LabelValueProperty] = (DocumentNode)context.DocumentContext.CreateNode(str);
        }
예제 #4
0
        private DataViewTemplateEntry GetOrCreateTemplateEntry(IPlatformMetadata platformMetadata, string typeName)
        {
            IType platformType = ((IPlatformTypes)platformMetadata).GetPlatformType(typeName);
            DataViewTemplateEntry viewTemplateEntry = this.TemplateEntries.Find((Predicate <DataViewTemplateEntry>)(t => t.DataType == platformType));

            if (viewTemplateEntry == null)
            {
                viewTemplateEntry = new DataViewTemplateEntry((ITypeId)platformType);
                this.TemplateEntries.Add(viewTemplateEntry);
            }
            return(viewTemplateEntry);
        }
예제 #5
0
        private void ProcessSingleSchemaPath(DataViewBuilderContext context, DataSchemaNodePath schemaPath, DataViewTemplate dataViewTemplate)
        {
            DataViewTemplateEntry templateEntryInternal = this.GetDataViewTemplateEntryInternal(schemaPath.Type, dataViewTemplate);

            if (templateEntryInternal == null)
            {
                return;
            }
            context.CurrentSchemaPath = schemaPath;
            context.CurrentLabelNode  = (DocumentCompositeNode)null;
            context.CurrentFieldNode  = (DocumentCompositeNode)null;
            this.CreateLabelElement(context, templateEntryInternal);
            this.CreateFieldElement(context, templateEntryInternal);
            this.layoutBuilder.SetElementLayout(context);
        }
예제 #6
0
        private DataViewTemplateEntry GetDataViewTemplateEntryInternal(IType platformType, DataViewTemplate dataViewTemplate)
        {
            if (platformType == null)
            {
                return((DataViewTemplateEntry)null);
            }
            DataViewTemplateEntry viewTemplateEntry = dataViewTemplate.TemplateEntries.Find((Predicate <DataViewTemplateEntry>)(entry => entry.DataType.IsAssignableFrom((ITypeId)platformType)));

            if (viewTemplateEntry == null)
            {
                if (!DataViewBuilder.ShouldTreatAsStringType(platformType))
                {
                    return((DataViewTemplateEntry)null);
                }
                platformType      = this.Platform.Metadata.ResolveType(PlatformTypes.String);
                viewTemplateEntry = dataViewTemplate.TemplateEntries.Find((Predicate <DataViewTemplateEntry>)(entry => entry.DataType.IsAssignableFrom((ITypeId)platformType)));
            }
            return(viewTemplateEntry);
        }
예제 #7
0
        private void UpdateTemplateEntry(DocumentCompositeNode entryNode, string typeName, bool isLabel)
        {
            DataViewTemplateEntry createTemplateEntry = this.GetOrCreateTemplateEntry(entryNode.PlatformMetadata, typeName);
            IProperty             property            = Enumerable.First <IProperty>((IEnumerable <IProperty>)entryNode.Properties.Keys, (Func <IProperty, bool>)(p => entryNode.Properties[(IPropertyId)p].Type.IsBinding));

            entryNode.Name          = (string)null;
            entryNode.SourceContext = (INodeSourceContext)null;
            if (isLabel)
            {
                createTemplateEntry.LabelNode          = entryNode;
                createTemplateEntry.LabelValueProperty = property;
                createTemplateEntry.LabelNode.ClearValue((IPropertyId)property);
            }
            else
            {
                createTemplateEntry.FieldNode          = entryNode;
                createTemplateEntry.FieldValueProperty = property;
            }
        }