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);
}
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));
}
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;
}
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();
}
}
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();
}
}
Aggregations