Skip to content

Commit

Permalink
Fixed a bug where association columns didn't show
Browse files Browse the repository at this point in the history
  • Loading branch information
mjr129 committed Nov 28, 2016
1 parent e7815f7 commit 2781c95
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 26 deletions.
19 changes: 15 additions & 4 deletions MetaboliteLevels/Data/Session/Associational/Association.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
using MetaboliteLevels.Properties;

namespace MetaboliteLevels.Data.Session.Associational
{
{
/// <summary>
/// Throwaway object that "associates" two other objects.
///
/// These are obtained by calling FindAssociations on an Associational object.
///
/// The type parameter (T) is needed because the list views need to find the correct columns.
/// </summary>
[XColumnConcreteGeneratorAttribute]
internal sealed class Association<T> : IColumnProvider, IIconProvider, IAssociation
{
[NotNull] public ContentsRequest OriginalRequest { get; }
Expand Down Expand Up @@ -59,13 +60,23 @@ public void GetXColumns( CustomColumnRequest request )
int closure = n;
Tuple<string, string> c = this.OriginalRequest.ExtraColumns[n];

results.Add( new Column<Association<T>>( c.Item1, EColumn.Visible, c.Item2, z => z._extraColumnValues[closure], z => Color.Blue ) );
results.Add( new Column<Association<T>>( c.Item1, EColumn.Visible, c.Item2, z => z.GetExtraColumnValue(closure), z => Color.Blue ) );
}
}

request.NoAutomaticColumns = true; // Else conflicts
}

}

private object GetExtraColumnValue( int closure )
{
if (closure < 0 || closure >= _extraColumnValues.Length)
{
return "Missing column data";
}

return _extraColumnValues[closure];
}

public Image Icon { get; private set; }

object IAssociation.Associated => this.Associated;
Expand Down
4 changes: 1 addition & 3 deletions MetaboliteLevels/Data/Session/Main/Associational.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ public static ContentsRequest FindAssociations( object target, ContentsRequest r
case EVisualClass.SpecialAdvanced:
case EVisualClass.SpecialMeta:
case EVisualClass.SpecialAll:
case EVisualClass.SpecialStatistic:
request.AddExtraColumn( "Value", "Value of the field" );

case EVisualClass.SpecialStatistic:
IEnumerable<Column> cols = ColumnManager.GetColumns( request.Core, target ).OrderBy( z => z.Special.Has( EColumn.Visible ) );
bool shortName;

Expand Down
1 change: 1 addition & 0 deletions MetaboliteLevels/Data/Session/Main/Cluster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ protected override void OnFindAssociations(ContentsRequest request)

foreach (var kvp in compounds)
{
// Pathway, compound, peaks
request.Add(kvp.Key, kvp.Value.ToArray(), peaks[kvp.Key].ToArray());
}
}
Expand Down
10 changes: 7 additions & 3 deletions MetaboliteLevels/Gui/Controls/Lists/ColumnManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using MetaboliteLevels.Data.Session.Associational;
using MetaboliteLevels.Data.Session.General;
using MGui.Helpers;

Expand Down Expand Up @@ -76,6 +77,8 @@ public CustomColumnRequest( ColumnCollection results, Core core )
}
}

class XColumnConcreteGeneratorAttribute : Attribute { }

class ColumnCollection<T> : ColumnCollection
{
public ColumnCollection( ColumnCollection columnList )
Expand Down Expand Up @@ -109,7 +112,7 @@ public static ColumnCollection GetColumns<T>( Core core )
public static ColumnCollection GetColumns( Type type, Core core )
{
return ColumnManager.GetColumns( type, null, core );
}
}

public static object QueryProperty( Core core, object target, string propertyId )
{
Expand Down Expand Up @@ -152,10 +155,11 @@ private static void GetCustomColumns( ColumnCollection results, Type type, objec
}

if (@object == null)
{
// Unfortunately this won't work if the type is abstract
{
// Unfortunately this won't work if the type is abstract
if (type.IsAbstract)
{
// This just means we get the "data" column alone
automaticColumns = false;
return;
}
Expand Down
23 changes: 22 additions & 1 deletion MetaboliteLevels/Gui/Controls/Lists/CtlAutoList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
Expand Down Expand Up @@ -1049,8 +1050,28 @@ private void GetAvailableColumns()
// Save the ID (this is used to load/save columns)
this._listViewOptionsKey = this._listView.FindForm().Name + "\\" + this._listView.Name + "\\" + dataType.Name;

IEnumerable<Column> cols;

// Get columns for the type "T"
IEnumerable<Column> cols = ColumnManager.GetColumns( dataType, this._core );
if (dataType.GetCustomAttribute<XColumnConcreteGeneratorAttribute>() != null)
{
// Hack for association columns
object concrete = _source.UntypedGetList( false ).FirstOrDefault2();

if (concrete == null)
{
// Wait for columns
cols = null;
}
else
{
cols = ColumnManager.GetColumns( this._core, concrete );
}
}
else
{
cols = ColumnManager.GetColumns( dataType, this._core );
}

if (cols == null)
{
Expand Down
30 changes: 15 additions & 15 deletions MetaboliteLevels/Gui/Forms/Activities/FrmMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2781c95

Please sign in to comment.