コード例 #1
0
        /// <summary>
        /// Gets the datatype for the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns>The datatype.</returns>
        protected virtual IDataType GetDataType(Item item)
        {
            // find the property
            Property editProperty = null;

            if (item.GetParsedNodeId().HasValue)
            {
                Document document = new Document(item.GetParsedNodeId().Value);
                editProperty = document.getProperty(item.Field);
            }

            // find the data type
            IDataType editDataType = null;

            if (editProperty != null)
            {
                PropertyType editPropertyType = editProperty.PropertyType;
                editDataType = editPropertyType.DataTypeDefinition.DataType;
            }
            else
            {
                if (item.PageElements[item.Field] != null)
                {
                    editDataType = new PageElementEditor(item);
                }
            }

            // only allow editing if we the data can be previewed
            IDataWithPreview data = editDataType.Data as IDataWithPreview;

            if (data == null)
            {
                editDataType = null;
            }
            else
            {
                if (editProperty != null)
                {
                    data.PropertyId = editProperty.Id;
                }
                data.PreviewMode = true;
                // display the latest updated value if available
                ItemUpdate latestUpdate
                    = LiveEditingContext.Updates.GetLatest <ItemUpdate>(u => u.NodeId == item.GetParsedNodeId() &&
                                                                        u.Field == item.Field);
                if (latestUpdate != null)
                {
                    data.Value = latestUpdate.Data;
                }
            }

            return(editDataType);
        }
コード例 #2
0
ファイル: ItemEditor.cs プロジェクト: elrute/Triphulcas
        /// <summary>
        /// Gets the datatype for the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns>The datatype.</returns>
        protected virtual IDataType GetDataType(Item item)
        {
            // find the property
            Property editProperty = null;
            if (item.GetParsedNodeId().HasValue)
            {
                Document document = new Document(item.GetParsedNodeId().Value);
                editProperty = document.getProperty(item.Field);
            }

            // find the data type
            IDataType editDataType = null;
            if (editProperty != null)
            {
                PropertyType editPropertyType = editProperty.PropertyType;
                editDataType = editPropertyType.DataTypeDefinition.DataType;
            }
            else
            {
                if (item.PageElements[item.Field] != null)
                {
                    editDataType = new PageElementEditor(item);
                }
            }

            // only allow editing if we the data can be previewed
            IDataWithPreview data = editDataType.Data as IDataWithPreview;
            if (data == null)
            {
                editDataType = null;
            }
            else
            {
                if (editProperty != null)
                    data.PropertyId = editProperty.Id;
                data.PreviewMode = true;
                // display the latest updated value if available
                ItemUpdate latestUpdate
                    = LiveEditingContext.Updates.GetLatest<ItemUpdate>(u => u.NodeId == item.GetParsedNodeId()
                                                                         && u.Field == item.Field);
                if (latestUpdate != null)
                    data.Value = latestUpdate.Data;
            }

            return editDataType;
        }