public BranchConfigViewModel(AppViewModel appDefinition, ConfigNodeViewModel parent
            , XmlNode definitionNode, string parentXPath, XmlNode configNode= null, bool initChildren= true)
        {
            commonInit(appDefinition,parent, definitionNode,parentXPath);

            m_className = definitionNode.Attributes[XMLConfig.classAttribute].Value;
            if (definitionNode.Attributes.GetNamedItem(XMLConfig.windowAttribute) != null)
                m_window = definitionNode.Attributes[XMLConfig.windowAttribute].Value;
            else m_window = "";
            if (definitionNode.Attributes.GetNamedItem(XMLConfig.optionalAttribute) != null)
                bIsOptional = definitionNode.Attributes[XMLConfig.optionalAttribute].Value == "true";
            else bIsOptional = false;

            if (configNode != null)
            {
                configNode = configNode[name];
                if (configNode != null && bIsOptional)
                    bIsUsed = true;
            }
            else if (bIsOptional)
                bIsUsed = true;

            if (initChildren)
                childrenInit(appDefinition, appDefinition.getClassDefinition(m_className), m_xPath, configNode);
        }
        public ChoiceElementConfigViewModel(AppViewModel appDefinition, ConfigNodeViewModel parent, XmlNode definitionNode
            , string parentXPath, XmlNode configNode= null)
        {
            commonInit(appDefinition,parent,definitionNode,parentXPath);

            m_className = definitionNode.Attributes[XMLConfig.classAttribute].Value;
            if (definitionNode.Attributes.GetNamedItem(XMLConfig.windowAttribute) != null)
                m_window = definitionNode.Attributes[XMLConfig.windowAttribute].Value;
            else m_window = "";
            if (definitionNode.Attributes.GetNamedItem(XMLConfig.optionalAttribute) != null)
                m_bOptional = definitionNode.Attributes[XMLConfig.optionalAttribute].Value == "true";
            else m_bOptional = false;
            if (definitionNode.Attributes.GetNamedItem(XMLConfig.loadXMLFileAttribute) != null)
                m_loadXML = definitionNode.Attributes[XMLConfig.loadXMLFileAttribute].Value;
            else m_loadXML = "";

            if (m_loadXML != "")
            {
                m_appViewModel.loadAuxDefinitions(m_loadXML);
            }

            if (configNode != null)
                configNode = configNode[name];
            //we allow an undefined class ("", most likely) and we just ignore children
            childrenInit(appDefinition, appDefinition.getClassDefinition(m_className,true)
                , m_xPath, configNode);
        }
 //constructor called from the editor on forking a node
 public ForkValueViewModel(string valueName, ForkedNodeViewModel parent, ConfigNodeViewModel forkedNode)
 {
     name = valueName;
     m_parent = parent;
     configNode = forkedNode;
     //the config node now hangs from this fork value
     configNode.parent = this;
 }
 //constructor called when loading a fork from a .badger file
 public ForkValueViewModel(AppViewModel appViewModel,XmlNode classDefinition
     , ConfigNodeViewModel parentNode, XmlNode configNode)
 {
     name = configNode.Attributes[XMLConfig.nameAttribute].Value;
     //not sure how to do this in a more elegant way
     this.configNode = ConfigNodeViewModel.getInstance(appViewModel, parentNode
         , classDefinition, parentNode.xPath, configNode);
     this.configNode.bCanBeForked = false; //already belongs to a fork
 }
        //Constructor used from the experiment editor
        public ForkedNodeViewModel(AppViewModel appViewModel,ConfigNodeViewModel forkedNode)
        {
            m_parent = forkedNode.parent;

            ForkValueViewModel newForkValue= new ForkValueViewModel("Value-0", this, forkedNode);
            children.Add(newForkValue);
            selectedForkValue = newForkValue;

            m_appViewModel = appViewModel;
            nodeDefinition = forkedNode.nodeDefinition;
            name = forkedNode.name;
            NotifyOfPropertyChange(() => selectedForkValue);
        }
        public DoubleValueConfigViewModel(AppViewModel appViewModel, ConfigNodeViewModel parent, XmlNode definitionNode, string parentXPath, XmlNode configNode = null)
        {
            commonInit(appViewModel, parent, definitionNode, parentXPath);

            if (configNode == null || configNode[name]==null)
            {
                //default init
                content = definitionNode.Attributes[XMLConfig.defaultAttribute].Value;
                textColor = XMLConfig.colorDefaultValue;
            }
            else
            {
                //init from config file
                content = configNode[name].InnerText;
            }
        }
        public EnumeratedValueConfigViewModel(AppViewModel appDefinition, ConfigNodeViewModel parent, XmlNode definitionNode, string parentXPath, XmlNode configNode = null)
        {
            commonInit(appDefinition, parent, definitionNode, parentXPath);

            m_class = definitionNode.Attributes[XMLConfig.classAttribute].Value;
            enumeratedNames = m_appViewModel.getEnumeratedType(m_class);

            if (configNode == null || configNode[name] == null)
            {
                content = m_default;
                textColor = XMLConfig.colorDefaultValue;
            }
            else
            {
                //init from config file
                content = configNode[name].InnerText;
            }
        }
        //Constructor called when loading an experiment config file
        public ForkedNodeViewModel(AppViewModel appViewModel,ConfigNodeViewModel parentNode
            ,XmlNode classDefinition,XmlNode configNode= null, bool initChildren= true)
        {
            m_appViewModel = appViewModel;
            nodeDefinition = classDefinition;
            m_parent = parentNode;
            name = configNode.Attributes[XMLConfig.nameAttribute].Value;

            if (initChildren)
            {
                foreach (XmlNode forkValueConfig in configNode.ChildNodes)
                {
                    children.Add(new ForkValueViewModel(appViewModel, classDefinition, this, forkValueConfig));
                }
            }
            //notify changes
            if (children.Count > 0)
                selectedForkValue = children[0] as ForkValueViewModel;
            NotifyOfPropertyChange(() => children);
        }
        public XmlDefRefValueConfigViewModel(AppViewModel appDefinition, ConfigNodeViewModel parent, XmlNode definitionNode, string parentXPath, XmlNode configNode = null)
        {
            commonInit(appDefinition, parent, definitionNode, parentXPath);

            m_hangingFrom = definitionNode.Attributes[XMLConfig.hangingFromAttribute].Value;

            if (configNode != null)
            {
                configNode = configNode[name];
                selectedEnumeratedName = configNode.InnerText;
            }

            //the xml definition file may not be yet loaded
            enumeratedNames = m_appViewModel.getAuxDefinition(m_hangingFrom);

            if (enumeratedNames == null)
            {
                //Either we have loaded the config but the list is of values has not yet been loaded
                //or no config file has been loaded. In Either case, we register for a deferred load step
                m_appViewModel.registerDeferredLoadStep(updateXMLDefRef);
            }

            m_appViewModel.registerXMLDefRef(updateXMLDefRef);
        }
        public MultiValuedConfigViewModel(AppViewModel appDefinition, ConfigNodeViewModel parent
            , XmlNode definitionNode, string parentXPath, XmlNode configNode= null, bool initChildren= true)
        {
            commonInit(appDefinition,parent, definitionNode,parentXPath);

            m_className = definitionNode.Attributes[XMLConfig.classAttribute].Value;
            if (definitionNode.Attributes.GetNamedItem(XMLConfig.optionalAttribute) != null)
                m_bOptional = definitionNode.Attributes[XMLConfig.optionalAttribute].Value == "true";
            else m_bOptional = false;

            if (configNode!=null)
            {
                foreach(XmlNode configChild in configNode.ChildNodes)
                {
                    if (configChild.Name==name)
                        children.Add(new MultiValuedItemConfigViewModel(appDefinition, this,definitionNode, m_xPath, configChild));
                }
            }
            else //default initialization
            {
                if (initChildren && !m_bOptional)
                    children.Add(new MultiValuedItemConfigViewModel(appDefinition, this,definitionNode, m_xPath));
            }
        }
        public ChoiceConfigViewModel(AppViewModel appDefinition, ConfigNodeViewModel parent
            , XmlNode definitionNode
            , string parentXPath, XmlNode configNode = null, bool initChildren= true)
        {
            string choiceElementName;
            commonInit(appDefinition, parent, definitionNode, parentXPath);

            if (configNode != null) configNode = configNode[name];

            if (initChildren)
            {
                foreach (XmlNode choiceElement in definitionNode.ChildNodes)
                {
                    choiceElementName = choiceElement.Attributes[XMLConfig.nameAttribute].Value;

                    m_choiceNames.Add(choiceElementName);

                    if (configNode != null && choiceElementName == configNode.ChildNodes[0].Name)
                    {
                        loadSelectedChoiceElement(choiceElementName, configNode);
                    }
                }
            }
        }