Search in sources :

Example 1 with ColumnGroupEntry

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

the class ColumnChooserDialogTest method populateTree.

@Test
public void populateTree() throws Exception {
    this.columnGroupModel.getColumnGroupByIndex(0).toggleCollapsed();
    Assert.assertEquals(9, this.testDialog.getSelectedTree().getItemCount());
    TreeItem item = this.testDialog.getSelectedTree().getItem(0);
    Assert.assertTrue(item.getData() instanceof ColumnGroupEntry);
    item = this.testDialog.getSelectedTree().getItem(1);
    Assert.assertTrue(item.getData() instanceof ColumnEntry);
    item = this.testDialog.getSelectedTree().getItem(2);
    Assert.assertTrue(item.getData() instanceof ColumnGroupEntry);
}
Also used : ColumnGroupEntry(org.eclipse.nebula.widgets.nattable.columnChooser.ColumnGroupEntry) TreeItem(org.eclipse.swt.widgets.TreeItem) ColumnEntry(org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry) Test(org.junit.Test)

Example 2 with ColumnGroupEntry

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

the class ColumnChooserDialog method moveSelectedToTop.

void moveSelectedToTop() {
    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
            List<List<Integer>> postionsGroupedByContiguous = PositionUtil.getGroupedByContiguous(allSelectedPositions);
            List<Integer> toPositions = new ArrayList<Integer>();
            int shift = getUpperMostPosition();
            for (List<Integer> groupedPositions : postionsGroupedByContiguous) {
                // check for unbreakable group
                // Position of first element in list
                int firstPositionInGroup = groupedPositions.get(0);
                // Column entry
                ColumnEntry columnEntry = getNextColumnEntryForPosition(this.selectedTree, firstPositionInGroup);
                int columnEntryIndex = columnEntry.getIndex();
                if (this.columnGroupModel != null && this.columnGroupModel.isPartOfAnUnbreakableGroup(columnEntryIndex)) {
                    List<Integer> groupMembers = this.columnGroupModel.getColumnGroupByIndex(columnEntryIndex).getMembers();
                    int groupUpperMost = groupMembers.get(0);
                    toPositions.add(groupUpperMost);
                } else {
                    toPositions.add(shift);
                    shift += groupedPositions.size();
                }
            }
            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)

Example 3 with ColumnGroupEntry

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

the class ColumnChooserDialog method moveSelectedDown.

/**
 * Move columns <i>down</i> in the 'Selected' Tree (Right)
 */
