protected function insertColumn(
        SwatTableViewColumn $column,
        SwatTableViewColumn $reference_column = null,
        $after = true
    ) {
        $this->validateColumn($column);

        if ($reference_column !== null) {
            $key = array_search($reference_column, $this->columns, true);

            if ($key === false) {
                throw new SwatWidgetNotFoundException(
                    'The reference column ' .
                        'could not be found in this table-view.'
                );
            }

            if ($after) {
                // insert after reference column
                array_splice($this->columns, $key, 1, array(
                    $reference_column,
                    $column
                ));
            } else {
                // insert before reference column
                array_splice($this->columns, $key, 1, array(
                    $column,
                    $reference_column
                ));
            }
        } else {
            if ($after) {
                // append to array
                $this->columns[] = $column;
            } else {
                // prepend to array
                array_unshift($this->columns, $column);
            }
        }

        if ($column->id !== null) {
            $this->columns_by_id[$column->id] = $column;
        }

        $column->view = $this; // deprecated reference
        $column->parent = $this;
    }