示例#1
0
        /// <summary>
        /// Adds the specified machine level group to the model.
        /// </summary>
        /// <param name="store">Target store</param>
        /// <param name="groupXMLNode">The group to add to the model.</param>
        /// <param name="activeForm">The current form</param>
        /// <param name="notifyAdded">Used during deserialization fixup</param>
        private static void AddGroupToModel(Store store, XmlNode groupXMLNode, CustomPropertiesManager activeForm, INotifyElementAdded notifyAdded)
        {
            CustomPropertyGroup grp = new CustomPropertyGroup(store);

            grp.Name        = groupXMLNode.Attributes["name"].Value;
            grp.Description = groupXMLNode.Attributes["description"].Value;

            if (notifyAdded != null)
            {
                notifyAdded.ElementAdded(grp, false);
            }

            TreeNode newGroupTreeNode = null;

            if (activeForm != null)
            {
                newGroupTreeNode     = activeForm._modelNode.Nodes.Add(grp.Name);
                newGroupTreeNode.Tag = grp;
                activeForm.tvCustomProperties.SelectedNode = newGroupTreeNode;
            }

            XmlNodeList xmlDefinitions = groupXMLNode.SelectNodes("def:CustomPropertyDefinition", _namespaceManager);

            foreach (XmlNode xmlDef in xmlDefinitions)
            {
                CustomPropertyDefinition def        = new CustomPropertyDefinition(store);
                XmlAttributeCollection   attributes = xmlDef.Attributes;
                def.CustomPropertyGroup = grp;
                def.Name        = attributes["name"].Value;
                def.Category    = attributes["category"].Value;
                def.Description = attributes["description"].Value;
                def.DataType    = (CustomPropertyDataType)Enum.Parse(typeof(CustomPropertyDataType), attributes["dataType"].Value, true);
                XmlAttribute defaultValueAttribute = attributes["defaultValue"];
                if (defaultValueAttribute != null)
                {
                    def.DefaultValue = defaultValueAttribute.Value;
                }
                XmlAttribute verbalizeDefaultAttribute = attributes["verbalizeDefaultValue"];
                if (verbalizeDefaultAttribute != null)
                {
                    string verbalizeDefaultText = verbalizeDefaultAttribute.Value.Trim();
                    def.VerbalizeDefaultValue = verbalizeDefaultText == "true" || verbalizeDefaultText == "1";
                }
                XmlNodeList types = xmlDef.SelectNodes("def:ORMTypes/def:ORMType", _namespaceManager);
                foreach (XmlNode ormType in types)
                {
                    def.ORMTypes = def.ORMTypes | (ORMTypes)Enum.Parse(typeof(ORMTypes), ormType.Attributes["name"].Value, true);
                }

                if (notifyAdded != null)
                {
                    notifyAdded.ElementAdded(def, true);
                }

                if (newGroupTreeNode != null)
                {
                    newGroupTreeNode.Nodes.Add(def.Name).Tag = def;
                }
            }
        }
示例#2
0
 /// <summary>
 /// Called by the verbalization engine when verbalization is completed.
 /// Return this instance to the cache so that it can be reused.
 /// </summary>
 void IDisposable.Dispose()
 {
     myDefinition = null;
     if (myCache == null)
     {
         System.Threading.Interlocked.CompareExchange <DefaultPropertyValueVerbalizer>(ref myCache, this, null as DefaultPropertyValueVerbalizer);
     }
 }
