• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

HicServices / RDMP / 6237307473

19 Sep 2023 04:02PM UTC coverage: 57.015% (-0.4%) from 57.44%
6237307473

push

github

web-flow
Feature/rc4 (#1570)

* Syntax tidying
* Dependency updates
* Event handling singletons (ThrowImmediately and co)

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: James A Sutherland <>
Co-authored-by: James Friel <jfriel001@dundee.ac.uk>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

10734 of 20259 branches covered (0.0%)

Branch coverage included in aggregate %.

5922 of 5922 new or added lines in 565 files covered. (100.0%)

30687 of 52390 relevant lines covered (58.57%)

7361.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/Application/ResearchDataManagementPlatform/WindowManagement/WindowFactory.cs
1
// Copyright (c) The University of Dundee 2018-2019
2
// This file is part of the Research Data Management Platform (RDMP).
3
// 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.
4
// 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.
5
// You should have received a copy of the GNU General Public License along with RDMP. If not, see <https://www.gnu.org/licenses/>.
6

7
using System.Windows.Forms;
8
using Rdmp.Core;
9
using Rdmp.Core.Curation.Data;
10
using Rdmp.Core.Curation.Data.Dashboarding;
11
using Rdmp.Core.MapsDirectlyToDatabaseTable;
12
using Rdmp.Core.Repositories;
13
using Rdmp.UI;
14
using Rdmp.UI.Collections;
15
using Rdmp.UI.ItemActivation;
16
using Rdmp.UI.Refreshing;
17
using Rdmp.UI.SimpleControls;
18
using Rdmp.UI.SingleControlForms;
19
using Rdmp.UI.TestsAndSetup.ServicePropogation;
20
using ResearchDataManagementPlatform.WindowManagement.ContentWindowTracking.Persistence;
21
using ResearchDataManagementPlatform.WindowManagement.TabPageContextMenus;
22
using SixLabors.ImageSharp;
23
using SixLabors.ImageSharp.PixelFormats;
24
using WeifenLuo.WinFormsUI.Docking;
25

26
namespace ResearchDataManagementPlatform.WindowManagement;
27

28
/// <summary>
29
/// Translates Controls into docked tabs (DockContent).  Provides overloads for the two main control Types IRDMPSingleDatabaseObjectControl and
30
/// IObjectCollectionControl (for <see cref="RDMPCollectionUI"/> see <see cref="WindowManager"/>).
31
/// </summary>
32
public class WindowFactory
33
{
34
    private readonly WindowManager _windowManager;
35

36
    /// <summary>
37
    /// Location of the Catalogue / Data export repository databases (and allows access to repository objects)
38
    /// </summary>
39
    public IRDMPPlatformRepositoryServiceLocator RepositoryLocator { get; set; }
×
40

41
    private readonly IconFactory _iconFactory = IconFactory.Instance;
×
42

43

44
    public WindowFactory(IRDMPPlatformRepositoryServiceLocator repositoryLocator, WindowManager windowManager)
×
45
    {
46
        _windowManager = windowManager;
×
47
        RepositoryLocator = repositoryLocator;
×
48
    }
×
49

50
    public PersistableToolboxDockContent Create(IActivateItems activator, Control control, string label,
51
        Image<Rgba32> image, RDMPCollection collection)
52
    {
53
        var content = new PersistableToolboxDockContent(collection);
×
54

55
        AddControlToDockContent(activator, control, content, label, image);
×
56

57
        return content;
×
58
    }
59

60
    public PersistableSingleDatabaseObjectDockContent Create(IActivateItems activator, RefreshBus refreshBus,
61
        IRDMPSingleDatabaseObjectControl control, Image<Rgba32> image, IMapsDirectlyToDatabaseTable databaseObject)
62
    {
63
        var content = new PersistableSingleDatabaseObjectDockContent(control, databaseObject, refreshBus);
×
64
        _windowManager.AddWindow(content);
×
65

66
        AddControlToDockContent(activator, (Control)control, content, "Loading...", image);
×
67

68
        if (!RDMPMainForm.Loading)
×
69
            activator.HistoryProvider.Add(databaseObject);
×
70

71
        return content;
×
72
    }
73

74
    public PersistableObjectCollectionDockContent Create(IActivateItems activator, IObjectCollectionControl control,
75
        IPersistableObjectCollection objectCollection, Image<Rgba32> image)
76
    {
77
        //create a new persistable docking tab
78
        var content = new PersistableObjectCollectionDockContent(activator, control, objectCollection);
×
79

80
        //add the control to the tab
81
        AddControlToDockContent(activator, (Control)control, content, content.TabText, image);
×
82

83
        //add to the window tracker
84
        _windowManager.AddWindow(content);
×
85

86
        //return the tab
87
        return content;
×
88
    }
89

90
    public PersistableSingleDatabaseObjectDockContent Create(IActivateItems activator,
91
        IRDMPSingleDatabaseObjectControl control, DatabaseEntity entity)
92
    {
93
        var content = new PersistableSingleDatabaseObjectDockContent(control, entity, activator.RefreshBus);
×
94

95
        var img = activator.CoreIconProvider.GetImage(entity);
×
96
        AddControlToDockContent(activator, (Control)control, content, entity.ToString(), img);
×
97

98
        if (!RDMPMainForm.Loading)
×
99
            activator.HistoryProvider.Add(entity);
×
100

101
        return content;
×
102
    }
103

104

105
    public DockContent Create(IActivateItems activator, Control control, string label, Image<Rgba32> image)
106
    {
107
        DockContent content = new RDMPSingleControlTab(activator.RefreshBus, control);
×
108

109
        AddControlToDockContent(activator, control, content, label, image);
×
110

111
        _windowManager.AddAdhocWindow(content);
×
112

113
        return content;
×
114
    }
115

116
    private void AddControlToDockContent(IActivateItems activator, Control control, DockContent content, string label,
117
        Image<Rgba32> image)
118
    {
119
        control.Dock = DockStyle.Fill;
×
120
        content.Controls.Add(control);
×
121
        content.TabText = label;
×
122

123
        if (image != null) content.Icon = _iconFactory.GetIcon(image);
×
124

125

126
        if (control is IConsultableBeforeClosing consult)
×
127
            content.FormClosing += consult.ConsultAboutClosing;
×
128

129
        if (control is ISaveableUI saveable)
×
130
            content.FormClosing += (s, e) => saveable.GetObjectSaverButton()?.CheckForUnsavedChangesAnOfferToSave();
×
131

132
        content.KeyPreview = true;
×
133

134
        if (content is RDMPSingleControlTab tab)
×
135
        {
136
            content.TabPageContextMenuStrip = new RDMPSingleControlTabMenu(activator, tab, _windowManager);
×
137

138
            //Create handler for AfterPublish
139
            void Handler(object s, RefreshObjectEventArgs e)
140
            {
141
                // After global changes, rebuild the context menu
142

143
                if (!content.IsDisposed)
144
                    content.TabPageContextMenuStrip = new RDMPSingleControlTabMenu(activator, tab, _windowManager);
145
                else activator.RefreshBus.AfterPublish -= Handler; //don't leak handlers
146
            }
147

148
            //register the event handler
149
            activator.RefreshBus.AfterPublish += Handler;
×
150
        }
151
    }
×
152
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc