Search in sources :

Example 21 with ColumnGroup

use of org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup in project nebula.widgets.nattable by eclipse.

the class ColumnGroupHeaderLayer method setGroupUnbreakable.

/**
 * @see ColumnGroup#setUnbreakable(boolean)
 */
public void setGroupUnbreakable(int columnIndex) {
    ColumnGroup columnGroup = this.model.getColumnGroupByIndex(columnIndex);
    columnGroup.setUnbreakable(true);
}
Also used : ColumnGroup(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup)

Example 22 with ColumnGroup

use of org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup in project nebula.widgets.nattable by eclipse.

the class ColumnGroupHeaderLayer method getConfigLabelsByPosition.

@Override
public LabelStack getConfigLabelsByPosition(int columnPosition, int rowPosition) {
    int columnIndex = getColumnIndexByPosition(columnPosition);
    if (rowPosition == 0 && this.model.isPartOfAGroup(columnIndex)) {
        LabelStack stack = new LabelStack();
        if (getConfigLabelAccumulator() != null) {
            getConfigLabelAccumulator().accumulateConfigLabels(stack, columnPosition, rowPosition);
        }
        stack.addLabel(GridRegion.COLUMN_GROUP_HEADER);
        if (this.model.isPartOfACollapseableGroup(columnIndex)) {
            ColumnGroup group = this.model.getColumnGroupByIndex(columnIndex);
            if (group.isCollapsed()) {
                stack.addLabelOnTop(DefaultColumnGroupHeaderLayerConfiguration.GROUP_COLLAPSED_CONFIG_TYPE);
            } else {
                stack.addLabelOnTop(DefaultColumnGroupHeaderLayerConfiguration.GROUP_EXPANDED_CONFIG_TYPE);
            }
        }
        return stack;
    } else {
        return this.columnHeaderLayer.getConfigLabelsByPosition(columnPosition, rowPosition);
    }
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) ColumnGroup(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup)

Example 23 with ColumnGroup

use of org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup in project nebula.widgets.nattable by eclipse.

the class ColumnGroupReorderLayer method updateColumnGroupModel.

/**
 * Updates the {@link ColumnGroupModel} with respect to a column reordering
 * operation.
 *
 * @param fromColumnPosition
 *            The column position that should be used for determining the
 *            necessary operation.
 * @param toColumnPosition
 *            The column position to which a column should be reordered.
 * @param reorderToLeftEdge
 *            Whether the toPosition should be calculated for attachment to
 *            the left or not.
 * @param fromColumnPositions
 *            The column positions that should be reordered.
 * @return <code>true</code> if only a {@link ColumnGroupModel} modification
 *         was triggered and no column reordering is necessary,
 *         <code>false</code> if additionally a column reordering needs to
 *         be performed.
 * @since 1.3
 */
