public void MoveTo(SwimlaneShapeBase dragObject, int endPosition, bool isUndoable = true)
        {
            bool shouldAdd = !this.Items.Contains(dragObject);
            bool addToDiagram = !this.Diagram.Items.Contains(dragObject);

            var diagramPosition = dragObject.Position;
            var startPosition = shouldAdd ? this.Items.Count : dragObject.ContainerPosition;
            endPosition = startPosition <= endPosition ? endPosition : endPosition + 1;

            var doAction = new Action<object>((o) =>
            {
                this.MoveContainer(startPosition, endPosition, dragObject);
                if (shouldAdd)
                    this.AddItem(dragObject);
                this.UpdateChildContainers();
            });

            if (isUndoable)
            {
                var command = new UndoableDelegateCommand("Move container",
                        doAction,
                         new Action<object>((o) =>
                         {
                             this.MoveContainer(endPosition, startPosition, dragObject);
                             if (shouldAdd)
                             {
                                 this.RemoveItem(dragObject);
                                 dragObject.Position = diagramPosition;
                                 if (addToDiagram)
                                     this.Diagram.Items.Remove(dragObject);
                             }
                             this.UpdateChildContainers();
                         }));
                this.Diagram.ServiceLocator.GetService<IUndoRedoService>().ExecuteCommand(command);
            }
            else
            {
                doAction.Invoke(null);
            }
        }
コード例 #2
0
        internal void ShowDragOverVisual(SwimlaneShapeBase shape)
        {
            if (shape.ParentMainContainer == null) return;

            var bounds = shape.Bounds;
            if (shape.ParentMainContainer.ChildrenPositioning == sys.Orientation.Vertical)
            {
                if (this.horizontalDragVisual == null) return;

                this.horizontalDragVisual.Visibility = System.Windows.Visibility.Visible;
                Canvas.SetLeft(this.horizontalDragVisual, bounds.X);
                Canvas.SetTop(this.horizontalDragVisual, bounds.Bottom);
                this.horizontalDragVisual.Width = bounds.Width;
            }
            else
            {
                if (this.verticalDragVisual == null) return;

                this.verticalDragVisual.Visibility = System.Windows.Visibility.Visible;
                Canvas.SetLeft(this.verticalDragVisual, bounds.Right);
                Canvas.SetTop(this.verticalDragVisual, bounds.Y);
                this.verticalDragVisual.Height = bounds.Height;
            }
        }
        private void MoveContainer(int startPosition, int endPosition, SwimlaneShapeBase dragObject)
        {
            if (startPosition <= endPosition)
            {
                for (int i = 0; i < this.OrderedChildren.Count; i++)
                {
                    var item = this.OrderedChildren[i];
                    if (item.ContainerPosition <= startPosition)
                        continue;
                    if (item.ContainerPosition > endPosition)
                        break;

                    item.ContainerPosition--;
                }

                dragObject.ContainerPosition = endPosition;
            }
            else
            {
                for (int i = 0; i < this.OrderedChildren.Count; i++)
                {
                    var item = this.OrderedChildren[i];
                    if (item.ContainerPosition < endPosition)
                        continue;
                    if (item.ContainerPosition >= startPosition)
                        break;

                    item.ContainerPosition++;
                }

                dragObject.ContainerPosition = endPosition;
            }
        }
        internal void SwapChildren(SwimlaneShapeBase first, SwimlaneShapeBase second)
        {
            int firstPosition = first.ContainerPosition;
            int secondPosition = second.ContainerPosition;
            var command = new UndoableDelegateCommand("Swap children",
                       new Action<object>((o) =>
                       {
                           first.ContainerPosition = secondPosition;
                           second.ContainerPosition = firstPosition;
                           this.UpdateChildContainers();
                       }),
                          new Action<object>((o) =>
                          {
                              first.ContainerPosition = firstPosition;
                              second.ContainerPosition = secondPosition;
                              this.UpdateChildContainers();
                          }));

            this.Diagram.ServiceLocator.GetService<IUndoRedoService>().ExecuteCommand(command);
        }