diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/fillhandle/action/FillHandleActionHelper.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/fillhandle/action/FillHandleActionHelper.java new file mode 100644 index 000000000..8817e209d --- /dev/null +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/fillhandle/action/FillHandleActionHelper.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2024 Dirk Fauth. + * + * 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: + * Dirk Fauth - initial API and implementation + ******************************************************************************/ +package org.eclipse.nebula.widgets.nattable.fillhandle.action; + +import java.util.Date; +import java.util.function.Consumer; +import java.util.function.Supplier; + +import org.eclipse.nebula.widgets.nattable.Messages; +import org.eclipse.nebula.widgets.nattable.NatTable; +import org.eclipse.nebula.widgets.nattable.copy.InternalCellClipboard; +import org.eclipse.nebula.widgets.nattable.fillhandle.command.FillHandlePasteCommand; +import org.eclipse.nebula.widgets.nattable.fillhandle.command.FillHandlePasteCommand.FillHandleOperation; +import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell; +import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MenuAdapter; +import org.eclipse.swt.events.MenuEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; + +/** + * Helper class for the fill handle actions. + * + * @since 2.5 + */ +public final class FillHandleActionHelper { + + private FillHandleActionHelper() { + // private default constructor for helper class + } + + /** + * Check if the menu should be shown for selecting copy or series fill + * operation. + * + * @param natTable + * The NatTable instance on which the operation is performed. + * @param clipboard + * The internal clipboard that carries the cells for the copy + * & paste operation triggered by using the fill handle. + * @return true if the menu should be shown, false + * if not. + */ + public static boolean showMenu(NatTable natTable, InternalCellClipboard clipboard) { + if (clipboard == null || clipboard.getCopiedCells() == null) { + return false; + } + + Class type = null; + for (ILayerCell[] cells : clipboard.getCopiedCells()) { + for (ILayerCell cell : cells) { + if (cell.getDataValue() == null) { + return false; + } else { + if (type == null) { + type = cell.getDataValue().getClass(); + if (!Number.class.isAssignableFrom(type) + && !Date.class.isAssignableFrom(type)) { + return false; + } + } else if (type != cell.getDataValue().getClass()) { + return false; + } + } + } + } + return true; + } + + /** + * Create the menu that should be opened on a fill operation. + * + * @param natTable + * The NatTable instance on which the operation is performed and + * the menu should be connected to. + * @param directionProvider + * The {@link Supplier} that provides the The direction in which + * the fill handle was dragged. + * @param resetRunnable + * The {@link Runnable} that should be executed when the menu is + * hidden. + * @return The menu that should be opened on a fill operation. + */ + public static Menu createFillHandleMenu(NatTable natTable, Supplier directionProvider, Consumer resetRunnable) { + Menu menu = new Menu(natTable); + MenuItem copyItem = new MenuItem(menu, SWT.PUSH); + copyItem.setText(Messages.getLocalizedMessage("%FillHandleDragMode.menu.item.copy")); //$NON-NLS-1$ + copyItem.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + natTable.doCommand( + new FillHandlePasteCommand( + FillHandleOperation.COPY, + directionProvider.get(), + natTable.getConfigRegistry())); + } + }); + MenuItem seriesItem = new MenuItem(menu, SWT.PUSH); + seriesItem.setText(Messages.getLocalizedMessage("%FillHandleDragMode.menu.item.series")); //$NON-NLS-1$ + seriesItem.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + natTable.doCommand( + new FillHandlePasteCommand( + FillHandleOperation.SERIES, + directionProvider.get(), + natTable.getConfigRegistry())); + } + }); + + // add a menu listener to reset the fill state when the menu is + // closed + menu.addMenuListener(new MenuAdapter() { + @Override + public void menuHidden(MenuEvent e) { + // perform the reset operation asynchronously because on + // several OS the hide event is processed BEFORE the + // selection event + Display.getDefault().asyncExec(() -> resetRunnable.accept(natTable)); + } + }); + + // add the dispose listener for disposing the menu + natTable.addDisposeListener(e -> menu.dispose()); + + return menu; + } +} diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/fillhandle/action/FillHandleColumnAction.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/fillhandle/action/FillHandleColumnAction.java new file mode 100644 index 000000000..db9e353dd --- /dev/null +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/fillhandle/action/FillHandleColumnAction.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * Copyright (c) 2024 Dirk Fauth. + * + * 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: + * Dirk Fauth - initial API and implementation + ******************************************************************************/ +package org.eclipse.nebula.widgets.nattable.fillhandle.action; + +import org.eclipse.nebula.widgets.nattable.NatTable; +import org.eclipse.nebula.widgets.nattable.copy.InternalCellClipboard; +import org.eclipse.nebula.widgets.nattable.copy.command.CopyDataToClipboardCommand; +import org.eclipse.nebula.widgets.nattable.fillhandle.command.FillHandlePasteCommand; +import org.eclipse.nebula.widgets.nattable.fillhandle.command.FillHandlePasteCommand.FillHandleOperation; +import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer; +import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum; +import org.eclipse.nebula.widgets.nattable.ui.action.IMouseAction; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Menu; + +/** + * {@link IMouseAction} that can be registered on double clicks on the fill + * handle to trigger an automatic fill operation for the whole column. + * + * @since 2.5 + */ +public class FillHandleColumnAction implements IMouseAction { + + protected SelectionLayer selectionLayer; + protected InternalCellClipboard clipboard; + + protected Menu menu; + + /** + * + * @param selectionLayer + * The {@link SelectionLayer} needed to determine the fill handle + * region and perform the update command. + * @param clipboard + * The internal clipboard that carries the cells for the copy + * & paste operation triggered by using the fill handle. + */ + public FillHandleColumnAction(SelectionLayer selectionLayer, InternalCellClipboard clipboard) { + if (selectionLayer == null) { + throw new IllegalArgumentException("SelectionLayer can not be null"); //$NON-NLS-1$ + } + this.selectionLayer = selectionLayer; + this.clipboard = clipboard; + } + + @Override + public void run(NatTable natTable, MouseEvent event) { + if (this.selectionLayer.hasColumnSelection()) { + + if (natTable.doCommand( + new CopyDataToClipboardCommand( + "\t", //$NON-NLS-1$ + System.getProperty("line.separator"), //$NON-NLS-1$ + natTable.getConfigRegistry()))) { + + // set the fill handle region to be the whole column + int startRow = this.selectionLayer.getSelectedRowPositions().iterator().next().start; + Rectangle region = new Rectangle( + this.selectionLayer.getSelectedColumnPositions()[0], + startRow, + this.selectionLayer.getSelectedColumnPositions().length, + this.selectionLayer.getRowCount() - startRow); + this.selectionLayer.setFillHandleRegion(region); + + if (this.clipboard != null) { + if (showMenu(natTable)) { + openMenu(natTable); + } else { + natTable.doCommand( + new FillHandlePasteCommand( + FillHandleOperation.COPY, + MoveDirectionEnum.DOWN, + natTable.getConfigRegistry())); + reset(natTable); + } + } else { + natTable.doCommand( + new FillHandlePasteCommand( + FillHandleOperation.COPY, + MoveDirectionEnum.DOWN, + natTable.getConfigRegistry())); + reset(natTable); + } + } else { + reset(natTable); + } + } + } + + /** + * Check if the menu should be shown for selecting copy or series fill + * operation. + * + * @param natTable + * The NatTable instance on which the operation is performed. + * @return true if the menu should be shown, false + * if not. + */ + protected boolean showMenu(final NatTable natTable) { + return FillHandleActionHelper.showMenu(natTable, this.clipboard); + } + + /** + * Opens a menu that enables a user to select whether values should simply + * be copied or if a series should be filled. + * + * @param natTable + * The NatTable instance on which the operation is performed. + */ + protected void openMenu(final NatTable natTable) { + // lazily create the menu + if (this.menu == null || this.menu.isDisposed()) { + this.menu = FillHandleActionHelper.createFillHandleMenu( + natTable, + () -> MoveDirectionEnum.DOWN, + (n) -> reset(n)); + } + + this.menu.setVisible(true); + } + + /** + * Reset the fill handle region in the {@link SelectionLayer}, clear the + * clipboard and redraw the given NatTable. + * + * @param natTable + * The NatTable instance on which the operation is performed. + */ + protected void reset(NatTable natTable) { + this.selectionLayer.setFillHandleRegion(null); + this.clipboard.clear(); + if (!natTable.isDisposed()) { + natTable.redraw(); + } + } + +} diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/fillhandle/action/FillHandleDragMode.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/fillhandle/action/FillHandleDragMode.java index 05b0fec85..870722301 100644 --- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/fillhandle/action/FillHandleDragMode.java +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/fillhandle/action/FillHandleDragMode.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2015, 2020 CEA LIST and others. + * Copyright (c) 2015, 2024 CEA LIST and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -12,9 +12,6 @@ *****************************************************************************/ package org.eclipse.nebula.widgets.nattable.fillhandle.action; -import java.util.Date; - -import org.eclipse.nebula.widgets.nattable.Messages; import org.eclipse.nebula.widgets.nattable.NatTable; import org.eclipse.nebula.widgets.nattable.config.Direction; import org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate; @@ -30,17 +27,10 @@ import org.eclipse.nebula.widgets.nattable.style.DisplayMode; import org.eclipse.nebula.widgets.nattable.ui.action.IDragMode; import org.eclipse.nebula.widgets.nattable.viewport.action.AutoScrollDragMode; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.MenuAdapter; -import org.eclipse.swt.events.MenuEvent; import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; /** * The {@link IDragMode} that is registered to get triggered for dragging the @@ -247,29 +237,7 @@ public void mouseUp(final NatTable natTable, MouseEvent event) { * if not. */ protected boolean showMenu(final NatTable natTable) { - if (this.clipboard == null || this.clipboard.getCopiedCells() == null) { - return false; - } - - Class type = null; - for (ILayerCell[] cells : this.clipboard.getCopiedCells()) { - for (ILayerCell cell : cells) { - if (cell.getDataValue() == null) { - return false; - } else { - if (type == null) { - type = cell.getDataValue().getClass(); - if (!Number.class.isAssignableFrom(type) - && !Date.class.isAssignableFrom(type)) { - return false; - } - } else if (type != cell.getDataValue().getClass()) { - return false; - } - } - } - } - return true; + return FillHandleActionHelper.showMenu(natTable, this.clipboard); } /** @@ -282,46 +250,10 @@ protected boolean showMenu(final NatTable natTable) { protected void openMenu(final NatTable natTable) { // lazily create the menu if (this.menu == null || this.menu.isDisposed()) { - this.menu = new Menu(natTable); - MenuItem copyItem = new MenuItem(this.menu, SWT.PUSH); - copyItem.setText(Messages.getLocalizedMessage("%FillHandleDragMode.menu.item.copy")); //$NON-NLS-1$ - copyItem.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - natTable.doCommand( - new FillHandlePasteCommand( - FillHandleOperation.COPY, - FillHandleDragMode.this.direction, - natTable.getConfigRegistry())); - } - }); - MenuItem seriesItem = new MenuItem(this.menu, SWT.PUSH); - seriesItem.setText(Messages.getLocalizedMessage("%FillHandleDragMode.menu.item.series")); //$NON-NLS-1$ - seriesItem.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - natTable.doCommand( - new FillHandlePasteCommand( - FillHandleOperation.SERIES, - FillHandleDragMode.this.direction, - natTable.getConfigRegistry())); - } - }); - - // add a menu listener to reset the fill state when the menu is - // closed - this.menu.addMenuListener(new MenuAdapter() { - @Override - public void menuHidden(MenuEvent e) { - // perform the reset operation asynchronously because on - // several OS the hide event is processed BEFORE the - // selection event - Display.getDefault().asyncExec(() -> reset(natTable)); - } - }); - - // add the dispose listener for disposing the menu - natTable.addDisposeListener(e -> FillHandleDragMode.this.menu.dispose()); + this.menu = FillHandleActionHelper.createFillHandleMenu( + natTable, + () -> FillHandleDragMode.this.direction, + (n) -> reset(n)); } this.menu.setVisible(true); diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/fillhandle/config/FillHandleConfiguration.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/fillhandle/config/FillHandleConfiguration.java index 7aecada39..3508e7e35 100644 --- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/fillhandle/config/FillHandleConfiguration.java +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/fillhandle/config/FillHandleConfiguration.java @@ -17,6 +17,7 @@ import org.eclipse.nebula.widgets.nattable.copy.InternalCellClipboard; import org.eclipse.nebula.widgets.nattable.copy.command.InternalCopyDataCommandHandler; import org.eclipse.nebula.widgets.nattable.fillhandle.FillHandleLayerPainter; +import org.eclipse.nebula.widgets.nattable.fillhandle.action.FillHandleColumnAction; import org.eclipse.nebula.widgets.nattable.fillhandle.action.FillHandleCursorAction; import org.eclipse.nebula.widgets.nattable.fillhandle.action.FillHandleDragMode; import org.eclipse.nebula.widgets.nattable.fillhandle.command.FillHandlePasteCommandHandler; @@ -90,6 +91,12 @@ public void configureUiBindings(UiBindingRegistry uiBindingRegistry) { matcher, new FillHandleDragMode(this.selectionLayer, this.clipboard)); + // Mouse double click + // trigger the handle double click operation + uiBindingRegistry.registerDoubleClickBinding( + matcher, + new FillHandleColumnAction(this.selectionLayer, this.clipboard)); + // Mouse click // ensure no selection is triggered on mouse down on the handle uiBindingRegistry.registerFirstMouseDownBinding( diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/formula/action/FormulaFillHandleActionHelper.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/formula/action/FormulaFillHandleActionHelper.java new file mode 100644 index 000000000..bfe44417c --- /dev/null +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/formula/action/FormulaFillHandleActionHelper.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2024 Dirk Fauth. + * + * 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: + * Dirk Fauth - initial API and implementation + ******************************************************************************/ +package org.eclipse.nebula.widgets.nattable.formula.action; + +import java.util.Date; + +import org.eclipse.nebula.widgets.nattable.NatTable; +import org.eclipse.nebula.widgets.nattable.copy.InternalCellClipboard; +import org.eclipse.nebula.widgets.nattable.formula.FormulaDataProvider; +import org.eclipse.nebula.widgets.nattable.formula.command.DisableFormulaEvaluationCommand; +import org.eclipse.nebula.widgets.nattable.formula.command.EnableFormulaEvaluationCommand; +import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell; + +/** + * Helper class for formula fill handle actions. + * + * @since 2.5 + */ +public final class FormulaFillHandleActionHelper { + + private FormulaFillHandleActionHelper() { + // private default constructor for helper class + } + + /** + * Check if the menu should be shown for selecting copy or series fill + * operation. Uses the {@link FormulaDataProvider} to use the data type for + * number evaluations. + * + * @param natTable + * The NatTable instance on which the operation is performed. + * @param clipboard + * The internal clipboard that carries the cells for the copy + * & paste operation triggered by using the fill handle. + * @param dataProvider + * The {@link FormulaDataProvider} that is needed to determine + * whether a value is a number value. + * @return true if the menu should be shown, false + * if not. + */ + public static boolean showMenu(NatTable natTable, InternalCellClipboard clipboard, FormulaDataProvider dataProvider) { + natTable.doCommand(new DisableFormulaEvaluationCommand()); + + try { + Class type = null; + for (ILayerCell[] cells : clipboard.getCopiedCells()) { + for (ILayerCell cell : cells) { + if (cell != null) { + if (cell.getDataValue() == null) { + return false; + } else { + if (type == null) { + type = cell.getDataValue().getClass(); + if (!Number.class.isAssignableFrom(type) + && !Date.class.isAssignableFrom(type) + && (String.class.isAssignableFrom(type) + && !dataProvider.getFormulaParser().isNumber((String) cell.getDataValue()))) { + return false; + } + } else if (type != cell.getDataValue().getClass()) { + return false; + } + } + } + } + } + } finally { + natTable.doCommand(new EnableFormulaEvaluationCommand()); + } + + return true; + } +} diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/formula/action/FormulaFillHandleColumnAction.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/formula/action/FormulaFillHandleColumnAction.java new file mode 100644 index 000000000..1139b9393 --- /dev/null +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/formula/action/FormulaFillHandleColumnAction.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2024 Dirk Fauth. + * + * 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: + * Dirk Fauth - initial API and implementation + ******************************************************************************/ +package org.eclipse.nebula.widgets.nattable.formula.action; + +import java.math.BigDecimal; + +import org.eclipse.nebula.widgets.nattable.NatTable; +import org.eclipse.nebula.widgets.nattable.copy.InternalCellClipboard; +import org.eclipse.nebula.widgets.nattable.fillhandle.action.FillHandleColumnAction; +import org.eclipse.nebula.widgets.nattable.formula.FormulaDataProvider; +import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer; + +/** + * Specialized {@link FillHandleColumnAction} that also opens the dialog in case + * of String values that can be converted to {@link BigDecimal} values using the + * {@link FormulaDataProvider}. + * + * @since 2.5 + */ +public class FormulaFillHandleColumnAction extends FillHandleColumnAction { + + protected FormulaDataProvider dataProvider; + + /** + * + * @param selectionLayer + * The {@link SelectionLayer} needed to determine the fill handle + * region and perform the update command. + * @param clipboard + * The internal clipboard that carries the cells for the copy + * & paste operation triggered by using the fill handle. + * @param dataProvider + * The {@link FormulaDataProvider} that is needed to determine + * whether a value is a number value. + */ + public FormulaFillHandleColumnAction(SelectionLayer selectionLayer, InternalCellClipboard clipboard, FormulaDataProvider dataProvider) { + super(selectionLayer, clipboard); + this.dataProvider = dataProvider; + } + + @Override + protected boolean showMenu(NatTable natTable) { + return FormulaFillHandleActionHelper.showMenu(natTable, this.clipboard, this.dataProvider); + } +} diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/formula/action/FormulaFillHandleDragMode.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/formula/action/FormulaFillHandleDragMode.java index 98592d010..8cea5e7ad 100644 --- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/formula/action/FormulaFillHandleDragMode.java +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/formula/action/FormulaFillHandleDragMode.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2015, 2020 CEA LIST. + * Copyright (c) 2015, 2024 CEA LIST. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -13,15 +13,11 @@ package org.eclipse.nebula.widgets.nattable.formula.action; import java.math.BigDecimal; -import java.util.Date; import org.eclipse.nebula.widgets.nattable.NatTable; import org.eclipse.nebula.widgets.nattable.copy.InternalCellClipboard; import org.eclipse.nebula.widgets.nattable.fillhandle.action.FillHandleDragMode; import org.eclipse.nebula.widgets.nattable.formula.FormulaDataProvider; -import org.eclipse.nebula.widgets.nattable.formula.command.DisableFormulaEvaluationCommand; -import org.eclipse.nebula.widgets.nattable.formula.command.EnableFormulaEvaluationCommand; -import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell; import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer; /** @@ -55,35 +51,6 @@ public FormulaFillHandleDragMode(SelectionLayer selectionLayer, InternalCellClip @Override protected boolean showMenu(final NatTable natTable) { - natTable.doCommand(new DisableFormulaEvaluationCommand()); - - try { - Class type = null; - for (ILayerCell[] cells : this.clipboard.getCopiedCells()) { - for (ILayerCell cell : cells) { - if (cell != null) { - if (cell.getDataValue() == null) { - return false; - } else { - if (type == null) { - type = cell.getDataValue().getClass(); - if (!Number.class.isAssignableFrom(type) - && !Date.class.isAssignableFrom(type) - && (String.class.isAssignableFrom(type) - && !this.dataProvider.getFormulaParser().isNumber((String) cell.getDataValue()))) { - return false; - } - } else if (type != cell.getDataValue().getClass()) { - return false; - } - } - } - } - } - } finally { - natTable.doCommand(new EnableFormulaEvaluationCommand()); - } - - return true; + return FormulaFillHandleActionHelper.showMenu(natTable, this.clipboard, this.dataProvider); } } diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/formula/config/DefaultFormulaConfiguration.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/formula/config/DefaultFormulaConfiguration.java index 396870392..64fa89e92 100644 --- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/formula/config/DefaultFormulaConfiguration.java +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/formula/config/DefaultFormulaConfiguration.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2015, 2020 CEA LIST. + * Copyright (c) 2015, 2024 CEA LIST. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -31,6 +31,7 @@ import org.eclipse.nebula.widgets.nattable.formula.FormulaDataProvider; import org.eclipse.nebula.widgets.nattable.formula.FormulaEditDisplayConverter; import org.eclipse.nebula.widgets.nattable.formula.FormulaResultDisplayConverter; +import org.eclipse.nebula.widgets.nattable.formula.action.FormulaFillHandleColumnAction; import org.eclipse.nebula.widgets.nattable.formula.action.FormulaFillHandleDragMode; import org.eclipse.nebula.widgets.nattable.formula.command.DisableFormulaEvaluationCommandHandler; import org.eclipse.nebula.widgets.nattable.formula.command.EnableFormulaEvaluationCommandHandler; @@ -128,13 +129,22 @@ public void configureUiBindings(UiBindingRegistry uiBindingRegistry) { new KeyEventMatcher(SWT.NONE, SWT.ESC), new ClearClipboardAction(this.clipboard)); + FillHandleEventMatcher matcher = new FillHandleEventMatcher((FillHandleLayerPainter) this.selectionLayer.getLayerPainter()); + // Mouse drag // trigger the handle drag operations // Note: we ensure a FillHandleLayerPainter is set in configureLayer uiBindingRegistry.registerFirstMouseDragMode( - new FillHandleEventMatcher((FillHandleLayerPainter) this.selectionLayer.getLayerPainter()), + matcher, new FormulaFillHandleDragMode(this.selectionLayer, this.clipboard, this.dataProvider)); + // Mouse double click + // trigger the handle double click operation + // Note: we ensure a FillHandleLayerPainter is set in configureLayer + uiBindingRegistry.registerFirstDoubleClickBinding( + matcher, + new FormulaFillHandleColumnAction(this.selectionLayer, this.clipboard, this.dataProvider)); + } @Override