use of org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry in project nebula.widgets.nattable by eclipse.
the class ColumnChooserDialogTest method createColumnChooserDialogTestHelper.
/**
* item string format: position:index{,position:index}* --> e.g. 0:0,1:1,2:2<br>
* column group string format: (index{,index}*) --> e.g. (0,1)<br>
*
* @param availableItems
* the column entries in the list of available columns.
* @param selectedItems
* the column entries in the list of selected columns.
* @param columnGroups
* the column groups.
* @return a helper class giving access to an instance of a
* {@link ColumnChooserDialog} parameterized as defined.
*/
private ColumnChooserDialogTestHelper createColumnChooserDialogTestHelper(String availableItems, String selectedItems, String... columnGroups) {
Shell shell = new Shell();
ColumnChooserDialog dialog = new ColumnChooserDialog(shell, "", "");
dialog.createDialogArea(shell);
List<ColumnEntry> availableEntries = parseEntryString(availableItems);
List<ColumnEntry> visibleEntries = parseEntryString(selectedItems);
ColumnGroupModel columnGroupModel = parseColumnGroups(columnGroups);
dialog.populateAvailableTree(availableEntries, columnGroupModel);
dialog.populateSelectedTree(visibleEntries, columnGroupModel);
TestTreeListener listener = new TestTreeListener();
dialog.addListener(listener);
return new ColumnChooserDialogTestHelper(dialog, listener);
}
use of org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry in project nebula.widgets.nattable by eclipse.
the class ColumnChooserDialog method moveSelectedUp.
/**
* Move columns <i>up</i> in the 'Selected' Tree (Right)
*/
@SuppressWarnings("boxing")
protected void moveSelectedUp() {
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. If a column group moves, a bunch
// of 'from' positions move to a single 'to' position
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);
// If already at first position do not move
int firstPositionInGroup = groupedPositions.get(0);
// Column entry
ColumnEntry columnEntry = getPreviousColumnEntryForPosition(this.selectedTree, firstPositionInGroup);
int columnEntryIndex = columnEntry.getIndex();
// Previous column entry
ColumnEntry previousColumnEntry = getPreviousColumnEntryForPosition(this.selectedTree, firstPositionInGroup - 1);
// tree is selected
if (previousColumnEntry == null) {
toPositions.add(firstPositionInGroup);
} else {
int previousColumnEntryIndex = previousColumnEntry.getIndex();
if (columnGroupMoved) {
// move above it.
if (this.columnGroupModel != null && this.columnGroupModel.isPartOfAGroup(previousColumnEntryIndex)) {
ColumnGroup previousColumnGroup = this.columnGroupModel.getColumnGroupByIndex(previousColumnEntryIndex);
toPositions.add(firstPositionInGroup - previousColumnGroup.getSize());
} else {
toPositions.add(firstPositionInGroup - 1);
}
} else {
// can't move up i.e. out of the group
if (this.columnGroupModel != null && this.columnGroupModel.isPartOfAnUnbreakableGroup(columnEntryIndex) && !ColumnGroupUtils.isInTheSameGroup(columnEntryIndex, previousColumnEntryIndex, this.columnGroupModel)) {
return;
}
// move above it
if (this.columnGroupModel != null && this.columnGroupModel.isPartOfAnUnbreakableGroup(previousColumnEntryIndex) && !this.columnGroupModel.isPartOfAGroup(columnEntryIndex) && !ColumnGroupUtils.isInTheSameGroup(columnEntryIndex, previousColumnEntryIndex, this.columnGroupModel)) {
ColumnGroup previousColumnGroup = this.columnGroupModel.getColumnGroupByIndex(previousColumnEntryIndex);
toPositions.add(firstPositionInGroup - previousColumnGroup.getSize());
} else {
toPositions.add(firstPositionInGroup - 1);
}
}
}
}
fireItemsMoved(MoveDirectionEnum.UP, selectedColumnGroupEntries, selectedColumnEntries, postionsGroupedByContiguous, toPositions);
}
}
}
Aggregations