Skip to content

Commit

Permalink
Add feature to select how the project are added over wizard: new grou…
Browse files Browse the repository at this point in the history
…ps are create based on project path, name includes project path or do not assign groups.
  • Loading branch information
krzysztof-lorenc committed Jan 17, 2020
1 parent 9bce73f commit 5cbdeb2
Show file tree
Hide file tree
Showing 18 changed files with 437 additions and 57 deletions.
5 changes: 3 additions & 2 deletions src/Soloplan.WhatsON.CruiseControl/CruiseControlPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override async Task<IList<Project>> GetProjects(string address)
var serverProjects = new List<Project>();
foreach (var project in allProjects.CruiseControlProject)
{
var serverProjectTreeItem = new Project { Name = project.Name, Address = address };
var serverProjectTreeItem = new Project(address, project.Name);
if (string.IsNullOrWhiteSpace(project.ServerName))
{
result.Add(serverProjectTreeItem);
Expand All @@ -51,12 +51,13 @@ public override async Task<IList<Project>> GetProjects(string address)
var serverProject = serverProjects.FirstOrDefault(s => s.Name == project.ServerName);
if (serverProject == null)
{
serverProject = new Project { Name = project.ServerName };
serverProject = new Project(null, project.ServerName);
serverProjects.Add(serverProject);
result.Add(serverProject);
}

serverProject.Children.Add(serverProjectTreeItem);
serverProjectTreeItem.Parent = serverProject;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IAdditionalWindowSettingsSupport.cs" company="Soloplan GmbH">
// Copyright (c) Soloplan GmbH. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Soloplan.WhatsON.GUI.Common
{
using System.Windows;
using Soloplan.WhatsON.GUI.Common.VisualConfig;

/// <summary>
/// Adds support for storing additional window settings values.
/// </summary>
public interface IAdditionalWindowSettingsSupport
{
/// <summary>
/// Applies the additional window settings to the <see cref="Window"/> instance.
/// </summary>
/// <param name="getAdditionalSettingValue">The get additional setting value.</param>
void Apply(WindowSettings.GetAdditionalSettingValueDelegate getAdditionalSettingValue);

/// <summary>
/// Parses the specified additional setting values from <see cref="Window"/> instance on which the interface is implemented.
/// </summary>
/// <param name="setAdditionalSettingValue">The set additional setting value.</param>
void Parse(WindowSettings.SetAdditionalSettingValueDelegate setAdditionalSettingValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<Compile Include="Converters\InvertBooleanConverter.cs" />
<Compile Include="Converters\InvertBooleanToVisibilityConverter.cs" />
<Compile Include="Converters\NullOrDefaultToVisibilityConverter.cs" />
<Compile Include="IAdditionalWindowSettingsSupport.cs" />
<Compile Include="OpenWebPageCommand.cs" />
<Compile Include="PresentationPlugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class MainWindowSettings

public WindowSettings ConfigDialogSettings { get; set; }

public WindowSettings WizardDialogSettings { get; set; } = new WindowSettings();

public ColorSettings ColorSettings { get; set; }
}
}
71 changes: 67 additions & 4 deletions src/Soloplan.WhatsON.GUI.Common/VisualConfig/WindowSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,87 @@

namespace Soloplan.WhatsON.GUI.Common.VisualConfig
{
using System.Collections.Generic;
using System.Linq;
using System.Windows;

public class WindowSettings
{
public double Width { get; set; }
/// <summary>
/// The delegate used to get additional settings values to apply them to window.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="defaultValue">The default value.</param>
/// <returns>The setting value.</returns>
public delegate string GetAdditionalSettingValueDelegate(string key, string defaultValue);

public double Height { get; set; }
/// <summary>
/// The delegate used to set additional settings values based on window.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
public delegate void SetAdditionalSettingValueDelegate(string key, string value);

public double? Width { get; set; }

public double? Height { get; set; }

public IList<KeyValuePair<string, string>> AdditionalSettingsStore { get; set; }

public void Apply(Window window)
{
window.Width = this.Width;
window.Height = this.Height;
if (this.Width.HasValue)
{
window.Width = this.Width.Value;
}

if (this.Height.HasValue)
{
window.Height = this.Height.Value;
}

if (window is IAdditionalWindowSettingsSupport additionalSettingsWindow)
{
additionalSettingsWindow.Apply(this.GetAdditionalSettingValue);
}
}

public string GetAdditionalSettingValue(string key, string defaultValue)
{
if (this.AdditionalSettingsStore == null)
{
return defaultValue;
}

var records = this.AdditionalSettingsStore.Where(a => a.Key == key).ToList();
return records.Count == 0 ? defaultValue : records.First().Value;
}

public void SetAdditionalSettingValue(string key, string value)
{
if (this.AdditionalSettingsStore == null)
{
this.AdditionalSettingsStore = new List<KeyValuePair<string, string>>();
}

var records = this.AdditionalSettingsStore.Where(a => a.Key == key).ToList();
if (records.Count == 1)
{
this.AdditionalSettingsStore.Remove(records.First());
}

this.AdditionalSettingsStore.Add(new KeyValuePair<string, string>(key, value));
}

public WindowSettings Parse(Window window)
{
this.Width = window.Width;
this.Height = window.Height;
if (window is IAdditionalWindowSettingsSupport additionalSettingsWindow)
{
additionalSettingsWindow.Parse(this.SetAdditionalSettingValue);
}

return this;
}
}
Expand Down
30 changes: 20 additions & 10 deletions src/Soloplan.WhatsON.GUI/Configuration/View/ConfigWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Soloplan.WhatsON.GUI.Configuration.View
using System.Windows.Forms;
using Soloplan.WhatsON.Composition;
using Soloplan.WhatsON.Configuration;
using Soloplan.WhatsON.GUI.Common.VisualConfig;
using Soloplan.WhatsON.GUI.Configuration.ViewModel;
using Soloplan.WhatsON.Model;
using Application = System.Windows.Application;
Expand Down Expand Up @@ -53,6 +54,11 @@ public partial class ConfigWindow : Window
/// </summary>
private readonly ConnectorPlugin newConnectorPlugin;

/// <summary>
/// The wizard dialog settings.
/// </summary>
private readonly WindowSettings wizardDialogSettings;

/// <summary>
/// The configuration source.
/// </summary>
Expand All @@ -79,12 +85,14 @@ public partial class ConfigWindow : Window
private bool windowShown;

/// <summary>
/// Initializes a new instance of the <see cref="ConfigWindow"/> class.
/// Initializes a new instance of the <see cref="ConfigWindow" /> class.
/// </summary>
/// <param name="configuration">The configuration.</param>
public ConfigWindow(ApplicationConfiguration configuration)
/// <param name="wizardDialogSettings">The wizard dialog settings.</param>
public ConfigWindow(ApplicationConfiguration configuration, WindowSettings wizardDialogSettings)
{
this.configurationSource = configuration;
this.wizardDialogSettings = wizardDialogSettings;
this.configurationViewModel.Load(configuration);
this.configurationViewModel.SingleConnectorMode = false;
this.DataContext = this.configurationViewModel;
Expand All @@ -100,12 +108,13 @@ public ConfigWindow(ApplicationConfiguration configuration)
}

/// <summary>
/// Initializes a new instance of the <see cref="ConfigWindow"/> class.
/// Initializes a new instance of the <see cref="ConfigWindow" /> class.
/// </summary>
/// <param name="configuration">The configuration.</param>
/// <param name="initialFocusedConnector">The connector focused on initialization.</param>
public ConfigWindow(ApplicationConfiguration configuration, Connector initialFocusedConnector)
: this(configuration)
/// <param name="wizardDialogSettings">The wizard dialog settings.</param>
public ConfigWindow(ApplicationConfiguration configuration, Connector initialFocusedConnector, WindowSettings wizardDialogSettings)
: this(configuration, wizardDialogSettings)
{
this.initialFocusedConnector = initialFocusedConnector;
this.configurationViewModel.SingleConnectorMode = true;
Expand All @@ -118,8 +127,9 @@ public ConfigWindow(ApplicationConfiguration configuration, Connector initialFoc
/// </summary>
/// <param name="configuration">The configuration.</param>
/// <param name="newConnectorPlugin">The new connector plugin.</param>
public ConfigWindow(ApplicationConfiguration configuration, ConnectorPlugin newConnectorPlugin)
: this(configuration)
/// <param name="wizardDialogSettings">The wizard dialog settings.</param>
public ConfigWindow(ApplicationConfiguration configuration, ConnectorPlugin newConnectorPlugin, WindowSettings wizardDialogSettings)
: this(configuration, wizardDialogSettings)
{
this.newConnectorPlugin = newConnectorPlugin;
this.configurationViewModel.SingleConnectorMode = true;
Expand Down Expand Up @@ -204,15 +214,15 @@ private void ListBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!this.configurationViewModel.SingleConnectorMode)
{
this.connectorPage = new ConnectorsPage(this.configurationViewModel.Connectors, this, this.configurationSource);
this.connectorPage = new ConnectorsPage(this.configurationViewModel.Connectors, this, this.configurationSource, this.wizardDialogSettings);
}
else if (this.initialFocusedConnector != null)
{
this.connectorPage = new ConnectorsPage(this.configurationViewModel.Connectors, this, this.initialFocusedConnector, this.configurationSource);
this.connectorPage = new ConnectorsPage(this.configurationViewModel.Connectors, this, this.initialFocusedConnector, this.configurationSource, this.wizardDialogSettings);
}
else
{
this.connectorPage = new ConnectorsPage(this.configurationViewModel.Connectors, this, this.newConnectorPlugin, this.configurationSource);
this.connectorPage = new ConnectorsPage(this.configurationViewModel.Connectors, this, this.newConnectorPlugin, this.configurationSource, this.wizardDialogSettings);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace Soloplan.WhatsON.GUI.Configuration.View
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
Expand All @@ -18,6 +17,7 @@ namespace Soloplan.WhatsON.GUI.Configuration.View
using MaterialDesignThemes.Wpf;
using Soloplan.WhatsON.Composition;
using Soloplan.WhatsON.Configuration;
using Soloplan.WhatsON.GUI.Common.VisualConfig;
using Soloplan.WhatsON.GUI.Configuration.ViewModel;
using Soloplan.WhatsON.GUI.Configuration.Wizard;
using Soloplan.WhatsON.Model;
Expand All @@ -34,6 +34,11 @@ public partial class ConnectorsPage : Page, INotifyPropertyChanged

private readonly ApplicationConfiguration config;

/// <summary>
/// The wizard dialog settings.
/// </summary>
private readonly WindowSettings wizardDialogSettings;

/// <summary>
/// The current connector.
/// </summary>
Expand All @@ -50,8 +55,10 @@ public partial class ConnectorsPage : Page, INotifyPropertyChanged
/// <param name="connectors">The connectors.</param>
/// <param name="ownerWindow">The owner <see cref="Window" />.</param>
/// <param name="initialFocusedConnector">The initial focused connector.</param>
public ConnectorsPage(ConnectorViewModelCollection connectors, Window ownerWindow, Connector initialFocusedConnector, ApplicationConfiguration config)
: this(connectors, ownerWindow, config)
/// <param name="config">The configuration.</param>
/// <param name="wizardDialogSettings">The wizard dialog settings.</param>
public ConnectorsPage(ConnectorViewModelCollection connectors, Window ownerWindow, Connector initialFocusedConnector, ApplicationConfiguration config, WindowSettings wizardDialogSettings)
: this(connectors, ownerWindow, config, wizardDialogSettings)
{
this.CurrentConnector = this.Connectors.FirstOrDefault(c => c.SourceConnectorConfiguration == initialFocusedConnector.Configuration);
this.InitilizeConnectorNameTextEditBinding();
Expand All @@ -64,8 +71,10 @@ public ConnectorsPage(ConnectorViewModelCollection connectors, Window ownerWindo
/// <param name="connectors">The connectors.</param>
/// <param name="ownerWindow">The owner <see cref="Window" />.</param>
/// <param name="newConnectorPlugin">The new connector plugin.</param>
public ConnectorsPage(ConnectorViewModelCollection connectors, Window ownerWindow, ConnectorPlugin newConnectorPlugin, ApplicationConfiguration config)
: this(connectors, ownerWindow, config)
/// <param name="config">The configuration.</param>
/// <param name="wizardDialogSettings">The wizard dialog settings.</param>
public ConnectorsPage(ConnectorViewModelCollection connectors, Window ownerWindow, ConnectorPlugin newConnectorPlugin, ApplicationConfiguration config, WindowSettings wizardDialogSettings)
: this(connectors, ownerWindow, config, wizardDialogSettings)
{
var newConnector = new ConnectorViewModel();

Expand All @@ -84,11 +93,14 @@ public ConnectorsPage(ConnectorViewModelCollection connectors, Window ownerWindo
/// </summary>
/// <param name="connectors">The connectors.</param>
/// <param name="ownerWindow">The owner <see cref="Window" />.</param>
public ConnectorsPage(ConnectorViewModelCollection connectors, Window ownerWindow, ApplicationConfiguration config)
/// <param name="config">The configuration.</param>
/// <param name="wizardDialogSettings">The wizard dialog settings.</param>
public ConnectorsPage(ConnectorViewModelCollection connectors, Window ownerWindow, ApplicationConfiguration config, WindowSettings wizardDialogSettings)
{
this.ownerWindow = ownerWindow;
this.Connectors = connectors;
this.config = config;
this.wizardDialogSettings = wizardDialogSettings;
this.DataContext = this;
this.InitializeComponent();
this.Connectors.Loaded -= this.ConnectorsLoaded;
Expand Down Expand Up @@ -283,7 +295,7 @@ private async void AddConnectorClick(object sender, System.Windows.RoutedEventAr
/// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
private void EditInWizardClick(object sender, System.Windows.RoutedEventArgs e)
{
var wizardController = new WizardController(this.ownerWindow, this.config);
var wizardController = new WizardController(this.ownerWindow, this.config, this.wizardDialogSettings);
if (wizardController.Start(this.CurrentConnector))
{
var selectedProjects = wizardController.GetSelectedProjects();
Expand All @@ -303,7 +315,7 @@ private void EditInWizardClick(object sender, System.Windows.RoutedEventArgs e)
/// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
private void NewInWizardClick(object sender, System.Windows.RoutedEventArgs e)
{
var wizardController = new WizardController(this.ownerWindow, this.config);
var wizardController = new WizardController(this.ownerWindow, this.config, this.wizardDialogSettings);
wizardController.MultiSelectionMode = false;
var result = false;
try
Expand Down
35 changes: 35 additions & 0 deletions src/Soloplan.WhatsON.GUI/Configuration/Wizard/GrouppingSetting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="GrouppingSetting.cs" company="Soloplan GmbH">
// Copyright (c) Soloplan GmbH. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Soloplan.WhatsON.GUI.Configuration.Wizard
{
/// <summary>
/// The grouping settings item.
/// </summary>
public class GrouppingSetting
{
/// <summary>
/// Initializes a new instance of the <see cref="GrouppingSetting"/> class.
/// </summary>
/// <param name="caption">The caption.</param>
/// <param name="id">The identifier.</param>
public GrouppingSetting(string caption, string id)
{
this.Caption = caption;
this.Id = id;
}

/// <summary>
/// Gets the caption.
/// </summary>
public string Caption { get; }

/// <summary>
/// Gets the identifier.
/// </summary>
public string Id { get; }
}
}
Loading

0 comments on commit 5cbdeb2

Please sign in to comment.