Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Plugin/DuneErosionPlugin.cs =================================================================== diff -u -r2c595d68a6fb2abeebed64c607fa2a3ab806f483 -r6af1173cfba5ef4f9fdf1db74c8feb892b87629f --- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Plugin/DuneErosionPlugin.cs (.../DuneErosionPlugin.cs) (revision 2c595d68a6fb2abeebed64c607fa2a3ab806f483) +++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Plugin/DuneErosionPlugin.cs (.../DuneErosionPlugin.cs) (revision 6af1173cfba5ef4f9fdf1db74c8feb892b87629f) @@ -19,11 +19,14 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Collections; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Windows.Forms; using Core.Common.Controls.TreeView; +using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Plugin; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Forms.PresentationObjects; @@ -33,6 +36,7 @@ using Ringtoets.DuneErosion.Forms.PropertyClasses; using Ringtoets.DuneErosion.Forms.Views; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; +using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; namespace Ringtoets.DuneErosion.Plugin { @@ -69,6 +73,16 @@ .AddOpenItem() .Build() }; + + yield return new TreeNodeInfo + { + Text = context => RingtoetsCommonDataResources.HydraulicBoundaryConditions_DisplayName, + Image = context => RingtoetsCommonFormsResources.GenericInputOutputIcon, + ForeColor = context => context.WrappedData.Count > 0 ? + Color.FromKnownColor(KnownColor.ControlText) : + Color.FromKnownColor(KnownColor.GrayText), + ContextMenuStrip = HydraulicBoundaryLocationsContextMenuStrip + }; } public override IEnumerable GetViewInfos() @@ -104,6 +118,7 @@ return new object[] { new CategoryTreeFolder(RingtoetsCommonFormsResources.FailureMechanism_Inputs_DisplayName, GetInputs(wrappedData, failureMechanismContext.Parent), TreeFolderCategory.Input), + new HydraulicBoundaryLocationsContext(wrappedData.HydraulicBoundaryLocations, wrappedData, failureMechanismContext.Parent), new CategoryTreeFolder(RingtoetsCommonFormsResources.FailureMechanism_Outputs_DisplayName, GetOutputs(wrappedData), TreeFolderCategory.Output) }; } @@ -174,8 +189,31 @@ #endregion + #region HydraulicBoundaryLocationsContext TreeNodeInfo + + private ContextMenuStrip HydraulicBoundaryLocationsContextMenuStrip(HydraulicBoundaryLocationsContext context, object parent, TreeViewControl treeViewControl) + { + var calculateAllItem = new StrictContextMenuItem(RingtoetsCommonFormsResources.Calculate_all, + RingtoetsCommonFormsResources.Calculate_all_ToolTip, + RingtoetsCommonFormsResources.CalculateAllIcon, + (sender, args) => { }) + { + Enabled = false + }; + + return Gui.Get(context, treeViewControl) + .AddExportItem() + .AddSeparator() + .AddCustomItem(calculateAllItem) + .AddSeparator() + .AddPropertiesItem() + .Build(); + } + #endregion + #endregion + #region ViewInfo #region DuneErosionFailureMechanismResultView ViewInfo Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/DuneErosionPluginTest.cs =================================================================== diff -u -r2c595d68a6fb2abeebed64c607fa2a3ab806f483 -r6af1173cfba5ef4f9fdf1db74c8feb892b87629f --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/DuneErosionPluginTest.cs (.../DuneErosionPluginTest.cs) (revision 2c595d68a6fb2abeebed64c607fa2a3ab806f483) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/DuneErosionPluginTest.cs (.../DuneErosionPluginTest.cs) (revision 6af1173cfba5ef4f9fdf1db74c8feb892b87629f) @@ -57,9 +57,10 @@ TreeNodeInfo[] treeNodeInfos = plugin.GetTreeNodeInfos().ToArray(); // Assert - Assert.AreEqual(2, treeNodeInfos.Length); + Assert.AreEqual(3, treeNodeInfos.Length); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(DuneErosionFailureMechanismContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(FailureMechanismSectionResultContext))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(HydraulicBoundaryLocationsContext))); } } Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/Ringtoets.DuneErosion.Plugin.Test.csproj =================================================================== diff -u -r23d1e296e2da4364fbfe346e68d582dfcf966bb0 -r6af1173cfba5ef4f9fdf1db74c8feb892b87629f --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/Ringtoets.DuneErosion.Plugin.Test.csproj (.../Ringtoets.DuneErosion.Plugin.Test.csproj) (revision 23d1e296e2da4364fbfe346e68d582dfcf966bb0) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/Ringtoets.DuneErosion.Plugin.Test.csproj (.../Ringtoets.DuneErosion.Plugin.Test.csproj) (revision 6af1173cfba5ef4f9fdf1db74c8feb892b87629f) @@ -60,6 +60,7 @@ + @@ -106,6 +107,10 @@ {4d840673-3812-4338-a352-84854e32b8a0} Ringtoets.Common.Forms + + {4843D6E5-066F-4795-94F5-1D53932DD03C} + Ringtoets.Common.Data.TestUtil + {D1068432-C172-4AA6-847B-D9DEB4C6DE26} Ringtoets.DuneErosion.Data Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/TreeNodeInfos/DuneErosionFailureMechanismContextTreeNodeInfoTest.cs =================================================================== diff -u -r2d006ceaaef282af15090fe5505ffeca58a291e0 -r6af1173cfba5ef4f9fdf1db74c8feb892b87629f --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/TreeNodeInfos/DuneErosionFailureMechanismContextTreeNodeInfoTest.cs (.../DuneErosionFailureMechanismContextTreeNodeInfoTest.cs) (revision 2d006ceaaef282af15090fe5505ffeca58a291e0) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/TreeNodeInfos/DuneErosionFailureMechanismContextTreeNodeInfoTest.cs (.../DuneErosionFailureMechanismContextTreeNodeInfoTest.cs) (revision 6af1173cfba5ef4f9fdf1db74c8feb892b87629f) @@ -106,7 +106,7 @@ var children = info.ChildNodeObjects(failureMechanismContext).ToArray(); // Assert - Assert.AreEqual(2, children.Length); + Assert.AreEqual(3, children.Length); var inputsFolder = (CategoryTreeFolder)children[0]; Assert.AreEqual("Invoer", inputsFolder.Name); @@ -120,7 +120,12 @@ var inputComment = (Comment)inputsFolder.Contents[1]; Assert.AreSame(failureMechanism.InputComments, inputComment); - var outputsFolder = (CategoryTreeFolder)children[1]; + var hydraulicBoundaryLocationsContext = (HydraulicBoundaryLocationsContext) children[1]; + Assert.AreSame(failureMechanism.HydraulicBoundaryLocations, hydraulicBoundaryLocationsContext.WrappedData); + Assert.AreSame(failureMechanism, hydraulicBoundaryLocationsContext.FailureMechanism); + Assert.AreSame(assessmentSectionStub, hydraulicBoundaryLocationsContext.AssessmentSection); + + var outputsFolder = (CategoryTreeFolder)children[2]; Assert.AreEqual("Oordeel", outputsFolder.Name); Assert.AreEqual(TreeFolderCategory.Output, outputsFolder.Category); Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/TreeNodeInfos/HydraulicBoundaryLocationsContextTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/TreeNodeInfos/HydraulicBoundaryLocationsContextTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/TreeNodeInfos/HydraulicBoundaryLocationsContextTreeNodeInfoTest.cs (revision 6af1173cfba5ef4f9fdf1db74c8feb892b87629f) @@ -0,0 +1,226 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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. +// +// This program 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. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.Drawing; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.TestUtil.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Forms.PresentationObjects; +using Ringtoets.DuneErosion.Plugin; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.DunErosion.Plugin.Test.TreeNodeInfos +{ + [TestFixture] + public class HydraulicBoundaryLocationsContextTreeNodeInfoTest + { + private MockRepository mocks; + private DuneErosionPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new DuneErosionPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(HydraulicBoundaryLocationsContext)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + + mocks.VerifyAll(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Setup + mocks.ReplayAll(); + + // Assert + Assert.AreEqual(typeof(HydraulicBoundaryLocationsContext), info.TagType); + Assert.IsNotNull(info.Text); + Assert.IsNotNull(info.ForeColor); + Assert.IsNotNull(info.Image); + Assert.IsNotNull(info.ContextMenuStrip); + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.EnsureVisibleOnCreate); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsName() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var mechanism = new DuneErosionFailureMechanism(); + var context = new HydraulicBoundaryLocationsContext(mechanism.HydraulicBoundaryLocations, mechanism, assessmentSection); + + // Call + var text = info.Text(context); + + // Assert + Assert.AreEqual("Hydraulische randvoorwaarden", text); + } + + [Test] + public void Image_Always_ReturnsGenericInputOutputIcon() + { + // Setup + mocks.ReplayAll(); + + // Call + var image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, image); + } + + [Test] + public void ForeColor_NoLocations_ReturnGrayText() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var mechanism = new DuneErosionFailureMechanism(); + var context = new HydraulicBoundaryLocationsContext(mechanism.HydraulicBoundaryLocations, mechanism, assessmentSection); + + // Call + Color textColor = info.ForeColor(context); + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), textColor); + } + + [Test] + public void ForeColor_WithLocations_ReturnControlText() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var mechanism = new DuneErosionFailureMechanism(); + mechanism.HydraulicBoundaryLocations.Add(new TestHydraulicBoundaryLocation()); + var context = new HydraulicBoundaryLocationsContext(mechanism.HydraulicBoundaryLocations, mechanism, assessmentSection); + + // Call + Color textColor = info.ForeColor(context); + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), textColor); + } + + [Test] + public void ContextMenuStrip_Always_CallsBuilder() + { + // Setup + using (var treeViewControl = new TreeViewControl()) + { + var assessmentSectionMock = mocks.StrictMock(); + var failureMechanism = new DuneErosionFailureMechanism(); + var context = new HydraulicBoundaryLocationsContext(failureMechanism.HydraulicBoundaryLocations, failureMechanism, assessmentSectionMock); + + var menuBuilder = mocks.StrictMock(); + + using (mocks.Ordered()) + { + menuBuilder.Expect(mb => mb.AddExportItem()).Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilder); + menuBuilder.Expect(mb => mb.Build()).Return(null); + } + + var gui = mocks.StrictMock(); + gui.Expect(cmp => cmp.Get(context, treeViewControl)).Return(menuBuilder); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(context, null, treeViewControl); + } + + // Assert + // Done in tearDown + } + + [Test] + public void ContextMenuStrip_Always_AddCustomItem() + { + // Setup + using (var treeViewControl = new TreeViewControl()) + { + var assessmentSectionMock = mocks.StrictMock(); + var failureMechanism = new DuneErosionFailureMechanism(); + var context = new HydraulicBoundaryLocationsContext(failureMechanism.HydraulicBoundaryLocations, failureMechanism, assessmentSectionMock); + + var builder = new CustomItemsOnlyContextMenuBuilder(); + + var gui = mocks.StrictMock(); + gui.Expect(cmp => cmp.Get(context, treeViewControl)).Return(builder); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(context, null, treeViewControl)) + { + // Assert + Assert.AreEqual(5, menu.Items.Count); + + TestHelper.AssertContextMenuStripContainsItem(menu, 2, + "Alles be&rekenen", + "Voer alle berekeningen binnen dit toetsspoor uit.", + RingtoetsCommonFormsResources.CalculateAllIcon, + false); + } + } + } + } +} \ No newline at end of file