Search in sources :

Example 11 with DBVEntityAttribute

use of org.jkiss.dbeaver.model.virtual.DBVEntityAttribute in project dbeaver by dbeaver.

the class EditVirtualColumnsPage method editSelectedAttribute.

private void editSelectedAttribute(Table attrTable) {
    TableItem[] selection = attrTable.getSelection();
    if (selection.length <= 0) {
        return;
    }
    TableItem tableItem = selection[0];
    DBVEntityAttribute vAttr = (DBVEntityAttribute) tableItem.getData();
    EditVirtualAttributePage editAttrPage = new EditVirtualAttributePage(viewer, vAttr);
    if (editAttrPage.edit(attrTable.getShell())) {
        tableItem.setText(0, vAttr.getName());
        tableItem.setText(1, vAttr.getTypeName());
        tableItem.setText(2, CommonUtils.notEmpty(vAttr.getExpression()));
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) DBVEntityAttribute(org.jkiss.dbeaver.model.virtual.DBVEntityAttribute)

Example 12 with DBVEntityAttribute

use of org.jkiss.dbeaver.model.virtual.DBVEntityAttribute in project dbeaver by dbeaver.

the class EditVirtualColumnsPage method createPageContents.

@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, ResultSetMessages.virtual_edit_columns_page_table_column_name);
    UIUtils.createTableColumn(attrTable, SWT.LEFT, ResultSetMessages.virtual_edit_columns_page_table_column_data_type);
    UIUtils.createTableColumn(attrTable, SWT.LEFT, ResultSetMessages.virtual_edit_columns_page_table_column_expression);
    {
        Composite buttonsPanel = UIUtils.createComposite(panel, 3);
        buttonsPanel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        Button btnAdd = UIUtils.createDialogButton(buttonsPanel, ResultSetMessages.virtual_edit_columns_page_dialog_button_add, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                DBVEntityAttribute vAttr = new DBVEntityAttribute(vEntity, null, "vcolumn");
                EditVirtualAttributePage editAttrPage = new EditVirtualAttributePage(viewer, vAttr);
                if (editAttrPage.edit(parent.getShell())) {
                    vAttr.setCustom(true);
                    vEntity.addVirtualAttribute(vAttr);
                    structChanged = true;
                    createAttributeItem(attrTable, vAttr);
                }
            }
        });
        Button btnEdit = UIUtils.createDialogButton(buttonsPanel, ResultSetMessages.virtual_edit_columns_page_dialog_button_edit, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                editSelectedAttribute(attrTable);
            }
        });
        btnEdit.setEnabled(false);
        Button btnRemove = UIUtils.createDialogButton(buttonsPanel, ResultSetMessages.virtual_edit_columns_page_dialog_button_remove, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                DBVEntityAttribute virtualAttr = (DBVEntityAttribute) attrTable.getSelection()[0].getData();
                if (!UIUtils.confirmAction(parent.getShell(), ResultSetMessages.virtual_edit_columns_page_confirm_action_delete, NLS.bind(ResultSetMessages.virtual_edit_columns_page_confirm_action_question_delete_column, virtualAttr.getName()))) {
                    return;
                }
                vEntity.removeVirtualAttribute(virtualAttr);
                attrTable.remove(attrTable.getSelectionIndices());
                structChanged = true;
            }
        });
        btnRemove.setEnabled(false);
        attrTable.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                boolean attrSelected = attrTable.getSelectionIndex() >= 0;
                btnEdit.setEnabled(attrSelected);
                btnRemove.setEnabled(attrSelected);
            }
        });
        attrTable.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDoubleClick(MouseEvent e) {
                editSelectedAttribute(attrTable);
            }
        });
    }
    refreshAttributes();
    return panel;
}
Also used : Table(org.eclipse.swt.widgets.Table) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBVEntityAttribute(org.jkiss.dbeaver.model.virtual.DBVEntityAttribute) MouseAdapter(org.eclipse.swt.events.MouseAdapter)

Example 13 with DBVEntityAttribute

use of org.jkiss.dbeaver.model.virtual.DBVEntityAttribute in project dbeaver by dbeaver.

the class VirtualAttributeAddAction method run.

@Override
public void run() {
    DBVEntity vEntity = resultSetViewer.getModel().getVirtualEntity(false);
    DBVEntityAttribute vAttr = new DBVEntityAttribute(vEntity, null, "vcolumn");
    if (new EditVirtualAttributePage(resultSetViewer, vAttr).edit(resultSetViewer.getControl().getShell())) {
        vAttr.setCustom(true);
        vEntity.addVirtualAttribute(vAttr);
        vEntity.persistConfiguration();
        resultSetViewer.refreshMetaData();
        DBDAttributeConstraint vAttrConstr = resultSetViewer.getModel().getDataFilter().getConstraint(vAttr, false);
        if (vAttrConstr != null) {
        }
    }
}
Also used : DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint) DBVEntityAttribute(org.jkiss.dbeaver.model.virtual.DBVEntityAttribute) DBVEntity(org.jkiss.dbeaver.model.virtual.DBVEntity)

