Skip to content

Commit

Permalink
#5934 Data viewer: references panel
Browse files Browse the repository at this point in the history
Former-commit-id: aa4d088
  • Loading branch information
serge-rider committed Jul 7, 2019
1 parent bf8dfd3 commit 32761d5
Show file tree
Hide file tree
Showing 5 changed files with 261 additions and 35 deletions.
Expand Up @@ -301,7 +301,7 @@ public Object getCellValue(@NotNull DBDAttributeBinding attribute, @NotNull Resu
if (depth == 0) {
final int index = attribute.getOrdinalPosition();
if (index >= row.values.length) {
log.debug("Bad attribute - index out of row values' bounds");
log.debug("Bad attribute '" + attribute.getName() + "' index: " + index + " is out of row values' bounds (" + row.values.length + ")");
return null;
} else {
return row.values[index];
Expand Down Expand Up @@ -624,6 +624,11 @@ private void updateRowColors(boolean reset, List<ResultSetRow> rows) {
}
if (!colorMapping.isEmpty()) {
for (Map.Entry<DBDAttributeBinding, List<AttributeColorSettings>> entry : colorMapping.entrySet()) {
if (!ArrayUtils.contains(attributes, entry.getKey())) {
// This may happen during FK navigation - attributes are already updated while colors mapping are still old
continue;
}

for (ResultSetRow row : rows) {
for (AttributeColorSettings acs : entry.getValue()) {
Color background = null, foreground = null;
Expand Down
Expand Up @@ -1603,6 +1603,15 @@ public DBSDataContainer getDataContainer()
return curState != null ? curState.dataContainer : container.getDataContainer();
}

public void setDataContainer(DBSDataContainer targetEntity, DBDDataFilter newFilter) {
// Workaround for script results
// In script mode history state isn't updated so we check for it here
if (curState == null) {
setNewState(targetEntity, model.getDataFilter());
}
runDataPump(targetEntity, newFilter, 0, getSegmentMaxRows(), -1, true, false, null);
}

////////////////////////////////////////////////////////////
// Grid/Record mode

Expand Down Expand Up @@ -2679,6 +2688,16 @@ public void navigateAssociation(@NotNull DBRProgressMonitor monitor, @Nullable D
@Override
public void navigateReference(@NotNull DBRProgressMonitor monitor, @NotNull DBSEntityAssociation association, @NotNull List<ResultSetRow> rows, boolean newWindow)
throws DBException
{
navigateReference(monitor, model, association, rows, newWindow);
}

/**
* Navigate reference
* @param bindingsModel data bindings providing model. Can be a model from another results viewer.
*/
public void navigateReference(@NotNull DBRProgressMonitor monitor, @NotNull ResultSetModel bindingsModel, @NotNull DBSEntityAssociation association, @NotNull List<ResultSetRow> rows, boolean newWindow)
throws DBException
{
if (!confirmProceed()) {
return;
Expand Down Expand Up @@ -2719,7 +2738,7 @@ public void navigateReference(@NotNull DBRProgressMonitor monitor, @NotNull DBSE
for (int i = 0; i < refAttrs.size(); i++) {
DBSEntityAttributeRef refAttr = refAttrs.get(i);

DBDAttributeBinding attrBinding = model.getAttributeBinding(refAttr.getAttribute());
DBDAttributeBinding attrBinding = bindingsModel.getAttributeBinding(refAttr.getAttribute());
if (attrBinding == null) {
log.error("Can't find attribute binding for ref attribute '" + refAttr.getAttribute().getName() + "'");
} else {
Expand Down Expand Up @@ -2757,13 +2776,7 @@ private void navigateEntity(@NotNull DBRProgressMonitor monitor, boolean newWind
if (newWindow) {
openResultsInNewWindow(monitor, targetEntity, newFilter);
} else {
DBSDataContainer targetDataContainer = (DBSDataContainer) targetEntity;
// Workaround for script results
// In script mode history state isn't updated so we check for it here
if (curState == null) {
setNewState(targetDataContainer, model.getDataFilter());
}
runDataPump(targetDataContainer, newFilter, 0, getSegmentMaxRows(), -1, true, false, null);
setDataContainer((DBSDataContainer) targetEntity, newFilter);
}
}

Expand Down Expand Up @@ -2972,6 +2985,9 @@ public void refresh()

// Pump data
DBSDataContainer dataContainer = getDataContainer();
if (dataContainer == null) {
return;
}
DBDDataFilter dataFilter = restoreDataFilter(dataContainer);

if (container.isReadyToRun() && dataContainer != null && dataPumpJob == null) {
Expand Down Expand Up @@ -3309,7 +3325,7 @@ public void done(IJobChangeEvent event) {
return true;
}

private void clearData()
public void clearData()
{
this.model.clearData();
this.curRow = null;
Expand Down
Expand Up @@ -18,12 +18,15 @@

import org.eclipse.jface.action.IContributionManager;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.resultset.IResultSetController;
import org.jkiss.dbeaver.ui.controls.resultset.IResultSetPanel;
import org.jkiss.dbeaver.ui.controls.resultset.IResultSetPresentation;
import org.jkiss.dbeaver.ui.controls.resultset.ResultSetListenerAdapter;
import org.jkiss.dbeaver.ui.controls.resultset.ResultSetUtils;

/**
Expand Down Expand Up @@ -52,7 +55,23 @@ public Control createContents(final IResultSetPresentation presentation, Composi

loadSettings();

this.resultsContainer = new ReferencesResultsContainer(parent, presentation);
this.resultsContainer = new ReferencesResultsContainer(parent, presentation.getController());

// Data listener
ResultSetListenerAdapter dataListener = new ResultSetListenerAdapter() {
@Override
public void handleResultSetLoad() {
refresh(true);
}
};
presentation.getController().addListener(dataListener);
presentation.getControl().addDisposeListener(e -> presentation.getController().removeListener(dataListener));

if (presentation instanceof ISelectionProvider) {
ISelectionChangedListener selectionListener = event -> resultsContainer.refreshReferences();
((ISelectionProvider) presentation).addSelectionChangedListener(selectionListener);
presentation.getControl().addDisposeListener(e -> ((ISelectionProvider) presentation).removeSelectionChangedListener(selectionListener));
}

return this.resultsContainer.getControl();
}
Expand Down Expand Up @@ -87,6 +106,7 @@ public void deactivatePanel() {

@Override
public void refresh(boolean force) {
resultsContainer.refreshReferences();
}

@Override
Expand Down

0 comments on commit 32761d5

Please sign in to comment.