Search in sources :

Example 6 with ColumnGroupEntry

use of org.eclipse.nebula.widgets.nattable.columnChooser.ColumnGroupEntry in project nebula.widgets.nattable by eclipse.

the class ColumnChooserDialog method moveSelectedUp.

/**
 * Move columns <i>up</i> in the 'Selected' Tree (Right)
 */
@SuppressWarnings("boxing")
protected void moveSelectedUp() {
    if (isAnyLeafSelected(this.selectedTree)) {
        if (!isFirstLeafSelected(this.selectedTree)) {
            List<ColumnEntry> selectedColumnEntries = getSelectedColumnEntriesIncludingNested(this.selectedTree);
            List<ColumnGroupEntry> selectedColumnGroupEntries = getSelectedColumnGroupEntries(this.selectedTree);
            List<Integer> allSelectedPositions = merge(selectedColumnEntries, selectedColumnGroupEntries);
            // Group continuous positions. If a column group moves, a bunch
            // of 'from' positions move to a single 'to' position
            List<List<Integer>> postionsGroupedByContiguous = PositionUtil.getGroupedByContiguous(allSelectedPositions);
            List<Integer> toPositions = new ArrayList<Integer>();
            // Set destination positions
            for (List<Integer> groupedPositions : postionsGroupedByContiguous) {
                // Do these contiguous positions contain a column group ?
                boolean columnGroupMoved = columnGroupMoved(groupedPositions, selectedColumnGroupEntries);
                // If already at first position do not move
                int firstPositionInGroup = groupedPositions.get(0);
                // Column entry
                ColumnEntry columnEntry = getPreviousColumnEntryForPosition(this.selectedTree, firstPositionInGroup);
                int columnEntryIndex = columnEntry.getIndex();
                // Previous column entry
                ColumnEntry previousColumnEntry = getPreviousColumnEntryForPosition(this.selectedTree, firstPositionInGroup - 1);
                // tree is selected
                if (previousColumnEntry == null) {
                    toPositions.add(firstPositionInGroup);
                } else {
                    int previousColumnEntryIndex = previousColumnEntry.getIndex();
                    if (columnGroupMoved) {
                        // move above it.
                        if (this.columnGroupModel != null && this.columnGroupModel.isPartOfAGroup(previousColumnEntryIndex)) {
                            ColumnGroup previousColumnGroup = this.columnGroupModel.getColumnGroupByIndex(previousColumnEntryIndex);
                            toPositions.add(firstPositionInGroup - previousColumnGroup.getSize());
                        } else {
                            toPositions.add(firstPositionInGroup - 1);
                        }
                    } else {
                        // can't move up i.e. out of the group
                        if (this.columnGroupModel != null && this.columnGroupModel.isPartOfAnUnbreakableGroup(columnEntryIndex) && !ColumnGroupUtils.isInTheSameGroup(columnEntryIndex, previousColumnEntryIndex, this.columnGroupModel)) {
                            return;
                        }
                        // move above it
                        if (this.columnGroupModel != null && this.columnGroupModel.isPartOfAnUnbreakableGroup(previousColumnEntryIndex) && !this.columnGroupModel.isPartOfAGroup(columnEntryIndex) && !ColumnGroupUtils.isInTheSameGroup(columnEntryIndex, previousColumnEntryIndex, this.columnGroupModel)) {
                            ColumnGroup previousColumnGroup = this.columnGroupModel.getColumnGroupByIndex(previousColumnEntryIndex);
                            toPositions.add(firstPositionInGroup - previousColumnGroup.getSize());
                        } else {
                            toPositions.add(firstPositionInGroup - 1);
                        }
                    }
                }
            }
            fireItemsMoved(MoveDirectionEnum.UP, selectedColumnGroupEntries, selectedColumnEntries, postionsGroupedByContiguous, toPositions);
        }
    }
}
Also used : ColumnGroupEntry(org.eclipse.nebula.widgets.nattable.columnChooser.ColumnGroupEntry) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ColumnEntry(org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry) ColumnGroup(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup)

Example 7 with ColumnGroupEntry

use of org.eclipse.nebula.widgets.nattable.columnChooser.ColumnGroupEntry in project nebula.widgets.nattable by eclipse.

the class ColumnChooserDialog method selectedTreeCollapsed.

private void selectedTreeCollapsed(TreeEvent event) {
    TreeItem item = (TreeItem) event.item;
    ColumnGroupEntry columnGroupEntry = (ColumnGroupEntry) item.getData();
    fireGroupCollapsed(columnGroupEntry);
}
Also used : ColumnGroupEntry(org.eclipse.nebula.widgets.nattable.columnChooser.ColumnGroupEntry) TreeItem(org.eclipse.swt.widgets.TreeItem)

Example 8 with ColumnGroupEntry

use of org.eclipse.nebula.widgets.nattable.columnChooser.ColumnGroupEntry in project nebula.widgets.nattable by eclipse.

the class ColumnChooserDialog method selectedTreeExpanded.

private void selectedTreeExpanded(TreeEvent event) {
    TreeItem item = (TreeItem) event.item;
    ColumnGroupEntry columnGroupEntry = (ColumnGroupEntry) item.getData();
    fireGroupExpanded(columnGroupEntry);
}
Also used : ColumnGroupEntry(org.eclipse.nebula.widgets.nattable.columnChooser.ColumnGroupEntry) TreeItem(org.eclipse.swt.widgets.TreeItem)

Example 9 with ColumnGroupEntry

use of org.eclipse.nebula.widgets.nattable.columnChooser.ColumnGroupEntry in project nebula.widgets.nattable by eclipse.

the class ColumnChooserDialog method expandAllLeaves.

public void expandAllLeaves() {
    List<TreeItem> allLeaves = ArrayUtil.asList(this.selectedTree.getItems());
    for (TreeItem leaf : allLeaves) {
        if (isColumnGroupLeaf(leaf)) {
            ColumnGroupEntry columnGroupEntry = (ColumnGroupEntry) leaf.getData();
            leaf.setExpanded(!columnGroupEntry.isCollapsed());
        }
    }
}
Also used : ColumnGroupEntry(org.eclipse.nebula.widgets.nattable.columnChooser.ColumnGroupEntry) TreeItem(org.eclipse.swt.widgets.TreeItem)

Aggregations

ColumnGroupEntry (org.eclipse.nebula.widgets.nattable.columnChooser.ColumnGroupEntry)9 ColumnEntry (org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry)6 TreeItem (org.eclipse.swt.widgets.TreeItem)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ColumnGroup (org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup)3 Test (org.junit.Test)1