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);
}
}
}
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);
}
}
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);
}
}
}
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");
}
}
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());
}
Aggregations