/// <summary> /// Determines whether the drop command can be executed /// </summary> /// <param name="param">The param.</param> /// <returns> /// <c>true</c> if this instance [can drop func] the specified param; otherwise, <c>false</c>. /// </returns> private bool CanDropFunc(object param) { bool canDrop = false; System.Windows.DragEventArgs args = param as System.Windows.DragEventArgs; TraceLab.UI.WPF.EventArgs.DropLinkEventArgs linkArgs = param as TraceLab.UI.WPF.EventArgs.DropLinkEventArgs; if (IsExperimentRunning == false) { var sourceNode = linkArgs.Source as ExperimentNode; var targetNode = linkArgs.Target as ExperimentNode; canDrop |= (linkArgs != null && IsValidLinkSource(sourceNode) && (linkArgs.ExistingEdge != null || IsValidLinkTarget(targetNode))); if (sourceNode != null && targetNode != null) { canDrop &= sourceNode.Owner == targetNode.Owner; } canDrop |= (args != null && args.Data.GetDataPresent("ComponentDefinition")); } else { if (args != null) { args.Effects = System.Windows.DragDropEffects.None; } } return(canDrop); }
/// <summary> /// Executes drop /// </summary> /// <param name="param">The param.</param> private void DropFunc(object param) { if (IsExperimentRunning == false) { TraceLab.UI.WPF.EventArgs.GraphDragEventArgs args = param as TraceLab.UI.WPF.EventArgs.GraphDragEventArgs; TraceLab.UI.WPF.EventArgs.DropLinkEventArgs linkArgs = param as TraceLab.UI.WPF.EventArgs.DropLinkEventArgs; if (args != null) { MetadataDefinition metadataDefinition = args.DragArguments.Data.GetData("ComponentDefinition") as MetadataDefinition; if (metadataDefinition != null) { System.Windows.Point pos = args.Position; AddComponentFromDefinition(metadataDefinition, pos.X, pos.Y); } } else if (linkArgs != null) { ExperimentNodeConnection edge = (ExperimentNodeConnection)linkArgs.ExistingEdge; // If we're NOT removing an edge, OR the new edge will be different than the old edge. if (linkArgs.ExistingEdge == null || (edge.Source == linkArgs.Source && edge.Target != linkArgs.Target)) { if (linkArgs.ExistingEdge != null) { RemoveConnection(edge); } if (linkArgs.Source != null && linkArgs.Target != null) { AddConnection((ExperimentNode)linkArgs.Source, (ExperimentNode)linkArgs.Target); } } } } }