Example #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;
                }
            }
        }
Example #2
0
 public sealed override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null)
     {
         ModelElement element = EditorUtility.ResolveContextInstance(context.Instance, false) as ModelElement;
         if (element != null)
         {
             CustomPropertiesManager.ShowCustomGroups(element.Store, provider);
         }
     }
     return(value);
 }
Example #3
0
        /// <summary>
        /// Goes through all of the machine level groups that are marked as default
        /// and adds them to the model if needed.
        /// </summary>
        /// <param name="store">The current store</param>
        /// <param name="activeForm">An active form</param>
        /// <param name="notifyAdded">Used during deserialization fixup</param>
        private static void ApplyDefaultGroups(Store store, CustomPropertiesManager activeForm, INotifyElementAdded notifyAdded)
        {
            XmlNodeList defaultGroups = _loadedDoc.SelectNodes("//def:CustomPropertyGroup[@isDefault='true']", _namespaceManager);
            Dictionary <CustomPropertyGroup, List <CustomPropertyDefinition> > groupsAndDefs = GetGroupsAndDefsFromStore(store);

            foreach (XmlNode xmlGroup in defaultGroups)
            {
                string groupName = xmlGroup.Attributes["name"].Value;
                if (!ListHasGroupName(groupsAndDefs, groupName))
                {
                    AddGroupToModel(store, xmlGroup, activeForm, notifyAdded);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Loads the form and shows the custom groups that have been defined on the machine
        /// and in the specified model.
        /// </summary>
        /// <param name="store">The store for the current model.</param>
        /// <param name="serviceProvider">The service provider to use to display the form.</param>
        public static void ShowCustomGroups(Store store, IServiceProvider serviceProvider)
        {
            if (store == null)
            {
                return;
            }
            if (serviceProvider == null)
            {
                serviceProvider = store;
            }
            using (Transaction t = store.TransactionManager.BeginTransaction(ResourceStrings.CustomPropertiesManagerTransactionName))
            {
                CustomPropertiesManager mgr = new CustomPropertiesManager();
                mgr._store = store;

                mgr.tvCustomProperties.Nodes.Clear();
                mgr._machineNode = mgr.tvCustomProperties.Nodes.Add("Machine");
                mgr._modelNode   = mgr.tvCustomProperties.Nodes.Add("Model");

                EnsureMachineDocument();

                XmlNodeList groups = _loadedDoc.SelectNodes("//def:CustomPropertyGroup", _namespaceManager);
                foreach (XmlNode group in groups)
                {
                    TreeNode newGroupNode = mgr._machineNode.Nodes.Add(group.Attributes["name"].InnerText);
                    newGroupNode.Tag = group;

                    if (group.Attributes["isDefault"] != null && group.Attributes["isDefault"].Value == "true")
                    {
                        newGroupNode.Text += " (Default)";
                    }

                    XmlNodeList defs = group.SelectNodes("def:CustomPropertyDefinition", _namespaceManager);
                    foreach (XmlNode def in defs)
                    {
                        TreeNode defNode = newGroupNode.Nodes.Add(def.Attributes["name"].InnerText);
                        defNode.Tag = def;
                    }
                }

                Dictionary <CustomPropertyGroup, List <CustomPropertyDefinition> > groupsAndDefs = GetGroupsAndDefsFromStore(store);
                foreach (CustomPropertyGroup grp in groupsAndDefs.Keys)
                {
                    TreeNode groupNode = mgr._modelNode.Nodes.Add(grp.Name);
                    groupNode.Tag = grp;
                    foreach (CustomPropertyDefinition def in groupsAndDefs[grp])
                    {
                        TreeNode defNode = groupNode.Nodes.Add(def.Name);
                        defNode.Tag = def;
                    }
                }

                ApplyDefaultGroups(store, mgr, null);

                bool saveChanges = false;
                IWindowsFormsEditorService windowsFormsEditorService = serviceProvider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
                IUIService uiService;
                if (windowsFormsEditorService != null)
                {
                    saveChanges = (windowsFormsEditorService.ShowDialog(mgr) == DialogResult.OK);
                }
                else if ((uiService = serviceProvider.GetService(typeof(IUIService)) as IUIService) != null)
                {
                    saveChanges = (uiService.ShowDialog(mgr) == DialogResult.OK);
                }

                if (saveChanges)
                {
                    t.Commit();
                }
                else
                {
                    t.Rollback();
                }
            }
        }