Search in sources :

Example 26 with DBDAttributeBinding

use of org.jkiss.dbeaver.model.data.DBDAttributeBinding in project dbeaver by serge-rider.

the class StatisticsPresentation method refreshData.

@Override
public void refreshData(boolean refreshMetadata, boolean append, boolean keepState) {
    table.removeAll();
    if (controller.getModel().getRowCount() > 0) {
        ResultSetRow row = controller.getModel().getRow(0);
        java.util.List<DBDAttributeBinding> visibleAttributes = controller.getModel().getVisibleAttributes();
        for (int i = 0; i < visibleAttributes.size(); i++) {
            DBDAttributeBinding attr = visibleAttributes.get(i);
            Object value = row.getValues()[i];
            String valueString = DBValueFormatting.getDefaultValueDisplayString(value, DBDDisplayFormat.UI);
            String[] lines = valueString.split("\n");
            for (int k = 0; k < lines.length; k++) {
                String line = lines[k];
                if (CommonUtils.isEmptyTrimmed(line)) {
                    continue;
                }
                line = line.replace("\t", "    ");
                TableItem item = new TableItem(table, SWT.LEFT);
                item.setText(0, k == 0 ? attr.getName() : "");
                item.setText(1, line);
                item.setData(attr);
            }
        }
    }
    UIUtils.packColumns(table);
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding)

Example 27 with DBDAttributeBinding

use of org.jkiss.dbeaver.model.data.DBDAttributeBinding in project dbeaver by serge-rider.

the class StatisticsPresentation method createPresentation.

@Override
public void createPresentation(@NotNull IResultSetController controller, @NotNull Composite parent) {
    super.createPresentation(controller, parent);
    UIUtils.createHorizontalLine(parent);
    table = new Table(parent, SWT.MULTI | SWT.FULL_SELECTION);
    table.setLinesVisible(!UIStyles.isDarkTheme());
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(GridData.FILL_BOTH));
    table.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            curAttribute = null;
            TableItem[] selection = table.getSelection();
            Object[] elements = new Object[selection.length];
            for (int i = 0; i < selection.length; i++) {
                elements[i] = selection[i].getData();
                if (curAttribute == null) {
                    curAttribute = (DBDAttributeBinding) elements[i];
                }
            }
            fireSelectionChanged(new StructuredSelection(elements));
        }
    });
    UIUtils.createTableColumn(table, SWT.LEFT, "Name");
    UIUtils.createTableColumn(table, SWT.LEFT, "Value");
    UIUtils.setControlContextMenu(table, manager -> UIUtils.fillDefaultTableContextMenu(manager, table));
}
Also used : Table(org.eclipse.swt.widgets.Table) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding)

Example 28 with DBDAttributeBinding

use of org.jkiss.dbeaver.model.data.DBDAttributeBinding in project dbeaver by serge-rider.

the class MetaDataPanel method createContents.

