Search in sources :

Example 11 with MultiColumnReorderCommand

use of org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand in project nebula.widgets.nattable by eclipse.

the class ColumnGroupReorderLayer method reorderColumnGroup.

/**
 * @param fromColumnPosition
 *            The column position of a column in the column group that
 *            should be reordered.
 * @param toColumnPosition
 *            The column position to which a column group should be
 *            reordered to.
 * @return <code>true</code> if the reorder command was executed and
 *         consumed successfully
 */
public boolean reorderColumnGroup(int fromColumnPosition, int toColumnPosition) {
    int fromColumnIndex = this.underlyingLayer.getColumnIndexByPosition(fromColumnPosition);
    List<Integer> fromColumnPositions = getColumnGroupPositions(fromColumnIndex);
    return this.underlyingLayer.doCommand(new MultiColumnReorderCommand(this, fromColumnPositions, toColumnPosition));
}
Also used : MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand)

Example 12 with MultiColumnReorderCommand

use of org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand in project nebula.widgets.nattable by eclipse.

the class ReorderColumnsAndGroupsCommandHandler method doCommand.

/**
 * Check if any column belongs to a group. If yes, add all columns in that
 * group. Assumes that the 'toLocation' is not inside another group
 */
@Override
protected boolean doCommand(ReorderColumnsAndGroupsCommand command) {
    final ILayer underlyingLayer = this.columnGroupReorderLayer.getUnderlyingLayer();
    List<String> groupsProcessed = new ArrayList<String>();
    List<Integer> fromColumnPositions = command.getFromColumnPositions();
    List<Integer> fromColumnPositionsWithGroupColumns = new ArrayList<Integer>();
    for (Integer fromColumnPosition : fromColumnPositions) {
        int fromColumnIndex = underlyingLayer.getColumnIndexByPosition(fromColumnPosition.intValue());
        ColumnGroupModel model = this.columnGroupReorderLayer.getModel();
        if (model.isPartOfAGroup(fromColumnIndex)) {
            String groupName = model.getColumnGroupByIndex(fromColumnIndex).getName();
            if (!groupsProcessed.contains(groupName)) {
                groupsProcessed.add(groupName);
                fromColumnPositionsWithGroupColumns.addAll(this.columnGroupReorderLayer.getColumnGroupPositions(fromColumnIndex));
            }
        } else {
            fromColumnPositionsWithGroupColumns.add(fromColumnPosition);
        }
    }
    return underlyingLayer.doCommand(new MultiColumnReorderCommand(this.columnGroupReorderLayer, fromColumnPositionsWithGroupColumns, command.getToColumnPosition(), command.isReorderToLeftEdge()));
}
Also used : MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ArrayList(java.util.ArrayList) ColumnGroupModel(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel)

Example 13 with MultiColumnReorderCommand

use of org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand in project nebula.widgets.nattable by eclipse.

the class ColumnGroupsCommandHandler method handleGroupColumnsCommand.

public void handleGroupColumnsCommand(String columnGroupName) {
    try {
        List<Integer> selectedPositions = new ArrayList<Integer>(this.columnIndexesToPositionsMap.size());
        int[] fullySelectedColumns = new int[this.columnIndexesToPositionsMap.size()];
        int count = 0;
        for (Integer columnIndex : this.columnIndexesToPositionsMap.keySet()) {
            fullySelectedColumns[count++] = columnIndex.intValue();
            selectedPositions.add(this.columnIndexesToPositionsMap.get(columnIndex));
        }
        this.model.addColumnsIndexesToGroup(columnGroupName, fullySelectedColumns);
        this.selectionLayer.doCommand(new MultiColumnReorderCommand(this.selectionLayer, selectedPositions, selectedPositions.get(0)));
        this.selectionLayer.clear();
    } catch (Throwable t) {
    }
    this.contextLayer.fireLayerEvent(new GroupColumnsEvent(this.contextLayer));
}
Also used : GroupColumnsEvent(org.eclipse.nebula.widgets.nattable.group.event.GroupColumnsEvent) MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) ArrayList(java.util.ArrayList) Point(org.eclipse.swt.graphics.Point)

