private List <DcTable> GetSchemaTypes() // The user chooses the desired column type from this list
        {
            var targetTypes = new List <DcTable>();

            if (SelectedTargetSchema == null)
            {
                ;
            }
            if (SelectedTargetSchema is SchemaCsv)
            {
                targetTypes.Add(SelectedTargetSchema.GetPrimitive("String"));
            }
            else
            {
                targetTypes.Add(SelectedTargetSchema.GetPrimitive("Integer"));
                targetTypes.Add(SelectedTargetSchema.GetPrimitive("Double"));
                targetTypes.Add(SelectedTargetSchema.GetPrimitive("String"));
            }

            return(targetTypes);
        }
        private void OkCommand_Executed(object state)
        {
            Mapping mapping;

            if (IsNew)
            {
                mapping = new Mapping(Column.Input, Column.Output);
            }
            else
            {
                mapping = Column.Definition.Mapping;
            }

            // For each entry decide what to do with the corresponding 1. match in the mapping 2. target column, depending on the comparision with the existing 1. match, target column
            foreach (var entry in Entries)
            {
                DcColumn sourceColumn = entry.Source;

                PathMatch match = mapping.GetMatchForSource(new DimPath(sourceColumn));

                DcColumn targetColumn;

                if (entry.IsMatched && match == null) // Newly added. Creation
                {
                    DcTable targetType       = entry.TargetType;
                    string  targetColumnName = sourceColumn.Name;

                    // Check if a column with this name already exists
                    targetColumn = Column.Output.GetColumn(targetColumnName);
                    if (targetColumn != null)
                    {
                        targetColumn.Output = targetType; // Alternatively, we can remove it and create a new column below
                    }

                    if (targetColumn == null) // Could not reuse an existing column
                    {
                        targetColumn = SelectedTargetSchema.CreateColumn(targetColumnName, Column.Output, targetType, entry.IsKey);
                        targetColumn.Add();
                    }

                    mapping.AddMatch(new PathMatch(new DimPath(sourceColumn), new DimPath(targetColumn)));
                }
                else if (!entry.IsMatched && match != null) // Newly removed. Deletion.
                {
                    targetColumn = match.TargetPath.FirstSegment;
                    targetColumn.Remove();

                    mapping.RemoveMatch(match.SourcePath, match.TargetPath);
                }
                else if (entry.IsMatched) // Remains included. Update properties (name, key, type etc.)
                {
                    targetColumn = match.TargetPath.FirstSegment;
                    if (targetColumn.Output != entry.TargetType) // Type has been changed
                    {
                        targetColumn.Remove();
                        targetColumn.Output = entry.TargetType;
                        targetColumn.Add();
                    }
                }
                else // Remains excluded
                {
                }
            }

            Column.Name = ColumnName;
            //Column.Output.Name = SelectedTargetTable.Name;

            if (IsNew)
            {
                // Target table could contain original columns from previous uses (loaded from csv file or added manually). Now they are not needed.
                foreach (DcColumn targetColumn in Column.Output.Columns)
                {
                    PathMatch match = mapping.GetMatchForTarget(new DimPath(targetColumn));
                    if (match != null)
                    {
                        continue;
                    }
                    if (targetColumn.Definition.DefinitionType != DcColumnDefinitionType.FREE)
                    {
                        continue;
                    }
                    if (targetColumn.Definition.DefinitionType != DcColumnDefinitionType.ANY)
                    {
                        continue;
                    }

                    targetColumn.Remove();
                }

                // Set parameters of the new column
                Column.Definition.DefinitionType = DcColumnDefinitionType.LINK;
                Column.Definition.Mapping        = mapping;
                Column.Definition.IsAppendData   = true;

                Column.Output.Definition.DefinitionType = DcTableDefinitionType.PROJECTION;
            }

            this.DialogResult = true;
        }