private bool NameValidation(ButtonTreeNode node)
        {
            bool result;

            if (node.Value == null)
            {
                return(false);
            }
            int c = 0;

            foreach (TreeNode n in this.TreeView.Nodes)
            {
                if (((ButtonTreeNode)n.Nodes[0]).Value.ToString() == (string)node.Value)
                {
                    c++;
                }
            }
            result = ((string)node.Value) != "" && c == 1;
            if (result)
            {
                node.ButtonControl.BackColor = Color.White;
            }
            else
            {
                node.ButtonControl.BackColor = SystemColors.Control;
            }
            return(result);
        }
        public ModelSubtree(Type projectType, TreeView parentControl)
            : base()
        {
            this._projectType       = projectType;
            this._description       = new SpectraContainerDescription();
            this._description.name  = String.Format("Document{0}{1}", ((parentControl.Nodes.Count > 8) ? "" : "0"), parentControl.Nodes.Count + 1);
            this._description.model = null;
            //this._description.groupsDefinition = model.GroupsDefinition;
            //this._groupsDefinition =
            this.Text = "Document";
            this.Nodes.Add(new ButtonTreeNode(_description.name, "Document Name", parentControl, new EventHandler(NameTreeNodeClick), new ValidationEventHandler(NameValidation)));
            ButtonTreeNode modelTreeNode = new ButtonTreeNode(_description.model, "Theoretical Model", parentControl, new EventHandler(ModelTreeNodeClick), new ValidationEventHandler(ModelValidation));

            //modelTreeNode.ButtonControl.Enabled = false;
            //modelTreeNode.ButtonControl.BackColor = Color.White;
            this.Nodes.Add(modelTreeNode);
            //foreach (GroupDefinition gd in GroupsDefinition)
            //    if (gd.allowMultiple) {
            //        ButtonTreeNode groupTreeNode = new ButtonTreeNode(new GroupDefinition[] { gd }, "Groups", parentControl, new EventHandler(GroupsTreeNodeClick), new ValidationEventHandler(GroupsValidation));
            //        //groupTreeNode.Value = this._groupsDefinition;
            //        this.Nodes.Add(groupTreeNode);
            //        break;
            //    }
            ButtonTreeNode SpectraTreeNode = new ButtonTreeNode(_description.spectraPaths, "Spectra", parentControl, new EventHandler(SpectraTreeNodeClick), new ValidationEventHandler(SpectraValidation));

            SpectraTreeNode.Name = "Spectra";
            this.Nodes.Add(SpectraTreeNode);
        }
        private bool ModelValidation(ButtonTreeNode node)
        {
            bool result = node.Value is IModel;

            if (result)
            {
                node.ButtonControl.BackColor = Color.White;
            }
            else
            {
                node.ButtonControl.BackColor = SystemColors.Control;
            }
            return(result);
            //return true;
        }
        private void ModelsTree_DrawNode(object sender, DrawTreeNodeEventArgs e)
        {
            Brush brush = null;

            foreach (TreeNode tn in ModelsTree.Nodes)
            {
                DisableButtonTreeNode(tn);
            }
            if (e.Node is ButtonTreeNode)
            {
                ButtonTreeNode btn  = e.Node as ButtonTreeNode;
                Rectangle      rect = new Rectangle(
                    ModelsTree.ClientRectangle.Width - 210,
                    e.Bounds.Y,
                    200,
                    ModelsTree.ItemHeight - 1);
                btn.ButtonControl.Bounds = rect;
                //color
            }
            if (e.Node is IValidable)
            {
                if (!((IValidable)e.Node).IsValid)
                {
                    brush = Brushes.Red;
                }
                else
                {
                    brush = Brushes.Green;
                }
            }
            else
            {
                if ((e.State & TreeNodeStates.Selected) == TreeNodeStates.Selected)
                {
                    brush = Brushes.White;
                }
                else
                {
                    brush = Brushes.Black;
                }
            }
            int x = (ModelsTree.ItemHeight - (int)e.Graphics.MeasureString(e.Node.Text, ModelsTree.Font).Height) / 2;

            e.Graphics.DrawString(e.Node.Text, ModelsTree.Font,
                                  brush, e.Bounds.Left, e.Bounds.Top + x);
            e.DrawDefault = false;
            ValidateProject();
        }
        private void ModelTreeNodeClick(object sender, EventArgs e)
        {
            ModelChooserDialog mcd = new ModelChooserDialog(_projectType);
            //if (Program.MainWindow.CurrentWizard != null)
            //    Program.MainWindow.CurrentWizard.DialogOpened(mcd);

            DialogResult result = mcd.ShowDialog();

            if (result == DialogResult.OK)
            {
                this._description.model = AvailableAssemblies.getModel(mcd.Selection.plugin.className);
                ((ButtonTreeNode)this.Nodes[1]).Value = this._description.model;
                ((Button)sender).Text = ButtonTreeNode.getButtonString(this._description.model);
                this.ProjectType      = this._description.model.ProjectType;
            }
            //if (Program.MainWindow.CurrentWizard != null)
            //    Program.MainWindow.CurrentWizard.DialogClosed();
            mcd.Dispose();
            this.TreeView.Invalidate();
        }
        private bool SpectraValidation(ButtonTreeNode node)
        {
            bool result;

            if (node.Value == null)
            {
                result = false;
            }
            else
            {
                result = ((string[])node.Value).Length > 0;
            }
            if (result)
            {
                node.ButtonControl.BackColor = Color.White;
            }
            else
            {
                node.ButtonControl.BackColor = SystemColors.Control;
            }
            return(result);
        }
        //private void GroupsTreeNodeClick(object sender, EventArgs e) {
        //    GroupsDialog groupsDialog = new GroupsDialog(this.GroupsDefinition, this._description.model.GroupsDefinition);
        //    if (groupsDialog.ShowDialog() == DialogResult.OK) {
        //        this._description.groupsDefinition = groupsDialog.GroupsDefinition;
        //        ((ButtonTreeNode)this.Nodes[2]).Value = this._description.groupsDefinition;
        //        ((Button)sender).Text = ButtonTreeNode.getButtonString(this._description.groupsDefinition);
        //    }
        //    groupsDialog.Dispose();
        //    this.TreeView.Invalidate();
        //}

        //private bool GroupsValidation(ButtonTreeNode node) {
        //    bool result = node.Value != null;
        //    if (result) {

        //        int zeroCount = 0;
        //        foreach (GroupDefinition gd in (GroupDefinition[])node.Value) {
        //            if (gd.kind == 1) zeroCount++;  //sample
        //        }
        //        result = zeroCount > 0;
        //    }
        //    if (result)
        //        node.ButtonControl.BackColor = Color.White;
        //    else
        //        node.ButtonControl.BackColor = SystemColors.Control;
        //    return result;
        //}

        private void SpectraTreeNodeClick(object sender, EventArgs e)
        {
            SpectraDialog sd;

            //if (this._description.spectraPaths != null) {
            sd = new SpectraDialog(this._description.spectraPaths);
            //}
            if (sd.ShowDialog() == DialogResult.OK)
            {
                this._description.spectraPaths = new string[sd.spectraList.Items.Count];
                for (int i = 0; i < sd.spectraList.Items.Count; i++)
                {
                    this._description.spectraPaths[i] = (string)sd.spectraList.Items[i];
                }

                //this._description.spectraPaths = sd.SpectraFiles;
                ButtonTreeNode treeNode = (ButtonTreeNode)(this.Nodes.Find("Spectra", false)[0]);
                treeNode.Value        = this._description.spectraPaths;
                ((Button)sender).Text = ButtonTreeNode.getButtonString(this._description.spectraPaths);
            }
            sd.Dispose();
            this.TreeView.Invalidate();
        }