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());
}
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;
}
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);
}
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);
}
}
}
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[] {}));
}
Aggregations