@Override
public Control createContents(final IResultSetPresentation presentation, Composite parent) {
    this.presentation = presentation;
    this.colorDisabled = presentation.getControl().getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
    this.attributeList = new MetaDataTable(parent);
    this.attributeList.setFitWidth(true);
    this.attributeList.getItemsViewer().addSelectionChangedListener(event -> {
        DBDAttributeBinding attr = getSelectedAttribute();
        if (attr != null && !updateSelection) {
            if (isAttributeVisible(attr)) {
                updateSelection = true;
                try {
                    presentation.setCurrentAttribute(attr);
                } finally {
                    updateSelection = false;
                }
            }
        }
    });
    if (this.presentation instanceof ISelectionProvider) {
        final ISelectionChangedListener listener = event -> {
            if (!updateSelection && MetaDataPanel.this.presentation.getController().getVisiblePanel() == MetaDataPanel.this) {
                DBDAttributeBinding attr = presentation.getCurrentAttribute();
                if (attr != null && attr != getSelectedAttribute()) {
                    updateSelection = true;
                    try {
                        attributeList.getItemsViewer().setSelection(new StructuredSelection(attr));
                    } finally {
                        updateSelection = false;
                    }
                }
            }
        };
        ((ISelectionProvider) this.presentation).addSelectionChangedListener(listener);
        attributeList.getControl().addDisposeListener(e -> ((ISelectionProvider) presentation).removeSelectionChangedListener(listener));
    }
    return this.attributeList;
}
Also used : DatabaseLoadService(org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService) Arrays(java.util.Arrays) Nullable(org.jkiss.code.Nullable) DBPImage(org.jkiss.dbeaver.model.DBPImage) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) NotNull(org.jkiss.code.NotNull) Composite(org.eclipse.swt.widgets.Composite) UIUtils(org.jkiss.dbeaver.ui.UIUtils) TextTransfer(org.eclipse.swt.dnd.TextTransfer) DatabaseObjectListControl(org.jkiss.dbeaver.ui.navigator.itemlist.DatabaseObjectListControl) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IResultSetPresentation(org.jkiss.dbeaver.ui.controls.resultset.IResultSetPresentation) TreeContentProvider(org.jkiss.dbeaver.ui.controls.TreeContentProvider) CommonUtils(org.jkiss.utils.CommonUtils) DBDAttributeBindingMeta(org.jkiss.dbeaver.model.data.DBDAttributeBindingMeta) DBValueFormatting(org.jkiss.dbeaver.model.DBValueFormatting) Collection(java.util.Collection) IContributionManager(org.eclipse.jface.action.IContributionManager) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) Action(org.eclipse.jface.action.Action) org.eclipse.jface.viewers(org.eclipse.jface.viewers) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) IResultSetPanel(org.jkiss.dbeaver.ui.controls.resultset.IResultSetPanel) Color(org.eclipse.swt.graphics.Color) Tree(org.eclipse.swt.widgets.Tree) SWT(org.eclipse.swt.SWT) Control(org.eclipse.swt.widgets.Control) LoadingJob(org.jkiss.dbeaver.ui.LoadingJob) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding)

Example 29 with DBDAttributeBinding

use of org.jkiss.dbeaver.model.data.DBDAttributeBinding in project dbeaver by serge-rider.

the class ReferencesResultsContainer method refreshReferenceKeyList.

/**
 * Load list of referencing keys
 */
private void refreshReferenceKeyList() {
    activeReferenceKey = null;
    referenceKeys.clear();
    UIUtils.syncExec(() -> {
        dataViewer.clearData();
        fkCombo.removeAll();
        dataViewer.showEmptyPresentation();
    });
    List<DBDAttributeBinding> visibleAttributes = parentController.getModel().getVisibleAttributes();
    if (visibleAttributes.isEmpty()) {
        return;
    }
    parentDataContainer = parentController.getDataContainer();
    if (parentDataContainer == null) {
        return;
    }
    Set<DBSEntity> allEntities = new LinkedHashSet<>();
    for (DBDAttributeBinding attr : visibleAttributes) {
        DBSEntityAttribute entityAttribute = attr.getEntityAttribute();
        if (entityAttribute != null) {
            allEntities.add(entityAttribute.getParentObject());
        }
    }
    if (allEntities.isEmpty() && parentDataContainer instanceof DBSEntity) {
        allEntities.add((DBSEntity) parentDataContainer);
    }
    List<ReferenceKeyMemo> refKeyMemos = new ArrayList<>();
    {
        DBVEntity vEntityOwner = DBVUtils.getVirtualEntity(parentDataContainer, false);
        if (vEntityOwner != null) {
            Object activeAssociations = vEntityOwner.getProperty(V_PROP_ACTIVE_ASSOCIATIONS);
            if (activeAssociations instanceof Collection) {
                for (Object refKeyMemoMap : (Collection) activeAssociations) {
                    if (refKeyMemoMap instanceof Map) {
                        refKeyMemos.add(new ReferenceKeyMemo((Map) refKeyMemoMap));
                    }
                }
            }
        }
    }
    if (!allEntities.isEmpty()) {
        new AbstractJob("Load reference keys") {

            @Override
            protected IStatus run(DBRProgressMonitor monitor) {
                monitor.beginTask("Load references", allEntities.size());
                try {
                    List<ReferenceKey> refs = new ArrayList<>();
                    for (DBSEntity entity : allEntities) {
                        monitor.subTask(entity.getName());
                        if (entity instanceof DBVEntity) {
                            // Skip virtual entities
                            continue;
                        }
                        // Foreign keys
                        Collection<? extends DBSEntityAssociation> associations = DBVUtils.getAllAssociations(monitor, entity);
                        for (DBSEntityAssociation assoc : associations) {
                            if (assoc instanceof DBSEntityReferrer) {
                                List<? extends DBSEntityAttributeRef> attrs = ((DBSEntityReferrer) assoc).getAttributeReferences(monitor);
                                if (!CommonUtils.isEmpty(attrs)) {
                                    ReferenceKey referenceKey = new ReferenceKey(monitor, false, assoc.getAssociatedEntity(), assoc, attrs);
                                    refs.add(referenceKey);
                                }
                            }
                        }
                        // References
                        Collection<? extends DBSEntityAssociation> references = DBVUtils.getAllReferences(monitor, entity);
                        {
                            for (DBSEntityAssociation assoc : references) {
                                if (assoc instanceof DBSEntityReferrer) {
                                    List<? extends DBSEntityAttributeRef> attrs = ((DBSEntityReferrer) assoc).getAttributeReferences(monitor);
                                    if (!CommonUtils.isEmpty(attrs)) {
                                        ReferenceKey referenceKey = new ReferenceKey(monitor, true, entity, assoc, attrs);
                                        refs.add(referenceKey);
                                    }
                                }
                            }
                        }
                        monitor.worked(1);
                    }
                    synchronized (referenceKeys) {
                        referenceKeys.clear();
                        referenceKeys.addAll(refs);
                        // Detect active ref key from memo
                        if (!referenceKeys.isEmpty()) {
                            if (!refKeyMemos.isEmpty()) {
                                for (ReferenceKey key : referenceKeys) {
                                    for (ReferenceKeyMemo memo : refKeyMemos) {
                                        if (key.matches(memo)) {
                                            activeReferenceKey = key;
                                            break;
                                        }
                                    }
                                    if (activeReferenceKey != null)
                                        break;
                                }
                            }
                            if (activeReferenceKey == null) {
                                activeReferenceKey = referenceKeys.get(0);
                            }
                        }
                    }
                    UIUtils.syncExec(() -> fillKeysCombo());
                } catch (DBException e) {
                    log.debug("Error reading references", e);
                // Do not show errors. References or FKs may be unsupported by current database
                } finally {
                    monitor.done();
                }
                return Status.OK_STATUS;
            }
        }.schedule();
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) IStatus(org.eclipse.core.runtime.IStatus) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) DBVEntity(org.jkiss.dbeaver.model.virtual.DBVEntity) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 30 with DBDAttributeBinding

