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

HicServices / RDMP / 7104759680

05 Dec 2023 06:06PM UTC coverage: 56.383% (+0.05%) from 56.338%
7104759680

push

github

web-flow
Feature/rdmp-113 datasets (#1682)

* Dataset PR

10585 of 20345 branches covered (0.0%)

Branch coverage included in aggregate %.

102 of 300 new or added lines in 18 files covered. (34.0%)

3 existing lines in 3 files now uncovered.

30488 of 52501 relevant lines covered (58.07%)

7275.97 hits per line

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

0.0
/Application/ResearchDataManagementPlatform/WindowManagement/TopBar/RDMPTaskBarUI.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;
8
using System.Windows.Forms;
9
using Rdmp.Core;
10
using Rdmp.Core.CommandExecution.AtomicCommands;
11
using Rdmp.Core.Curation.Data;
12
using Rdmp.Core.Icons.IconProvision;
13
using Rdmp.Core.MapsDirectlyToDatabaseTable;
14
using Rdmp.Core.ReusableLibraryCode.Checks;
15
using Rdmp.Core.ReusableLibraryCode.Settings;
16
using Rdmp.UI;
17
using Rdmp.UI.SimpleDialogs;
18
using Rdmp.UI.Theme;
19

20
namespace ResearchDataManagementPlatform.WindowManagement.TopBar;
21

22
/// <summary>
23
/// Allows you to access the main object collections that make up the RDMP.  These include
24
/// </summary>
25
public partial class RDMPTaskBarUI : UserControl
26
{
27
    private WindowManager _manager;
28

29
    private const string CreateNewLayout = "<<New Layout>>";
30

31
    public RDMPTaskBarUI()
×
32
    {
33
        InitializeComponent();
×
34

35
        btnHome.Image = FamFamFamIcons.application_home.ImageToBitmap();
×
36
        btnCatalogues.Image = CatalogueIcons.Catalogue.ImageToBitmap();
×
37
        btnCatalogues.BackgroundImage =
×
38
            BackColorProvider.GetBackgroundImage(btnCatalogues.Size, RDMPCollection.Catalogue);
×
39

40
        btnCohorts.Image = CatalogueIcons.CohortIdentificationConfiguration.ImageToBitmap();
×
41
        btnCohorts.BackgroundImage = BackColorProvider.GetBackgroundImage(btnCohorts.Size, RDMPCollection.Cohort);
×
42

43
        btnSavedCohorts.Image = CatalogueIcons.AllCohortsNode.ImageToBitmap();
×
44
        btnSavedCohorts.BackgroundImage =
×
45
            BackColorProvider.GetBackgroundImage(btnSavedCohorts.Size, RDMPCollection.SavedCohorts);
×
46

47
        btnDataExport.Image = CatalogueIcons.Project.ImageToBitmap();
×
48
        btnDataExport.BackgroundImage =
×
49
            BackColorProvider.GetBackgroundImage(btnDataExport.Size, RDMPCollection.DataExport);
×
50

51
        btnTables.Image = CatalogueIcons.TableInfo.ImageToBitmap();
×
52
        btnTables.BackgroundImage = BackColorProvider.GetBackgroundImage(btnTables.Size, RDMPCollection.Tables);
×
53

NEW
54
        btnDataSets.Image = CatalogueIcons.Dataset.ImageToBitmap();
×
NEW
55
        btnDataSets.BackgroundImage = BackColorProvider.GetBackgroundImage(btnDataSets.Size, RDMPCollection.Datasets);
×
56

NEW
57
        btnLoads.Image = CatalogueIcons.LoadMetadata.ImageToBitmap();
×
NEW
58
        btnLoads.BackgroundImage = BackColorProvider.GetBackgroundImage(btnDataSets.Size, RDMPCollection.DataLoad);
×
59

60
        btnFavourites.Image = CatalogueIcons.Favourite.ImageToBitmap();
×
61
        btnDeleteLayout.Image = FamFamFamIcons.delete.ImageToBitmap();
×
62

63
        cbCommits.Image = CatalogueIcons.Commit.ImageToBitmap();
×
64
        cbCommits.Checked = UserSettings.EnableCommits;
×
65
        cbCommits.CheckedChanged += (s, e) => UserSettings.EnableCommits = cbCommits.Checked;
×
66
        cbCommits.CheckOnClick = true;
×
67
    }
×
68

69
    public void SetWindowManager(WindowManager manager)
70
    {
71
        _manager = manager;
×
72

73
        //Update task bar buttons enabledness when the user navigates somewhere
74
        _manager.Navigation.Changed += (s, e) => UpdateForwardBackEnabled();
×
75

76
        btnDataExport.Enabled = manager.RepositoryLocator.DataExportRepository != null;
×
77

78
        ReCreateDropDowns();
×
79

80
        SetupToolTipText();
×
81

82
        _manager.ActivateItems.Theme.ApplyTo(toolStrip1);
×
83

84
        // if we don't support commit system then disable the task bar button for it
85
        if (!_manager.ActivateItems.RepositoryLocator.CatalogueRepository.SupportsCommits)
×
86
        {
87
            cbCommits.Enabled = false;
×
88
            cbCommits.Text = "Repository does not support commits";
×
89
        }
90
    }
×
91

92
    /// <summary>
93
    /// Updates the enabled status (greyed out) of the Forward/Back buttons based on the current <see cref="_manager"/> <see cref="NavigationTrack{T}"/>
94
    /// </summary>
95
    private void UpdateForwardBackEnabled()
96
    {
97
        btnBack.Enabled = _manager.Navigation.CanBack();
×
98
        btnForward.Enabled = _manager.Navigation.CanForward();
×
99
    }
×
100

101

102
    private void SetupToolTipText()
103
    {
104
        try
105
        {
106
            btnHome.ToolTipText = "Home screen, shows recent objects etc";
×
107
            btnCatalogues.ToolTipText = "All datasets configured for access by RDMP";
×
108
            btnCohorts.ToolTipText = "Built queries for creating cohorts";
×
109
            btnSavedCohorts.ToolTipText = "Finalised identifier lists, ready for linkage and extraction";
×
110
            btnDataExport.ToolTipText = "Show Projects and Extractable Dataset Packages allowing data extraction";
×
111
            btnTables.ToolTipText = "Advanced features e.g. logging, credentials, dashboards etc";
×
NEW
112
            btnLoads.ToolTipText = "Load configurations for reading data into your databases";
×
113
            btnFavourites.ToolTipText = "Collection of all objects that you have favourited";
×
NEW
114
            btnDataSets.ToolTipText = "All external datasets that have been configured for use in RDMP";
×
115
        }
×
116
        catch (Exception e)
×
117
        {
118
            _manager.ActivateItems.GlobalErrorCheckNotifier.OnCheckPerformed(
×
119
                new CheckEventArgs("Failed to setup tool tips", CheckResult.Fail, e));
×
120
        }
×
121
    }
×
122

123
    private void ReCreateDropDowns()
124
    {
125
        CreateDropDown<WindowLayout>(cbxLayouts, CreateNewLayout);
×
126
    }
×
127

128
    private void CreateDropDown<T>(ToolStripComboBox cbx, string createNewDashboard)
129
        where T : IMapsDirectlyToDatabaseTable, INamed
130
    {
131
        const int xPaddingForComboText = 10;
132

133
        if (cbx.ComboBox == null)
×
134
            throw new Exception("Expected combo box!");
×
135

136
        cbx.ComboBox.Items.Clear();
×
137

138
        var objects = _manager.RepositoryLocator.CatalogueRepository.GetAllObjects<T>();
×
139

140
        cbx.ComboBox.Items.Add("");
×
141

142
        //minimum size that it will be (same width as the combo box)
143
        var proposedComboBoxWidth = cbx.Width - xPaddingForComboText;
×
144

145
        foreach (var o in objects)
×
146
        {
147
            //add dropdown item
148
            cbx.ComboBox.Items.Add(o);
×
149

150
            //will that label be too big to fit in text box? if so expand the max width
151
            proposedComboBoxWidth = Math.Max(proposedComboBoxWidth, TextRenderer.MeasureText(o.Name, cbx.Font).Width);
×
152
        }
153

154
        cbx.DropDownWidth = Math.Min(400, proposedComboBoxWidth + xPaddingForComboText);
×
155
        cbx.ComboBox.SelectedItem = "";
×
156

157
        cbx.Items.Add(createNewDashboard);
×
158
    }
×
159

160
    private void btnHome_Click(object sender, EventArgs e)
161
    {
162
        _manager.PopHome();
×
163
    }
×
164

165
    private void ToolboxButtonClicked(object sender, EventArgs e)
166
    {
167
        var collection = ButtonToEnum(sender);
×
168

169
        if (_manager.IsVisible(collection))
×
170
            _manager.Pop(collection);
×
171
        else
172
            _manager.Create(collection);
×
173
    }
×
174

175
    private RDMPCollection ButtonToEnum(object button)
176
    {
177
        RDMPCollection collectionToToggle;
178

179
        if (button == btnCatalogues)
×
180
            collectionToToggle = RDMPCollection.Catalogue;
×
181
        else if (button == btnCohorts)
×
182
            collectionToToggle = RDMPCollection.Cohort;
×
183
        else if (button == btnDataExport)
×
184
            collectionToToggle = RDMPCollection.DataExport;
×
185
        else if (button == btnTables)
×
186
            collectionToToggle = RDMPCollection.Tables;
×
NEW
187
        else if (button == btnLoads)
×
188
            collectionToToggle = RDMPCollection.DataLoad;
×
189
        else if (button == btnSavedCohorts)
×
190
            collectionToToggle = RDMPCollection.SavedCohorts;
×
191
        else if (button == btnFavourites)
×
192
            collectionToToggle = RDMPCollection.Favourites;
×
NEW
193
        else if (button == btnDataSets)
×
NEW
194
            collectionToToggle = RDMPCollection.Datasets;
×
195
        else
196
            throw new ArgumentOutOfRangeException(nameof(button));
×
197

198
        return collectionToToggle;
×
199
    }
200

201

202
    private void cbx_DropDownClosed(object sender, EventArgs e)
203
    {
204
        var cbx = (ToolStripComboBox)sender;
×
205

206
        if (ReferenceEquals(cbx.SelectedItem, CreateNewLayout))
×
207
            AddNewLayout();
×
208

209
        if (cbx.SelectedItem is INamed toOpen)
×
210
        {
211
            var cmd = new ExecuteCommandActivate(_manager.ActivateItems, toOpen);
×
212
            cmd.Execute();
×
213
        }
214

215
        UpdateButtonEnabledness();
×
216
    }
×
217

218

219
    private void cbx_SelectedIndexChanged(object sender, EventArgs e)
220
    {
221
        UpdateButtonEnabledness();
×
222
    }
×
223

224
    private void UpdateButtonEnabledness()
225
    {
226
        btnSaveWindowLayout.Enabled = cbxLayouts.SelectedItem is WindowLayout;
×
227
        btnDeleteLayout.Enabled = cbxLayouts.SelectedItem is WindowLayout;
×
228
    }
×
229

230
    private void AddNewLayout()
231
    {
232
        var xml = _manager.MainForm.GetCurrentLayoutXml();
×
233

234
        var dialog = new TypeTextOrCancelDialog("Layout Name", "Name", 100, null, false);
×
235
        if (dialog.ShowDialog() == DialogResult.OK)
×
236
        {
237
            var layout = new WindowLayout(_manager.RepositoryLocator.CatalogueRepository, dialog.ResultText, xml);
×
238

239
            var cmd = new ExecuteCommandActivate(_manager.ActivateItems, layout);
×
240
            cmd.Execute();
×
241

242
            ReCreateDropDowns();
×
243
        }
244
    }
×
245

246

247
    public void InjectButton(ToolStripButton button)
248
    {
249
        toolStrip1.Items.Add(button);
×
250
    }
×
251

252
    private void btnDelete_Click(object sender, EventArgs e)
253
    {
254
        ToolStripComboBox cbx;
255
        if (sender == btnDeleteLayout)
×
256
            cbx = cbxLayouts;
×
257
        else
258
            throw new Exception("Unexpected sender");
×
259

260
        if (cbx.SelectedItem is IDeleteable d)
×
261
        {
262
            _manager.ActivateItems.DeleteWithConfirmation(d);
×
263
            ReCreateDropDowns();
×
264
        }
265
    }
×
266

267
    private void btnSaveWindowLayout_Click(object sender, EventArgs e)
268
    {
269
        if (cbxLayouts.SelectedItem is WindowLayout layout)
×
270
        {
271
            var xml = _manager.MainForm.GetCurrentLayoutXml();
×
272

273
            layout.LayoutData = xml;
×
274
            layout.SaveToDatabase();
×
275
        }
276
    }
×
277

278
    private void btnBack_ButtonClick(object sender, EventArgs e)
279
    {
280
        _manager.Navigation.Back(true);
×
281
    }
×
282

283
    private void btnForward_Click(object sender, EventArgs e)
284
    {
285
        _manager.Navigation.Forward(true);
×
286
    }
×
287

288
    private void btnBack_DropDownOpening(object sender, EventArgs e)
289
    {
290
        btnBack.DropDownItems.Clear();
×
291

292
        var backIndex = 1;
×
293

294
        foreach (var history in _manager.Navigation.GetHistory(16))
×
295
        {
296
            var i = backIndex++;
×
297
            btnBack.DropDownItems.Add(history.ToString(), null, (a, b) => _manager.Navigation.Back(i, true));
×
298
        }
299
    }
×
300
}
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