Index: Ringtoets/Common/src/Ringtoets.Common.Data/Calculation/ICalculation.cs
===================================================================
diff -u -rfff12e249602fb700b2854c14a3b7cdd0b73c023 -r6b43c39e0f54d1054729aaed5aa6dc19149ef72a
--- Ringtoets/Common/src/Ringtoets.Common.Data/Calculation/ICalculation.cs (.../ICalculation.cs) (revision fff12e249602fb700b2854c14a3b7cdd0b73c023)
+++ Ringtoets/Common/src/Ringtoets.Common.Data/Calculation/ICalculation.cs (.../ICalculation.cs) (revision 6b43c39e0f54d1054729aaed5aa6dc19149ef72a)
@@ -29,6 +29,11 @@
public interface ICalculation : ICalculationBase, ICommentable
{
///
+ /// Gets or sets the name of this calculation item.
+ ///
+ new string Name { get; set; }
+
+ ///
/// Gets a value indicating whether or not this calculation item contains calculation output.
///
bool HasOutput { get; }
Index: Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/CalculationTreeNodeInfoFactory.cs
===================================================================
diff -u -rd0553e74a8d5ff6534acf03faf4a8801c28bf7c0 -r6b43c39e0f54d1054729aaed5aa6dc19149ef72a
--- Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/CalculationTreeNodeInfoFactory.cs (.../CalculationTreeNodeInfoFactory.cs) (revision d0553e74a8d5ff6534acf03faf4a8801c28bf7c0)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/CalculationTreeNodeInfoFactory.cs (.../CalculationTreeNodeInfoFactory.cs) (revision 6b43c39e0f54d1054729aaed5aa6dc19149ef72a)
@@ -81,12 +81,15 @@
///
/// The icon of the .
/// The function for obtaining the child node objects.
+ /// The function for obtaining the context menu strip.
+ /// The action to perform on removing a node.
/// The type of calculation context to create a object for.
/// A object.
public static TreeNodeInfo CreateCalculationContextTreeNodeInfo(
Bitmap icon,
Func childeNodeObjects,
- Func contextMenuStrip)
+ Func contextMenuStrip,
+ Action onNodeRemoved)
where TCalculationContext : ICalculationContext
{
return new TreeNodeInfo
@@ -95,7 +98,16 @@
Image = context => icon,
EnsureVisibleOnCreate = (context, parent) => true,
ChildNodeObjects = childeNodeObjects,
- ContextMenuStrip = contextMenuStrip
+ ContextMenuStrip = contextMenuStrip,
+ CanRename = (context, parent) => true,
+ OnNodeRenamed = (context, newName) =>
+ {
+ context.WrappedData.Name = newName;
+ context.WrappedData.NotifyObservers();
+ },
+ CanRemove = (context, parentData) => CalculationContextCanRemove(context, parentData),
+ OnNodeRemoved = onNodeRemoved,
+ CanDrag = (context, parentData) => true
};
}
@@ -340,5 +352,15 @@
# endregion
# endregion
+
+ #region Helper methods for CreateCalculationContextTreeNodeInfo
+
+ private static bool CalculationContextCanRemove(ICalculationContext calculationContext, object parentNodeData)
+ {
+ var calculationGroupContext = parentNodeData as ICalculationContext;
+ return calculationGroupContext != null && calculationGroupContext.WrappedData.Children.Contains(calculationContext.WrappedData);
+ }
+
+ #endregion
}
}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/CalculationTreeNodeInfoFactoryTest.cs
===================================================================
diff -u -rd0553e74a8d5ff6534acf03faf4a8801c28bf7c0 -r6b43c39e0f54d1054729aaed5aa6dc19149ef72a
--- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/CalculationTreeNodeInfoFactoryTest.cs (.../CalculationTreeNodeInfoFactoryTest.cs) (revision d0553e74a8d5ff6534acf03faf4a8801c28bf7c0)
+++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/CalculationTreeNodeInfoFactoryTest.cs (.../CalculationTreeNodeInfoFactoryTest.cs) (revision 6b43c39e0f54d1054729aaed5aa6dc19149ef72a)
@@ -985,15 +985,17 @@
var icon = RingtoetsFormsResources.CalculateIcon;
Func childNodeObjects = context => new object[0];
Func contextMenuStrip = (context, parent, treeViewControl) => new ContextMenuStrip();
+ Action onNodeRemoved = (context, parent) => { };
// Call
- var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(icon, childNodeObjects, contextMenuStrip);
+ var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(icon, childNodeObjects, contextMenuStrip, onNodeRemoved);
// Assert
Assert.AreEqual(typeof(TestCalculationContext), treeNodeInfo.TagType);
TestHelper.AssertImagesAreEqual(icon, treeNodeInfo.Image(null));
Assert.AreSame(childNodeObjects, treeNodeInfo.ChildNodeObjects);
Assert.AreSame(contextMenuStrip, treeNodeInfo.ContextMenuStrip);
+ Assert.AreSame(onNodeRemoved, treeNodeInfo.OnNodeRemoved);
Assert.IsNull(treeNodeInfo.ForeColor);
Assert.IsNull(treeNodeInfo.CanCheck);
Assert.IsNull(treeNodeInfo.IsChecked);
@@ -1016,7 +1018,7 @@
};
var context = new TestCalculationContext(calculation, failureMechanismMock);
- var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null);
+ var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null, null);
// Call
var text = treeNodeInfo.Text(context);
@@ -1030,7 +1032,7 @@
public void EnsureVisibleOnCreateOfCalculationContextTreeNodeInfo_Always_ReturnsTrue()
{
// Setup
- var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null);
+ var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null, null);
// Call
var result = treeNodeInfo.EnsureVisibleOnCreate(null, null);
@@ -1039,6 +1041,133 @@
Assert.IsTrue(result);
}
+ [Test]
+ public void CanRenameCalculationContextTreeNodeInfo_Always_ReturnTrue()
+ {
+ // Setup
+ var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null, null);
+
+ // Call
+ var renameAllowed = treeNodeInfo.CanRename(null, null);
+
+ // Assert
+ Assert.IsTrue(renameAllowed);
+ }
+
+ [Test]
+ public void OnNodeRenamedOfCalculationContextTreeNodeInfo_Always_SetNewNameToPipingCalculationScenarioAndNotifyObserver()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var observerMock = mocks.StrictMock();
+ observerMock.Expect(o => o.UpdateObserver());
+
+ var failureMechanismMock = mocks.StrictMock();
+ mocks.ReplayAll();
+
+ var calculation = new TestCalculation
+ {
+ Name = ""
+ };
+
+ var context = new TestCalculationContext(calculation, failureMechanismMock);
+ var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null, null);
+
+ context.WrappedData.Attach(observerMock);
+
+ // Call
+ const string newName = "";
+ treeNodeInfo.OnNodeRenamed(context, newName);
+
+ // Assert
+ Assert.AreEqual(newName, calculation.Name);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ [TestCase(true)]
+ [TestCase(false)]
+ public void CanRemoveCalculationContextTreeNodeInfo_ParentIsCalculationGroupWithCalculation_ReturnTrue(bool groupNameEditable)
+ {
+ // Setup
+ var calculationToBeRemoved = new TestCalculation();
+ var group = new CalculationGroup("", groupNameEditable);
+ group.Children.Add(calculationToBeRemoved);
+
+ var mocks = new MockRepository();
+ var failureMechanismMock = mocks.StrictMock();
+ mocks.ReplayAll();
+
+ var context = new TestCalculationContext(calculationToBeRemoved, failureMechanismMock);
+ var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null, null);
+
+ var groupContext = new TestCalculationGroupContext(group, failureMechanismMock);
+
+ // Call
+ bool removalAllowed = treeNodeInfo.CanRemove(context, groupContext);
+
+ // Assert
+ Assert.IsTrue(removalAllowed);
+ }
+
+ [Test]
+ [TestCase(true)]
+ [TestCase(false)]
+ public void CanRemoveCalculationContextTreeNodeInfo_ParentIsCalculationGroupWithoutCalculation_ReturnFalse(bool groupNameEditable)
+ {
+ // Setup
+ var calculationToBeRemoved = new TestCalculation();
+ var group = new CalculationGroup("", groupNameEditable);
+
+ var mocks = new MockRepository();
+ var failureMechanismMock = mocks.StrictMock();
+ mocks.ReplayAll();
+
+ var context = new TestCalculationContext(calculationToBeRemoved, failureMechanismMock);
+ var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null, null);
+
+ var groupContext = new TestCalculationGroupContext(group, failureMechanismMock);
+
+ // Call
+ bool removalAllowed = treeNodeInfo.CanRemove(context, groupContext);
+
+ // Assert
+ Assert.IsFalse(removalAllowed);
+ }
+
+ [Test]
+ public void CanRemoveCalculationContextTreeNodeInfo_EverythingElse_ReturnFalse()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var dataMock = mocks.StrictMock