Skip to content

Commit 200a91d

Browse files
author
Alex Vorobiev
authored
Merge pull request #172 from RHEAGROUP/feat/highlight
Features and improvements to Relationship Matrix
2 parents 8e4de22 + 08bde2e commit 200a91d

9 files changed

Lines changed: 340 additions & 35 deletions
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="TableViewMenuBehavior.cs" company="RHEA System S.A.">
3+
// Copyright (c) 2015-2019 RHEA System S.A.
4+
// </copyright>
5+
// --------------------------------------------------------------------------------------------------------------------
6+
7+
namespace CDP4RelationshipMatrix.Behaviour
8+
{
9+
using DevExpress.Xpf.Grid;
10+
using System.Windows;
11+
using System.Windows.Input;
12+
using DevExpress.Mvvm.UI.Interactivity;
13+
using DevExpress.Xpf.Bars;
14+
using DevExpress.Xpf.Core;
15+
16+
/// <summary>
17+
/// Behavior defining manipulation of the column header context menus of the matrix
18+
/// </summary>
19+
/// <remarks>Sample modified from https://www.devexpress.com/Support/Center/Question/Details/Q515611/how-to-edit-wpf-grid-header-contextmneu </remarks>
20+
public class TableViewMenuBehavior : Behavior<TableView>
21+
{
22+
/// <summary>
23+
/// The Command property dependency property
24+
/// </summary>
25+
public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command", typeof(ICommand), typeof(TableViewMenuBehavior), null);
26+
27+
/// <summary>
28+
/// The command
29+
/// </summary>
30+
public ICommand Command
31+
{
32+
get
33+
{
34+
return (ICommand)this.GetValue(CommandProperty);
35+
}
36+
set
37+
{
38+
this.SetValue(CommandProperty, value);
39+
}
40+
}
41+
42+
/// <summary>
43+
/// The attaching view
44+
/// </summary>
45+
TableView View
46+
{
47+
get
48+
{
49+
return this.AssociatedObject;
50+
}
51+
}
52+
53+
/// <summary>
54+
/// Behavior attachment callback
55+
/// </summary>
56+
protected override void OnAttached()
57+
{
58+
base.OnAttached();
59+
this.View.ShowGridMenu += this.ShowGridMenu;
60+
}
61+
62+
/// <summary>
63+
/// Show grid menu event handler
64+
/// </summary>
65+
/// <param name="sender">The sender object</param>
66+
/// <param name="e">Event arguments</param>
67+
private void ShowGridMenu(object sender, GridMenuEventArgs e)
68+
{
69+
if (e.MenuType != GridMenuType.Column)
70+
{
71+
return;
72+
}
73+
74+
// Remove the Column Chooser menu item.
75+
e.Customizations.Add(new RemoveBarItemAndLinkAction()
76+
{
77+
ItemName = DefaultColumnMenuItemNames.ColumnChooser
78+
});
79+
80+
// Create a custom menu item and add it to the context menu.
81+
var barButtonItem = new BarButtonItem();
82+
83+
barButtonItem.Name = "toggleHighlight";
84+
barButtonItem.Content = "Toggle Highlight";
85+
barButtonItem.Command = this.Command;
86+
barButtonItem.CommandParameter = e.MenuInfo.Column;
87+
88+
barButtonItem.Glyph = DXImageHelper.GetImageSource(@"Images/Conditional Formatting/HighlightCellsRules_16x16.png");
89+
90+
barButtonItem.SetValue(BarItemLinkActionBase.ItemLinkIndexProperty, 0);
91+
92+
e.Customizations.Add(barButtonItem);
93+
}
94+
}
95+
}

