/// <summary> /// Format the grid. /// </summary> private void FormatGrid() { for (int i = 0; i < properties.Count; i++) { IGridCell cell = grid.GetCell(1, i); if (properties[i] is VariableObject) { cell.EditorType = EditorTypeEnum.TextBox; grid.SetRowAsSeparator(i, true); } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.TableName) { cell.EditorType = EditorTypeEnum.DropDown; cell.DropDownStrings = storage.Reader.TableNames.ToArray(); } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.CultivarName) { cell.EditorType = EditorTypeEnum.DropDown; IPlant crop = GetCrop(properties); if (crop != null) { cell.DropDownStrings = GetCultivarNames(crop); } } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.FileName) { cell.EditorType = EditorTypeEnum.Button; } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.FieldName) { cell.EditorType = EditorTypeEnum.DropDown; List <string> fieldNames = GetFieldNames(); if (fieldNames != null) { fieldNames.Insert(0, string.Empty); cell.DropDownStrings = fieldNames.ToArray(); } } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.ResidueName && model is SurfaceOrganicMatter) { cell.EditorType = EditorTypeEnum.DropDown; string[] fieldNames = GetResidueNames(); if (fieldNames != null) { cell.DropDownStrings = fieldNames; } } else if (properties[i].Display != null && (properties[i].Display.Type == DisplayType.CLEMResourceName)) { cell.EditorType = EditorTypeEnum.DropDown; List <string> fieldNames = new List <string>(); fieldNames.AddRange(this.GetCLEMResourceNames(this.properties[i].Display.CLEMResourceNameResourceGroups)); // add any extras elements provided to the list. if (this.properties[i].Display.CLEMExtraEntries != null) { fieldNames.AddRange(this.properties[i].Display.CLEMExtraEntries); } if (fieldNames.Count != 0) { cell.DropDownStrings = fieldNames.ToArray(); } } else if (properties[i].Display != null && (properties[i].Display.Type == DisplayType.CLEMCropFileName)) { cell.EditorType = EditorTypeEnum.DropDown; List <string> fieldNames = new List <string>(); Simulation clemParent = Apsim.Parent(this.model, typeof(Simulation)) as Simulation; // get crop file names fieldNames.AddRange(Apsim.ChildrenRecursively(clemParent, typeof(FileCrop)).Select(a => a.Name).ToList()); fieldNames.AddRange(Apsim.ChildrenRecursively(clemParent, typeof(FileSQLiteCrop)).Select(a => a.Name).ToList()); if (fieldNames.Count != 0) { cell.DropDownStrings = fieldNames.ToArray(); } } else if (properties[i].Display != null && (properties[i].Display.Type == DisplayType.CLEMGraspFileName)) { cell.EditorType = EditorTypeEnum.DropDown; List <string> fieldNames = new List <string>(); Simulation clemParent = Apsim.Parent(this.model, typeof(Simulation)) as Simulation; // get GRASP file names fieldNames.AddRange(Apsim.ChildrenRecursively(clemParent, typeof(FileGRASP)).Select(a => a.Name).ToList()); fieldNames.AddRange(Apsim.ChildrenRecursively(clemParent, typeof(FileSQLiteGRASP)).Select(a => a.Name).ToList()); if (fieldNames.Count != 0) { cell.DropDownStrings = fieldNames.ToArray(); } } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.Model) { cell.EditorType = EditorTypeEnum.DropDown; string[] modelNames = GetModelNames(properties[i].Display.ModelType); if (modelNames != null) { cell.DropDownStrings = modelNames; } } else { object cellValue = properties[i].ValueWithArrayHandling; if (cellValue is DateTime) { cell.EditorType = EditorTypeEnum.DateTime; } else if (cellValue is bool) { cell.EditorType = EditorTypeEnum.Boolean; } else if (cellValue.GetType().IsEnum) { cell.EditorType = EditorTypeEnum.DropDown; cell.DropDownStrings = VariableProperty.EnumToStrings(cellValue); Enum cellValueAsEnum = cellValue as Enum; if (cellValueAsEnum != null) { cell.Value = VariableProperty.GetEnumDescription(cellValueAsEnum); } } else if (cellValue.GetType() == typeof(IPlant)) { cell.EditorType = EditorTypeEnum.DropDown; List <string> cropNames = new List <string>(); foreach (Model crop in Apsim.FindAll(model, typeof(IPlant))) { cropNames.Add(crop.Name); } cell.DropDownStrings = cropNames.ToArray(); } else if (properties[i].DataType == typeof(IPlant)) { List <string> plantNames = Apsim.FindAll(model, typeof(IPlant)).Select(m => m.Name).ToList(); cell.EditorType = EditorTypeEnum.DropDown; cell.DropDownStrings = plantNames.ToArray(); } else if (!string.IsNullOrWhiteSpace(properties[i].Display?.Values)) { MethodInfo method = model.GetType().GetMethod(properties[i].Display.Values); string[] values = ((IEnumerable <object>)method.Invoke(model, null))?.Select(v => v?.ToString())?.ToArray(); cell.EditorType = EditorTypeEnum.DropDown; cell.DropDownStrings = values; } else { cell.EditorType = EditorTypeEnum.TextBox; } } } IGridColumn descriptionColumn = grid.GetColumn(0); descriptionColumn.Width = -1; descriptionColumn.ReadOnly = true; IGridColumn valueColumn = grid.GetColumn(1); valueColumn.Width = -1; }
/// <summary> /// Format the grid. /// </summary> private void FormatGrid() { for (int i = 0; i < this.properties.Count; i++) { IGridCell cell = this.grid.GetCell(1, i); if (this.properties[i] is VariableObject) { cell.EditorType = EditorTypeEnum.TextBox; grid.SetRowAsSeparator(i, true); } else if (this.properties[i].Display != null && this.properties[i].Display.Type == DisplayType.TableName) { cell.EditorType = EditorTypeEnum.DropDown; cell.DropDownStrings = this.storage.TableNames.ToArray(); } else if (this.properties[i].Display != null && this.properties[i].Display.Type == DisplayType.CultivarName) { cell.EditorType = EditorTypeEnum.DropDown; IPlant crop = this.GetCrop(this.properties); if (crop != null) { cell.DropDownStrings = this.GetCultivarNames(crop); } } else if (this.properties[i].Display != null && this.properties[i].Display.Type == DisplayType.FileName) { cell.EditorType = EditorTypeEnum.Button; } else if (this.properties[i].Display != null && this.properties[i].Display.Type == DisplayType.FieldName) { cell.EditorType = EditorTypeEnum.DropDown; string[] fieldNames = this.GetFieldNames(); if (fieldNames != null) { cell.DropDownStrings = fieldNames; } } else if (this.properties[i].Display != null && this.properties[i].Display.Type == DisplayType.ResidueName && this.model is Models.Surface.SurfaceOrganicMatter) { cell.EditorType = EditorTypeEnum.DropDown; string[] fieldNames = GetResidueNames(); if (fieldNames != null) { cell.DropDownStrings = fieldNames; } } else if (this.properties[i].Display != null && properties[i].Display.Type == DisplayType.Model) { cell.EditorType = EditorTypeEnum.DropDown; string[] modelNames = GetModelNames(properties[i].Display.ModelType); if (modelNames != null) { cell.DropDownStrings = modelNames; } } else { object cellValue = this.properties[i].ValueWithArrayHandling; if (cellValue is DateTime) { cell.EditorType = EditorTypeEnum.DateTime; } else if (cellValue is bool) { cell.EditorType = EditorTypeEnum.Boolean; } else if (cellValue.GetType().IsEnum) { cell.EditorType = EditorTypeEnum.DropDown; cell.DropDownStrings = VariableProperty.EnumToStrings(cellValue); Enum cellValueAsEnum = cellValue as Enum; if (cellValueAsEnum != null) { cell.Value = VariableProperty.GetEnumDescription(cellValueAsEnum); } } else if (cellValue.GetType() == typeof(IPlant)) { cell.EditorType = EditorTypeEnum.DropDown; List <string> cropNames = new List <string>(); foreach (Model crop in Apsim.FindAll(this.model, typeof(IPlant))) { cropNames.Add(crop.Name); } cell.DropDownStrings = cropNames.ToArray(); } else if (this.properties[i].DataType == typeof(IPlant)) { List <string> plantNames = Apsim.FindAll(this.model, typeof(IPlant)).Select(m => m.Name).ToList(); cell.EditorType = EditorTypeEnum.DropDown; cell.DropDownStrings = plantNames.ToArray(); } else { cell.EditorType = EditorTypeEnum.TextBox; } } } IGridColumn descriptionColumn = this.grid.GetColumn(0); descriptionColumn.Width = -1; descriptionColumn.ReadOnly = true; IGridColumn valueColumn = this.grid.GetColumn(1); valueColumn.Width = -1; }
/// <summary> /// Format the grid. /// </summary> protected virtual void FormatGrid() { for (int i = 0; i < properties.Count; i++) { IGridCell cell = grid.GetCell(1, i); if (properties[i] is VariableObject) { cell.EditorType = EditorTypeEnum.TextBox; grid.SetRowAsSeparator(i, true); } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.TableName) { cell.EditorType = EditorTypeEnum.DropDown; if (storage == null) { storage = model.FindInScope <IDataStore>(); } cell.DropDownStrings = storage.Reader.TableNames.ToArray(); } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.CultivarName) { cell.EditorType = EditorTypeEnum.DropDown; IPlant crop; if (properties[i].Display.PlantName != null) { crop = model.FindInScope <IPlant>(properties[i].Display.PlantName); } else { crop = GetCrop(properties); } if (crop != null) { cell.DropDownStrings = PropertyPresenterHelpers.GetCultivarNames(crop); } } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.LifeCycleName) { cell.EditorType = EditorTypeEnum.DropDown; Zone zone = model.FindInScope <Zone>(); if (zone != null) { cell.DropDownStrings = PropertyPresenterHelpers.GetLifeCycleNames(zone); } } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.LifePhaseName) { cell.EditorType = EditorTypeEnum.DropDown; LifeCycle lifeCycle = GetLifeCycle(properties); if (lifeCycle != null) { cell.DropDownStrings = PropertyPresenterHelpers.GetPhaseNames(lifeCycle); } } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.FileName) { cell.EditorType = EditorTypeEnum.Button; } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.FileNames) { cell.EditorType = EditorTypeEnum.MultiFiles; } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.DirectoryName) { cell.EditorType = EditorTypeEnum.DirectoryChooser; } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.FieldName) { cell.EditorType = EditorTypeEnum.DropDown; List <string> fieldNames = GetFieldNames(); if (fieldNames != null) { fieldNames.Insert(0, string.Empty); cell.DropDownStrings = fieldNames.ToArray(); } } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.ResidueName && model is SurfaceOrganicMatter) { cell.EditorType = EditorTypeEnum.DropDown; string[] fieldNames = GetResidueNames(); if (fieldNames != null) { cell.DropDownStrings = fieldNames; } } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.Model) { cell.EditorType = EditorTypeEnum.DropDown; string[] modelNames = GetModelNames(properties[i].Display.ModelType); if (modelNames != null) { cell.DropDownStrings = modelNames; } } else { object cellValue = properties[i].ValueWithArrayHandling; if (cellValue is DateTime) { cell.EditorType = EditorTypeEnum.DateTime; } else if (cellValue is bool) { cell.EditorType = EditorTypeEnum.Boolean; } else if (cellValue.GetType().IsEnum) { cell.EditorType = EditorTypeEnum.DropDown; cell.DropDownStrings = VariableProperty.EnumToStrings(cellValue); Enum cellValueAsEnum = cellValue as Enum; if (cellValueAsEnum != null) { cell.Value = VariableProperty.GetEnumDescription(cellValueAsEnum); } } else if (cellValue.GetType() == typeof(IPlant)) { cell.EditorType = EditorTypeEnum.DropDown; List <string> cropNames = new List <string>(); foreach (Model crop in model.FindAllInScope <IPlant>()) { cropNames.Add(crop.Name); } cell.DropDownStrings = cropNames.ToArray(); } else if (properties[i].DataType == typeof(IPlant)) { cell.EditorType = EditorTypeEnum.DropDown; cell.DropDownStrings = model.FindAllInScope <IPlant>().OfType <IModel>().Select(m => m.Name).ToArray(); } else if (!string.IsNullOrWhiteSpace(properties[i].Display?.Values)) { explorerPresenter.ApsimXFile.Links.Resolve(model, allLinks: true, throwOnFail: false); BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy; MethodInfo method = model.GetType().GetMethod(properties[i].Display.Values, flags); string[] values = ((IEnumerable <object>)method.Invoke(model, properties[i].Display.ValuesArgs))?.Select(v => v?.ToString())?.ToArray(); cell.EditorType = EditorTypeEnum.DropDown; cell.DropDownStrings = values; } else { cell.EditorType = EditorTypeEnum.TextBox; } } cell.IsRowReadonly = !IsPropertyEnabled(i); } IGridColumn descriptionColumn = grid.GetColumn(0); descriptionColumn.Width = -1; descriptionColumn.ReadOnly = true; IGridColumn valueColumn = grid.GetColumn(1); valueColumn.Width = -1; }
/// <summary> /// Format the grid. /// </summary> protected virtual void FormatGrid() { for (int i = 0; i < properties.Count; i++) { IGridCell cell = grid.GetCell(1, i); if (properties[i] is VariableObject) { cell.EditorType = EditorTypeEnum.TextBox; grid.SetRowAsSeparator(i, true); } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.TableName) { cell.EditorType = EditorTypeEnum.DropDown; cell.DropDownStrings = storage.Reader.TableNames.ToArray(); } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.CultivarName) { cell.EditorType = EditorTypeEnum.DropDown; IPlant crop; if (properties[i].Display.PlantName != null) { crop = model.FindInScope <IPlant>(properties[i].Display.PlantName); } else { crop = GetCrop(properties); } if (crop != null) { cell.DropDownStrings = PropertyPresenterHelpers.GetCultivarNames(crop); } } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.LifeCycleName) { cell.EditorType = EditorTypeEnum.DropDown; Zone zone = model.FindInScope <Zone>(); if (zone != null) { cell.DropDownStrings = PropertyPresenterHelpers.GetLifeCycleNames(zone); } } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.LifePhaseName) { cell.EditorType = EditorTypeEnum.DropDown; LifeCycle lifeCycle = GetLifeCycle(properties); if (lifeCycle != null) { cell.DropDownStrings = PropertyPresenterHelpers.GetPhaseNames(lifeCycle); } } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.FileName) { cell.EditorType = EditorTypeEnum.Button; } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.FileNames) { cell.EditorType = EditorTypeEnum.MultiFiles; } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.DirectoryName) { cell.EditorType = EditorTypeEnum.DirectoryChooser; } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.FieldName) { cell.EditorType = EditorTypeEnum.DropDown; List <string> fieldNames = GetFieldNames(); if (fieldNames != null) { fieldNames.Insert(0, string.Empty); cell.DropDownStrings = fieldNames.ToArray(); } } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.ResidueName && model is SurfaceOrganicMatter) { cell.EditorType = EditorTypeEnum.DropDown; string[] fieldNames = GetResidueNames(); if (fieldNames != null) { cell.DropDownStrings = fieldNames; } } else if (properties[i].Display != null && (properties[i].Display.Type == DisplayType.CLEMResource)) { cell.EditorType = EditorTypeEnum.DropDown; List <string> fieldNames = new List <string>(); fieldNames.AddRange(this.GetCLEMResourceNames(this.properties[i].Display.CLEMResourceGroups)); // add any extras elements provided to the list. if (this.properties[i].Display.CLEMExtraEntries != null) { fieldNames.AddRange(this.properties[i].Display.CLEMExtraEntries); } if (fieldNames.Count != 0) { cell.DropDownStrings = fieldNames.ToArray(); } } else if (properties[i].Display != null && (properties[i].Display.Type == DisplayType.CLEMCropFileReader)) { cell.EditorType = EditorTypeEnum.DropDown; List <string> fieldNames = new List <string>(); Simulation clemParent = model.FindAncestor <Simulation>(); // get crop file names fieldNames.AddRange(clemParent.FindAllDescendants <FileCrop>().Select(a => a.Name).ToList()); fieldNames.AddRange(clemParent.FindAllDescendants <FileSQLiteCrop>().Select(a => a.Name).ToList()); if (fieldNames.Count != 0) { cell.DropDownStrings = fieldNames.ToArray(); } } else if (properties[i].Display != null && (properties[i].Display.Type == DisplayType.CLEMPastureFileReader)) { cell.EditorType = EditorTypeEnum.DropDown; List <string> fieldNames = new List <string>(); Simulation clemParent = model.FindAncestor <Simulation>(); // get Pasture file names fieldNames.AddRange(clemParent.FindAllDescendants <FilePasture>().Select(a => a.Name).ToList()); fieldNames.AddRange(clemParent.FindAllDescendants <FileSQLitePasture>().Select(a => a.Name).ToList()); if (fieldNames.Count != 0) { cell.DropDownStrings = fieldNames.ToArray(); } } else if (properties[i].Display != null && properties[i].Display.Type == DisplayType.Model) { cell.EditorType = EditorTypeEnum.DropDown; string[] modelNames = GetModelNames(properties[i].Display.ModelType); if (modelNames != null) { cell.DropDownStrings = modelNames; } } else { object cellValue = properties[i].ValueWithArrayHandling; if (cellValue is DateTime) { cell.EditorType = EditorTypeEnum.DateTime; } else if (cellValue is bool) { cell.EditorType = EditorTypeEnum.Boolean; } else if (cellValue.GetType().IsEnum) { cell.EditorType = EditorTypeEnum.DropDown; cell.DropDownStrings = VariableProperty.EnumToStrings(cellValue); Enum cellValueAsEnum = cellValue as Enum; if (cellValueAsEnum != null) { cell.Value = VariableProperty.GetEnumDescription(cellValueAsEnum); } } else if (cellValue.GetType() == typeof(IPlant)) { cell.EditorType = EditorTypeEnum.DropDown; List <string> cropNames = new List <string>(); foreach (Model crop in model.FindAllInScope <IPlant>()) { cropNames.Add(crop.Name); } cell.DropDownStrings = cropNames.ToArray(); } else if (properties[i].DataType == typeof(IPlant)) { cell.EditorType = EditorTypeEnum.DropDown; cell.DropDownStrings = model.FindAllInScope <IPlant>().OfType <IModel>().Select(m => m.Name).ToArray(); } else if (!string.IsNullOrWhiteSpace(properties[i].Display?.Values)) { explorerPresenter.ApsimXFile.Links.Resolve(model, allLinks: true, throwOnFail: false); MethodInfo method = model.GetType().GetMethod(properties[i].Display.Values); string[] values = ((IEnumerable <object>)method.Invoke(model, null))?.Select(v => v?.ToString())?.ToArray(); cell.EditorType = EditorTypeEnum.DropDown; cell.DropDownStrings = values; } else { cell.EditorType = EditorTypeEnum.TextBox; } } cell.IsRowReadonly = !IsPropertyEnabled(i); } IGridColumn descriptionColumn = grid.GetColumn(0); descriptionColumn.Width = -1; descriptionColumn.ReadOnly = true; IGridColumn valueColumn = grid.GetColumn(1); valueColumn.Width = -1; }