示例#3
0
        private void tsbAddDefinition_Click(object sender, EventArgs e)
        {
            TreeNode rootNode = GetRootNode();

            TreeNode groupNode;

            groupNode = tvCustomProperties.SelectedNode.Level == _groupLevel ?
                        tvCustomProperties.SelectedNode : tvCustomProperties.SelectedNode.Parent;
            if (rootNode == _machineNode)
            {
                XmlNode groupXmlNode;

                groupXmlNode = groupNode.Tag as XmlNode;
                CustomPropertyGroup groupObject = groupNode.Tag as CustomPropertyGroup;

                XmlNode newProperty = _loadedDoc.CreateNode(XmlNodeType.Element, "CustomPropertyDefinition", CustomPropertiesDomainModel.XmlNamespace);
                XmlNode newOrmTypes = _loadedDoc.CreateElement("ORMTypes", CustomPropertiesDomainModel.XmlNamespace);
                newProperty.AppendChild(newOrmTypes);
                groupXmlNode.AppendChild(newProperty);

                XmlAttribute nameAttrib     = _loadedDoc.CreateAttribute("name");
                XmlAttribute categoryAttrib = _loadedDoc.CreateAttribute("category");
                XmlAttribute dataTypeAttrib = _loadedDoc.CreateAttribute("dataType");
                XmlAttribute descAttrib     = _loadedDoc.CreateAttribute("description");

                newProperty.Attributes.Append(nameAttrib);
                newProperty.Attributes.Append(categoryAttrib);
                newProperty.Attributes.Append(dataTypeAttrib);
                newProperty.Attributes.Append(descAttrib);

                if (groupXmlNode != null)
                {
                    nameAttrib.Value = PickNewDefinitionName(groupXmlNode);
                }
                else if (groupObject != null)
                {
                    nameAttrib.Value = PickNewDefinitionName(groupObject);
                }

                dataTypeAttrib.Value = "String";

                TreeNode newPropertyNode = groupNode.Nodes.Add(nameAttrib.Value);
                newPropertyNode.Tag             = newProperty;
                tvCustomProperties.SelectedNode = newPropertyNode;
            }
            else if (rootNode == _modelNode)
            {
                CustomPropertyGroup      grp = groupNode.Tag as CustomPropertyGroup;
                CustomPropertyDefinition def = new CustomPropertyDefinition(_store);
                def.CustomPropertyGroup = grp;
                def.Name = PickNewDefinitionName(grp);
                TreeNode newDefNode = groupNode.Nodes.Add(def.Name);
                newDefNode.Tag = def;
                tvCustomProperties.SelectedNode = newDefNode;
            }
        }
示例#4
0
                    bool IVerbalize.GetVerbalization(TextWriter writer, IDictionary <Type, IVerbalizationSets> snippetsDictionary, IVerbalizationContext verbalizationContext, VerbalizationSign sign)
                    {
                        CustomPropertyDefinition propertyDefinition = myDefinition;
                        object defaultValue = propertyDefinition.DefaultValue;

                        verbalizationContext.BeginVerbalization(VerbalizationContent.Normal);
                        writer.Write(string.Format(
                                         ((IVerbalizationSets <CustomPropertyVerbalizationSnippetType>)snippetsDictionary[typeof(CustomPropertyVerbalizationSnippetType)]).GetSnippet(CustomPropertyVerbalizationSnippetType.CustomPropertiesVerbalization),
                                         propertyDefinition.Name,
                                         propertyDefinition.DefaultValue.ToString(),
                                         propertyDefinition.CustomPropertyGroup.Name,
                                         propertyDefinition.Description));
                        return(true);
                    }
示例#5
0
        /// <summary>
        /// Gets all of the groups and their definitions from the store.
        /// </summary>
        /// <returns>All of the groups and their definitions.</returns>
        private static Dictionary <CustomPropertyGroup, List <CustomPropertyDefinition> > GetGroupsAndDefsFromStore(Store store)
        {
            ReadOnlyCollection <ModelElement> mdlDefs = store.ElementDirectory.FindElements(CustomPropertyDefinition.DomainClassId);
            Dictionary <CustomPropertyGroup, List <CustomPropertyDefinition> > groupsAndDefs = new Dictionary <CustomPropertyGroup, List <CustomPropertyDefinition> >();

            foreach (ModelElement elemnt in mdlDefs)
            {
                CustomPropertyDefinition def = elemnt as CustomPropertyDefinition;
                if (!groupsAndDefs.ContainsKey(def.CustomPropertyGroup))
                {
                    List <CustomPropertyDefinition> defs = new List <CustomPropertyDefinition>();
                    defs.Add(def);
                    groupsAndDefs.Add(def.CustomPropertyGroup, defs);
                }
                else
                {
                    groupsAndDefs[def.CustomPropertyGroup].Add(def);
                }
            }
            return(groupsAndDefs);
        }