RelationshipMatrix/CDP4RelationshipMatrix.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@
205205
</ItemGroup>
206206
<ItemGroup>
207207
<Compile Include="Behaviour\CellSelectionBehavior.cs" />
208+
<Compile Include="Behaviour\TableViewMenuBehavior.cs" />
209+
<Compile Include="Converters\BooleanToHighlightConverter.cs" />
208210
<Compile Include="Converters\TooltipConverter.cs" />
209211
<Compile Include="Converters\RowDoubleClickEventArgsConverter.cs" />
210212
<Compile Include="Converters\MarkupExtensionBase.cs" />
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="BooleanToHighlightConverter.cs" company="RHEA System S.A.">
3+
// Copyright (c) 2015-2019 RHEA System S.A.
4+
// </copyright>
5+
// --------------------------------------------------------------------------------------------------------------------
6+
7+
namespace CDP4RelationshipMatrix.Converters
8+
{
9+
using System;
10+
using System.Globalization;
11+
using System.Windows.Data;
12+
using System.Windows.Media;
13+
using DevExpress.Xpf.Grid;
14+
15+
/// <summary>
16+
/// The converter to convert a boolean to a highlighting color
17+
/// </summary>
18+
public class BooleanToHighlightConverter : IValueConverter
19+
{
20+
/// <summary>
21+
/// The conversion method color of the column header.
22+
/// </summary>
23+
/// <param name="value">
24+
/// The incoming value.
25+
/// </param>
26+
/// <param name="targetType">
27+
/// The target type.
28+
/// </param>
29+
/// <param name="parameter">
30+
/// The parameter passed on to this conversion.
31+
/// </param>
32+
/// <param name="culture">
33+
/// The culture information.
34+
/// </param>
35+
/// <returns>
36+
/// The <see cref="object"/> containing the same objects as the input collection.
37+
/// </returns>
38+
public virtual object Convert(object value, Type targetType, object parameter, CultureInfo culture)
39+
{
40+
if (value == null || !(bool)value)
41+
{
42+
return new SolidColorBrush(Colors.Transparent);
43+
}
44+
45+
return new SolidColorBrush(Colors.Gold);
46+
}
47+
48+
/// <summary>
49+
/// Not implemented
50+
/// </summary>
51+
/// <param name="value">
52+
/// The incoming collection.
53+
/// </param>
54+
/// <param name="targetType">
55+
/// The target type.
56+
/// </param>
57+
/// <param name="parameter">
58+
/// The parameter passed on to this conversion.
59+
/// </param>
60+
/// <param name="culture">
61+
/// The culture information.
62+
/// </param>
63+
/// <returns>
64+
/// The result
65+
/// </returns>
66+
public virtual object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
67+
{
68+
throw new NotSupportedException();
69+
}
70+
}
71+
}

RelationshipMatrix/ViewModels/ColumnDefinition.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public class ColumnDefinition : ReactiveObject
2727
/// </summary>
2828
private string toolTip;
2929

30+
/// <summary>
31+
/// Backing field for <see cref="IsHighlighted"/>
32+
/// </summary>
33+
private bool isHighlighted;
34+
3035
/// <summary>
3136
/// Initializes a new instance of the <see cref="ColumnDefinition"/> class
3237
/// </summary>
@@ -39,6 +44,7 @@ public ColumnDefinition(DefinedThing thing, DisplayKind displayKind)
3944
this.ToolTip = thing.Tooltip();
4045
this.FieldName = thing.ShortName;
4146
this.ThingId = thing.Iid;
47+
this.IsHighlighted = false;
4248
}
4349

4450
/// <summary>
@@ -52,6 +58,7 @@ public ColumnDefinition(string header, string fieldname, bool offsetCount = fals
5258
this.RelationshipCount = offsetCount? -1 : 0;
5359
this.Header = header;
5460
this.FieldName = fieldname;
61+
this.IsHighlighted = false;
5562
}
5663

5764
/// <summary>
@@ -77,6 +84,15 @@ public string ToolTip
7784
private set { this.RaiseAndSetIfChanged(ref this.toolTip, value); }
7885
}
7986

87+
/// <summary>
88+
/// Gets or sets the highlighted state.
89+
/// </summary>
90+
public bool IsHighlighted
91+
{
92+
get { return this.isHighlighted; }
93+
private set { this.RaiseAndSetIfChanged(ref this.isHighlighted, value); }
94+
}
95+
8096
/// <summary>
8197
/// Gets the name of the fieldname for this column
8298
/// </summary>
@@ -86,5 +102,13 @@ public string ToolTip
86102
/// Gets or sets the total count of relationships this column has.
87103
/// </summary>
88104
public int RelationshipCount { get; set; }
105+
106+
/// <summary>
107+
/// Toggles column highlight;
108+
/// </summary>
109+
public void ToggleHighlight()
110+
{
111+
this.IsHighlighted = !this.IsHighlighted;
112+
}
89113
}
90114
}

RelationshipMatrix/ViewModels/MatrixCellViewModel.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public class MatrixCellViewModel : ReactiveObject
5757
/// </summary>
5858
private string tooltip;
5959