@SuppressWarnings("boxing")
protected void moveSelectedDown() {
    if (isAnyLeafSelected(this.selectedTree)) {
        if (!isLastLeafSelected(this.selectedTree)) {
            List<ColumnEntry> selectedColumnEntries = getSelectedColumnEntriesIncludingNested(this.selectedTree);
            List<ColumnGroupEntry> selectedColumnGroupEntries = getSelectedColumnGroupEntries(this.selectedTree);
            List<Integer> allSelectedPositions = merge(selectedColumnEntries, selectedColumnGroupEntries);
            // Group continuous positions
            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);
                // Position of last element in list
                int lastListIndex = groupedPositions.size() - 1;
                int lastPositionInGroup = groupedPositions.get(lastListIndex);
                // Column entry
                ColumnEntry columnEntry = getNextColumnEntryForPosition(this.selectedTree, lastPositionInGroup);
                int columnEntryIndex = columnEntry.getIndex();
                // Next Column Entry
                ColumnEntry nextColumnEntry = getNextColumnEntryForPosition(this.selectedTree, lastPositionInGroup + 1);
                // is selected
                if (nextColumnEntry == null) {
                    toPositions.add(lastPositionInGroup);
                } else {
                    int nextColumnEntryIndex = nextColumnEntry.getIndex();
                    if (columnGroupMoved) {
                        // move past it.
                        if (this.columnGroupModel != null && this.columnGroupModel.isPartOfAGroup(nextColumnEntryIndex)) {
                            ColumnGroup nextColumnGroup = this.columnGroupModel.getColumnGroupByIndex(nextColumnEntryIndex);
                            toPositions.add(lastPositionInGroup + nextColumnGroup.getSize());
                        } else {
                            toPositions.add(lastPositionInGroup + 1);
                        }
                    } else {
                        // move down i.e. out of the group
                        if (this.columnGroupModel != null && this.columnGroupModel.isPartOfAnUnbreakableGroup(columnEntryIndex) && !ColumnGroupUtils.isInTheSameGroup(columnEntryIndex, nextColumnEntryIndex, this.columnGroupModel)) {
                            return;
                        }
                        // move past it
                        if (this.columnGroupModel != null && this.columnGroupModel.isPartOfAnUnbreakableGroup(nextColumnEntryIndex) && !this.columnGroupModel.isPartOfAGroup(columnEntryIndex) && !ColumnGroupUtils.isInTheSameGroup(columnEntryIndex, nextColumnEntryIndex, this.columnGroupModel)) {
                            ColumnGroup nextColumnGroup = this.columnGroupModel.getColumnGroupByIndex(nextColumnEntryIndex);
                            toPositions.add(lastPositionInGroup + nextColumnGroup.getSize());
                        } else {
                            toPositions.add(lastPositionInGroup + 1);
                        }
                    }
                }
            }
            fireItemsMoved(MoveDirectionEnum.DOWN, 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 4 with ColumnGroupEntry

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

the class ColumnChooserDialog method populateModel.

/**
 * Populates the tree. Looks for column group and adds an extra node for the
 * group. The column leaves carry a {@link ColumnEntry} object as data. The
 * column group leaves carry a {@link ColumnGroupEntry} object as data.
 */
private void populateModel(Tree tree, List<ColumnEntry> columnEntries, ColumnGroupModel columnGroupModel) {
    this.columnGroupModel = columnGroupModel;
    for (ColumnEntry columnEntry : columnEntries) {
        TreeItem treeItem;
        int columnEntryIndex = columnEntry.getIndex().intValue();
        // Create a node for the column group - if needed
        if (columnGroupModel != null && columnGroupModel.isPartOfAGroup(columnEntryIndex)) {
            ColumnGroup columnGroup = columnGroupModel.getColumnGroupByIndex(columnEntryIndex);
            String columnGroupName = columnGroup.getName();
            TreeItem columnGroupTreeItem = getTreeItem(tree, columnGroupName);
            if (columnGroupTreeItem == null) {
                columnGroupTreeItem = new TreeItem(tree, SWT.NONE);
                ColumnGroupEntry columnGroupEntry = new ColumnGroupEntry(columnGroupName, columnEntry.getPosition(), columnEntry.getIndex(), columnGroup.isCollapsed());
                columnGroupTreeItem.setData(columnGroupEntry);
                columnGroupTreeItem.setText(columnGroupEntry.getLabel());
            }
            treeItem = new TreeItem(columnGroupTreeItem, SWT.NONE);
        } else {
            treeItem = new TreeItem(tree, SWT.NONE);
        }
        treeItem.setText(columnEntry.getLabel());
        treeItem.setData(columnEntry);
    }
}
Also used : ColumnGroupEntry(org.eclipse.nebula.widgets.nattable.columnChooser.ColumnGroupEntry) TreeItem(org.eclipse.swt.widgets.TreeItem) ColumnEntry(org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry) ColumnGroup(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup)

Example 5 with ColumnGroupEntry

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

the class ColumnChooserDialog method moveSelectedToBottom.

void moveSelectedToBottom() {
    if (isAnyLeafSelected(this.selectedTree)) {
        if (!isLastLeafSelected(this.selectedTree)) {
            List<ColumnEntry> selectedColumnEntries = getSelectedColumnEntriesIncludingNested(this.selectedTree);
            List<ColumnGroupEntry> selectedColumnGroupEntries = getSelectedColumnGroupEntries(this.selectedTree);
            List<Integer> allSelectedPositions = merge(selectedColumnEntries, selectedColumnGroupEntries);
            // Group continuous positions
            List<List<Integer>> positionsGroupedByContiguous = PositionUtil.getGroupedByContiguous(allSelectedPositions);
            List<Integer> toPositions = new ArrayList<Integer>();
            List<List<Integer>> reversed = new ArrayList<List<Integer>>(positionsGroupedByContiguous);
            Collections.reverse(reversed);
            int lowerMost = getLowerMostPosition();
            int shift = 0;
            for (List<Integer> groupedPositions : reversed) {
                // check for unbreakable group
                // Position of last element in list
                int lastListIndex = groupedPositions.size() - 1;
                int lastPositionInGroup = groupedPositions.get(lastListIndex);
                // Column entry
                ColumnEntry columnEntry = getNextColumnEntryForPosition(this.selectedTree, lastPositionInGroup);
                int columnEntryIndex = columnEntry.getIndex();
                if (this.columnGroupModel != null && this.columnGroupModel.isPartOfAnUnbreakableGroup(columnEntryIndex)) {
                    List<Integer> groupMembers = this.columnGroupModel.getColumnGroupByIndex(columnEntryIndex).getMembers();
                    int groupLowerMost = groupMembers.get(groupMembers.size() - 1);
                    toPositions.add(groupLowerMost);
                } else {
                    toPositions.add(Integer.valueOf(lowerMost - shift));
                    shift += groupedPositions.size();
                }
            }
            fireItemsMoved(MoveDirectionEnum.DOWN, selectedColumnGroupEntries, selectedColumnEntries, reversed, 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)

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