<commit_before>/*
 * DBeaver - Universal Database Manager
 * Copyright (C) 2010-2019 <NAME> (<EMAIL>)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jkiss.dbeaver.ui.controls.resultset;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.model.DBValueFormatting;
import org.jkiss.dbeaver.model.virtual.DBVEntity;
import org.jkiss.dbeaver.model.virtual.DBVEntityAttribute;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.editors.object.struct.BaseObjectEditPage;
import org.jkiss.utils.CommonUtils;

/**
 * Custom virtual attributes edit dialog
 */
public class EditVirtualColumnsPage extends BaseObjectEditPage {

    private ResultSetViewer viewer;
    private DBVEntity vEntity;
    private boolean structChanged;
    private Table attrTable;

    public EditVirtualColumnsPage(ResultSetViewer viewer, DBVEntity vEntity) {
        super("Add virtual columns", DBIcon.TREE_COLUMN);
        this.viewer = viewer;
        this.vEntity = vEntity;
    }

    public boolean isStructChanged() {
        return structChanged;
    }

    @Override
    protected Composite createPageContents(Composite parent) {
        Composite panel = new Composite(parent, 1);
        panel.setLayoutData(new GridData(GridData.FILL_BOTH));
        panel.setLayout(new GridLayout(1, false));

        attrTable = new Table(panel, SWT.FULL_SELECTION | SWT.BORDER);
        attrTable.setLayoutData(new GridData(GridData.FILL_BOTH));
        attrTable.setHeaderVisible(true);
        UIUtils.executeOnResize(attrTable, () -> UIUtils.packColumns(attrTable, true));

        UIUtils.createTableColumn(attrTable, SWT.LEFT, "Name");
        UIUtils.createTableColumn(attrTable, SWT.LEFT, "Data type");
        UIUtils.createTableColumn(attrTable, SWT.LEFT, "Expression");

        {
            Composite buttonsPanel = UIUtils.createComposite(panel, 3);
            buttonsPanel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));

            Button btnAdd = UIUtils.createDialogButton(buttonsPanel, "Add", new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    DBVEntityAttribute vAttr = new DBVEntityAttribute(vEntity, null, "vcolumn");
                    EditVirtualAttributePage editAttrPage = new EditVirtualAttributePage(parent.getShell(), viewer, vAttr);
                    if (editAttrPage.edit()) {
                        vAttr.setCustom(true);
                        vEntity.addVirtualAttribute(vAttr);
                        structChanged = true;
                        createAttributeItem(attrTable, vAttr);
                    }
                }
            });<commit_msg>UI fixes<commit_after>/*
 * DBeaver - Universal Database Manager
 * Copyright (C) 2010-2019 <NAME> (<EMAIL>)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jkiss.dbeaver.ui.controls.resultset;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.model.DBValueFormatting;
import org.jkiss.dbeaver.model.virtual.DBVEntity;
import org.jkiss.dbeaver.model.virtual.DBVEntityAttribute;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.editors.object.struct.BaseObjectEditPage;
import org.jkiss.utils.CommonUtils;

/**
 * Custom virtual attributes edit dialog
 */
public class EditVirtualColumnsPage extends BaseObjectEditPage {

    private ResultSetViewer viewer;
    private DBVEntity vEntity;
    private boolean structChanged;
    private Table attrTable;

    public EditVirtualColumnsPage(ResultSetViewer viewer, DBVEntity vEntity) {
        super("Add virtual columns", DBIcon.TREE_COLUMN);
        this.viewer = viewer;
        this.vEntity = vEntity;
    }

    public boolean isStructChanged() {
        return structChanged;
    }

    @Override
    protected Composite createPageContents(Composite parent) {
        Composite panel = UIUtils.createComposite(parent, 1);
        panel.setLayoutData(new GridData(GridData.FILL_BOTH));

        attrTable = new Table(panel, SWT.FULL_SELECTION | SWT.BORDER);
        attrTable.setLayoutData(new GridData(GridData.FILL_BOTH));
        attrTable.setHeaderVisible(true);
        UIUtils.executeOnResize(attrTable, () -> UIUtils.packColumns(attrTable, true));

        UIUtils.createTableColumn(attrTable, SWT.LEFT, "Name");
        UIUtils.createTableColumn(attrTable, SWT.LEFT, "Data type");
        UIUtils.createTableColumn(attrTable, SWT.LEFT, "Expression");

        {
            Composite buttonsPanel = UIUtils.createComposite(panel, 3);
            buttonsPanel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));

            Button btnAdd = UIUtils.createDialogButton(buttonsPanel, "Add", new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    DBVEntityAttribute vAttr = new DBVEntityAttribute(vEntity, null, "vcolumn");
                    EditVirtualAttributePage editAttrPage = new EditVirtualAttributePage(parent.getShell(), viewer, vAttr);
                    if (editAttrPage.edit()) {
                        vAttr.setCustom(true);
                        vEntity.addVirtualAttribute(vAttr);
                        structChanged = true;
                        createAttributeItem(attrTable, vAttr);
                    }
                }
            });
{'fraction_non_alphanumeric': 0.09260774686306601, 'fraction_numerical': 0.003955264593562466, 'mean_word_length': 3.21921749136939, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2776213', 'n_tokens_mistral': 2123, 'n_tokens_neox': 2041, 'n_words': 477}