Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,13 +15,15 @@
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;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
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;
Expand Down Expand Up @@ -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);

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 <code>true</code> there
* will be also no OK/Cancel buttons but only a Close button. The default is
* <code>false</code>. 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.
Expand Down Expand Up @@ -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<String, Object> editDialogSettings);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
}
}
}
});
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -204,7 +216,8 @@ public Control createExampleControl(Composite parent) {
columnPropertyAccessor,
columnHeaderLayer,
columnHeaderDataProvider,
configRegistry);
configRegistry,
false);

// build the row header layer
IDataProvider rowHeaderDataProvider =
Expand Down Expand Up @@ -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<String, Object> 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) {
Expand Down Expand Up @@ -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<String, Object> 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;
}

Expand Down