示例#6
0
        public sealed override void SetValue(object component, object value)
        {
            CustomPropertyDefinition customPropertyDefinition = this.customPropertyDefinition;
            IORMExtendableElement    modelElement;

            if (null != (modelElement = ResolveComponent(component)))
            {
                CustomProperty customProperty = FindCustomProperty(modelElement);
                using (Transaction transaction = this.StartTransaction(modelElement.Store))
                {
                    if (customProperty != null)
                    {
                        if (!object.Equals(customProperty.Value, value))
                        {
                            if (value == null || object.Equals(customPropertyDefinition.DefaultValue, value))
                            {
                                customProperty.Delete();
                            }
                            else
                            {
                                customProperty.Value = value;
                            }
                        }
                    }
                    else if (value != null && !object.Equals(customPropertyDefinition.DefaultValue, value))
                    {
                        customProperty = new CustomProperty(modelElement.Store.DefaultPartition, new PropertyAssignment(CustomProperty.ValueDomainPropertyId, value));
                        customProperty.CustomPropertyDefinition = customPropertyDefinition;
                        modelElement.ExtensionCollection.Add(customProperty);
                    }
                    if (transaction.HasPendingChanges)
                    {
                        transaction.Commit();
                    }
                }
            }
        }
        public sealed override void SetValue(object component, object value)
        {
            CustomPropertyDefinition customPropertyDefinition = this.customPropertyDefinition;
            ORMModelElement          modelElement             = EditorUtility.ResolveContextInstance(component, false) as ORMModelElement;

            System.Diagnostics.Debug.Assert(modelElement != null);
            CustomProperty customProperty = FindCustomProperty(modelElement);

            using (Transaction transaction = this.StartTransaction(modelElement))
            {
                if (customProperty != null)
                {
                    if (!object.Equals(customProperty.Value, value))
                    {
                        if (value == null || object.Equals(customPropertyDefinition.DefaultValue, value))
                        {
                            customProperty.Delete();
                        }
                        else
                        {
                            customProperty.Value = value;
                        }
                    }
                }
                else if (value != null && !object.Equals(customPropertyDefinition.DefaultValue, value))
                {
                    customProperty = new CustomProperty(modelElement.Partition, new PropertyAssignment(CustomProperty.ValueDomainPropertyId, value));
                    customProperty.CustomPropertyDefinition = customPropertyDefinition;
                    modelElement.ExtensionCollection.Add(customProperty);
                }
                if (transaction.HasPendingChanges)
                {
                    transaction.Commit();
                }
            }
        }
 internal static void SetCustomPropertyDefinition(CustomProperty element, CustomPropertyDefinition newCustomPropertyDefinition)
 {
     DslModeling::DomainRoleInfo.SetLinkedElement(element, CustomPropertyDomainRoleId, newCustomPropertyDefinition);
 }
 internal static DslModeling::LinkedElementCollection <CustomProperty> GetCustomPropertyCollection(CustomPropertyDefinition element)
 {
     return(GetRoleCollection <DslModeling::LinkedElementCollection <CustomProperty>, CustomProperty>(element, CustomPropertyDefinitionDomainRoleId));
 }
示例#10
0
 /// <summary>
 /// Constructor
 /// Creates a CustomPropertyGroupContainsCustomPropertyDefinition link in the same Partition as the given CustomPropertyGroup
 /// </summary>
 /// <param name="source">CustomPropertyGroup to use as the source of the relationship.</param>
 /// <param name="target">CustomPropertyDefinition to use as the target of the relationship.</param>
 public CustomPropertyGroupContainsCustomPropertyDefinition(CustomPropertyGroup source, CustomPropertyDefinition target)
     : base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[] { new DslModeling::RoleAssignment(CustomPropertyGroupContainsCustomPropertyDefinition.CustomPropertyGroupDomainRoleId, source), new DslModeling::RoleAssignment(CustomPropertyGroupContainsCustomPropertyDefinition.CustomPropertyDefinitionDomainRoleId, target) }, null)
 {
 }
示例#11
0
 public static DslModeling::LinkedElementCollection <CustomProperty> GetCustomPropertyCollection(CustomPropertyDefinition element)
 {
     return(new DslModeling::LinkedElementCollection <CustomProperty>(element, CustomPropertyDefinitionDomainRoleId));
 }
