Search in sources :

Example 1 with DBSTableColumn

use of org.jkiss.dbeaver.model.struct.rdb.DBSTableColumn in project dbeaver by dbeaver.

the class ExasolCreateForeignKeyDialog method handleUniqueKeySelect.

private void handleUniqueKeySelect() {
    curConstraint = null;
    fkColumns.clear();
    ownColumns = null;
    columnsTable.removeAll();
    if (curConstraints.isEmpty() || uniqueKeyCombo.getSelectionIndex() < 0) {
        return;
    }
    curConstraint = curConstraints.get(uniqueKeyCombo.getSelectionIndex());
    try {
        // Read column nodes with void monitor because we already cached them above
        for (DBSEntityAttributeRef pkColumn : curConstraint.getAttributeReferences(new VoidProgressMonitor())) {
            FKColumnInfo fkColumnInfo = new FKColumnInfo(pkColumn.getAttribute());
            // Try to find matched column in own table
            Collection<? extends DBSEntityAttribute> tmpColumns = ownTable.getAttributes(new VoidProgressMonitor());
            ownColumns = tmpColumns == null ? Collections.<DBSTableColumn>emptyList() : new ArrayList<>(ownTable.getAttributes(new VoidProgressMonitor()));
            if (!CommonUtils.isEmpty(ownColumns)) {
                for (DBSEntityAttribute ownColumn : ownColumns) {
                    if (ownColumn.getName().equals(pkColumn.getAttribute().getName()) && ownTable != pkColumn.getAttribute().getParentObject()) {
                        fkColumnInfo.ownColumn = ownColumn;
                        break;
                    }
                }
            }
            fkColumns.add(fkColumnInfo);
            TableItem item = new TableItem(columnsTable, SWT.NONE);
            if (fkColumnInfo.ownColumn != null) {
                item.setText(0, fkColumnInfo.ownColumn.getName());
                item.setImage(0, getColumnIcon(fkColumnInfo.ownColumn));
                item.setText(1, fkColumnInfo.ownColumn.getFullTypeName());
            }
            item.setText(2, pkColumn.getAttribute().getName());
            item.setImage(2, getColumnIcon(pkColumn.getAttribute()));
            item.setText(3, pkColumn.getAttribute().getFullTypeName());
            item.setData(fkColumnInfo);
        }
    } catch (DBException e) {
        DBUserInterface.getInstance().showError(CoreMessages.dialog_struct_edit_fk_error_load_constraint_columns_title, CoreMessages.dialog_struct_edit_fk_error_load_constraint_columns_message, e);
    }
    UIUtils.packColumns(columnsTable, true);
}
Also used : DBSEntityAttributeRef(org.jkiss.dbeaver.model.struct.DBSEntityAttributeRef) DBException(org.jkiss.dbeaver.DBException) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBSTableColumn(org.jkiss.dbeaver.model.struct.rdb.DBSTableColumn)

Aggregations

ArrayList (java.util.ArrayList)1 TableItem (org.eclipse.swt.widgets.TableItem)1 DBException (org.jkiss.dbeaver.DBException)1 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)1 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)1 DBSEntityAttributeRef (org.jkiss.dbeaver.model.struct.DBSEntityAttributeRef)1 DBSTableColumn (org.jkiss.dbeaver.model.struct.rdb.DBSTableColumn)1