Example #1
0
        public async void AddColumn(bool addRight, int index = -1, IDominoShape colorReference = null)
        {
            var selected = GetSelectedDominoes();

            try
            {
                if (selected.Count > 0 || index != -1)
                {
                    int selDomino = selected.Count > 0 ? selected.First() : index;
                    int color     = (colorReference ?? dominoTransfer[selDomino]).Color;
                    if (CurrentProject is IRowColumnAddableDeletable)
                    {
                        AddColumns addRows = new AddColumns((CurrentProject as IRowColumnAddableDeletable), selDomino, 1, color, addRight);
                        ClearCanvas();
                        ExecuteOperation(addRows);

                        RecreateCanvasViewModel();
                        SelectionTool.Select(addRows.added_indizes, true);
                        UpdateUIElements();
                        DisplaySettingsTool.SliceImage();
                    }
                    else
                    {
                        await Errorhandler.RaiseMessage(_("Adding columns is not supported in this project."), _("Add Row"), Errorhandler.MessageType.Warning);
                    }
                }
            }
            catch (InvalidOperationException ex)
            {
                await Errorhandler.RaiseMessage(ex.Message, _("Error"), Errorhandler.MessageType.Error);
            }
        }
        private void AddColumn(bool addRight)
        {
            try
            {
                if (selectedDominoes.Count > 0)
                {
                    int selDomino = selectedDominoes.First();
                    if (CurrentProject is IRowColumnAddableDeletable)
                    {
                        AddColumns addRows = new AddColumns((CurrentProject as IRowColumnAddableDeletable), selDomino, 1, dominoTransfer[selDomino].color, addRight);
                        ClearCanvas();
                        ExecuteOperation(addRows);

                        DisplaySettingsTool.ResetCanvas();
                        SelectionTool.Select(addRows.added_indizes, true);
                        UpdateUIElements();
                    }
                    else
                    {
                        Errorhandler.RaiseMessage("Could not add a row in this project.", "Add Row", Errorhandler.MessageType.Warning);
                    }
                }
            }
            catch (InvalidOperationException ex)
            {
                Errorhandler.RaiseMessage(ex.Message, "Error", Errorhandler.MessageType.Error);
            }
        }
 protected override void VisitAddColumns(AddColumns item)
 {
     this.CurrentAddColumns = item;
     if (item.Columns != null && item.Columns.Any())
     {
         if (item.Columns.Count() > 1)
         {
             throw new NotSupportedException("Only a single column can be added at a time.");
         }
         IVisitableBuilder first = item.Columns.First();
         first.Accept(this);
     }
 }
        public static void InsertColumnStructureTest(StructureParameters s)
        {
            AddColumns addColumns = new AddColumns(s, 40, 2, 1, true);

            addColumns.Apply();
            AddColumns addColumns2 = new AddColumns(s, 1500, 2, 5, false);

            addColumns2.Apply();
            s.Generate().GenerateImage().Save("tests/StructureFilterTests/nachColumnEinfügen.png");
            SaveFieldPlan(s, "tests/StructureFilterTests/FeldplanNachColumnEinfuegen.html");
            addColumns2.Undo();
            addColumns.Undo();
            s.Generate().GenerateImage().Save("tests/StructureFilterTests/nachColumnEinfügenUndo.png");
        }
        public static void InsertColumnFieldTest(FieldParameters fp)
        {
            AddColumns addCol = new AddColumns(fp, 1, 5, 5, true);

            addCol.Apply();
            AddColumns addCol2 = new AddColumns(fp, 0, 5, 5, false);

            addCol2.Apply();
            fp.Generate().GenerateImage().Save("tests/FilterTests/nachColumnEinfügen.png");
            SaveFieldPlan(fp, "tests/FilterTests/FeldplanNachColumnEinfuegen.html");
            addCol2.Undo();
            addCol.Undo();
            fp.Generate().GenerateImage().Save("tests/FilterTests/nachColumnEinfügenUndo.png");
        }
        protected override MergeResult DoMerge(Operation operation)
        {
            if (base.DoMerge(operation) == MergeResult.Stop)
            {
                return(MergeResult.Stop);
            }

            // only table object operations that operate on this table are allowed.
            if (operation is TableObjectOperation otherAsTableObjectOp &&
                !ObjectName.Equals(otherAsTableObjectOp.TableObjectName, StringComparison.InvariantCultureIgnoreCase))
            {
                return(MergeResult.Stop);
            }

            switch (operation)
            {
            case AddDefaultConstraintOperation otherAsAddDefaultConstraintOp when !otherAsAddDefaultConstraintOp.WithValues:
            {
                var column = FindColumn(otherAsAddDefaultConstraintOp.ColumnName);
                if (column != null)
                {
                    column.DefaultExpression               = otherAsAddDefaultConstraintOp.Expression;
                    column.DefaultConstraintName           = otherAsAddDefaultConstraintOp.Name;
                    otherAsAddDefaultConstraintOp.Disabled = true;
                    return(MergeResult.Continue);
                }

                break;
            }

            case AddRowGuidColOperation otherAsAddRowGuidColOp:
            {
                var column = FindColumn(otherAsAddRowGuidColOp.ColumnName);
                if (column != null && column.DataType == DataType.UniqueIdentifier)
                {
                    column.RowGuidCol = true;
                    otherAsAddRowGuidColOp.Disabled = true;
                    return(MergeResult.Continue);
                }

                break;
            }

            case RemoveDefaultConstraintOperation otherAsRemoveDefaultConstraintOp:
            {
                var column = FindColumn(otherAsRemoveDefaultConstraintOp.ColumnName);
                if (column != null)
                {
                    column.DefaultExpression = null;
                    otherAsRemoveDefaultConstraintOp.Disabled = true;
                    return(MergeResult.Continue);
                }

                break;
            }

            case RemoveRowGuidColOperation otherAsRemoveRowGuidColOp:
            {
                var column = FindColumn(otherAsRemoveRowGuidColOp.ColumnName);
                if (column != null && column.DataType == DataType.UniqueIdentifier)
                {
                    column.RowGuidCol = false;
                    otherAsRemoveRowGuidColOp.Disabled = true;
                    return(MergeResult.Continue);
                }

                break;
            }

            case RenameColumnOperation otherAsRenameColumnOp:
            {
                var column = FindColumn(otherAsRenameColumnOp.Name);
                if (column != null)
                {
                    column.Name = otherAsRenameColumnOp.NewName;
                    otherAsRenameColumnOp.Disabled = true;
                    return(MergeResult.Continue);
                }

                break;
            }

            case RenameObjectOperation otherAsRenameObjectOp:
            {
                var column = AddColumns
                             .Concat(UpdateColumns)
                             .FirstOrDefault(c => null != c.DefaultConstraintName &&
                                             c.DefaultConstraintName.Equals(otherAsRenameObjectOp.Name, StringComparison.InvariantCultureIgnoreCase));

                if (null != column)
                {
                    column.DefaultConstraintName   = otherAsRenameObjectOp.NewName;
                    otherAsRenameObjectOp.Disabled = true;
                    return(MergeResult.Stop);
                }

                break;
            }

            case UpdateTableOperation otherAsUpdateTableOp:
            {
                if (otherAsUpdateTableOp.Disabled)
                {
                    return(MergeResult.Stop);
                }

                AddColumns.AddRange(otherAsUpdateTableOp.AddColumns);

                foreach (var addColumn in otherAsUpdateTableOp.AddColumns)
                {
                    for (var thisIdx = RemoveColumns.Count - 1; thisIdx >= 0; --thisIdx)
                    {
                        if (addColumn.Name.Equals(RemoveColumns[thisIdx],
                                                  StringComparison.InvariantCultureIgnoreCase))
                        {
                            RemoveColumns.RemoveAt(thisIdx);
                            break;
                        }
                    }
                }

                foreach (var otherColumn in otherAsUpdateTableOp.UpdateColumns)
                {
                    var found = false;
                    for (var thisIdx = 0; thisIdx < AddColumns.Count; ++thisIdx)
                    {
                        var thisColumn = AddColumns[thisIdx];
                        if (thisColumn.Name.Equals(otherColumn.Name, StringComparison.InvariantCultureIgnoreCase))
                        {
                            found = true;
                            AddColumns[thisIdx] = otherColumn;
                            break;
                        }
                    }

                    for (var thisIdx = 0; thisIdx < UpdateColumns.Count; ++thisIdx)
                    {
                        var thisColumn = UpdateColumns[thisIdx];
                        if (thisColumn.Name.Equals(otherColumn.Name, StringComparison.InvariantCultureIgnoreCase))
                        {
                            found = true;
                            UpdateColumns[thisIdx] = otherColumn;
                            break;
                        }
                    }

                    if (!found)
                    {
                        UpdateColumns.Add(otherColumn);
                    }
                }

                foreach (var columnToRemove in otherAsUpdateTableOp.RemoveColumns)
                {
                    var found = false;
                    for (var thisIdx = AddColumns.Count - 1; thisIdx >= 0; --thisIdx)
                    {
                        var thisColumn = AddColumns[thisIdx];
                        if (thisColumn.Name.Equals(columnToRemove, StringComparison.InvariantCultureIgnoreCase))
                        {
                            found = true;
                            AddColumns.RemoveAt(thisIdx);
                            break;
                        }
                    }

                    for (var thisIdx = UpdateColumns.Count - 1; thisIdx >= 0; --thisIdx)
                    {
                        var thisColumn = UpdateColumns[thisIdx];
                        if (thisColumn.Name.Equals(columnToRemove, StringComparison.InvariantCultureIgnoreCase))
                        {
                            found = true;
                            UpdateColumns.RemoveAt(thisIdx);
                            break;
                        }
                    }

                    if (!found)
                    {
                        RemoveColumns.Add(columnToRemove);
                    }
                }

                otherAsUpdateTableOp.Disabled = true;

                if (AddColumns.Count == 0 && UpdateColumns.Count == 0 && RemoveColumns.Count == 0)
                {
                    Disabled = true;
                    return(MergeResult.Stop);
                }

                return(MergeResult.Continue);
            }
            }

            return(MergeResult.Continue);
        }
 private Column FindColumn(string name)
 {
     return(AddColumns
            .Concat(UpdateColumns)
            .FirstOrDefault(c => c.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)));
 }