use of net.sourceforge.nattable.columnChooser.ColumnEntry in project translationstudio8 by heartsome.
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[] {}));
}
use of net.sourceforge.nattable.columnChooser.ColumnEntry in project translationstudio8 by heartsome.
the class ColumnChooserDialog method moveSelectedDown.
/**
* Move columns <i>down</i> in the 'Selected' Tree (Right)
*/
@SuppressWarnings("boxing")
protected void moveSelectedDown() {
if (isAnyLeafSelected(selectedTree)) {
if (!isLastLeafSelected(selectedTree)) {
List<ColumnEntry> selectedColumnEntries = getSelectedColumnEntriesIncludingNested(selectedTree);
List<ColumnGroupEntry> selectedColumnGroupEntries = getSelectedColumnGroupEntries(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 = getColumnEntryForPosition(selectedTree, lastPositionInGroup);
int columnEntryIndex = columnEntry.getIndex();
// Next Column Entry
ColumnEntry nextColumnEntry = getColumnEntryForPosition(selectedTree, lastPositionInGroup + 1);
// Next column entry will be null the last leaf in the tree is selected
if (nextColumnEntry == null) {
return;
}
int nextColumnEntryIndex = nextColumnEntry.getIndex();
if (columnGroupMoved) {
// If the next entry is a column group - move past it.
if (columnGroupModel != null && columnGroupModel.isPartOfAGroup(nextColumnEntryIndex)) {
toPositions.add(lastPositionInGroup + columnGroupModel.getColumnIndexesInGroup(nextColumnEntryIndex).size());
} else {
toPositions.add(lastPositionInGroup + 1);
}
} else {
// If is last member of the unbreakable group, can't move down i.e. out of the group
if (columnGroupModel != null && columnGroupModel.isPartOfAnUnbreakableGroup(columnEntryIndex) && !ColumnGroupUtils.isInTheSameGroup(columnEntryIndex, nextColumnEntryIndex, columnGroupModel)) {
return;
}
// If next entry is an unbreakable column group - move past it
if (columnGroupModel != null && columnGroupModel.isPartOfAnUnbreakableGroup(nextColumnEntryIndex) && !ColumnGroupUtils.isInTheSameGroup(columnEntryIndex, nextColumnEntryIndex, columnGroupModel)) {
toPositions.add(lastPositionInGroup + columnGroupModel.getColumnIndexesInGroup(nextColumnEntryIndex).size());
} else {
toPositions.add(lastPositionInGroup + 1);
}
}
}
fireItemsMoved(MoveDirectionEnum.DOWN, selectedColumnGroupEntries, selectedColumnEntries, postionsGroupedByContiguous, toPositions);
}
}
}
use of net.sourceforge.nattable.columnChooser.ColumnEntry in project translationstudio8 by heartsome.
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(hiddenEntries, index);
if (ObjectUtils.isNull(columnEntry)) {
System.err.println("Column index " + index + " is present " + "in the Column Categories model, " + "but not in the underlying data");
return String.valueOf(index);
}
return columnEntry.getLabel();
default:
return "Unknown";
}
}
use of net.sourceforge.nattable.columnChooser.ColumnEntry in project translationstudio8 by heartsome.
the class ColumnChooserDialog method moveSelectedUp.
/**
* Move columns <i>up</i> in the 'Selected' Tree (Right)
*/
@SuppressWarnings("boxing")
protected void moveSelectedUp() {
if (isAnyLeafSelected(selectedTree)) {
if (!isFirstLeafSelected(selectedTree)) {
List<ColumnEntry> selectedColumnEntries = getSelectedColumnEntriesIncludingNested(selectedTree);
List<ColumnGroupEntry> selectedColumnGroupEntries = getSelectedColumnGroupEntries(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);
if (firstPositionInGroup == 0) {
return;
}
// Column entry
ColumnEntry columnEntry = getColumnEntryForPosition(selectedTree, firstPositionInGroup);
int columnEntryIndex = columnEntry.getIndex();
// Previous column entry
ColumnEntry previousColumnEntry = getColumnEntryForPosition(selectedTree, firstPositionInGroup - 1);
int previousColumnEntryIndex = previousColumnEntry.getIndex();
if (columnGroupMoved) {
// If the previous entry is a column group - move above it.
if (columnGroupModel != null && columnGroupModel.isPartOfAGroup(previousColumnEntryIndex)) {
toPositions.add(firstPositionInGroup - columnGroupModel.getColumnIndexesInGroup(previousColumnEntryIndex).size());
} else {
toPositions.add(firstPositionInGroup - 1);
}
} else {
// If is first member of the unbreakable group, can't move up i.e. out of the group
if (columnGroupModel != null && columnGroupModel.isPartOfAnUnbreakableGroup(columnEntryIndex) && !ColumnGroupUtils.isInTheSameGroup(columnEntryIndex, previousColumnEntryIndex, columnGroupModel)) {
return;
}
// If previous entry is an unbreakable column group - move above it
if (columnGroupModel != null && columnGroupModel.isPartOfAnUnbreakableGroup(previousColumnEntryIndex) && !ColumnGroupUtils.isInTheSameGroup(columnEntryIndex, previousColumnEntryIndex, columnGroupModel)) {
toPositions.add(firstPositionInGroup - columnGroupModel.getColumnIndexesInGroup(previousColumnEntryIndex).size());
} else {
toPositions.add(firstPositionInGroup - 1);
}
}
}
fireItemsMoved(MoveDirectionEnum.UP, selectedColumnGroupEntries, selectedColumnEntries, postionsGroupedByContiguous, toPositions);
}
}
}
use of net.sourceforge.nattable.columnChooser.ColumnEntry in project translationstudio8 by heartsome.
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)) {
String columnGroupName = columnGroupModel.getColumnGroupNameForIndex(columnEntryIndex);
TreeItem columnGroupTreeItem = getTreeItem(tree, columnGroupName);
if (columnGroupTreeItem == null) {
columnGroupTreeItem = new TreeItem(tree, SWT.NONE);
ColumnGroupEntry columnGroupEntry = new ColumnGroupEntry(columnGroupName, columnEntry.getPosition(), columnEntry.getIndex(), columnGroupModel.isCollapsed(columnEntryIndex));
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);
}
}
Aggregations