Example 14 with MultiColumnReorderCommand

use of org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand in project nebula.widgets.nattable by eclipse.

the class HierarchicalTreeLayer method doCommand.

@Override
public boolean doCommand(ILayerCommand command) {
    if (command instanceof SelectCellCommand && command.convertToTargetLayer(this)) {
        // perform selection of level on level header click
        SelectCellCommand selection = (SelectCellCommand) command;
        if (isLevelHeaderColumn(selection.getColumnPosition())) {
            ILayerCell clickedCell = getCellByPosition(selection.getColumnPosition(), selection.getRowPosition());
            // calculate number of header columns to the right
            int levelHeaderCount = 0;
            for (int i = this.levelHeaderPositions.length - 1; i >= 0; i--) {
                if (this.levelHeaderPositions[i] >= selection.getColumnPosition()) {
                    levelHeaderCount++;
                }
            }
            SelectRegionCommand selectRegion = new SelectRegionCommand(this, clickedCell.getColumnPosition() + 1, clickedCell.getOriginRowPosition(), getColumnCount() - levelHeaderCount - (clickedCell.getColumnPosition()), clickedCell.getRowSpan(), selection.isShiftMask(), selection.isControlMask());
            this.underlyingLayer.doCommand(selectRegion);
            return true;
        }
    } else if (command instanceof ConfigureScalingCommand) {
        this.dpiConverter = ((ConfigureScalingCommand) command).getHorizontalDpiConverter();
    } else if (command instanceof ClientAreaResizeCommand && command.convertToTargetLayer(this)) {
        ClientAreaResizeCommand clientAreaResizeCommand = (ClientAreaResizeCommand) command;
        Rectangle possibleArea = clientAreaResizeCommand.getScrollable().getClientArea();
        // remove the tree level header width from the client area to
        // ensure that the percentage calculation is correct
        possibleArea.width = possibleArea.width - (this.levelHeaderPositions.length * getScaledLevelHeaderWidth());
        clientAreaResizeCommand.setCalcArea(possibleArea);
    } else if (command instanceof ColumnReorderCommand) {
        ColumnReorderCommand crCommand = ((ColumnReorderCommand) command);
        if (!isValidTargetColumnPosition(crCommand.getFromColumnPosition(), crCommand.getToColumnPosition())) {
            // command without doing anything
            return true;
        }
        if (isLevelHeaderColumn(crCommand.getToColumnPosition())) {
            // tree level header
            return super.doCommand(new ColumnReorderCommand(this, crCommand.getFromColumnPosition(), crCommand.getToColumnPosition() + 1));
        }
    } else if (command instanceof MultiColumnReorderCommand) {
        MultiColumnReorderCommand crCommand = ((MultiColumnReorderCommand) command);
        for (int fromColumnPosition : crCommand.getFromColumnPositions()) {
            if (!isValidTargetColumnPosition(fromColumnPosition, crCommand.getToColumnPosition())) {
                // command would be skipped
                return true;
            }
        }
        if (isLevelHeaderColumn(crCommand.getToColumnPosition())) {
            // tree level header
            return super.doCommand(new MultiColumnReorderCommand(this, crCommand.getFromColumnPositions(), crCommand.getToColumnPosition() + 1));
        }
    }
    return super.doCommand(command);
}
Also used : SelectRegionCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand) MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) ConfigureScalingCommand(org.eclipse.nebula.widgets.nattable.layer.command.ConfigureScalingCommand)

Aggregations

MultiColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand)14 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)3 List (java.util.List)2 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)2 DefaultBodyLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack)2 ColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand)2 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)2 EventList (ca.odell.glazedlists.EventList)1 FilterList (ca.odell.glazedlists.FilterList)1 SortedList (ca.odell.glazedlists.SortedList)1 TransformedList (ca.odell.glazedlists.TransformedList)1 HashMap (java.util.HashMap)1 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 ILayerCommand (org.eclipse.nebula.widgets.nattable.command.ILayerCommand)1 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)1 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)1 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)1 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)1 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)1