Example 14 with DBVEntityAttribute

use of org.jkiss.dbeaver.model.virtual.DBVEntityAttribute in project dbeaver by serge-rider.

the class EditVirtualColumnsPage method editSelectedAttribute.

private void editSelectedAttribute(Table attrTable) {
    TableItem[] selection = attrTable.getSelection();
    if (selection.length <= 0) {
        return;
    }
    TableItem tableItem = selection[0];
    DBVEntityAttribute vAttr = (DBVEntityAttribute) tableItem.getData();
    EditVirtualAttributePage editAttrPage = new EditVirtualAttributePage(viewer, vAttr);
    if (editAttrPage.edit(attrTable.getShell())) {
        tableItem.setText(0, vAttr.getName());
        tableItem.setText(1, vAttr.getTypeName());
        tableItem.setText(2, CommonUtils.notEmpty(vAttr.getExpression()));
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) DBVEntityAttribute(org.jkiss.dbeaver.model.virtual.DBVEntityAttribute)

Example 15 with DBVEntityAttribute

use of org.jkiss.dbeaver.model.virtual.DBVEntityAttribute in project dbeaver by serge-rider.

the class EditVirtualColumnsPage method createPageContents.

@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, ResultSetMessages.virtual_edit_columns_page_table_column_name);
    UIUtils.createTableColumn(attrTable, SWT.LEFT, ResultSetMessages.virtual_edit_columns_page_table_column_data_type);
    UIUtils.createTableColumn(attrTable, SWT.LEFT, ResultSetMessages.virtual_edit_columns_page_table_column_expression);
    {
        Composite buttonsPanel = UIUtils.createComposite(panel, 3);
        buttonsPanel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        Button btnAdd = UIUtils.createDialogButton(buttonsPanel, ResultSetMessages.virtual_edit_columns_page_dialog_button_add, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                DBVEntityAttribute vAttr = new DBVEntityAttribute(vEntity, null, "vcolumn");
                EditVirtualAttributePage editAttrPage = new EditVirtualAttributePage(viewer, vAttr);
                if (editAttrPage.edit(parent.getShell())) {
                    vAttr.setCustom(true);
                    vEntity.addVirtualAttribute(vAttr);
                    structChanged = true;
                    createAttributeItem(attrTable, vAttr);
                }
            }
        });
        Button btnEdit = UIUtils.createDialogButton(buttonsPanel, ResultSetMessages.virtual_edit_columns_page_dialog_button_edit, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                editSelectedAttribute(attrTable);
            }
        });
        btnEdit.setEnabled(false);
        Button btnRemove = UIUtils.createDialogButton(buttonsPanel, ResultSetMessages.virtual_edit_columns_page_dialog_button_remove, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                DBVEntityAttribute virtualAttr = (DBVEntityAttribute) attrTable.getSelection()[0].getData();
                if (!UIUtils.confirmAction(parent.getShell(), ResultSetMessages.virtual_edit_columns_page_confirm_action_delete, NLS.bind(ResultSetMessages.virtual_edit_columns_page_confirm_action_question_delete_column, virtualAttr.getName()))) {
                    return;
                }
                vEntity.removeVirtualAttribute(virtualAttr);
                attrTable.remove(attrTable.getSelectionIndices());
                structChanged = true;
            }
        });
        btnRemove.setEnabled(false);
        attrTable.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                boolean attrSelected = attrTable.getSelectionIndex() >= 0;
                btnEdit.setEnabled(attrSelected);
                btnRemove.setEnabled(attrSelected);
            }
        });
        attrTable.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDoubleClick(MouseEvent e) {
                editSelectedAttribute(attrTable);
            }
        });
    }
    refreshAttributes();
    return panel;
}
Also used : Table(org.eclipse.swt.widgets.Table) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBVEntityAttribute(org.jkiss.dbeaver.model.virtual.DBVEntityAttribute) MouseAdapter(org.eclipse.swt.events.MouseAdapter)

Aggregations

DBVEntityAttribute (org.jkiss.dbeaver.model.virtual.DBVEntityAttribute)22 DBVEntity (org.jkiss.dbeaver.model.virtual.DBVEntity)10 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)6 DBVTransformSettings (org.jkiss.dbeaver.model.virtual.DBVTransformSettings)6 GridData (org.eclipse.swt.layout.GridData)4 Composite (org.eclipse.swt.widgets.Composite)4 DBDAttributeBindingCustom (org.jkiss.dbeaver.model.data.DBDAttributeBindingCustom)4 ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2 List (java.util.List)2 JexlExpression (org.apache.commons.jexl3.JexlExpression)2 ComboContentAdapter (org.eclipse.jface.fieldassist.ComboContentAdapter)2 SWT (org.eclipse.swt.SWT)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Button (org.eclipse.swt.widgets.Button)2 Combo (org.eclipse.swt.widgets.Combo)2 Control (org.eclipse.swt.widgets.Control)2