示例#12
0
					/// <summary>
					/// Attach the property to verbalize to this instance
					/// </summary>
					/// <param name="definition">A <see cref="CustomPropertyDefinition"/> with a default value.</param>
					public void Attach(CustomPropertyDefinition definition)
					{
						myDefinition = definition;
					}
示例#13
0
		public static DslModeling::LinkedElementCollection<CustomProperty> GetCustomPropertyCollection(CustomPropertyDefinition element)
		{
			return new DslModeling::LinkedElementCollection<CustomProperty>(element, CustomPropertyDefinitionDomainRoleId);
		}
 /// <summary>
 /// Constructor
 /// Creates a CustomPropertyHasCustomPropertyDefinition link in the same Partition as the given CustomProperty
 /// </summary>
 /// <param name="source">CustomProperty to use as the source of the relationship.</param>
 /// <param name="target">CustomPropertyDefinition to use as the target of the relationship.</param>
 internal CustomPropertyHasCustomPropertyDefinition(CustomProperty source, CustomPropertyDefinition target)
     : base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[] { new DslModeling::RoleAssignment(CustomPropertyHasCustomPropertyDefinition.CustomPropertyDomainRoleId, source), new DslModeling::RoleAssignment(CustomPropertyHasCustomPropertyDefinition.CustomPropertyDefinitionDomainRoleId, target) }, null)
 {
 }
示例#15
0
		/// <summary>
		/// Constructor
		/// Creates a CustomPropertyGroupContainsCustomPropertyDefinition link in the same Partition as the given CustomPropertyGroup
		/// </summary>
		/// <param name="source">CustomPropertyGroup to use as the source of the relationship.</param>
		/// <param name="target">CustomPropertyDefinition to use as the target of the relationship.</param>
		internal CustomPropertyGroupContainsCustomPropertyDefinition(CustomPropertyGroup source, CustomPropertyDefinition target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(CustomPropertyGroupContainsCustomPropertyDefinition.CustomPropertyGroupDomainRoleId, source), new DslModeling::RoleAssignment(CustomPropertyGroupContainsCustomPropertyDefinition.CustomPropertyDefinitionDomainRoleId, target)}, null)
		{
		}
示例#16
0
        public static CustomPropertyDescriptor GetDescriptorForCustomPropertyDefinition(CustomPropertyDefinition customPropertyDefinition)
        {
            CustomPropertyDescriptor descriptor;

            if (!Descriptors.TryGetValue(customPropertyDefinition, out descriptor))
            {
                descriptor = new CustomPropertyDescriptor(customPropertyDefinition);
                Descriptors[customPropertyDefinition] = descriptor;
            }
            return(descriptor);
        }
示例#17
0
		/// <summary>
		/// Constructor
		/// Creates a CustomPropertyHasCustomPropertyDefinition link in the same Partition as the given CustomProperty
		/// </summary>
		/// <param name="source">CustomProperty to use as the source of the relationship.</param>
		/// <param name="target">CustomPropertyDefinition to use as the target of the relationship.</param>
		public CustomPropertyHasCustomPropertyDefinition(CustomProperty source, CustomPropertyDefinition target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(CustomPropertyHasCustomPropertyDefinition.CustomPropertyDomainRoleId, source), new DslModeling::RoleAssignment(CustomPropertyHasCustomPropertyDefinition.CustomPropertyDefinitionDomainRoleId, target)}, null)
		{
		}
示例#18
0
		public static void SetCustomPropertyGroup(CustomPropertyDefinition element, CustomPropertyGroup newCustomPropertyGroup)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, CustomPropertyDefinitionDomainRoleId, newCustomPropertyGroup);
		}
示例#19
0
		public static CustomPropertyGroup GetCustomPropertyGroup(CustomPropertyDefinition element)
		{
			return DslModeling::DomainRoleInfo.GetLinkedElement(element, CustomPropertyDefinitionDomainRoleId) as CustomPropertyGroup;
		}