60+
/// <summary>
61+
/// Backing field for <see cref="IsHighlighted"/>
62+
/// </summary>
63+
private bool isHighlighted;
64+
6065
/// <summary>
6166
/// Initializes a new instance of the <see cref="MatrixCellViewModel"/> class
6267
/// </summary>
@@ -72,7 +77,8 @@ public MatrixCellViewModel(Thing sourceY, Thing sourceX, IReadOnlyList<BinaryRel
7277
this.Rule = rule;
7378
this.Relationships = binaryRelationship ?? new List<BinaryRelationship>();
7479
this.DisplayKind = displayKind;
75-
80+
this.IsHighlighted = false;
81+
7682
if (binaryRelationship == null || binaryRelationship.Count == 0)
7783
{
7884
this.RelationshipDirection = RelationshipDirectionKind.None;
@@ -114,6 +120,15 @@ public MatrixCellViewModel(Thing sourceY, Thing sourceX, IReadOnlyList<BinaryRel
114120
/// </summary>
115121
public DisplayKind? DisplayKind { get; }
116122

123+
/// <summary>
124+
/// Gets or sets the highlighted state.
125+
/// </summary>
126+
public bool IsHighlighted
127+
{
128+
get { return this.isHighlighted; }
129+
private set { this.RaiseAndSetIfChanged(ref this.isHighlighted, value); }
130+
}
131+
117132
/// <summary>
118133
/// Gets or sets the tooltip of the cell.
119134
/// </summary>

RelationshipMatrix/ViewModels/MatrixViewModel.cs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace CDP4RelationshipMatrix.ViewModels
1919
using CDP4Common.SiteDirectoryData;
2020
using CDP4Dal;
2121
using CDP4Dal.Operations;
22-
using DevExpress.XtraPrinting.Native;
22+
using DevExpress.Xpf.Grid;
2323
using NLog;
2424
using ReactiveUI;
2525
using Settings;
@@ -155,6 +155,8 @@ public MatrixViewModel(ISession session, Iteration iteration, RelationshipMatrix
155155
this.ProcessAltCellCommand = ReactiveCommand.CreateAsyncTask(x => this.ProcessAltCellCommandExecute((List<object>)x), RxApp.MainThreadScheduler);
156156
this.ProcessAltControlCellCommand = ReactiveCommand.CreateAsyncTask(x => this.ProcessAltControlCellCommandExecute((List<object>)x), RxApp.MainThreadScheduler);
157157

158+
this.ToggleColumnHighlightCommand = ReactiveCommand.CreateAsyncTask(x => this.ToggleColumnHighlightCommandExecute(x as GridColumn), RxApp.MainThreadScheduler);
159+
158160
this.SubscribeCommandExceptions();
159161

160162
this.WhenAnyValue(x => x.SelectedCell).Subscribe(_ => this.ComputeCommandCanExecute());
@@ -269,6 +271,11 @@ public bool IsVisibleDeleteAll
269271
/// </summary>
270272
public ReactiveCommand<Unit> ProcessAltControlCellCommand { get; private set; }
271273

274+
/// <summary>
275+
/// Gets the command to process column highlight toggle.
276+
/// </summary>
277+
public ReactiveCommand<Unit> ToggleColumnHighlightCommand { get; private set; }
278+
272279
/// <summary>
273280
/// Gets or sets the selected cell
274281
/// </summary>
@@ -489,10 +496,7 @@ private void SubscribeCommandExceptions()
489496
private IList<ColumnDefinition> CreateColumns(IReadOnlyList<DefinedThing> source, DisplayKind displayKind, bool showRelatedOnly, IList<BinaryRelationship> relationships)
490497
{
491498
var columns = new List<ColumnDefinition>();
492-
493-
// column that contains the name of the thing to display for each row
494-
columns.Add(new ColumnDefinition(CDP4_NAME_HEADER, ROW_NAME_COLUMN, true));
495-
499+
496500
foreach (var definedThing in source.DistinctBy(x => x.ShortName))
497501
{
498502
if (showRelatedOnly && !relationships.Any(x =>
@@ -512,6 +516,12 @@ private IList<ColumnDefinition> CreateColumns(IReadOnlyList<DefinedThing> source
512516
columns.Add(new ColumnDefinition(definedThing, displayKind));
513517
}
514518

519+
if (columns.Any())
520+
{
521+
// column that contains the name of the thing to display for each row
522+
columns.Insert(0, new ColumnDefinition(CDP4_NAME_HEADER, ROW_NAME_COLUMN, true));
523+
}
524+
515525
return columns;
516526
}
517527

@@ -808,6 +818,22 @@ private async Task ProcessAltControlCellCommandExecute(List<object> cellInfo)
808818
}
809819
}
810820

821+
/// <summary>
822+
/// Executes a toggle of column highlight command
823+
/// </summary>
824+
/// <param name="column">The column.</param>
825+
private async Task ToggleColumnHighlightCommandExecute(GridColumn column)
826+
{
827+
if (column == null)
828+
{
829+
return;
830+
}
831+
832+
var vm = column.DataContext as ColumnDefinition;
833+
834+
vm?.ToggleHighlight();
835+
}
836+
811837
/// <summary>
812838
/// Creates a <see cref="BinaryRelationship"/> for the selected cell
813839
/// </summary>

0 commit comments

Comments
 (0)