| /*=============================================================================# |
| # 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.ui.matcher; |
| |
| import org.eclipse.swt.events.MouseEvent; |
| |
| import org.eclipse.statet.ecommons.waltable.NatTable; |
| import org.eclipse.statet.ecommons.waltable.layer.LabelStack; |
| import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; |
| import org.eclipse.statet.ecommons.waltable.ui.NatEventData; |
| |
| |
| /** |
| * Matches mouse clicks on cells to which a specified configuration label has been applied. |
| */ |
| public class CellLabelMouseEventMatcher extends MouseEventMatcher { |
| |
| |
| private final String labelToMatch; |
| |
| |
| public CellLabelMouseEventMatcher(final String regionName, final int button, final String labelToMatch) { |
| super(regionName, button); |
| this.labelToMatch= labelToMatch; |
| } |
| |
| public CellLabelMouseEventMatcher(final int stateMask, final String regionName, final int button, final String labelToMatch) { |
| super(stateMask, regionName, button); |
| this.labelToMatch= labelToMatch; |
| } |
| |
| |
| @Override |
| public boolean matches(final NatTable natTable, final MouseEvent event, final LabelStack regionLabels) { |
| final NatEventData eventData= NatEventData.createInstanceFromEvent(event); |
| final ILayerCell cell= natTable.getCellByPosition(eventData.getColumnPosition(), eventData.getRowPosition()); |
| return (cell != null |
| && super.matches(natTable, event, regionLabels) |
| && cell.getConfigLabels().getLabels().contains(this.labelToMatch) ); |
| } |
| |
| } |