Skip to content

Commit

Permalink
#4209 Dashboards: keyboard navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-rider committed Feb 9, 2019
1 parent b5a01d0 commit 0086d6b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
Expand Up @@ -118,6 +118,13 @@ public void focusLost(FocusEvent e) {
}
});

chartCanvas.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
groupContainer.handleKeyEvent(e);
}
});

dashboardControl.addDisposeListener(e -> renderer.disposeDashboard(DashboardItem.this));
}

Expand Down
Expand Up @@ -19,6 +19,8 @@
import org.eclipse.jface.action.MenuManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.*;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.*;
Expand Down Expand Up @@ -90,6 +92,49 @@ public void mouseDown(MouseEvent e) {
setFocus();
}
});
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
handleKeyEvent(e);
}
});
}

void handleKeyEvent(KeyEvent e) {
switch (e.keyCode) {
case SWT.CR:
ActionUtils.runCommand(DashboardConstants.CMD_VIEW_DASHBOARD, DashboardList.this.site);
break;
case SWT.ARROW_LEFT:
case SWT.ARROW_UP:
moveSelection(-1);
break;
case SWT.ARROW_RIGHT:
case SWT.ARROW_DOWN:
moveSelection(1);
break;
}
}

private void moveSelection(int delta) {
if (items.isEmpty()) {
return;
}
if (selectedItem == null) {
setSelection(items.get(0));
} else {
int curIndex = items.indexOf(selectedItem);
curIndex += delta;
if (curIndex < 0) {
curIndex = items.size() - 1;
} else if (curIndex >= items.size()) {
curIndex = 0;
}
DashboardItem newSelection = items.get(curIndex);
newSelection.getDashboardControl().setFocus();
setSelection(newSelection);
newSelection.redraw();
}
}

private void registerContextMenu() {
Expand Down Expand Up @@ -135,6 +180,12 @@ public void addItem(String dashboardId) {
layout(true, true);
}

@Override
public void selectItem(DashboardContainer item) {
setSelection((DashboardItem) item);
item.getDashboardControl().setFocus();
}

void createDefaultDashboards() {
List<DashboardDescriptor> dashboards = DashboardRegistry.getInstance().getDashboards(
viewContainer.getDataSourceContainer(), true);
Expand Down
Expand Up @@ -31,4 +31,5 @@ public interface DashboardGroupContainer {

void addItem(String dashboardId);

void selectItem(DashboardContainer item);
}
Expand Up @@ -25,9 +25,13 @@
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.IDataSourceContainerProvider;
import org.jkiss.dbeaver.ui.dashboard.control.DashboardListViewer;
import org.jkiss.dbeaver.ui.dashboard.model.DashboardContainer;
import org.jkiss.dbeaver.ui.dashboard.model.DashboardGroupContainer;
import org.jkiss.dbeaver.ui.dashboard.model.DashboardViewConfiguration;
import org.jkiss.utils.CommonUtils;

import java.util.List;

public class DashboardView extends ViewPart implements IDataSourceContainerProvider {
public static final String VIEW_ID = "org.jkiss.dbeaver.ui.dashboardView";

Expand Down Expand Up @@ -70,7 +74,13 @@ public void createPartControl(Composite parent) {

@Override
public void setFocus() {

if (dashboardListViewer != null) {
DashboardGroupContainer group = dashboardListViewer.getDefaultGroup();
List<? extends DashboardContainer> items = group.getItems();
if (!items.isEmpty()) {
group.selectItem(items.get(0));
}
}
}

@Override
Expand Down
Expand Up @@ -90,6 +90,8 @@ protected Composite createDialogArea(Composite parent) {
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.CLOSE_LABEL, true);

UIUtils.asyncExec(() -> getButton(IDialogConstants.OK_ID).setFocus());
}

}

0 comments on commit 0086d6b

Please sign in to comment.