Index: Core/Common/src/Core.Common.Gui/Commands/GuiImportHandler.cs =================================================================== diff -u -rd3b0170f6c1237721a45b92504a11353064ca8e1 -r3a1baec7e10e459689c326e20e95e140c597b0d6 --- Core/Common/src/Core.Common.Gui/Commands/GuiImportHandler.cs (.../GuiImportHandler.cs) (revision d3b0170f6c1237721a45b92504a11353064ca8e1) +++ Core/Common/src/Core.Common.Gui/Commands/GuiImportHandler.cs (.../GuiImportHandler.cs) (revision 3a1baec7e10e459689c326e20e95e140c597b0d6) @@ -42,28 +42,35 @@ private static readonly ILog log = LogManager.GetLogger(typeof(GuiImportHandler)); private readonly IWin32Window dialogParent; - private readonly IEnumerable fileImporters; private readonly IEnumerable importInfos; /// /// Initializes a new instance of the class. /// /// The parent window to show dialogs on top. - /// An enumeration of . /// An enumeration of . - public GuiImportHandler(IWin32Window dialogParent, IEnumerable fileImporters, IEnumerable importInfos) + public GuiImportHandler(IWin32Window dialogParent, IEnumerable importInfos) { this.dialogParent = dialogParent; - this.fileImporters = fileImporters; this.importInfos = importInfos; } public bool CanImportOn(object target) { - return fileImporters.Any(fileImporter => fileImporter.CanImportOn(target)) || - GetSupportedImportInfos(target).Any(); + return GetSupportedImportInfos(target).Any(); } + public void ImportOn(object target) + { + IFileImporter importer = GetSupportedImporterUsingDialog(target); + if (importer == null) + { + return; + } + + ImportItemsUsingDialog(importer, target); + } + private IEnumerable GetSupportedImportInfos(object target) { if (target == null) @@ -76,21 +83,9 @@ return importInfos.Where(info => (info.DataType == targetType || targetType.Implements(info.DataType)) && info.IsEnabled(target)); } - public void ImportOn(object target) - { - IFileImporter importer = GetSupportedImporterUsingDialog(target); - if (importer == null) - { - return; - } - - ImportItemsUsingDialog(importer, target); - } - private IFileImporter GetSupportedImporterUsingDialog(object target) { - IFileImporter[] importers = fileImporters.Where(fileImporter => fileImporter.CanImportOn(target)). - Concat(GetSupportedImportInfos(target).Select(i => i.CreateFileImporter(target))).ToArray(); + IFileImporter[] importers = GetSupportedImportInfos(target).Select(i => i.CreateFileImporter(target)).ToArray(); if (importers.Length == 0) { MessageBox.Show(Resources.GuiImportHandler_GetSupportedImporterForTargetType_No_importer_available_for_this_item, Index: Core/Common/src/Core.Common.Gui/GuiCore.cs =================================================================== diff -u -rd3b0170f6c1237721a45b92504a11353064ca8e1 -r3a1baec7e10e459689c326e20e95e140c597b0d6 --- Core/Common/src/Core.Common.Gui/GuiCore.cs (.../GuiCore.cs) (revision d3b0170f6c1237721a45b92504a11353064ca8e1) +++ Core/Common/src/Core.Common.Gui/GuiCore.cs (.../GuiCore.cs) (revision 3a1baec7e10e459689c326e20e95e140c597b0d6) @@ -118,7 +118,7 @@ viewCommandHandler = new ViewCommandHandler(this, this, this); storageCommandHandler = new StorageCommandHandler(projectStore, this, MainWindow); - importCommandHandler = new GuiImportHandler(MainWindow, Plugins.SelectMany(p => p.GetFileImporters()), Plugins.SelectMany(p => p.GetImportInfos())); + importCommandHandler = new GuiImportHandler(MainWindow, Plugins.SelectMany(p => p.GetImportInfos())); exportCommandHandler = new GuiExportHandler(MainWindow, Plugins.SelectMany(p => p.GetExportInfos())); WindowsApplication.EnableVisualStyles(); @@ -136,11 +136,6 @@ #endregion - public void Dispose() - { - Dispose(true); - } - /// /// Runs the user interface, causing all user interface components to initialize, /// loading plugins, opening a saved project and displaying the main window. @@ -167,6 +162,11 @@ MessageWindowLogAppender.Instance.Enabled = true; } + public void Dispose() + { + Dispose(true); + } + public void ExitApplication() { if (isExiting) @@ -643,7 +643,7 @@ private readonly ViewCommandHandler viewCommandHandler; private readonly GuiImportHandler importCommandHandler; private readonly GuiExportHandler exportCommandHandler; - private StorageCommandHandler storageCommandHandler; + private readonly StorageCommandHandler storageCommandHandler; public IApplicationFeatureCommands ApplicationCommands { Index: Core/Common/src/Core.Common.Gui/Plugin/PluginBase.cs =================================================================== diff -u -rd3b0170f6c1237721a45b92504a11353064ca8e1 -r3a1baec7e10e459689c326e20e95e140c597b0d6 --- Core/Common/src/Core.Common.Gui/Plugin/PluginBase.cs (.../PluginBase.cs) (revision d3b0170f6c1237721a45b92504a11353064ca8e1) +++ Core/Common/src/Core.Common.Gui/Plugin/PluginBase.cs (.../PluginBase.cs) (revision 3a1baec7e10e459689c326e20e95e140c597b0d6) @@ -22,7 +22,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Core.Common.Base.IO; using Core.Common.Controls.TreeView; using Core.Common.Gui.Forms; @@ -60,15 +59,6 @@ public virtual void Deactivate() {} /// - /// This method returns an enumeration of . - /// - /// The enumeration of provided by the . - public virtual IEnumerable GetFileImporters() - { - yield break; - } - - /// /// This method returns an enumeration of . /// /// The enumeration of provided by the . Index: Core/Common/test/Core.Common.Gui.Test/Commands/GuiImportHandlerTest.cs =================================================================== diff -u -rd3b0170f6c1237721a45b92504a11353064ca8e1 -r3a1baec7e10e459689c326e20e95e140c597b0d6 --- Core/Common/test/Core.Common.Gui.Test/Commands/GuiImportHandlerTest.cs (.../GuiImportHandlerTest.cs) (revision d3b0170f6c1237721a45b92504a11353064ca8e1) +++ Core/Common/test/Core.Common.Gui.Test/Commands/GuiImportHandlerTest.cs (.../GuiImportHandlerTest.cs) (revision 3a1baec7e10e459689c326e20e95e140c597b0d6) @@ -19,11 +19,8 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System.Collections.Generic; -using System.Drawing; using System.Linq; using System.Windows.Forms; -using Core.Common.Base.IO; using Core.Common.Gui.Commands; using Core.Common.Gui.Forms.MainWindow; using Core.Common.Gui.Plugin; @@ -55,7 +52,7 @@ messageBox.ClickOk(); }; - var importHandler = new GuiImportHandler(mainWindow, Enumerable.Empty(), Enumerable.Empty()); + var importHandler = new GuiImportHandler(mainWindow, Enumerable.Empty()); // Call importHandler.ImportOn(typeof(long)); @@ -67,40 +64,6 @@ } [Test] - public void ImportOn_NoSupportedImporterAvailable_GivesMessageBox() - { - // Setup - var fileImporters = new List - { - new UnsupportedFileImporter() - }; - var mockRepository = new MockRepository(); - var mainWindow = mockRepository.Stub(); - mockRepository.ReplayAll(); - - string messageBoxTitle = null, messageBoxText = null; - DialogBoxHandler = (name, wnd) => - { - var messageBox = new MessageBoxTester(wnd); - - messageBoxText = messageBox.Text; - messageBoxTitle = messageBox.Title; - - messageBox.ClickOk(); - }; - - var importHandler = new GuiImportHandler(mainWindow, fileImporters, Enumerable.Empty()); - - // Call - importHandler.ImportOn(typeof(long)); - - // Assert - Assert.AreEqual("Fout", messageBoxTitle); - Assert.AreEqual("Geen enkele 'Importer' is beschikbaar voor dit element.", messageBoxText); - mockRepository.VerifyAll(); - } - - [Test] public void ImportOn_NoSupportedImportInfoAvailable_GivesMessageBox() { // Setup @@ -119,7 +82,7 @@ messageBox.ClickOk(); }; - var importHandler = new GuiImportHandler(mainWindow, Enumerable.Empty(), new ImportInfo[] + var importHandler = new GuiImportHandler(mainWindow, new ImportInfo[] { new ImportInfo() }); @@ -141,7 +104,7 @@ var dialogParent = mocks.Stub(); mocks.ReplayAll(); - var commandHandler = new GuiImportHandler(dialogParent, Enumerable.Empty(), Enumerable.Empty()); + var commandHandler = new GuiImportHandler(dialogParent, Enumerable.Empty()); // Call bool isImportPossible = commandHandler.CanImportOn(new object()); @@ -152,33 +115,6 @@ } [Test] - public void CanImportOn_HasOneFileImporterForTarget_ReturnTrue() - { - // Setup - var target = new object(); - - var mocks = new MockRepository(); - var dialogParent = mocks.Stub(); - var objectImporter = mocks.Stub(); - objectImporter.Stub(i => i.CanImportOn(target)).Return(true); - mocks.ReplayAll(); - - var fileImporters = new List - { - objectImporter - }; - - var commandHandler = new GuiImportHandler(dialogParent, fileImporters, Enumerable.Empty()); - - // Call - bool isImportPossible = commandHandler.CanImportOn(target); - - // Assert - Assert.IsTrue(isImportPossible); - mocks.VerifyAll(); - } - - [Test] public void CanImportOn_HasOneImportInfoForTarget_ReturnTrue() { // Setup @@ -188,7 +124,7 @@ var dialogParent = mocks.Stub(); mocks.ReplayAll(); - var commandHandler = new GuiImportHandler(dialogParent, Enumerable.Empty(), new ImportInfo[] + var commandHandler = new GuiImportHandler(dialogParent, new ImportInfo[] { new ImportInfo() }); @@ -202,32 +138,6 @@ } [Test] - public void CanImportOn_HasOneFileImporterForTargetThatCannotImportOnTarget_ReturnFalse() - { - // Setup - var target = new object(); - var mocks = new MockRepository(); - var dialogParent = mocks.Stub(); - var objectImporter = mocks.Stub(); - objectImporter.Stub(i => i.CanImportOn(target)).Return(false); - mocks.ReplayAll(); - - var fileImporters = new List - { - objectImporter - }; - - var commandHandler = new GuiImportHandler(dialogParent, fileImporters, Enumerable.Empty()); - - // Call - bool isImportPossible = commandHandler.CanImportOn(target); - - // Assert - Assert.IsFalse(isImportPossible); - mocks.VerifyAll(); - } - - [Test] public void CanImportOn_HasOneImporterInfoForTargetThatIsNotEnabledForTarget_ReturnFalse() { // Setup @@ -236,7 +146,7 @@ var dialogParent = mocks.Stub(); mocks.ReplayAll(); - var commandHandler = new GuiImportHandler(dialogParent, Enumerable.Empty(), new ImportInfo[] + var commandHandler = new GuiImportHandler(dialogParent, new ImportInfo[] { new ImportInfo { @@ -253,34 +163,6 @@ } [Test] - public void CanImportOn_HasMultipleFileImporterForTargetWhereAtLeastOneCanHandleTargetItem_ReturnTrue() - { - // Setup - var target = new object(); - var mocks = new MockRepository(); - var dialogParent = mocks.Stub(); - var objectImporter1 = mocks.Stub(); - objectImporter1.Stub(i => i.CanImportOn(target)).Return(false); - var objectImporter2 = mocks.Stub(); - objectImporter2.Stub(i => i.CanImportOn(target)).Return(true); - mocks.ReplayAll(); - - var fileImporters = new List - { - objectImporter1, objectImporter2 - }; - - var commandHandler = new GuiImportHandler(dialogParent, fileImporters, Enumerable.Empty()); - - // Call - bool isImportPossible = commandHandler.CanImportOn(target); - - // Assert - Assert.IsTrue(isImportPossible); - mocks.VerifyAll(); - } - - [Test] public void CanImportOn_HasMultipleImportInfosForTargetWhereAtLeastOneEnabledForTargetItem_ReturnTrue() { // Setup @@ -289,7 +171,7 @@ var dialogParent = mocks.Stub(); mocks.ReplayAll(); - var commandHandler = new GuiImportHandler(dialogParent, Enumerable.Empty(), new ImportInfo[] + var commandHandler = new GuiImportHandler(dialogParent, new ImportInfo[] { new ImportInfo { @@ -310,34 +192,6 @@ } [Test] - public void CanImportOn_HasMultipleFileImporterForTargetThatCannotBeUsedForImporting_ReturnFalse() - { - // Setup - var target = new object(); - var mocks = new MockRepository(); - var dialogParent = mocks.Stub(); - var objectImporter1 = mocks.Stub(); - objectImporter1.Stub(i => i.CanImportOn(target)).Return(false); - var objectImporter2 = mocks.Stub(); - objectImporter2.Stub(i => i.CanImportOn(target)).Return(false); - mocks.ReplayAll(); - - var fileImporters = new List - { - objectImporter1, objectImporter2 - }; - - var commandHandler = new GuiImportHandler(dialogParent, fileImporters, Enumerable.Empty()); - - // Call - bool isImportPossible = commandHandler.CanImportOn(target); - - // Assert - Assert.IsFalse(isImportPossible); - mocks.VerifyAll(); - } - - [Test] public void CanImportOn_HasMultipleImportInfosForTargetThatCannotBeUsedForImporting_ReturnFalse() { // Setup @@ -346,7 +200,7 @@ var dialogParent = mocks.Stub(); mocks.ReplayAll(); - var commandHandler = new GuiImportHandler(dialogParent, Enumerable.Empty(), new ImportInfo[] + var commandHandler = new GuiImportHandler(dialogParent, new ImportInfo[] { new ImportInfo { @@ -365,32 +219,5 @@ Assert.IsFalse(isImportPossible); mocks.VerifyAll(); } - - private class UnsupportedFileImporter : IFileImporter - { - public string Name { get; private set; } - - public string Category { get; private set; } - - public Bitmap Image { get; private set; } - - public string FileFilter { get; private set; } - - public ProgressChangedDelegate ProgressChanged { get; set; } - - public bool CanImportOn(object targetItem) - { - return false; - } - - public bool Import(object targetItem, string filePath) - { - return false; - } - - public void Cancel() {} - - public void DoPostImportUpdates(object targetItem) {} - } } } \ No newline at end of file Index: Core/Common/test/Core.Common.Gui.Test/Plugin/PluginBaseTest.cs =================================================================== diff -u -r0d22462e91eb69208ab2aee6ed2c621d31006b02 -r3a1baec7e10e459689c326e20e95e140c597b0d6 --- Core/Common/test/Core.Common.Gui.Test/Plugin/PluginBaseTest.cs (.../PluginBaseTest.cs) (revision 0d22462e91eb69208ab2aee6ed2c621d31006b02) +++ Core/Common/test/Core.Common.Gui.Test/Plugin/PluginBaseTest.cs (.../PluginBaseTest.cs) (revision 3a1baec7e10e459689c326e20e95e140c597b0d6) @@ -192,28 +192,6 @@ } [Test] - public void GetFileImporters_ReturnsEmpty() - { - // Setup - var mocks = new MockRepository(); - var gui = mocks.StrictMock(); - mocks.ReplayAll(); - - using (var plugin = new SimplePlugin - { - Gui = gui - }) - { - // Call - var infos = plugin.GetFileImporters(); - - // Assert - CollectionAssert.IsEmpty(infos); - } - mocks.VerifyAll(); - } - - [Test] public void GetExportInfos_ReturnsEmptyEnumerable() { // Setup @@ -247,7 +225,7 @@ { Gui = gui }; - + // Call plugin.Dispose(); Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/GrassCoverErosionInwardsPluginTest.cs =================================================================== diff -u -rc43715cf3e6dce0c427b10c4852d5ae54e6d668d -r3a1baec7e10e459689c326e20e95e140c597b0d6 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/GrassCoverErosionInwardsPluginTest.cs (.../GrassCoverErosionInwardsPluginTest.cs) (revision c43715cf3e6dce0c427b10c4852d5ae54e6d668d) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/GrassCoverErosionInwardsPluginTest.cs (.../GrassCoverErosionInwardsPluginTest.cs) (revision 3a1baec7e10e459689c326e20e95e140c597b0d6) @@ -19,9 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System.Collections.Generic; using System.Linq; -using Core.Common.Base.IO; using Core.Common.Controls.TreeView; using Core.Common.Gui; using Core.Common.Gui.Commands; @@ -154,29 +152,6 @@ } [Test] - public void GetFileImporters_Always_ReturnsExpectedFileImporter() - { - // Setup - var mocks = new MockRepository(); - var guiStub = mocks.Stub(); - guiStub.Stub(g => g.ApplicationCommands).Return(mocks.Stub()); - mocks.ReplayAll(); - - using (var plugin = new GrassCoverErosionInwardsPlugin - { - Gui = guiStub - }) - { - // Call - IEnumerable importers = plugin.GetFileImporters(); - - // Assert - CollectionAssert.IsEmpty(importers); - } - mocks.VerifyAll(); - } - - [Test] public void GetImportInfos_Always_ReturnsExpectedImportInfos() { // Setup