use of org.jkiss.dbeaver.model.data.DBDAttributeBinding in project dbeaver by serge-rider.

the class ValueViewerPanel method refreshValue.

private void refreshValue(boolean force) {
    DBDAttributeBinding attr = presentation.getCurrentAttribute();
    ResultSetRow row = presentation.getController().getCurrentRow();
    if (attr == null || row == null) {
        clearValue();
        return;
    }
    boolean updateActions;
    if (previewController == null) {
        previewController = new ResultSetValueController(presentation.getController(), attr, row, IValueController.EditType.PANEL, viewPlaceholder) {

            @Override
            public void updateValue(@Nullable Object value, boolean updatePresentation) {
                valueSaving = true;
                try {
                    super.updateValue(value, updatePresentation);
                } finally {
                    valueSaving = false;
                }
                presentation.updateValueView();
            }
        };
        updateActions = true;
        force = true;
    } else {
        updateActions = force = (force || previewController.getBinding() != attr);
        previewController.setCurRow(row);
        previewController.setBinding(attr);
    }
    viewValue(force);
    if (updateActions) {
        presentation.getController().updatePanelActions();
    }
}
Also used : DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding)

Aggregations

DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)147 ArrayList (java.util.ArrayList)32 DBException (org.jkiss.dbeaver.DBException)29 ResultSetRow (org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow)24 DBDContent (org.jkiss.dbeaver.model.data.DBDContent)23 DBDContentStorage (org.jkiss.dbeaver.model.data.DBDContentStorage)23 List (java.util.List)18 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)16 DBSAttributeBase (org.jkiss.dbeaver.model.struct.DBSAttributeBase)14 Reader (java.io.Reader)13 PrintWriter (java.io.PrintWriter)12 GridData (org.eclipse.swt.layout.GridData)12 Nullable (org.jkiss.code.Nullable)12 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)12 Date (java.util.Date)10 SWT (org.eclipse.swt.SWT)10 NotNull (org.jkiss.code.NotNull)10 DBDDataFilter (org.jkiss.dbeaver.model.data.DBDDataFilter)10 DBPPreferenceStore (org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)10 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)10