Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDMP-220 Add View Parent Tree Burger Option #1905

Merged
merged 8 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public RDMPSingleControlTabMenu(IActivateItems activator, RDMPSingleControlTab t

var gotoMenu = new ToolStripMenuItem(AtomicCommandFactory.GoTo) { Enabled = false };
Items.Add(gotoMenu);

foreach (var cmd in builder.GetCommands(single.DatabaseObject).OfType<ExecuteCommandShow>())
{
gotoMenu.DropDownItems.Add(uiFactory.CreateMenuItem(cmd));
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


# Changelog
All notable changes to this project will be documented in this file.

Expand All @@ -12,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Misc improvements to the DQE
- Fix Project Creation UI issue
- Fix issue with whitespace confusing encryption key paths
- Add "View Parent Tree" functionality
- Add ability to add description to new cohort versions
- Add functionality to revert to historical cohort version

Expand Down
1 change: 1 addition & 0 deletions Rdmp.Core/CommandExecution/AtomicCommandFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class AtomicCommandFactory : CommandFactoryBase
public const string Advanced = "Advanced";
public const string View = "View";
public const string Deprecation = "Deprecation";
public const string ViewParentTree = "View Parent Tree";

public AtomicCommandFactory(IBasicActivateItems activator)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) The University of Dundee 2024-2024
// This file is part of the Research Data Management Platform (RDMP).
// RDMP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
// RDMP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along with RDMP. If not, see <https://www.gnu.org/licenses/>.

using Rdmp.Core.CommandExecution;
using Rdmp.Core.CommandExecution.AtomicCommands;
using Rdmp.Core.Providers;
using Rdmp.UI.SimpleDialogs;
using System.Linq;

namespace Rdmp.UI.CommandExecution.AtomicCommands;
public class ExecuteCommandViewParentTree : BasicCommandExecution, IAtomicCommand
{

private readonly IBasicActivateItems _activator;
private readonly object _databaseObject;
private DescendancyList _tree;

public ExecuteCommandViewParentTree(IBasicActivateItems activator, object databaseObject) : base(activator)
{
_activator = activator;
_databaseObject = databaseObject;
}

private void BuildTree()
{
_tree = _activator.CoreChildProvider.GetDescendancyListIfAnyFor(_databaseObject);
}

public override void Execute()
{
base.Execute();
BuildTree();
if (_activator.IsInteractive)
{
var tree = _tree.GetUsefulParents().ToList();
tree.Add(_databaseObject);
var dialog = new ViewParentTreeDialog(_activator, tree);
dialog.ShowDialog();
}
}
}
75 changes: 75 additions & 0 deletions Rdmp.UI/SimpleDialogs/ViewParentTreeDialog.Designer.cs

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

78 changes: 78 additions & 0 deletions Rdmp.UI/SimpleDialogs/ViewParentTreeDialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using BrightIdeasSoftware;
using Rdmp.Core.CommandExecution;
using Rdmp.Core.CommandExecution.AtomicCommands;
using Rdmp.Core.Curation.Data;
using Rdmp.Core.Icons.IconProvision;
using Rdmp.Core.MapsDirectlyToDatabaseTable;
using Rdmp.Core.Providers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Rdmp.UI.SimpleDialogs
{
public partial class ViewParentTreeDialog : Form
{
private readonly List<object> _tree;
private readonly IBasicActivateItems _activator;

public ViewParentTreeDialog(IBasicActivateItems activator, List<object> tree)
{
_tree = tree;
_activator = activator;
InitializeComponent();
this.tlv.CanExpandGetter = delegate (object x)
{
return tree.IndexOf(x) < tree.Count() - 1;
};
this.tlv.ChildrenGetter = delegate (object x)
{
var item = tree[tree.IndexOf(x) + 1];
return new List<object>() { item };
};
this.tlv.Roots = new List<object>() { tree[0] };
this.tlvParentColumn.FillsFreeSpace = true;
this.tlv.ExpandAll();
}

private Bitmap ImageGetter(object rowObject)
{
var image = _activator.CoreIconProvider.GetImage(rowObject);
return image.ImageToBitmap();
}

private static bool Is<T>(object o, out T match)
{
while (true)
switch (o)
{
case T o1:
match = o1;
return true;
case IMasqueradeAs m:
o = m.MasqueradingAs();
continue;
default:
match = default;
return false;
}
}

private void ClickHandler(object sender, CellClickEventArgs e)
{
if (e.HitTest.HitTestLocation == HitTestLocation.ExpandButton) return;
if (e.RowIndex > _tree.Count) return;
var item = _tree[e.RowIndex];
if (Is(item, out IMapsDirectlyToDatabaseTable mt))
{
_activator.Activate(mt);
}
}
}
}
120 changes: 120 additions & 0 deletions Rdmp.UI/SimpleDialogs/ViewParentTreeDialog.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
using Rdmp.Core.CommandExecution.AtomicCommands;
using Rdmp.Core.Curation.Data;
using Rdmp.Core.Curation.Data.Aggregation;
using Rdmp.Core.Icons.IconProvision;
using Rdmp.Core.MapsDirectlyToDatabaseTable;
using Rdmp.Core.ReusableLibraryCode.Settings;
using Rdmp.UI.CommandExecution.AtomicCommands;
using Rdmp.UI.ExtractionUIs.FilterUIs;
using Rdmp.UI.ItemActivation;
using Rdmp.UI.Refreshing;
using Rdmp.UI.Rules;
using Rdmp.UI.SimpleControls;
using Rdmp.UI.Theme;
using SixLabors.ImageSharp.PixelFormats;

namespace Rdmp.UI.TestsAndSetup.ServicePropogation;

Expand Down Expand Up @@ -147,6 +150,8 @@ public virtual void SetDatabaseObject(IActivateItems activator, T databaseObject
cmd.SuggestedCategory = AtomicCommandFactory.GoTo;
CommonFunctionality.AddToMenu(cmd, null, null, AtomicCommandFactory.GoTo);
}
var viewParentTreeCmd = new ExecuteCommandViewParentTree(activator, databaseObject);
CommonFunctionality.AddToMenu(viewParentTreeCmd, AtomicCommandFactory.ViewParentTree, SixLabors.ImageSharp.Image.Load<Rgba32>(CatalogueIcons.CatalogueFolder));
}

protected bool BeforeSave_PromptRenameOfExtractionFilterContainer(DatabaseEntity _)
Expand Down