Index: Core/Common/src/Core.Common.Gui/ContextMenu/ContextMenuBuilder.cs =================================================================== diff -u -ra80efa8773c3efec54ba44940945b03bc3f3ff7e -r97989f272e0b9aadccf3a444a90e61879616a0ab --- Core/Common/src/Core.Common.Gui/ContextMenu/ContextMenuBuilder.cs (.../ContextMenuBuilder.cs) (revision a80efa8773c3efec54ba44940945b03bc3f3ff7e) +++ Core/Common/src/Core.Common.Gui/ContextMenu/ContextMenuBuilder.cs (.../ContextMenuBuilder.cs) (revision 97989f272e0b9aadccf3a444a90e61879616a0ab) @@ -24,17 +24,14 @@ /// to the items of the . If null, this builder will not render items which /// require this type of information. /// The for which to create a . + /// Thrown when is null. public ContextMenuBuilder(IGui gui, ITreeNode treeNode) { - if (treeNode == null) - { - throw new ArgumentNullException("treeNode", Resources.ContextMenuBuilder_ContextMenuBuilder_Can_not_build_context_menu_for_empty_tree_node); - } if (gui != null) { - guiItemsFactory = new GuiContextMenuItemFactory(gui); + guiItemsFactory = new GuiContextMenuItemFactory(gui, treeNode); } - treeViewItemsFactory = new TreeViewContextMenuItemFactory(); + treeViewItemsFactory = new TreeViewContextMenuItemFactory(treeNode); contextMenu = new ContextMenuStrip(); this.treeNode = treeNode; } @@ -45,7 +42,7 @@ /// The itself, so that operations can be easily chained. public ContextMenuBuilder AddExpandAllItem() { - AddItem(treeViewItemsFactory.CreateExpandAllItem(treeNode)); + AddItem(treeViewItemsFactory.CreateExpandAllItem()); return this; } @@ -55,7 +52,7 @@ /// The itself, so that operations can be easily chained. public ContextMenuBuilder AddCollapseAllItem() { - AddItem(treeViewItemsFactory.CreateCollapseAllItem(treeNode)); + AddItem(treeViewItemsFactory.CreateCollapseAllItem()); return this; } @@ -68,7 +65,7 @@ { if (guiItemsFactory != null) { - AddItem(guiItemsFactory.CreateExportItem(treeNode)); + AddItem(guiItemsFactory.CreateExportItem()); } return this; } @@ -82,7 +79,7 @@ { if (guiItemsFactory != null) { - AddItem(guiItemsFactory.CreateImportItem(treeNode)); + AddItem(guiItemsFactory.CreateImportItem()); } return this; } @@ -96,7 +93,7 @@ { if (guiItemsFactory != null) { - AddItem(guiItemsFactory.CreatePropertiesItem(treeNode)); + AddItem(guiItemsFactory.CreatePropertiesItem()); } return this; } Index: Core/Common/src/Core.Common.Gui/ContextMenu/GuiContextMenuItemFactory.cs =================================================================== diff -u -ra80efa8773c3efec54ba44940945b03bc3f3ff7e -r97989f272e0b9aadccf3a444a90e61879616a0ab --- Core/Common/src/Core.Common.Gui/ContextMenu/GuiContextMenuItemFactory.cs (.../GuiContextMenuItemFactory.cs) (revision a80efa8773c3efec54ba44940945b03bc3f3ff7e) +++ Core/Common/src/Core.Common.Gui/ContextMenu/GuiContextMenuItemFactory.cs (.../GuiContextMenuItemFactory.cs) (revision 97989f272e0b9aadccf3a444a90e61879616a0ab) @@ -14,31 +14,39 @@ internal class GuiContextMenuItemFactory { private readonly IGui gui; + private readonly ITreeNode treeNode; /// /// Creates a new instance of , which uses the to create /// . /// /// The which contains information for creating the . - /// Thrown when is null. - public GuiContextMenuItemFactory(IGui gui) + /// The for which to create . + /// Thrown when + /// + /// is null + /// is null + /// + public GuiContextMenuItemFactory(IGui gui, ITreeNode treeNode) { if (gui == null) { - throw new ArgumentNullException("gui", Resources.GuiContextMenuItemFactory_GuiContextMenuItemFactory_Can_not_create_gui_context_menu_items_without_gui); + throw new ArgumentNullException("gui", Resources.GuiContextMenuItemFactory_Can_not_create_gui_context_menu_items_without_gui); } + if (treeNode == null) + { + throw new ArgumentNullException("treeNode", Resources.ContextMenuItemFactory_Can_not_create_context_menu_items_without_tree_node); + } + this.treeNode = treeNode; this.gui = gui; } /// /// Creates a which is bound to the action of exporting - /// the data of the given . + /// the data of the . /// - /// The for which to create the - /// and for which to export its data if clicked. - /// /// The created . - public ToolStripItem CreateExportItem(ITreeNode treeNode) + public ToolStripItem CreateExportItem() { var data = treeNode.Tag; var exporters = gui.ApplicationCore.GetSupportedFileExporters(data); @@ -54,13 +62,10 @@ /// /// Creates a which is bound to the action of importing - /// the data of the given . + /// the data of the given . /// - /// The for which to create the - /// and for which to import its data if clicked. - /// /// The created . - public ToolStripItem CreateImportItem(ITreeNode treeNode) + public ToolStripItem CreateImportItem() { var data = treeNode.Tag; var importers = gui.ApplicationCore.GetSupportedFileImporters(data); @@ -76,13 +81,10 @@ /// /// Creates a which is bound to the action of showing - /// the properties of the data of the given . + /// the properties of the data of the given . /// - /// The for which to create the - /// and for which to show the properties of its data if clicked. - /// /// The created . - public ToolStripItem CreatePropertiesItem(ITreeNode treeNode) + public ToolStripItem CreatePropertiesItem() { var data = treeNode.Tag; var propertyInfos = gui.Plugins.SelectMany(p => p.GetPropertyInfos()).Where(pi => pi.ObjectType == data.GetType()); Index: Core/Common/src/Core.Common.Gui/ContextMenu/TreeViewContextMenuItemFactory.cs =================================================================== diff -u -ra80efa8773c3efec54ba44940945b03bc3f3ff7e -r97989f272e0b9aadccf3a444a90e61879616a0ab --- Core/Common/src/Core.Common.Gui/ContextMenu/TreeViewContextMenuItemFactory.cs (.../TreeViewContextMenuItemFactory.cs) (revision a80efa8773c3efec54ba44940945b03bc3f3ff7e) +++ Core/Common/src/Core.Common.Gui/ContextMenu/TreeViewContextMenuItemFactory.cs (.../TreeViewContextMenuItemFactory.cs) (revision 97989f272e0b9aadccf3a444a90e61879616a0ab) @@ -1,4 +1,5 @@ -using System.Windows.Forms; +using System; +using System.Windows.Forms; using Core.Common.Controls; using Core.Common.Gui.Properties; @@ -11,14 +12,28 @@ /// internal class TreeViewContextMenuItemFactory { + private readonly ITreeNode treeNode; + /// + /// Creates a new instance of for the given . + /// + /// The for which to create . + /// Thrown when is null. + public TreeViewContextMenuItemFactory(ITreeNode treeNode) + { + if (treeNode == null) + { + throw new ArgumentNullException("treeNode", Resources.ContextMenuItemFactory_Can_not_create_context_menu_items_without_tree_node); + } + this.treeNode = treeNode; + } + + /// /// Creates a which is bound to the action of expanding - /// the . + /// the . /// - /// The for which to create the - /// and which to expand if clicked. /// The created . - public ToolStripItem CreateExpandAllItem(ITreeNode treeNode) + public ToolStripItem CreateExpandAllItem() { var toolStripMenuItem = new ToolStripMenuItem(Resources.Expand_all) { @@ -31,12 +46,10 @@ /// /// Creates a which is bound to the action of collapsing - /// the . + /// the . /// - /// The for which to create the - /// and which to collapse if clicked. /// The created . - public ToolStripItem CreateCollapseAllItem(ITreeNode treeNode) + public ToolStripItem CreateCollapseAllItem() { var toolStripMenuItem = new ToolStripMenuItem(Resources.Collapse_all) { Index: Core/Common/src/Core.Common.Gui/Properties/Resources.Designer.cs =================================================================== diff -u -ra80efa8773c3efec54ba44940945b03bc3f3ff7e -r97989f272e0b9aadccf3a444a90e61879616a0ab --- Core/Common/src/Core.Common.Gui/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision a80efa8773c3efec54ba44940945b03bc3f3ff7e) +++ Core/Common/src/Core.Common.Gui/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 97989f272e0b9aadccf3a444a90e61879616a0ab) @@ -540,6 +540,15 @@ } /// + /// Looks up a localized string similar to Kan geen element in het contextmenu creëren zonder dat de knoop bekend is.. + /// + public static string ContextMenuItemFactory_Can_not_create_context_menu_items_without_tree_node { + get { + return ResourceManager.GetString("ContextMenuItemFactory_Can_not_create_context_menu_items_without_tree_node", resourceCulture); + } + } + + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// public static System.Drawing.Bitmap control_play { @@ -1125,10 +1134,9 @@ /// /// Looks up a localized string similar to Kan geen GUI-afhankelijk element in het contextmenu creëren zonder een GUI.. /// - public static string GuiContextMenuItemFactory_GuiContextMenuItemFactory_Can_not_create_gui_context_menu_items_without_gui { + public static string GuiContextMenuItemFactory_Can_not_create_gui_context_menu_items_without_gui { get { - return ResourceManager.GetString("GuiContextMenuItemFactory_GuiContextMenuItemFactory_Can_not_create_gui_context_me" + - "nu_items_without_gui", resourceCulture); + return ResourceManager.GetString("GuiContextMenuItemFactory_Can_not_create_gui_context_menu_items_without_gui", resourceCulture); } } Index: Core/Common/src/Core.Common.Gui/Properties/Resources.resx =================================================================== diff -u -ra80efa8773c3efec54ba44940945b03bc3f3ff7e -r97989f272e0b9aadccf3a444a90e61879616a0ab --- Core/Common/src/Core.Common.Gui/Properties/Resources.resx (.../Resources.resx) (revision a80efa8773c3efec54ba44940945b03bc3f3ff7e) +++ Core/Common/src/Core.Common.Gui/Properties/Resources.resx (.../Resources.resx) (revision 97989f272e0b9aadccf3a444a90e61879616a0ab) @@ -863,7 +863,10 @@ Kan geen contextmenu opbouwen voor een lege knoop. - + Kan geen GUI-afhankelijk element in het contextmenu creëren zonder een GUI. + + Kan geen element in het contextmenu creëren zonder dat de knoop bekend is. + \ No newline at end of file Index: Core/Common/test/Core.Common.Gui.Test/ContextMenu/GuiContextMenuItemFactoryTest.cs =================================================================== diff -u -ra80efa8773c3efec54ba44940945b03bc3f3ff7e -r97989f272e0b9aadccf3a444a90e61879616a0ab --- Core/Common/test/Core.Common.Gui.Test/ContextMenu/GuiContextMenuItemFactoryTest.cs (.../GuiContextMenuItemFactoryTest.cs) (revision a80efa8773c3efec54ba44940945b03bc3f3ff7e) +++ Core/Common/test/Core.Common.Gui.Test/ContextMenu/GuiContextMenuItemFactoryTest.cs (.../GuiContextMenuItemFactoryTest.cs) (revision 97989f272e0b9aadccf3a444a90e61879616a0ab) @@ -1,7 +1,9 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Core.Common.Base; using Core.Common.Controls; using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.Properties; using Core.Common.TestUtils; using NUnit.Framework; using Rhino.Mocks; @@ -24,6 +26,41 @@ } [Test] + public void Constructor_WithoutGui_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new GuiContextMenuItemFactory(null, null); + + // Assert + var message = Assert.Throws(test).Message; + StringAssert.StartsWith(Resources.GuiContextMenuItemFactory_Can_not_create_gui_context_menu_items_without_gui, message); + StringAssert.EndsWith("gui", message); + + } + + [Test] + public void Constructor_WithoutTreeNode_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new GuiContextMenuItemFactory(mocks.StrictMock(), null); + + // Assert + var message = Assert.Throws(test).Message; + StringAssert.StartsWith(Resources.ContextMenuItemFactory_Can_not_create_context_menu_items_without_tree_node, message); + StringAssert.EndsWith("treeNode", message); + } + + [Test] + public void Constructor_WithGuiAndTreeNode_NewInstance() + { + // Call + var result = new GuiContextMenuItemFactory(mocks.StrictMock(), mocks.StrictMock()); + + // Assert + Assert.IsInstanceOf(result); + } + + [Test] public void CreateExportItem_NoImportersForType_Disabled() { // Setup @@ -33,12 +70,12 @@ var applicationCore = new ApplicationCore(); applicationCore.AddPlugin(new TestApplicationPlugin(mocks)); guiMock.Expect(g => g.ApplicationCore).Return(applicationCore); - var contextMenuFactory = new GuiContextMenuItemFactory(guiMock); + var contextMenuFactory = new GuiContextMenuItemFactory(guiMock, treeNodeMock); mocks.ReplayAll(); // Call - var item = contextMenuFactory.CreateExportItem(treeNodeMock); + var item = contextMenuFactory.CreateExportItem(); // Assert Assert.AreEqual(Properties.Resources.Export, item.Text); @@ -57,12 +94,12 @@ var applicationCore = new ApplicationCore(); applicationCore.AddPlugin(new TestApplicationPlugin(mocks)); guiMock.Expect(g => g.ApplicationCore).Return(applicationCore); - var contextMenuFactory = new GuiContextMenuItemFactory(guiMock); + var contextMenuFactory = new GuiContextMenuItemFactory(guiMock, treeNodeMock); mocks.ReplayAll(); // Call - var item = contextMenuFactory.CreateExportItem(treeNodeMock); + var item = contextMenuFactory.CreateExportItem(); // Assert Assert.AreEqual(Properties.Resources.Export, item.Text); @@ -81,12 +118,12 @@ var applicationCore = new ApplicationCore(); applicationCore.AddPlugin(new TestApplicationPlugin(mocks)); guiMock.Expect(g => g.ApplicationCore).Return(applicationCore); - var contextMenuFactory = new GuiContextMenuItemFactory(guiMock); + var contextMenuFactory = new GuiContextMenuItemFactory(guiMock, treeNodeMock); mocks.ReplayAll(); // Call - var item = contextMenuFactory.CreateImportItem(treeNodeMock); + var item = contextMenuFactory.CreateImportItem(); // Assert Assert.AreEqual(Properties.Resources.Import, item.Text); @@ -105,12 +142,12 @@ var applicationCore = new ApplicationCore(); applicationCore.AddPlugin(new TestApplicationPlugin(mocks)); guiMock.Expect(g => g.ApplicationCore).Return(applicationCore); - var contextMenuFactory = new GuiContextMenuItemFactory(guiMock); + var contextMenuFactory = new GuiContextMenuItemFactory(guiMock, treeNodeMock); mocks.ReplayAll(); // Call - var item = contextMenuFactory.CreateImportItem(treeNodeMock); + var item = contextMenuFactory.CreateImportItem(); // Assert Assert.AreEqual(Properties.Resources.Import, item.Text); @@ -128,12 +165,12 @@ treeNodeMock.Tag = 0; guiMock.Expect(g => g.Plugins).Return(pluginList); guiMock.Expect(g => g.CommandHandler).Return(null); - var contextMenuFactory = new GuiContextMenuItemFactory(guiMock); + var contextMenuFactory = new GuiContextMenuItemFactory(guiMock, treeNodeMock); mocks.ReplayAll(); // Call - var item = contextMenuFactory.CreatePropertiesItem(treeNodeMock); + var item = contextMenuFactory.CreatePropertiesItem(); // Assert Assert.AreEqual(Properties.Resources.Properties, item.Text); @@ -153,12 +190,12 @@ treeNodeMock.Tag = ""; guiMock.Expect(g => g.Plugins).Return(pluginList); guiMock.Expect(g => g.CommandHandler).Return(null); - var contextMenuFactory = new GuiContextMenuItemFactory(guiMock); + var contextMenuFactory = new GuiContextMenuItemFactory(guiMock, treeNodeMock); mocks.ReplayAll(); // Call - var item = contextMenuFactory.CreatePropertiesItem(treeNodeMock); + var item = contextMenuFactory.CreatePropertiesItem(); // Assert Assert.AreEqual(Properties.Resources.Properties, item.Text); @@ -178,11 +215,11 @@ treeNodeMock.Tag = 0; guiMock.Expect(g => g.Plugins).Return(pluginList); guiMock.Expect(g => g.CommandHandler).Return(null); - var contextMenuFactory = new GuiContextMenuItemFactory(guiMock); + var contextMenuFactory = new GuiContextMenuItemFactory(guiMock, treeNodeMock); mocks.ReplayAll(); - var item = contextMenuFactory.CreatePropertiesItem(treeNodeMock); + var item = contextMenuFactory.CreatePropertiesItem(); // Call & Assert item.PerformClick(); @@ -201,11 +238,11 @@ guiMock.Expect(g => g.Plugins).Return(pluginList); guiMock.Expect(g => g.CommandHandler).Return(commandHandlerMock); commandHandlerMock.Expect(ch => ch.ShowProperties()); - var contextMenuFactory = new GuiContextMenuItemFactory(guiMock); + var contextMenuFactory = new GuiContextMenuItemFactory(guiMock, treeNodeMock); mocks.ReplayAll(); - var item = contextMenuFactory.CreatePropertiesItem(treeNodeMock); + var item = contextMenuFactory.CreatePropertiesItem(); // Call & Assert item.PerformClick(); Index: Core/Common/test/Core.Common.Gui.Test/ContextMenu/TreeViewContextMenuItemFactoryTest.cs =================================================================== diff -u -ra80efa8773c3efec54ba44940945b03bc3f3ff7e -r97989f272e0b9aadccf3a444a90e61879616a0ab --- Core/Common/test/Core.Common.Gui.Test/ContextMenu/TreeViewContextMenuItemFactoryTest.cs (.../TreeViewContextMenuItemFactoryTest.cs) (revision a80efa8773c3efec54ba44940945b03bc3f3ff7e) +++ Core/Common/test/Core.Common.Gui.Test/ContextMenu/TreeViewContextMenuItemFactoryTest.cs (.../TreeViewContextMenuItemFactoryTest.cs) (revision 97989f272e0b9aadccf3a444a90e61879616a0ab) @@ -1,4 +1,5 @@ -using Core.Common.Controls; +using System; +using Core.Common.Controls; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Properties; using Core.Common.TestUtils; @@ -19,6 +20,28 @@ } [Test] + public void Constructor_WithoutTreeNode_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new TreeViewContextMenuItemFactory(null); + + // Assert + var message = Assert.Throws(test).Message; + StringAssert.StartsWith(Resources.ContextMenuItemFactory_Can_not_create_context_menu_items_without_tree_node, message); + StringAssert.EndsWith("treeNode", message); + } + + [Test] + public void Constructor_WithTreeNode_NewInstance() + { + // Call + var result = new TreeViewContextMenuItemFactory(mocks.StrictMock()); + + // Assert + Assert.IsInstanceOf(result); + } + + [Test] public void CreateExpandAllItem_Always_ItemWithExpandFunction() { // Setup @@ -29,10 +52,10 @@ mocks.ReplayAll(); - var factory = new TreeViewContextMenuItemFactory(); + var factory = new TreeViewContextMenuItemFactory(treeNodeMock); // Call - var item = factory.CreateExpandAllItem(treeNodeMock); + var item = factory.CreateExpandAllItem(); item.PerformClick(); // Assert @@ -54,10 +77,10 @@ mocks.ReplayAll(); - var factory = new TreeViewContextMenuItemFactory(); + var factory = new TreeViewContextMenuItemFactory(treeNodeMock); // Call - var item = factory.CreateCollapseAllItem(treeNodeMock); + var item = factory.CreateCollapseAllItem(); item.PerformClick(); // Assert Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/PlaceholderWithReadonlyNameNodePresenter.cs =================================================================== diff -u -ra80efa8773c3efec54ba44940945b03bc3f3ff7e -r97989f272e0b9aadccf3a444a90e61879616a0ab --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/PlaceholderWithReadonlyNameNodePresenter.cs (.../PlaceholderWithReadonlyNameNodePresenter.cs) (revision a80efa8773c3efec54ba44940945b03bc3f3ff7e) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/PlaceholderWithReadonlyNameNodePresenter.cs (.../PlaceholderWithReadonlyNameNodePresenter.cs) (revision 97989f272e0b9aadccf3a444a90e61879616a0ab) @@ -16,12 +16,10 @@ /// public class PlaceholderWithReadonlyNameNodePresenter : RingtoetsNodePresenterBase { - private IGuiCommandHandler guiHandler; - private IContextMenuBuilderProvider contextMenuBuilderProvider; + private readonly IContextMenuBuilderProvider contextMenuBuilderProvider; - public PlaceholderWithReadonlyNameNodePresenter(IContextMenuBuilderProvider contextMenuBuilderProvider, IGuiCommandHandler guiHandler = null) + public PlaceholderWithReadonlyNameNodePresenter(IContextMenuBuilderProvider contextMenuBuilderProvider) { - this.guiHandler = guiHandler; this.contextMenuBuilderProvider = contextMenuBuilderProvider; } Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs =================================================================== diff -u -ra80efa8773c3efec54ba44940945b03bc3f3ff7e -r97989f272e0b9aadccf3a444a90e61879616a0ab --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs (.../RingtoetsGuiPlugin.cs) (revision a80efa8773c3efec54ba44940945b03bc3f3ff7e) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs (.../RingtoetsGuiPlugin.cs) (revision 97989f272e0b9aadccf3a444a90e61879616a0ab) @@ -33,7 +33,7 @@ { yield return new AssessmentSectionBaseNodePresenter(); yield return new FailureMechanismNodePresenter((IContextMenuBuilderProvider)Gui); - yield return new PlaceholderWithReadonlyNameNodePresenter((IContextMenuBuilderProvider)Gui, Gui.CommandHandler); + yield return new PlaceholderWithReadonlyNameNodePresenter((IContextMenuBuilderProvider)Gui); yield return new CategoryTreeFolderNodePresenter(); } }