use of org.jboss.gwt.elemento.core.Key in project console by hal.
the class FinderColumn method onNavigation.
private void onNavigation(KeyboardEvent event) {
if (hasVisibleElements()) {
Key key = Key.fromEvent(event);
switch(key) {
case ArrowUp:
case ArrowDown:
{
HTMLElement activeElement = activeElement();
if (!Elements.isVisible(activeElement)) {
activeElement = null;
}
HTMLElement select = key == ArrowUp ? previousVisibleElement(activeElement) : nextVisibleElement(activeElement);
if (select != null && select != noItems) {
event.preventDefault();
event.stopPropagation();
select.scrollIntoView(false);
row(select).click();
}
break;
}
case ArrowLeft:
{
HTMLElement previousElement = (HTMLElement) root.previousElementSibling;
if (previousElement != null) {
FinderColumn<?> previousColumn = finder.getColumn(previousElement.id);
if (previousColumn != null) {
event.preventDefault();
event.stopPropagation();
Elements.setVisible(previousElement, true);
finder.reduceTo(previousColumn);
finder.selectColumn(previousColumn.getId());
FinderRow selectedRow = previousColumn.selectedRow();
if (selectedRow != null) {
selectedRow.updatePreview();
selectedRow.element().scrollIntoView(false);
}
finder.updateContext();
finder.updateHistory();
}
}
break;
}
case ArrowRight:
{
HTMLElement activeElement = activeElement();
String nextColumn = row(activeElement).getNextColumn();
if (Elements.isVisible(activeElement) && nextColumn != null) {
event.preventDefault();
event.stopPropagation();
finder.reduceTo(this);
finder.appendColumn(nextColumn, new AsyncCallback<FinderColumn>() {
@Override
public void onFailure(Throwable throwable) {
logger.error("Unable to append next column '{}' on keyboard right: {}", nextColumn, throwable.getMessage());
}
@Override
public void onSuccess(FinderColumn column) {
if (column.activeElement() == null && column.hasVisibleElements()) {
HTMLElement firstElement = column.nextVisibleElement(null);
column.markSelected(firstElement.id);
column.row(firstElement).updatePreview();
}
finder.updateContext();
finder.updateHistory();
finder.selectColumn(nextColumn);
}
});
}
break;
}
case Enter:
{
HTMLElement activeItem = activeElement();
T item = row(activeItem).getItem();
ItemActionHandler<T> primaryAction = row(activeItem).getPrimaryAction();
if (Elements.isVisible(activeItem) && item != null && primaryAction != null) {
event.preventDefault();
event.stopPropagation();
row(activeItem).click();
primaryAction.execute(item);
}
break;
}
default:
break;
}
}
}
Aggregations