Search in sources :

Example 11 with ColumnEntry

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);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ColumnEntry(org.eclipse.nebula.widgets.nattable.columnChooser.ColumnEntry) ColumnGroupModel(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel)

Example 12 with ColumnEntry

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);
        }
    }
}
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) ColumnGroup(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup)

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