private void AddPipelineComponent(IPipelineComponent toRealize, DataFlowComponentVisualisation.Role role) { Exception exConstruction; //create the pipeline realization (might fail var value = _pipelineFactory.TryCreateComponent(toRealize, out exConstruction); if (role != DataFlowComponentVisualisation.Role.Source) { AddDividerIfReorderingAvailable(); } //create the visualization var component = new PipelineComponentVisualisation(toRealize, role, value, exConstruction, component_shouldAllowDrop); component.DragDrop += component_DragDrop; flpPipelineDiagram.Controls.Add(component);//add the component //try to initialize the realization (we do this after creating visualization so that when the events come in we can record where on UI the consumption events happen and also because later on it might be that initialization takes ages and we want to use a Thread) if (value != null) { try { if (!_useCase.IsDesignTime) { _useCase.GetContext().PreInitializeGeneric(new ThrowImmediatelyDataLoadEventListener(), value, _useCase.GetInitializationObjects().ToArray()); component.Check(); } component.CheckMandatoryProperties(); } catch (Exception exInit) { //initialization failed component.ExInitialization = exInit; } } component.AllowDrag = AllowReOrdering; if (AllowSelection) { component.AllowSelection = true; component.ComponentSelected += component_Selected; } //PipelineComponents can never be locked because they are user setup things component.IsLocked = false; }
private int GetOrderMakingSpaceIfNessesary(PipelineComponentVisualisation beingReorderedIfAny, DividerLineControl divider) { int newOrder = 0; int toReturn = 0; //for each component in the diagram for (int i = 0; i < flpPipelineDiagram.Controls.Count; i++) { var controlAtIndex = flpPipelineDiagram.Controls[i]; var pipelineComponentVisAtIndex = flpPipelineDiagram.Controls[i] as PipelineComponentVisualisation; //do not set the order on the thing being reordered! note that this is null in the case of newly dragged in controls so will never execute continue for new drop operations if (controlAtIndex == beingReorderedIfAny) { continue; } //found pipeline component if (pipelineComponentVisAtIndex != null) { //increment the order pipelineComponentVisAtIndex.PipelineComponent.Order = newOrder; pipelineComponentVisAtIndex.PipelineComponent.SaveToDatabase(); newOrder++; } //found the divider this is the order we are supposed to be inserting / reordering into if (controlAtIndex == divider) { //found divider so mark this as the insertion order point toReturn = newOrder; newOrder++; } } return(toReturn); }
private void HandleReorder(PipelineComponentVisualisation forReorder, DividerLineControl divider) { forReorder.PipelineComponent.Order = GetOrderMakingSpaceIfNessesary(forReorder, divider); forReorder.PipelineComponent.SaveToDatabase(); }