Search in sources :

Example 1 with ColumnGroup

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

the class ColumnGroupModelTest method shouldNotRemoveFromAnUnbreakableGroup.

@Test
public void shouldNotRemoveFromAnUnbreakableGroup() throws Exception {
    ColumnGroup columnGroup = this.model.getColumnGroupByIndex(7);
    columnGroup.setUnbreakable(true);
    assertFalse(columnGroup.removeColumn(7));
}
Also used : ColumnGroup(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup) Test(org.junit.Test)

Example 2 with ColumnGroup

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

the class ColumnGroupModelTest method noColumnGroup.

@Test
public void noColumnGroup() throws Exception {
    ColumnGroup columnGroup = this.model.getColumnGroupByIndex(100);
    assertNull(columnGroup);
}
Also used : ColumnGroup(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup) Test(org.junit.Test)

Example 3 with ColumnGroup

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

the class ColumnGroupReorderLayerTest method shouldDragFirstCellRightAndAddColumnToGroup.

@Test
public void shouldDragFirstCellRightAndAddColumnToGroup() {
    ColumnGroup columnGroup = this.modelFixture.getColumnGroupByIndex(0);
    columnGroup.removeColumn(0);
    assertEquals(1, getColumnIndexesInGroup(1).size());
    this.modelFixture.insertColumnIndexes(ColumnGroupModelFixture.TEST_GROUP_1, 2);
    assertEquals(2, getColumnIndexesInGroup(1).size());
    // Drag right into group
    ColumnReorderCommand command = new ColumnReorderCommand(this.layer, 0, 2);
    this.layer.doCommand(command);
    final int fromColumnIndex = 0;
    final int toColumnIndex = 2;
    assertEquals(ColumnGroupModelFixture.TEST_GROUP_1, this.modelFixture.getColumnGroupByIndex(fromColumnIndex).getName());
    assertEquals(ColumnGroupModelFixture.TEST_GROUP_1, this.modelFixture.getColumnGroupByIndex(toColumnIndex).getName());
    assertEquals(ColumnGroupModelFixture.TEST_GROUP_1, this.modelFixture.getColumnGroupByIndex(2).getName());
    assertEquals(3, getColumnIndexesInGroup(fromColumnIndex).size());
}
Also used : ColumnGroup(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) Test(org.junit.Test)

Example 4 with ColumnGroup

use of org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup 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 5 with ColumnGroup

use of org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup 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)

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