示例#20
0
		public static void SetCustomPropertyDefinition(CustomProperty element, CustomPropertyDefinition newCustomPropertyDefinition)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, CustomPropertyDomainRoleId, newCustomPropertyDefinition);
		}
 internal static CustomPropertyGroup GetCustomPropertyGroup(CustomPropertyDefinition element)
 {
     return(DslModeling::DomainRoleInfo.GetLinkedElement(element, CustomPropertyDefinitionDomainRoleId) as CustomPropertyGroup);
 }
 internal static void SetCustomPropertyGroup(CustomPropertyDefinition element, CustomPropertyGroup newCustomPropertyGroup)
 {
     DslModeling::DomainRoleInfo.SetLinkedElement(element, CustomPropertyDefinitionDomainRoleId, newCustomPropertyGroup);
 }
示例#23
0
					/// <summary>
					/// Called by the verbalization engine when verbalization is completed.
					/// Return this instance to the cache so that it can be reused.
					/// </summary>
					void IDisposable.Dispose()
					{
						myDefinition = null;
						if (myCache == null)
						{
							System.Threading.Interlocked.CompareExchange<DefaultPropertyValueVerbalizer>(ref myCache, this, null as DefaultPropertyValueVerbalizer);
						}
					}
示例#24
0
        private void tsbAddGroupToMachine_Click(object sender, EventArgs e)
        {
            //Grab the model group that we are adding to the machine.
            TreeNode modelGroupNode = null;

            switch (tvCustomProperties.SelectedNode.Level)
            {
            case _groupLevel:
                modelGroupNode = tvCustomProperties.SelectedNode;
                break;

            case _definitionLevel:
                modelGroupNode = tvCustomProperties.SelectedNode.Parent;
                break;
            }

            CustomPropertyGroup cpg = modelGroupNode.Tag as CustomPropertyGroup;

            //Create the XML for the Group and it's attributes.
            XmlNode      groupsNode = _loadedDoc.SelectSingleNode("//def:CustomPropertyGroups", _namespaceManager);
            XmlNode      newGroup   = _loadedDoc.CreateNode(XmlNodeType.Element, "CustomPropertyGroup", CustomPropertiesDomainModel.XmlNamespace);
            XmlAttribute nameAttrib = _loadedDoc.CreateAttribute("name");
            XmlAttribute descAttrib = _loadedDoc.CreateAttribute("description");
            XmlAttribute idAttrib   = _loadedDoc.CreateAttribute("id");

            groupsNode.AppendChild(newGroup);
            newGroup.Attributes.Append(nameAttrib);
            newGroup.Attributes.Append(descAttrib);
            newGroup.Attributes.Append(idAttrib);

            //Assign the values from the model group.
            nameAttrib.Value = cpg.Name;
            descAttrib.Value = cpg.Description;
            idAttrib.Value   = cpg.Id.ToString();

            //Create the tree node for the group and set the tag
            TreeNode tNode = _machineNode.Nodes.Add(nameAttrib.Value);

            tNode.Tag = newGroup;
            tvCustomProperties.SelectedNode = tNode;

            //Add all of the definitions for the group we just added to the machine.
            foreach (TreeNode nd in modelGroupNode.Nodes)
            {
                CustomPropertyDefinition newDef = nd.Tag as CustomPropertyDefinition;

                //Create the XML objects for the definition.
                XmlNode newProperty = _loadedDoc.CreateNode(XmlNodeType.Element, "CustomPropertyDefinition", CustomPropertiesDomainModel.XmlNamespace);
                XmlNode newOrmTypes = _loadedDoc.CreateElement("ORMTypes", CustomPropertiesDomainModel.XmlNamespace);
                newProperty.AppendChild(newOrmTypes);
                newGroup.AppendChild(newProperty);

                XmlAttribute defNameAttrib  = _loadedDoc.CreateAttribute("name");
                XmlAttribute categoryAttrib = _loadedDoc.CreateAttribute("category");
                XmlAttribute dataTypeAttrib = _loadedDoc.CreateAttribute("dataType");
                XmlAttribute defDescAttrib  = _loadedDoc.CreateAttribute("description");

                newProperty.Attributes.Append(defNameAttrib);
                newProperty.Attributes.Append(categoryAttrib);
                newProperty.Attributes.Append(dataTypeAttrib);
                newProperty.Attributes.Append(defDescAttrib);

                //Assign them their values from the model object.
                defNameAttrib.Value  = newDef.Name;
                categoryAttrib.Value = newDef.Category;
                defDescAttrib.Value  = newDef.Description;
                dataTypeAttrib.Value = newDef.DataType.ToString();

                //Probably a better way to do this but since the newDef.ORMTypes property is a bit field
                //we need to find out each enumeration that has been specified for the object and add it to the xml.
                AddORMTypeToGroupIfNeeded(newDef.ORMTypes, ORMTypes.AllConstraints, newOrmTypes);
                AddORMTypeToGroupIfNeeded(newDef.ORMTypes, ORMTypes.Model, newOrmTypes);
                AddORMTypeToGroupIfNeeded(newDef.ORMTypes, ORMTypes.ORMDiagram, newOrmTypes);
                AddORMTypeToGroupIfNeeded(newDef.ORMTypes, ORMTypes.ElementGrouping, newOrmTypes);
                AddORMTypeToGroupIfNeeded(newDef.ORMTypes, ORMTypes.EntityType, newOrmTypes);
                AddORMTypeToGroupIfNeeded(newDef.ORMTypes, ORMTypes.CardinalityConstraint, newOrmTypes);
                AddORMTypeToGroupIfNeeded(newDef.ORMTypes, ORMTypes.EqualityConstraint, newOrmTypes);
                AddORMTypeToGroupIfNeeded(newDef.ORMTypes, ORMTypes.ExclusionConstraint, newOrmTypes);
                AddORMTypeToGroupIfNeeded(newDef.ORMTypes, ORMTypes.FactType, newOrmTypes);
                AddORMTypeToGroupIfNeeded(newDef.ORMTypes, ORMTypes.FrequencyConstraint, newOrmTypes);
                AddORMTypeToGroupIfNeeded(newDef.ORMTypes, ORMTypes.MandatoryConstraint, newOrmTypes);
                AddORMTypeToGroupIfNeeded(newDef.ORMTypes, ORMTypes.RingConstraint, newOrmTypes);
                AddORMTypeToGroupIfNeeded(newDef.ORMTypes, ORMTypes.Role, newOrmTypes);
                AddORMTypeToGroupIfNeeded(newDef.ORMTypes, ORMTypes.SubsetConstraint, newOrmTypes);
                AddORMTypeToGroupIfNeeded(newDef.ORMTypes, ORMTypes.SubtypeFact, newOrmTypes);
                AddORMTypeToGroupIfNeeded(newDef.ORMTypes, ORMTypes.UniquenessConstraint, newOrmTypes);
                AddORMTypeToGroupIfNeeded(newDef.ORMTypes, ORMTypes.ValueComparisonConstraint, newOrmTypes);
                AddORMTypeToGroupIfNeeded(newDef.ORMTypes, ORMTypes.ValueConstraint, newOrmTypes);
                AddORMTypeToGroupIfNeeded(newDef.ORMTypes, ORMTypes.ValueType, newOrmTypes);

                //Add the new definition to the TreeView and set it's tag.
                TreeNode newPropertyNode = tNode.Nodes.Add(defNameAttrib.Value);
                newPropertyNode.Tag = newProperty;
            }
        }
示例#25
0
 /// <summary>
 /// Attach the property to verbalize to this instance
 /// </summary>
 /// <param name="definition">A <see cref="CustomPropertyDefinition"/> with a default value.</param>
 public void Attach(CustomPropertyDefinition definition)
 {
     myDefinition = definition;
 }
示例#26
0
 private CustomPropertyDescriptor(CustomPropertyDefinition customPropertyDefinition)
     : base(customPropertyDefinition.Name, null)
 {
     this.customPropertyDefinition = customPropertyDefinition;
 }
示例#27
0
		internal static DslModeling::LinkedElementCollection<CustomProperty> GetCustomPropertyCollection(CustomPropertyDefinition element)
		{
			return GetRoleCollection<DslModeling::LinkedElementCollection<CustomProperty>, CustomProperty>(element, CustomPropertyDefinitionDomainRoleId);
		}