/// <summary>Populate the checkpoint list control.</summary> /// <param name="models"></param> private void PopulateList() { var checkpointNames = storage.Reader.CheckpointNames; rootNode = new TreeViewNode() { Name = "Checkpoints", ResourceNameForImage = ExplorerPresenter.GetIconResourceName(typeof(Folder), null, null) }; foreach (var checkpointName in checkpointNames) { var node = new TreeViewNode() { Name = checkpointName, ResourceNameForImage = "ApsimNG.Resources.TreeViewImages.Document.png" }; if (storage.Reader.GetCheckpointShowOnGraphs(checkpointName)) { node.ResourceNameForImage = "ApsimNG.Resources.TreeViewImages.DocumentCheck.png"; } rootNode.Children.Add(node); } checkpointList.Populate(rootNode); checkpointList.ExpandChildren(".Checkpoints"); }
private static void AddTreeNodeIfDoesntExist(Apsim.ModelDescription modelThatCanBeAdded, TreeViewNode parent) { var namespaceWords = modelThatCanBeAdded.ModelType.Namespace.Split(".".ToCharArray()).ToList(); // Remove the first namespace word ('Models') namespaceWords.Remove(namespaceWords.First()); foreach (var namespaceWord in namespaceWords.Where(word => word != "Models")) { var node = parent.Children.Find(n => n.Name == namespaceWord); if (node == null) { node = new TreeViewNode() { Name = namespaceWord, ResourceNameForImage = ExplorerPresenter.GetIconResourceName(typeof(Folder), null, null) }; parent.Children.Add(node); } parent = node; } // Add the last model var description = new TreeViewNode() { Name = modelThatCanBeAdded.ModelName, ResourceNameForImage = ExplorerPresenter.GetIconResourceName(modelThatCanBeAdded.ModelType, modelThatCanBeAdded.ModelName, modelThatCanBeAdded.ResourceString) }; parent.Children.Add(description); }
private static void AddTreeNodeIfDoesntExist(Apsim.ModelDescription modelThatCanBeAdded, TreeViewNode parent) { List <string> namespaceWords; // Remove the first namespace word ('Models') bool resourceIsInSubDirectory = false; if (modelThatCanBeAdded.ResourceString != null) { // Need to determine if the resource name is in a sub directory of Models.Resources e.g. Models.Resources.GrazPlan.Cattle.Angus.json var subDirectory = modelThatCanBeAdded.ResourceString.Replace("Models.Resources.", "").Replace(".json", ""); resourceIsInSubDirectory = subDirectory.Contains('.'); } if (resourceIsInSubDirectory) { var path = modelThatCanBeAdded.ResourceString.Replace("Models.Resources.", ""); namespaceWords = path.Split(".".ToCharArray()).ToList(); namespaceWords.Remove(namespaceWords.Last()); // remove the "json" word at the end. namespaceWords.Remove(namespaceWords.Last()); // remove the model name at the end. } else { namespaceWords = modelThatCanBeAdded.ModelType.Namespace.Split(".".ToCharArray()).ToList(); namespaceWords.Remove(namespaceWords.First()); modelThatCanBeAdded.ResourceString = modelThatCanBeAdded.ModelName; } foreach (var namespaceWord in namespaceWords.Where(word => word != "Models")) { var node = parent.Children.Find(n => n.Name == namespaceWord); if (node == null) { node = new TreeViewNode() { Name = namespaceWord, ResourceNameForImage = ExplorerPresenter.GetIconResourceName(typeof(Folder), null, null) }; parent.Children.Add(node); } parent = node; } // Add the last model var description = new TreeViewNode() { Name = modelThatCanBeAdded.ModelName, ResourceNameForImage = ExplorerPresenter.GetIconResourceName(modelThatCanBeAdded.ModelType, modelThatCanBeAdded.ModelName, modelThatCanBeAdded.ResourceString) }; parent.Children.Add(description); }
/// <summary>Populate the tree control.</summary> /// <param name="models"></param> private void PopulateTree(IEnumerable <Apsim.ModelDescription> models) { var rootNode = new TreeViewNode() { Name = "Models", ResourceNameForImage = ExplorerPresenter.GetIconResourceName(typeof(Simulations), null, null) }; foreach (var modelThatCanBeAdded in models) { AddTreeNodeIfDoesntExist(modelThatCanBeAdded, rootNode); } tree.Populate(rootNode); if (models.Count() < 10) { tree.ExpandChildren(".Models"); } }