private void okButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(NewTableName) || string.IsNullOrWhiteSpace(NewColumnName) || projectionDims.SelectedItems.Count == 0)
            {
                return;
            }

            CsSchema schema = SourceTable.Top;

            // Initialize a list of selected dimensions (from the whole list of all greater dimensions
            List <CsColumn> projDims = new List <CsColumn>();

            foreach (var item in projectionDims.SelectedItems)
            {
                projDims.Add((CsColumn)item);
            }

            // Remove all existing greater dims (clean the target table before defining new structure)
            foreach (CsColumn dim in TargetTable.GreaterDims.ToList())
            {
                if (dim.IsSuper)
                {
                    continue;
                }
                dim.Remove();
            }

            // 1. Create a mapping object from the selected projection dimensions
            // 2. Create identity dimensions for the extracted set and their mapping to the projection dimensions
            Mapping mapping = new Mapping(SourceTable, TargetTable);

            foreach (CsColumn projDim in projDims)
            {
                CsTable  idSet = projDim.GreaterSet;
                CsColumn idDim = schema.CreateColumn(projDim.Name, TargetTable, idSet, true);
                idDim.Add();

                mapping.AddMatch(new PathMatch(new DimPath(projDim), new DimPath(idDim)));
            }
            Column.Definition.DefinitionType = ColumnDefinitionType.LINK;
            Column.Definition.Mapping        = mapping;
            Column.Definition.IsGenerating   = true;
            Column.Name = NewColumnName;

            TargetTable.Definition.DefinitionType = TableDefinitionType.PROJECTION;

            TargetTable.Name = NewTableName;

            // If new then add objects to the schema (or do it outside?)
            if (IsNew)
            {
                schema.AddTable(TargetTable, SourceTable.SuperSet, null);
                Column.Add();
            }

            this.DialogResult = true;
        }
        public ExtractTableBox(CsColumn column, CsColumn srcColumn)
        {
            Column = column;

            NewTableName = column.GreaterSet.Name;

            NewColumnName = column.Name;

            SourceTable = column.LesserSet;
            TargetTable = column.GreaterSet;

            if (TargetTable.SuperDim != null)
            {
                IsNew = false;
            }
            else
            {
                IsNew = true;
            }

            // Initialize a list of columns to be used for extraction
            ProjectionDims = new List <CsColumn>();
            ProjectionDims.AddRange(SourceTable.GreaterDims);
            ProjectionDims.Remove(SourceTable.SuperDim);
            if (!IsNew)
            {
                ProjectionDims.Remove(column);
            }

            InitializeComponent();

            if (srcColumn != null)
            {
                projectionDims.SelectedItem = srcColumn;
            }
            if (!IsNew && column.Definition.Mapping != null)
            {
                // Select columns that are used in the current definition (sources of the mapping)
                foreach (var match in column.Definition.Mapping.Matches)
                {
                    CsColumn col = match.TargetPath.FirstSegment;
                    projectionDims.SelectedItems.Add(col); // TODO: Does not work. Maybe use a kind of item.IsSelected=true
                }
            }

            RefreshAll();
        }