From a2cfb094af13e8e11d6b49e1804fad79d5d5fc9a Mon Sep 17 00:00:00 2001 From: Dirk Fauth Date: Mon, 5 Jan 2026 07:48:18 +0100 Subject: [PATCH] Impl #180 - FilterRowComboBoxCellEditor can not be opened in dialog Signed-off-by: Dirk Fauth --- .../nattable/edit/gui/CellEditDialog.java | 33 ++++- .../nattable/edit/gui/ICellEditDialog.java | 13 +- .../filterrow/combobox/FilterNatCombo.java | 4 +- .../combobox/FilterRowComboBoxCellEditor.java | 11 +- ...038_ExtendedExcelLikeFilterRowExample.java | 118 +++++++++++++++++- 5 files changed, 169 insertions(+), 10 deletions(-) diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/edit/gui/CellEditDialog.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/edit/gui/CellEditDialog.java index a9a62818d..5e1cfd660 100644 --- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/edit/gui/CellEditDialog.java +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/edit/gui/CellEditDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2020 Dirk Fauth and others. + * Copyright (c) 2013, 2026 Dirk Fauth and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -15,6 +15,7 @@ import java.util.Map; import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.nebula.widgets.nattable.Messages; @@ -22,6 +23,7 @@ import org.eclipse.nebula.widgets.nattable.edit.DialogEditHandler; import org.eclipse.nebula.widgets.nattable.edit.EditTypeEnum; import org.eclipse.nebula.widgets.nattable.edit.ICellEditHandler; +import org.eclipse.nebula.widgets.nattable.edit.InlineEditHandler; import org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor; import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell; import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum; @@ -206,11 +208,29 @@ protected Control createDialogArea(Composite parent) { .applyTo(customMessageLabel); } + // If the dialog should commit the editor on edit like in the inline + // mode, we need to wrap the existing cell edit handler to commit the + // editor value in the data model directly and commit it in the dialog + // to be consistent. + ICellEditHandler eh = this.cellEditHandler; + if ((boolean) this.editDialogSettings.getOrDefault(DIALOG_COMMIT_EDITOR_ON_EDIT, Boolean.FALSE)) { + eh = new InlineEditHandler( + this.cell.getLayer(), + this.cell.getColumnPosition(), + this.cell.getRowPosition()) { + @Override + public boolean commit(Object canonicalValue, MoveDirectionEnum direction) { + CellEditDialog.this.cellEditHandler.commit(canonicalValue, direction); + return super.commit(canonicalValue, direction); + } + }; + } + // activate the new editor this.cellEditor.activateCell(panel, this.originalCanonicalValue, EditModeEnum.DIALOG, - this.cellEditHandler, + eh, this.cell, this.configRegistry); @@ -232,6 +252,15 @@ protected Control createDialogArea(Composite parent) { return panel; } + @Override + protected void createButtonsForButtonBar(Composite parent) { + if ((boolean) this.editDialogSettings.getOrDefault(DIALOG_COMMIT_EDITOR_ON_EDIT, Boolean.FALSE)) { + createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CLOSE_LABEL, true); + } else { + super.createButtonsForButtonBar(parent); + } + } + @Override public Object getCommittedValue() { return this.cellEditHandler.getCommittedValue(); diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/edit/gui/ICellEditDialog.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/edit/gui/ICellEditDialog.java index c060de262..fba630b74 100644 --- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/edit/gui/ICellEditDialog.java +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/edit/gui/ICellEditDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2020 Dirk Fauth and others. + * Copyright (c) 2013, 2026 Dirk Fauth and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -59,6 +59,16 @@ public interface ICellEditDialog { * value needs to be a {@link java.lang.String}. */ String DIALOG_MESSAGE = "DIALOG_MESSAGE"; //$NON-NLS-1$ + /** + * Key to specify whether the cell editor shown in the dialog should + * directly commit on editing like in the inline mode, or if it should + * commit only on clicking the OK button. If set to true there + * will be also no OK/Cancel buttons but only a Close button. The default is + * false. The value needs to be a {@link java.lang.Boolean}. + * + * @since 2.7 + */ + String DIALOG_COMMIT_EDITOR_ON_EDIT = "DIALOG_COMMIT_EDITOR_ON_EDIT"; //$NON-NLS-1$ /** * @return The canonical value that was committed to the editor control. @@ -120,6 +130,7 @@ public interface ICellEditDialog { * @see ICellEditDialog#DIALOG_SHELL_SIZE * @see ICellEditDialog#DIALOG_SHELL_RESIZABLE * @see ICellEditDialog#DIALOG_MESSAGE + * @see ICellEditDialog#DIALOG_COMMIT_EDITOR_ON_EDIT * @see EditConfigAttributes#EDIT_DIALOG_SETTINGS */ void setDialogSettings(Map editDialogSettings); diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/filterrow/combobox/FilterNatCombo.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/filterrow/combobox/FilterNatCombo.java index 5d67fc90e..28c30f87b 100644 --- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/filterrow/combobox/FilterNatCombo.java +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/filterrow/combobox/FilterNatCombo.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2024 Dirk Fauth and others. + * Copyright (c) 2013, 2026 Dirk Fauth and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -534,7 +534,7 @@ public void widgetSelected(SelectionEvent e) { @Override protected void setDropdownSelection(String[] selection) { super.setDropdownSelection(selection); - if (this.selectAllItemViewer != null) { + if (this.selectAllItemViewer != null && !this.selectAllItemViewer.getControl().isDisposed()) { this.selectAllItemViewer.refresh(); } } diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/filterrow/combobox/FilterRowComboBoxCellEditor.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/filterrow/combobox/FilterRowComboBoxCellEditor.java index f1f8fdb36..8c676bba6 100644 --- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/filterrow/combobox/FilterRowComboBoxCellEditor.java +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/filterrow/combobox/FilterRowComboBoxCellEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2025 Dirk Fauth and others. + * Copyright (c) 2013, 2026 Dirk Fauth and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -224,7 +224,12 @@ public void keyPressed(KeyEvent event) { if (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR || event.keyCode == SWT.ESC) { - close(); + + if (FilterRowComboBoxCellEditor.this.editMode == EditModeEnum.INLINE) { + close(); + } else { + combo.hideDropdownControl(); + } } } }); @@ -336,7 +341,7 @@ public boolean commit(MoveDirectionEnum direction, boolean closeAfterCommit) { if (!isClosed()) { try { Object canonicalValue = getCanonicalValue(); - if (!canonicalValuesEquals(canonicalValue)) { + if (!canonicalValuesEquals(canonicalValue) || this.editMode == EditModeEnum.DIALOG) { if (super.commit(direction, closeAfterCommit)) { this.currentCanonicalValue = canonicalValue; diff --git a/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_600_GlazedLists/_603_Filter/_6038_ExtendedExcelLikeFilterRowExample.java b/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_600_GlazedLists/_603_Filter/_6038_ExtendedExcelLikeFilterRowExample.java index a78509e15..ff8851d67 100644 --- a/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_600_GlazedLists/_603_Filter/_6038_ExtendedExcelLikeFilterRowExample.java +++ b/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_600_GlazedLists/_603_Filter/_6038_ExtendedExcelLikeFilterRowExample.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2025 Dirk Fauth and others. + * Copyright (c) 2025, 2026 Dirk Fauth and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -23,6 +23,7 @@ import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.nebula.widgets.nattable.NatTable; import org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration; +import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes; import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry; import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration; import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry; @@ -34,14 +35,19 @@ import org.eclipse.nebula.widgets.nattable.dataset.person.ExtendedPersonWithAddress; import org.eclipse.nebula.widgets.nattable.dataset.person.PersonService; import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes; +import org.eclipse.nebula.widgets.nattable.edit.gui.ICellEditDialog; import org.eclipse.nebula.widgets.nattable.examples.AbstractNatExample; import org.eclipse.nebula.widgets.nattable.examples.runner.StandaloneNatExampleRunner; import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer; import org.eclipse.nebula.widgets.nattable.extension.glazedlists.filterrow.ComboBoxFilterRowHeaderComposite; +import org.eclipse.nebula.widgets.nattable.filterrow.combobox.ComboBoxFilterIconPainter; +import org.eclipse.nebula.widgets.nattable.filterrow.combobox.ComboBoxFilterRowConfiguration; import org.eclipse.nebula.widgets.nattable.filterrow.combobox.ComboBoxFilterUtils; import org.eclipse.nebula.widgets.nattable.filterrow.combobox.FilterRowCategoryValueMapper; +import org.eclipse.nebula.widgets.nattable.filterrow.combobox.FilterRowComboBoxCellEditor; import org.eclipse.nebula.widgets.nattable.freeze.CompositeFreezeLayer; import org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer; +import org.eclipse.nebula.widgets.nattable.grid.GridRegion; import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider; import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider; import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider; @@ -56,18 +62,24 @@ import org.eclipse.nebula.widgets.nattable.layer.ILayer; import org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler; import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer; +import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes; +import org.eclipse.nebula.widgets.nattable.style.DisplayMode; +import org.eclipse.nebula.widgets.nattable.style.Style; import org.eclipse.nebula.widgets.nattable.ui.menu.DebugMenuConfiguration; import org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration; import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder; +import org.eclipse.nebula.widgets.nattable.util.GUIHelper; import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; import ca.odell.glazedlists.EventList; import ca.odell.glazedlists.FilterList; @@ -204,7 +216,8 @@ public Control createExampleControl(Composite parent) { columnPropertyAccessor, columnHeaderLayer, columnHeaderDataProvider, - configRegistry); + configRegistry, + false); // build the row header layer IDataProvider rowHeaderDataProvider = @@ -248,6 +261,64 @@ public Control createExampleControl(Composite parent) { natTable.setConfigRegistry(configRegistry); natTable.addConfiguration(new DefaultNatTableStyleConfiguration()); + natTable.addConfiguration(new AbstractRegistryConfiguration() { + + @Override + public void configureRegistry(IConfigRegistry configRegistry) { + configRegistry.registerConfigAttribute( + EditConfigAttributes.OPEN_IN_DIALOG, + Boolean.FALSE, + DisplayMode.EDIT, + GridRegion.FILTER_ROW); + + // configure a custom style for the filter row editor in a + // dialog + Style cellStyle = new Style(); + cellStyle.setAttributeValue( + CellStyleAttributes.BACKGROUND_COLOR, + GUIHelper.COLOR_WHITE); + configRegistry.registerConfigAttribute( + CellConfigAttributes.CELL_STYLE, + cellStyle, + DisplayMode.EDIT, + GridRegion.FILTER_ROW); + + // configure custom dialog settings + Display display = Display.getCurrent(); + Map editDialogSettings = new HashMap<>(); + editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_TITLE, "Column Filter"); + editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_RESIZABLE, Boolean.TRUE); + + Point size = new Point(400, 300); + editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_SIZE, size); + + int screenWidth = display.getBounds().width; + int screenHeight = display.getBounds().height; + Point location = new Point( + (screenWidth / (2 * display.getMonitors().length)) - (size.x / 2), + (screenHeight / 2) - (size.y / 2)); + editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_LOCATION, location); + + // add custum message + editDialogSettings.put(ICellEditDialog.DIALOG_MESSAGE, "Select the filter values to apply:"); + + configRegistry.registerConfigAttribute( + EditConfigAttributes.EDIT_DIALOG_SETTINGS, + editDialogSettings, + DisplayMode.EDIT, + GridRegion.FILTER_ROW); + + } + }); + + FilterRowComboBoxCellEditor editor = new FilterRowComboBoxCellEditor(filterRowHeaderLayer.getComboBoxDataProvider(), 10); + editor.configureDropdownFilter(true, true); + + natTable.addConfiguration(new ComboBoxFilterRowConfiguration( + editor, + new ComboBoxFilterIconPainter(filterRowHeaderLayer.getComboBoxDataProvider()), + filterRowHeaderLayer.getComboBoxDataProvider())); + natTable.addConfiguration(new HeaderMenuConfiguration(natTable) { @Override protected PopupMenuBuilder createCornerMenu(NatTable natTable) { @@ -339,6 +410,49 @@ public void widgetSelected(SelectionEvent e) { } }); + // Add checkbox to open filter in dialog + Button openInDialogCheckbox = new Button(buttonPanel, SWT.CHECK); + Button closeButtonCheckbox = new Button(buttonPanel, SWT.CHECK); + + openInDialogCheckbox.setText("Open Filter in Dialog"); + openInDialogCheckbox.setSelection(false); + openInDialogCheckbox.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean selected = openInDialogCheckbox.getSelection(); + + configRegistry.registerConfigAttribute( + EditConfigAttributes.OPEN_IN_DIALOG, + selected, + DisplayMode.EDIT, + GridRegion.FILTER_ROW); + + closeButtonCheckbox.setEnabled(selected); + } + }); + + // Add checkbox to control commit on edit behavior + closeButtonCheckbox.setText("Commit on Edit"); + closeButtonCheckbox.setSelection(false); + closeButtonCheckbox.setEnabled(false); + closeButtonCheckbox.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean selected = closeButtonCheckbox.getSelection(); + + Map editDialogSettings = configRegistry.getConfigAttribute( + EditConfigAttributes.EDIT_DIALOG_SETTINGS, + DisplayMode.EDIT, + GridRegion.FILTER_ROW); + editDialogSettings.put(ICellEditDialog.DIALOG_COMMIT_EDITOR_ON_EDIT, selected); + configRegistry.registerConfigAttribute( + EditConfigAttributes.EDIT_DIALOG_SETTINGS, + editDialogSettings, + DisplayMode.EDIT, + GridRegion.FILTER_ROW); + } + }); + return container; }