Search in sources :

Example 6 with ColumnEntry

use of org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry 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 7 with ColumnEntry

use of org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry 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 8 with ColumnEntry

use of org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry 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)

Example 9 with ColumnEntry

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

the class ColumnCategoriesLabelProvider method getText.

@Override
public String getText(Object element) {
    Node node = (Node) element;
    switch(node.getType()) {
        case CATEGORY:
            return node.getData();
        case COLUMN:
            int index = Integer.parseInt(node.getData());
            ColumnEntry columnEntry = ColumnChooserUtils.find(this.hiddenEntries, index);
            if (ObjectUtils.isNull(columnEntry)) {
                log.error(// $NON-NLS-1$ //$NON-NLS-2$
                "Column index " + index + " is present " + // $NON-NLS-1$
                "in the Column Categories model, " + // $NON-NLS-1$
                "but not in the underlying data");
                return String.valueOf(index);
            }
            return columnEntry.getLabel();
        default:
            // $NON-NLS-1$
            return Messages.getString("Unknown");
    }
}
Also used : Node(org.eclipse.nebula.widgets.nattable.columnCategories.Node) ColumnEntry(org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry)

Example 10 with ColumnEntry

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

the class ColumnChooserUtilsTest method find.

@Test
public void find() throws Exception {
    ColumnEntry found = ColumnChooserUtils.find(this.entriesFixture, 5);
    assertEquals("Index5", found.getLabel());
}
Also used : ColumnEntry(org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry) Test(org.junit.Test)

Aggregations

ColumnEntry (org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry)12 ColumnGroupEntry (org.eclipse.nebula.widgets.nattable.columnChooser.ColumnGroupEntry)6 ArrayList (java.util.ArrayList)5 List (java.util.List)4 ColumnGroup (org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup)3 TreeItem (org.eclipse.swt.widgets.TreeItem)3 Test (org.junit.Test)3 Node (org.eclipse.nebula.widgets.nattable.columnCategories.Node)1 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)1 DefaultGridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)1 ColumnGroupModel (org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel)1 ColumnHideShowLayer (org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer)1 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)1 ColumnHeaderLayerFixture.getDataLayer (org.eclipse.nebula.widgets.nattable.test.fixture.layer.ColumnHeaderLayerFixture.getDataLayer)1 Shell (org.eclipse.swt.widgets.Shell)1