| /*=============================================================================# |
| # Copyright (c) 2010, 2021 Stephan Wahlbrink and others. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License 2.0 which is available at |
| # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| # which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| # |
| # Contributors: |
| # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.ecommons.waltable.viewport; |
| |
| import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; |
| import org.eclipse.statet.ecommons.waltable.layer.ILayer; |
| import org.eclipse.statet.ecommons.waltable.selection.SelectRelativeCellCommand; |
| |
| |
| public class SelectRelativePageCommandHandler extends AbstractLayerCommandHandler<SelectRelativePageCommand> { |
| |
| |
| private final ILayer viewportLayer; |
| |
| |
| public SelectRelativePageCommandHandler(final ILayer viewportLayer) { |
| this.viewportLayer= viewportLayer; |
| } |
| |
| |
| @Override |
| public Class<SelectRelativePageCommand> getCommandClass() { |
| return SelectRelativePageCommand.class; |
| } |
| |
| @Override |
| protected boolean doCommand(final SelectRelativePageCommand command) { |
| if (command.convertToTargetLayer(this.viewportLayer)) { |
| long stepCount; |
| switch (command.getDirection()) { |
| case UP: |
| case DOWN: |
| stepCount= this.viewportLayer.getRowCount(); |
| break; |
| case LEFT: |
| case RIGHT: |
| stepCount= this.viewportLayer.getColumnCount(); |
| break; |
| default: |
| return false; |
| } |
| this.viewportLayer.doCommand(new SelectRelativeCellCommand( |
| command.getDirection(), stepCount, command.getSelectionFlags() )); |
| } |
| return true; |
| } |
| |
| } |