/// <summary> /// Computes a row /// </summary> /// <param name="rowThing">The <see cref="Thing" /> of the current row</param> /// <param name="columnThings">The <see cref="Thing" />s displayed in the columns</param> /// <param name="relationships">The current set of <see cref="BinaryRelationship" /></param> /// <param name="relationshipRule">The current <see cref="BinaryRelationshipRule" /></param> /// <param name="displayKind">The <see cref="DisplayKind" /> of the current Row.</param> /// <param name="columnDefinitions">The defined columns.</param> /// <returns>The <see cref="IDictionary{TKey,TValue}" /> that corresponds to a row</returns> private IDictionary <string, MatrixCellViewModel> ComputeRow(DefinedThing rowThing, IReadOnlyList <DefinedThing> columnThings, IReadOnlyList <BinaryRelationship> relationships, BinaryRelationshipRule relationshipRule, DisplayKind displayKind, IList <ColumnDefinition> columnDefinitions) { var record = new Dictionary <string, MatrixCellViewModel> { { ROW_NAME_COLUMN, new MatrixCellViewModel(rowThing, null, null, relationshipRule, displayKind) } }; foreach (var definedThing in columnThings) { if (columnDefinitions.All(x => !x.ThingId.Equals(definedThing.Iid))) { continue; } var cellValue = this.ComputeCell(rowThing, definedThing, relationships, relationshipRule); record.Add(definedThing.ShortName, cellValue); this.UpdateCurrentCell(rowThing, definedThing, cellValue); if (cellValue.RelationshipDirection != RelationshipDirectionKind.None) { columnDefinitions.Single(s => s.ThingId.Equals(definedThing.Iid)).RelationshipCount++; } } return(record); }
/// <summary> /// Initializes a new instance of the <see cref="ColumnDefinition"/> class /// </summary> /// <param name="thing">The represented <see cref="Thing"/></param> /// <param name="displayKind">The <see cref="DisplayKind"/> of the column.</param> public ColumnDefinition(DefinedThing thing, DisplayKind displayKind) { this.RelationshipCount = 0; this.Header = displayKind == DisplayKind.Name ? thing.Name : thing.ShortName; this.ToolTip = thing.Tooltip(); this.FieldName = thing.ShortName; this.ThingId = thing.Iid; this.IsHighlighted = false; }
public void AddDisplay(DisplayKind kind) { var text = kind.ToString().Replace("_", "-"); Add("display", text); }
/// <summary> /// Creates the column definitions based on the source. /// </summary> /// <param name="source">The <see cref="Thing" /> representing the columns</param> /// <param name="displayKind">The <see cref="DisplayKind" /> of the column.</param> /// <param name="showRelatedOnly">Indicate whether to only show related elements.</param> /// <param name="relationships">The list of all relationships.</param> private IList <ColumnDefinition> CreateColumns(IReadOnlyList <DefinedThing> source, DisplayKind displayKind, bool showRelatedOnly, IList <BinaryRelationship> relationships) { var columns = new List <ColumnDefinition>(); foreach (var definedThing in source.DistinctBy(x => x.ShortName)) { if (showRelatedOnly && !relationships.Any(x => x.Source.Iid.Equals(definedThing.Iid) || x.Target.Iid.Equals(definedThing.Iid))) { // if thing is not in any relationships, skip continue; } if (columns.Any(x => x.FieldName == definedThing.ShortName)) { // skip duplicated shortname continue; } // Set fieldname to use as iid columns.Add(new ColumnDefinition(definedThing, displayKind)); } if (columns.Any()) { // column that contains the name of the thing to display for each row columns.Insert(0, new ColumnDefinition(CDP4_NAME_HEADER, ROW_NAME_COLUMN, true)); } return(columns); }