public boolean updateColumnGroupModel(int fromColumnPosition, int toColumnPosition, boolean reorderToLeftEdge, List<Integer> fromColumnPositions) {
    MoveDirectionEnum moveDirection = ColumnGroupUtils.getMoveDirection(fromColumnPosition, toColumnPosition);
    if (reorderToLeftEdge && toColumnPosition > 0 && MoveDirectionEnum.RIGHT == moveDirection) {
        toColumnPosition--;
    }
    if (fromColumnPosition == -1 || toColumnPosition == -1) {
        log.error(// $NON-NLS-1$
        "Invalid reorder positions, fromPosition: " + fromColumnPosition + ", toPosition: " + // $NON-NLS-1$
        toColumnPosition);
    }
    boolean jump = Math.abs(fromColumnPosition - toColumnPosition) > 1;
    int fromColumnIndex = this.getUnderlyingLayer().getColumnIndexByPosition(fromColumnPosition);
    int toColumnIndex = this.getUnderlyingLayer().getColumnIndexByPosition(toColumnPosition);
    // check if the column to reorder is part of a group
    ColumnGroup fromColumnGroup = this.model.getColumnGroupByIndex(fromColumnIndex);
    ColumnGroup toColumnGroup = this.model.getColumnGroupByIndex(toColumnIndex);
    int[] fromColumnIndexes = getColumnIndexesForPositions(fromColumnPositions);
    boolean consumeCommand = false;
    // without group modifications
    if (fromColumnGroup != null && toColumnGroup != null && fromColumnGroup.getName().equals(toColumnGroup.getName()) && fromColumnPosition == toColumnPosition) {
        // handle first/last column in last group
        if (fromColumnIndexes.length > 1) {
            if (MoveDirectionEnum.RIGHT == moveDirection) {
                // check if there are columns to the left that are reordered
                // too
                int collectionPos = fromColumnPositions.indexOf(Integer.valueOf(fromColumnPosition));
                if (collectionPos > 0) {
                    this.model.insertColumnIndexes(toColumnGroup.getName(), fromColumnIndexes);
                } else {
                    this.model.removeColumnIndexes(fromColumnGroup.getName(), fromColumnIndexes);
                }
            } else if (MoveDirectionEnum.LEFT == moveDirection) {
                // check if there are columns to the right that are
                // reordered too
                int collectionPos = fromColumnPositions.indexOf(Integer.valueOf(fromColumnPosition));
                if (collectionPos == 0) {
                    this.model.insertColumnIndexes(toColumnGroup.getName(), fromColumnIndexes);
                } else {
                    this.model.removeColumnIndexes(fromColumnGroup.getName(), fromColumnIndexes);
                }
            }
        } else {
            // only remove if we are at the edge of a column group
            if (ColumnGroupUtils.isLeftEdgeOfAColumnGroup(this, fromColumnPosition, fromColumnIndex, this.model) || ColumnGroupUtils.isRightEdgeOfAColumnGroup(this, fromColumnPosition, fromColumnIndex, this.model)) {
                this.model.removeColumnIndexes(fromColumnGroup.getName(), fromColumnIndexes);
            }
        }
        consumeCommand = true;
    } else if (fromColumnGroup == null && toColumnGroup != null) {
        // special case
        // add the column to the column group if we step instead of jumping
        consumeCommand = this.model.insertColumnIndexes(toColumnGroup.getName(), fromColumnIndexes);
        if (jump) {
            consumeCommand = false;
        }
    } else if (fromColumnGroup != null && toColumnGroup == null) {
        this.model.removeColumnIndexes(fromColumnGroup.getName(), fromColumnIndexes);
    } else if (fromColumnGroup == null && toColumnGroup == null && fromColumnPosition == toColumnPosition) {
        // this might happen on drag and drop operations when trying to add
        // a column back into an adjacent column group
        int adjacentPos = (moveDirection == MoveDirectionEnum.RIGHT) ? fromColumnPosition + 1 : fromColumnPosition - 1;
        int adjacentIndex = this.getUnderlyingLayer().getColumnIndexByPosition(adjacentPos);
        // check if there is an adjacent column group
        ColumnGroup adjacentColumnGroup = this.model.getColumnGroupByIndex(adjacentIndex);
        if (adjacentColumnGroup != null) {
            this.model.insertColumnIndexes(adjacentColumnGroup.getName(), fromColumnIndexes);
            consumeCommand = false;
        }
    } else if (fromColumnGroup != null && toColumnGroup != null && !fromColumnGroup.getName().equals(toColumnGroup.getName())) {
        // of the current column group
        if (MoveDirectionEnum.RIGHT == moveDirection) {
            if (toColumnGroup != null) {
                // check if reorder is started from right edge of a group
                boolean fromRightEdge = ColumnGroupUtils.isRightEdgeOfAColumnGroup(this, fromColumnPosition, fromColumnIndex, this.model);
                boolean removed = true;
                if (fromColumnGroup != null) {
                    removed = this.model.removeColumnIndexes(fromColumnGroup.getName(), fromColumnIndexes);
                }
                if (removed && ((!fromRightEdge && !jump) || jump)) {
                    // column removed from another group
                    // not from the right edge of another group
                    // add it to the following group
                    consumeCommand = this.model.insertColumnIndexes(toColumnGroup.getName(), fromColumnIndexes);
                    if (jump) {
                        consumeCommand = !jump;
                    }
                } else {
                    consumeCommand = !jump;
                }
            }
        } else if (MoveDirectionEnum.LEFT == moveDirection) {
            if (toColumnGroup != null) {
                // check if reorder is started from left edge of a group
                boolean fromLeftEdge = ColumnGroupUtils.isLeftEdgeOfAColumnGroup(this, fromColumnPosition, fromColumnIndex, this.model);
                boolean removed = true;
                if (fromColumnGroup != null) {
                    removed = this.model.removeColumnIndexes(fromColumnGroup.getName(), fromColumnIndexes);
                }
                if (removed && ((!fromLeftEdge && !jump) || jump)) {
                    // column removed from another group
                    // not from the left edge of another group
                    // add it to the previous group
                    consumeCommand = this.model.insertColumnIndexes(toColumnGroup.getName(), fromColumnIndexes);
                    if (jump) {
                        consumeCommand = !jump;
                    }
                } else {
                    consumeCommand = !jump;
                }
            }
        }
    }
    // don't consume the command to perform reordering
    return consumeCommand;
}
Also used : MoveDirectionEnum(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum) ColumnGroup(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup)

