//create TriStateTreeView from Object Model public void ShowAllFeatures(TriStateTreeView treeView, FeatureModel fm) { rootFeature = fm.RootFeature; // Clear TriStateTreeView treeView.Nodes.Clear(); // treeView.BeginUpdate(); treeView.InitializeRootFeature(ref rootFeature); FeatureTreeNode rn = new FeatureTreeNode(); rn.Text = rootFeature.name; rn.InitializeRootFeature(ref rootFeature); //treeView.SetChecked(rn, TriStateTreeView.CheckState.Checked); treeView.SetChecked(rn, TriStateTreeView.CheckState.Greyed); treeView.Nodes.Add(rn); foreach (object o in rootFeature.Items) { if (o.GetType() == typeof(FeatureType)) { FeatureType ft = (FeatureType)o; FeatureTreeNode subRootNode = new FeatureTreeNode(); subRootNode.Text = ft.name; subRootNode.InitializeFeature(ref ft); if (ft.kind == KindType.Optional || ft.kind == KindType.FeatureSetFeature) { subRootNode.NodeFont = new System.Drawing.Font("Arial", 8, System.Drawing.FontStyle.Bold); } switch (ft.configuration) { case ConfigType.Included: if (ft.kind == KindType.Mandatory) { //treeView.SetChecked(subRootNode, TriStateTreeView.CheckState.Checked); treeView.SetChecked(subRootNode, TriStateTreeView.CheckState.Greyed); } else { treeView.SetChecked(subRootNode, TriStateTreeView.CheckState.Checked); } break; case ConfigType.Excluded: treeView.SetChecked(subRootNode, TriStateTreeView.CheckState.Unchecked); break; case ConfigType.Unspecified: treeView.SetChecked(subRootNode, TriStateTreeView.CheckState.QuestionMark); break; } rn.Nodes.Add(subRootNode); CreateTreeNode(subRootNode, ft, treeView); } else if (o.GetType() == typeof(FeatureSetType)) { FeatureSetType fst = (FeatureSetType)o; FeatureTreeNode subRootNode = new FeatureTreeNode(); subRootNode.Text = string.Format("FeatureSet [{0}...{1}]", fst.min, fst.max); treeView.SetChecked(subRootNode, TriStateTreeView.CheckState.FeatureSet); rn.Nodes.Add(subRootNode); CreateTreeNode(subRootNode, fst, treeView); } } treeView.ExpandAll(); treeView.EndUpdate(); }
private void loadModelFromXmlFileToolStripMenuItem_Click(object sender, EventArgs e) { this.toolStripStatusLabel.Text = "Ready"; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Feature Configuration Files (*.featureconfig)|*.featureconfig|All Files (*.*)|*.*"; openFileDialog.AddExtension = true; openFileDialog.CheckFileExists = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { //this.statusTextBox.Text = ""; FeatureModelConfigurator.Properties.Settings settings = new FeatureModelConfigurator.Properties.Settings(); string path = Application.StartupPath; FeatureModel oldFeatureModel = featureModel; featureModel = new FeatureModel(openFileDialog.FileName); try { featureModel.ValidateXmlFile(string.Concat(path, "\\", settings.xmlschemapath)); if (featureModel.Validity) { this.triStateTreeView.InitializeFeatureModel(ref featureModel); //this.triStateTreeView.InitializeStatusTextBox(ref this.statusTextBox); // Set Text of Gpoupbox with model filename this.featureModelGroupBox.Text = openFileDialog.FileName; featureModel.CreateTreeViewFromXmlFile(this.triStateTreeView); this.triStateTreeView.Visible = true; // this.toolStripStatusLabel.Text = string.Format("Model from '{0}' successfully loaded", openFileDialog.FileName); // this.saveModelToXmlFileToolStripMenuItem.Enabled = true; this.toolStripButtonReset.Enabled = true; this.toolStripButtonSave.Enabled = true; this.toolStripButtonSaveAs.Enabled = true; this.toolStripButtonClose.Enabled = true; this.variabilityFMCheckBox.Enabled = true; // ArrayList errorArray = featureModel.CheckConfiguredModel(); string[] array = (string[])errorArray.ToArray(typeof(string)); //this.statusTextBox.Lines = array; } else { //this.statusTextBox.Text = string.Format("XML-File '{0}' is not valid!", featureModel.FileName); this.toolStripStatusLabel.Text = "Loading failed"; featureModel = oldFeatureModel; } } catch (Exception exception) { System.Windows.Forms.MessageBox.Show(exception.Message, "Feature Model Loading Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
///// ------------------------------------------------------------------------------------ ///// <summary> ///// Build a list of all of the tag data for checked items in the tree. ///// </summary> ///// <param name="node"></param> ///// <param name="list"></param> ///// ------------------------------------------------------------------------------------ //private void BuildTagDataList(TreeNode node, ArrayList list) //{ // if (GetChecked(node) == CheckState.Checked && node.Tag != null) // list.Add(node.Tag); // foreach (TreeNode child in node.Nodes) // BuildTagDataList(child, list); //} ///// ------------------------------------------------------------------------------------ ///// <summary> ///// Look through the tree nodes to find the node that has given tag data and check it. ///// </summary> ///// <param name="node"></param> ///// <param name="tag"></param> ///// <param name="state"></param> ///// ------------------------------------------------------------------------------------ //private void FindAndCheckNode(TreeNode node, object tag, CheckState state) //{ // if (node.Tag != null && node.Tag.Equals(tag)) // { // SetChecked(node, state); // return; // } // foreach (TreeNode child in node.Nodes) // FindAndCheckNode(child, tag, state); //} #endregion #region Public methods //public void InitializeStatusTextBox(ref TextBox _statusTextBox) //{ // this.statusTextBox = _statusTextBox; //} public void InitializeFeatureModel(ref FeatureModel _featureModel) { this.featureModel = _featureModel; }