提交 036e0ebd 编写于 作者: S Serge Rider

Data viewer: navigate to multiple rows fks/refs


Former-commit-id: 4d5311af
上级 8d26f88e
......@@ -22,7 +22,6 @@ import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchPartSite;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
......@@ -34,7 +33,6 @@ import org.jkiss.dbeaver.model.data.DBDDataReceiver;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSDataContainer;
import org.jkiss.dbeaver.model.struct.DBSEntityAssociation;
import org.jkiss.dbeaver.ui.data.IDataController;
......@@ -140,10 +138,10 @@ public interface IResultSetController extends IDataController, DBPContextProvide
/**
* Navigates to association. One of @association OR @attr must be specified.
*/
void navigateAssociation(@NotNull DBRProgressMonitor monitor, @Nullable DBSEntityAssociation association, @Nullable DBDAttributeBinding attr, @NotNull ResultSetRow row, boolean newWindow)
void navigateAssociation(@NotNull DBRProgressMonitor monitor, @Nullable DBSEntityAssociation association, @Nullable DBDAttributeBinding attr, @NotNull List<ResultSetRow> rows, boolean newWindow)
throws DBException;
void navigateReference(@NotNull DBRProgressMonitor monitor, @NotNull DBSEntityAssociation association, @NotNull ResultSetRow row, boolean newWindow)
void navigateReference(@NotNull DBRProgressMonitor monitor, @NotNull DBSEntityAssociation association, @NotNull List<ResultSetRow> rows, boolean newWindow)
throws DBException;
int getHistoryPosition();
......
......@@ -384,14 +384,13 @@ public class ResultSetHandlerMain extends AbstractHandler {
action.run();
break;
case CMD_NAVIGATE_LINK: {
final ResultSetRow row = rsv.getCurrentRow();
final DBDAttributeBinding attr = rsv.getActivePresentation().getCurrentAttribute();
if (row != null && attr != null) {
if (attr != null) {
new AbstractJob("Navigate association") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
rsv.navigateAssociation(monitor, null, attr, row, false);
rsv.navigateAssociation(monitor, null, attr, rsv.getSelection().getSelectedRows(), false);
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
......
......@@ -59,7 +59,7 @@ public class ResultSetReferenceMenu
}
static void fillRefTablesActions(ResultSetViewer viewer, ResultSetRow row, DBSEntity singleSource, IMenuManager manager, boolean openInNewWindow) {
static void fillRefTablesActions(ResultSetViewer viewer, List<ResultSetRow> rows, DBSEntity singleSource, IMenuManager manager, boolean openInNewWindow) {
final List<DBSEntityAssociation> references = new ArrayList<>();
final List<DBSEntityAssociation> associations = new ArrayList<>();
......@@ -152,7 +152,7 @@ public class ResultSetReferenceMenu
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
viewer.navigateAssociation(new VoidProgressMonitor(), association, null, row, openInNewWindow);
viewer.navigateAssociation(new VoidProgressMonitor(), association, null, rows, openInNewWindow);
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
......@@ -182,7 +182,7 @@ public class ResultSetReferenceMenu
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
viewer.navigateReference(new VoidProgressMonitor(), refAssociation, row, openInNewWindow);
viewer.navigateReference(new VoidProgressMonitor(), refAssociation, rows, openInNewWindow);
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
......
......@@ -2052,11 +2052,7 @@ public class ResultSetViewer extends Viewer
}
void showReferencesMenu(boolean openInNewWindow) {
ResultSetRow currentRow = getCurrentRow();
if (currentRow == null || currentRow.getRowNumber() < 0) {
return;
}
MenuManager menuManager = createRefTablesMenu(currentRow, openInNewWindow);
MenuManager menuManager = createRefTablesMenu(openInNewWindow);
if (menuManager != null) {
showContextMenuAtCursor(menuManager);
viewerPanel.addDisposeListener(e -> menuManager.dispose());
......@@ -2252,7 +2248,7 @@ public class ResultSetViewer extends Viewer
}
if (model.isSingleSource()) {
// Add menu for referencing tables
MenuManager refTablesMenu = createRefTablesMenu(row, false);
MenuManager refTablesMenu = createRefTablesMenu(false);
if (refTablesMenu != null) {
navigateMenu.add(refTablesMenu);
hasNavTables = true;
......@@ -2364,7 +2360,7 @@ public class ResultSetViewer extends Viewer
}
@Nullable
private MenuManager createRefTablesMenu(ResultSetRow row, boolean openInNewWindow) {
private MenuManager createRefTablesMenu(boolean openInNewWindow) {
DBSEntity singleSource = model.getSingleSource();
if (singleSource == null) {
return null;
......@@ -2374,7 +2370,8 @@ public class ResultSetViewer extends Viewer
MenuManager refTablesMenu = new MenuManager(menuName, null, "ref-tables");
refTablesMenu.setActionDefinitionId(ResultSetHandlerMain.CMD_REFERENCES_MENU);
refTablesMenu.add(ResultSetReferenceMenu.NOREFS_ACTION);
refTablesMenu.addMenuListener(manager -> ResultSetReferenceMenu.fillRefTablesActions(this, row, singleSource, manager, openInNewWindow));
refTablesMenu.addMenuListener(manager ->
ResultSetReferenceMenu.fillRefTablesActions(this, getSelection().getSelectedRows(), singleSource, manager, openInNewWindow));
return refTablesMenu;
}
......@@ -2561,7 +2558,7 @@ public class ResultSetViewer extends Viewer
}
@Override
public void navigateAssociation(@NotNull DBRProgressMonitor monitor, @Nullable DBSEntityAssociation association, @Nullable DBDAttributeBinding attr, @NotNull ResultSetRow row, boolean newWindow)
public void navigateAssociation(@NotNull DBRProgressMonitor monitor, @Nullable DBSEntityAssociation association, @Nullable DBDAttributeBinding attr, @NotNull List<ResultSetRow> rows, boolean newWindow)
throws DBException
{
if (!confirmProceed()) {
......@@ -2629,9 +2626,7 @@ public class ResultSetViewer extends Viewer
constraint.setVisible(true);
constraints.add(constraint);
Object keyValue = model.getCellValue(ownBinding, row);
constraint.setOperator(DBCLogicalOperator.EQUALS);
constraint.setValue(keyValue);
createFilterConstraint(rows, ownBinding, constraint);
}
// Save cur data filter in state
curState.filter = new DBDDataFilter(model.getDataFilter());
......@@ -2639,7 +2634,7 @@ public class ResultSetViewer extends Viewer
}
@Override
public void navigateReference(@NotNull DBRProgressMonitor monitor, @NotNull DBSEntityAssociation association, @NotNull ResultSetRow row, boolean newWindow)
public void navigateReference(@NotNull DBRProgressMonitor monitor, @NotNull DBSEntityAssociation association, @NotNull List<ResultSetRow> rows, boolean newWindow)
throws DBException
{
if (!confirmProceed()) {
......@@ -2691,14 +2686,28 @@ public class ResultSetViewer extends Viewer
constraint.setVisible(true);
constraints.add(constraint);
Object keyValue = model.getCellValue(attrBinding, row);
constraint.setOperator(DBCLogicalOperator.EQUALS);
constraint.setValue(keyValue);
createFilterConstraint(rows, attrBinding, constraint);
}
}
navigateEntity(monitor, newWindow, targetEntity, constraints);
}
private void createFilterConstraint(@NotNull List<ResultSetRow> rows, DBDAttributeBinding attrBinding, DBDAttributeConstraint constraint) {
if (rows.size() == 1) {
Object keyValue = model.getCellValue(attrBinding, rows.get(0));
constraint.setOperator(DBCLogicalOperator.EQUALS);
constraint.setValue(keyValue);
} else {
Object[] keyValues = new Object[rows.size()];
for (int k = 0; k < rows.size(); k++) {
keyValues[k] = model.getCellValue(attrBinding, rows.get(k));
}
constraint.setOperator(DBCLogicalOperator.IN);
constraint.setValue(keyValues);
}
}
private void navigateEntity(@NotNull DBRProgressMonitor monitor, boolean newWindow, DBSEntity targetEntity, List<DBDAttributeConstraint> constraints) {
DBDDataFilter newFilter = new DBDDataFilter(constraints);
......
......@@ -1009,7 +1009,7 @@ public class SpreadsheetPresentation extends AbstractPresentation implements IRe
protected IStatus run(DBRProgressMonitor monitor) {
try {
boolean ctrlPressed = (state & SWT.CTRL) == SWT.CTRL;
controller.navigateAssociation(monitor, null, attr, row, ctrlPressed);
controller.navigateAssociation(monitor, null, attr, Collections.singletonList(row), ctrlPressed);
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册