Search in sources :

Example 1 with ColumnEntry

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

the class ColumnChooserUtilsTest method getVisibleColumnEntries.

@Test
public void getVisibleColumnEntries() throws Exception {
    DefaultGridLayer gridLayer = new DefaultGridLayer(RowDataListFixture.getList(), RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap());
    ColumnHideShowLayer columnHideShowLayer = gridLayer.getBodyLayer().getColumnHideShowLayer();
    ColumnHeaderLayer columnHeaderLayer = gridLayer.getColumnHeaderLayer();
    DataLayer columnHeaderDataLayer = (DataLayer) gridLayer.getColumnHeaderDataLayer();
    List<ColumnEntry> visibleEntries = ColumnChooserUtils.getVisibleColumnsEntries(columnHideShowLayer, columnHeaderLayer, columnHeaderDataLayer);
    // All columns shown
    assertEquals(RowDataListFixture.getPropertyNames().length, visibleEntries.size());
    // Hide a few columns
    gridLayer.getBodyLayer().getColumnHideShowLayer().hideColumnPositions(Arrays.asList(1, 2, 3));
    visibleEntries = ColumnChooserUtils.getVisibleColumnsEntries(columnHideShowLayer, columnHeaderLayer, columnHeaderDataLayer);
    assertEquals(RowDataListFixture.getPropertyNames().length - 3, visibleEntries.size());
    // Check the hidden entries
    List<ColumnEntry> hiddenEntries = ColumnChooserUtils.getHiddenColumnEntries(columnHideShowLayer, columnHeaderLayer, columnHeaderDataLayer);
    assertEquals(3, hiddenEntries.size());
}
Also used : DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) ColumnHeaderLayerFixture.getDataLayer(org.eclipse.nebula.widgets.nattable.test.fixture.layer.ColumnHeaderLayerFixture.getDataLayer) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) ColumnHideShowLayer(org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer) ColumnEntry(org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) Test(org.junit.Test)

Example 2 with ColumnEntry

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

the class ColumnChooserDialogTest method parseEntryString.

private static List<ColumnEntry> parseEntryString(String entryString) {
    List<ColumnEntry> result = new ArrayList<ColumnEntry>();
    if (!entryString.isEmpty()) {
        String[] entries = entryString.split(",");
        for (String entry : entries) {
            String[] values = entry.split(":");
            int position = Integer.valueOf(values[0]);
            int index = Integer.valueOf(values[1]);
            result.add(new ColumnEntry("Column " + index, index, position));
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ColumnEntry(org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry)

Example 3 with ColumnEntry

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

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

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

the class ColumnChooserDialog method setGroupsSelectionIfRequired.

/**
 * If all the leaves in a group are selected the group is also selected
 */
private void setGroupsSelectionIfRequired(Tree tree, List<Integer> columnEntryIndexes) {
    Collection<TreeItem> allLeaves = ArrayUtil.asCollection(tree.getItems());
    Collection<TreeItem> selectedLeaves = ArrayUtil.asCollection(tree.getSelection());
    for (TreeItem leaf : allLeaves) {
        if (isColumnGroupLeaf(leaf)) {
            boolean markSelected = true;
            Collection<TreeItem> nestedLeaves = ArrayUtil.asCollection(leaf.getItems());
            for (TreeItem nestedLeaf : nestedLeaves) {
                ColumnEntry columnEntry = getColumnEntryInLeaf(nestedLeaf);
                if (!columnEntryIndexes.contains(columnEntry.getIndex())) {
                    markSelected = false;
                }
            }
            if (markSelected) {
                selectedLeaves.add(leaf);
            }
        }
    }
    tree.setSelection(selectedLeaves.toArray(new TreeItem[] {}));
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) ColumnEntry(org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry)

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