| /*=============================================================================# |
| # Copyright (c) 2012, 2021 Original NatTable authors 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. |
| # |
| # SPDX-License-Identifier: EPL-2.0 |
| # |
| # Contributors: |
| # Original NatTable authors and others - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.ecommons.waltable.sort; |
| |
| import org.eclipse.swt.custom.BusyIndicator; |
| |
| import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; |
| import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; |
| |
| |
| /** |
| * Handle sort commands |
| */ |
| public class SortPositionCommandHandler extends AbstractLayerCommandHandler<SortDimPositionCommand> { |
| |
| |
| private final ISortModel sortModel; |
| |
| |
| public SortPositionCommandHandler(final ISortModel sortModel) { |
| this.sortModel= sortModel; |
| } |
| |
| |
| @Override |
| public Class<SortDimPositionCommand> getCommandClass() { |
| return SortDimPositionCommand.class; |
| } |
| |
| @Override |
| protected boolean doCommand(final SortDimPositionCommand command) { |
| final long columnId= command.getDim() |
| .getPositionId(command.getPosition(), command.getPosition()); |
| |
| // with busy indicator |
| final Runnable sortRunner= new Runnable() { |
| @Override |
| public void run() { |
| final ILayerDim dim= command.getDim(); |
| |
| final SortDirection newSortDirection= (command.getDirection() != null) ? |
| command.getDirection() : |
| SortPositionCommandHandler.this.sortModel.getSortDirection(columnId).getNextSortDirection(); |
| SortPositionCommandHandler.this.sortModel.sort(columnId, |
| newSortDirection, command.isAccumulate() ); |
| |
| // Fire event |
| final SortColumnEvent sortEvent= new SortColumnEvent(dim, |
| command.getPosition() ); |
| dim.getLayer().fireLayerEvent(sortEvent); |
| } |
| }; |
| BusyIndicator.showWhile(null, sortRunner); |
| |
| return true; |
| } |
| |
| } |