Example 24 with ColumnGroup

use of org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup in project nebula.widgets.nattable by eclipse.

the class ColumnGroupExpandCollapseCommandHandler method doCommand.

@Override
protected boolean doCommand(ColumnGroupExpandCollapseCommand command) {
    int columnIndex = this.columnGroupExpandCollapseLayer.getColumnIndexByPosition(command.getColumnPosition());
    ColumnGroupModel model = this.columnGroupExpandCollapseLayer.getModel(command.getRowPosition());
    ColumnGroup columnGroup = model.getColumnGroupByIndex(columnIndex);
    // further operation ...
    if (columnGroup == null || !columnGroup.isCollapseable()) {
        return true;
    }
    List<Integer> columnIndexes = new ArrayList<Integer>(columnGroup.getMembers());
    columnIndexes.removeAll(columnGroup.getStaticColumnIndexes());
    boolean wasCollapsed = columnGroup.isCollapsed();
    if (wasCollapsed) {
        // we need to cleanup the column position list before we toggle
        // because the columns are hidden before the toggle and will be
        // visible afterwards
        cleanupColumnIndexes(columnIndexes);
    }
    columnGroup.toggleCollapsed();
    if (!wasCollapsed) {
        // we need to cleanup the column position list after we toggle
        // because the columns are hidden now
        cleanupColumnIndexes(columnIndexes);
    }
    ILayerEvent event;
    if (wasCollapsed) {
        event = new ShowColumnPositionsEvent(this.columnGroupExpandCollapseLayer, columnIndexes);
    } else {
        event = new HideColumnPositionsEvent(this.columnGroupExpandCollapseLayer, columnIndexes);
    }
    this.columnGroupExpandCollapseLayer.fireLayerEvent(event);
    return true;
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) HideColumnPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent) ArrayList(java.util.ArrayList) ColumnGroup(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup) ColumnGroupModel(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel) ShowColumnPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.ShowColumnPositionsEvent)

Example 25 with ColumnGroup

use of org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup in project nebula.widgets.nattable by eclipse.

the class ColumnGroupsCommandHandler method handleRemovalFromGroup.

private void handleRemovalFromGroup(Map<String, Integer> toColumnPositions, int columnIndex) {
    ColumnGroup columnGroup = this.model.getColumnGroupByIndex(columnIndex);
    final String columnGroupName = columnGroup.getName();
    final List<Integer> columnIndexesInGroup = columnGroup.getMembers();
    final int columnGroupSize = columnIndexesInGroup.size();
    if (!toColumnPositions.containsKey(columnGroupName)) {
        for (int colGroupIndex : columnIndexesInGroup) {
            if (ColumnGroupUtils.isFirstVisibleColumnIndexInGroup(colGroupIndex, this.contextLayer, this.selectionLayer, this.model)) {
                int toPosition = this.selectionLayer.getColumnPositionByIndex(colGroupIndex);
                if (colGroupIndex == columnIndex) {
                    if (columnGroupSize == 1) {
                        break;
                    } else {
                        toPosition++;
                    }
                }
                toColumnPositions.put(columnGroupName, toPosition);
                break;
            }
        }
    } else {
        if (columnGroupSize - 1 <= 0) {
            toColumnPositions.remove(columnGroupName);
        }
    }
    columnGroup.removeColumn(columnIndex);
}
Also used : ColumnGroup(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup) Point(org.eclipse.swt.graphics.Point)

Aggregations

ColumnGroup (org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup)27 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 ColumnEntry (org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry)3 ColumnGroupEntry (org.eclipse.nebula.widgets.nattable.columnChooser.ColumnGroupEntry)3 List (java.util.List)2 IUniqueIndexLayer (org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer)2 LabelStack (org.eclipse.nebula.widgets.nattable.layer.LabelStack)2 Point (org.eclipse.swt.graphics.Point)2 HashSet (java.util.HashSet)1 ColumnRenameDialog (org.eclipse.nebula.widgets.nattable.columnRename.ColumnRenameDialog)1 ColumnGroupModel (org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel)1 HideColumnPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent)1 ShowColumnPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.ShowColumnPositionsEvent)1 ILayerEvent (org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent)1 ColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand)1 MultiColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand)1 MoveDirectionEnum (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1