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
Expand Up @@ -90,6 +90,7 @@ Export-Package: org.eclipse.nebula.widgets.nattable;version="2.6.0",
org.eclipse.nebula.widgets.nattable.group.performance.event;version="2.6.0",
org.eclipse.nebula.widgets.nattable.group.performance.gui;version="2.6.0",
org.eclipse.nebula.widgets.nattable.group.performance.painter;version="2.6.0",
org.eclipse.nebula.widgets.nattable.groupby;version="2.6.0",
org.eclipse.nebula.widgets.nattable.hideshow;version="2.6.0",
org.eclipse.nebula.widgets.nattable.hideshow.command;version="2.6.0",
org.eclipse.nebula.widgets.nattable.hideshow.event;version="2.6.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2020 Original authors and others.
* Copyright (c) 2012, 2025 Original authors 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 @@ -33,4 +33,8 @@ private GridRegion() {
public static final String BODY = "BODY"; //$NON-NLS-1$
public static final String DATAGRID = "DATAGRID"; //$NON-NLS-1$
public static final String FILTER_ROW = "FILTER_ROW"; //$NON-NLS-1$
/**
* @since 2.6
*/
public static final String GROUP_BY_REGION = "GROUP_BY_REGION"; //$NON-NLS-1$
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*******************************************************************************
* Copyright (c) 2025 Dirk Fauth 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:
* Dirk Fauth <dirk.fauth@googlemail.com> - initial API and implementation
*******************************************************************************/
package org.eclipse.nebula.widgets.nattable.groupby;

import org.eclipse.nebula.widgets.nattable.command.ILayerCommand;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;

/**
* Command to trigger a groupBy action.
*
* @since 2.6
*/
public class GroupByCommand implements ILayerCommand {

public enum GroupByAction {
/**
* Action to add indexes an existing grouping.
*/
ADD,
/**
* Action to clear the existing grouping.
*/
CLEAR,
/**
* Action to remove indexes from an existing grouping.
*/
REMOVE,
/**
* Action to set indexes as new grouping which overrides the existing
* grouping.
*/
SET
};

private final GroupByAction action;
private final int[] indexes;

/**
* Performs the specified groupBy action for the given indexes.
*
* @param action
* The groupBy action to perform
* <ul>
* <li>{@link GroupByAction#ADD} - Add the given indexes to the
* existing grouping.</li>
* <li>{@link GroupByAction#CLEAR} - Clears the existing
* grouping. Given indexes will be ignored.</li>
* <li>{@link GroupByAction#REMOVE} - Removes the given indexes
* from the existing grouping.</li>
* <li>{@link GroupByAction#SET} - Set the given indexes which
* overrides the existing grouping.</li>
* </ul>
* @param indexes
* The indexes of the columns/rows that should be grouped.
*/
public GroupByCommand(GroupByAction action, int... indexes) {
this.action = action;
this.indexes = indexes;
}

/**
*
* @return The groupBy action to perform.
*/
public GroupByAction getAction() {
return this.action;
}

/**
*
* @return The indexes of the columns/rows that should be grouped.
*/
public int[] getIndexes() {
return this.indexes;
}

@Override
public GroupByCommand cloneCommand() {
return this;
}

@Override
public boolean convertToTargetLayer(ILayer targetLayer) {
return true;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013, 2021 Dirk Fauth and others.
* Copyright (c) 2013, 2025 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 @@ -52,6 +52,8 @@
import org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer;
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
import org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer;
import org.eclipse.nebula.widgets.nattable.groupby.GroupByCommand;
import org.eclipse.nebula.widgets.nattable.groupby.GroupByCommand.GroupByAction;
import org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer;
import org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform;
import org.eclipse.nebula.widgets.nattable.layer.CompositeLayer;
Expand Down Expand Up @@ -350,7 +352,7 @@ public void widgetSelected(SelectionEvent e) {
groupLastFirstButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
bodyLayerStack.groupByModel.setGroupByColumnIndexes(1, 0);
natTable.doCommand(new GroupByCommand(GroupByAction.SET, 1, 0));
}
});

Expand All @@ -359,7 +361,7 @@ public void widgetSelected(SelectionEvent e) {
groupFirstLastButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
bodyLayerStack.groupByModel.setGroupByColumnIndexes(0, 1);
natTable.doCommand(new GroupByCommand(GroupByAction.SET, 0, 1));
}
});

Expand All @@ -368,7 +370,7 @@ public void widgetSelected(SelectionEvent e) {
groupLastMarriedButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
bodyLayerStack.groupByModel.setGroupByColumnIndexes(1, 5);
natTable.doCommand(new GroupByCommand(GroupByAction.SET, 1, 5));
}
});

Expand All @@ -377,7 +379,7 @@ public void widgetSelected(SelectionEvent e) {
clearGroupByButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
bodyLayerStack.groupByModel.clearGroupByColumnIndexes();
natTable.doCommand(new GroupByCommand(GroupByAction.CLEAR));
}
});

Expand Down
Loading