Search in sources :

Example 6 with ColumnReorderEvent

use of org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent in project nebula.widgets.nattable by eclipse.

the class ColumnReorderLayer method reorderColumnPosition.

/**
 * Reorders the given from-column to the specified edge of the column to
 * move to and fires a {@link ColumnReorderEvent}.
 *
 * @param fromColumnPosition
 *            column position to move
 * @param toColumnPosition
 *            position to move the column to
 * @param reorderToLeftEdge
 *            <code>true</code> if the column should be moved to the left of
 *            the given column to move to, <code>false</code> if it should
 *            be positioned to the right
 */
public void reorderColumnPosition(int fromColumnPosition, int toColumnPosition, boolean reorderToLeftEdge) {
    moveColumn(fromColumnPosition, toColumnPosition, reorderToLeftEdge);
    fireLayerEvent(new ColumnReorderEvent(this, fromColumnPosition, toColumnPosition, reorderToLeftEdge));
}
Also used : ColumnReorderEvent(org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent)

Example 7 with ColumnReorderEvent

use of org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent in project tdq-studio-se by Talend.

the class DataSampleTable method addCustomSelectionBehaviour.

private void addCustomSelectionBehaviour() {
    natTable.addLayerListener(new ILayerListener() {

        @Override
        public void handleLayerEvent(ILayerEvent event) {
            if (event instanceof ColumnHeaderSelectionEvent) {
                ColumnHeaderSelectionEvent columnEvent = (ColumnHeaderSelectionEvent) event;
                Collection<Range> ranges = columnEvent.getColumnPositionRanges();
                if (ranges.size() > 0) {
                    Range range = ranges.iterator().next();
                    handleColumnSelectionChange(range.start);
                }
            } else if (event instanceof ColumnReorderEvent) {
                if (ColumnIndexMap == null) {
                    ColumnIndexMap = new HashMap<String, Integer>();
                } else {
                    ColumnIndexMap.clear();
                }
                // save propertyNames oder into lastTimePropertyNameOrder
                initPropertyNameOrder();
                // Fill elements into ColumnIndexMap before the order change ones.
                fillPreElement();
                // Fill the oder all of elements which display on the table into ColumnIndexMap
                fillElementWhichDisplayOnTable();
                // Fill the oder all of elements which after the order change ones.
                fillEndElement();
                // update newest order state on the lastTimePropertyNameOrder list
                savePropertyNameState();
                notifyObservers();
            }
        }

        /**
         * DOC talend Comment method "fillElementWhichDisplayOnTable". copy by #fillElementWhichDisplayOnTable
         */
        private void fillElementWhichDisplayOnTable() {
            for (int index = 1; index < natTable.getColumnCount(); index++) {
                int columnIndexByPosition = natTable.getColumnIndexByPosition(index);
                ColumnIndexMap.put(propertyNames[columnIndexByPosition], ColumnIndexMap.size());
            }
        }

        private void fillEndElement() {
            for (int index = ColumnIndexMap.size(); index < propertyNames.length; index++) {
                ColumnIndexMap.put(lastTimePropertyNameOrder.get(index), index);
            }
        }

        private void fillPreElement() {
            int disColumnCount = natTable.getColumnCount() - 1;
            // display all case so that no preElement one need to be filled
            if (disColumnCount >= lastTimePropertyNameOrder.size()) {
                return;
            }
            // not all display
            String endName = propertyNames[natTable.getColumnIndexByPosition(1)];
            int firstOneLastPosition = lastTimePropertyNameOrder.indexOf(endName);
            endName = propertyNames[natTable.getColumnIndexByPosition(2)];
            int secondOneLastPosition = lastTimePropertyNameOrder.indexOf(endName);
            if (secondOneLastPosition - firstOneLastPosition > 0) {
                // 1 is not be change order case
                endName = lastTimePropertyNameOrder.get(firstOneLastPosition);
                // For example 1->2+
                if (secondOneLastPosition - firstOneLastPosition == 1) {
                    String moveColName = findMoveColumnName(firstOneLastPosition - 1);
                    if (moveColName != null) {
                        endName = moveColName;
                    }
                }
            // For example 1->2,2+->1
            } else if (secondOneLastPosition - firstOneLastPosition < 0) {
                // in fact the value shoud be
                // firstOneLastPosition+secondOneLastPosition-firstOneLastPosition
                endName = lastTimePropertyNameOrder.get(secondOneLastPosition);
            }
            // ~ not all display
            int index = 0;
            for (String propertyName : lastTimePropertyNameOrder) {
                if (endName.equals(propertyName)) {
                    break;
                }
                ColumnIndexMap.put(propertyName, index++);
            }
        }

        /**
         * Find the column name which be moved on the ui
         *
         * @param spacing
         * @return
         */
        private String findMoveColumnName(int spacing) {
            for (int index = 3; index < natTable.getColumnCount() - 1; index++) {
                String propertyName = propertyNames[natTable.getColumnIndexByPosition(index)];
                int lastPosition = lastTimePropertyNameOrder.indexOf(propertyName);
                if (spacing > lastPosition - index) {
                    return propertyName;
                } else if (spacing == lastPosition - index) {
                    continue;
                } else {
                    break;
                }
            }
            return null;
        }
    });
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) ColumnHeaderSelectionEvent(org.eclipse.nebula.widgets.nattable.grid.layer.event.ColumnHeaderSelectionEvent) Collection(java.util.Collection) ColumnReorderEvent(org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range)

Example 8 with ColumnReorderEvent

use of org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent in project nebula.widgets.nattable by eclipse.

the class MultiColumnReorderEventDiffTest method testReorderLeftConvertToLocal.

/**
 * + - - - before: 0 1 2 3 4 5 6 7 8 9 10 after: 0 1 7 8 9 2 3 4 5 6 10 + +
 * + -
 */
@Test
public void testReorderLeftConvertToLocal() {
    this.event = new ColumnReorderEvent(this.dataLayer, Arrays.asList(new Integer[] { 7, 8, 9 }), 2, true);
    this.event.convertToLocal(this.viewportLayer);
    Collection<StructuralDiff> columnDiffs = this.event.getColumnDiffs();
    Assert.assertNotNull(columnDiffs);
    Assert.assertEquals(2, columnDiffs.size());
    Iterator<StructuralDiff> iterator = columnDiffs.iterator();
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.DELETE, new Range(5, 8), new Range(8, 8)), iterator.next());
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(0, 0), new Range(0, 3)), iterator.next());
}
Also used : StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) ColumnReorderEvent(org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 9 with ColumnReorderEvent

use of org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent in project nebula.widgets.nattable by eclipse.

the class MultiColumnReorderEventDiffTest method testReorderRightConvertToLocal.

/**
 * - - - + before: 0 1 2 3 4 5 6 7 8 after: 0 1 5 6 2 3 4 7 8 - + + +
 */
@Test
public void testReorderRightConvertToLocal() {
    this.event = new ColumnReorderEvent(this.dataLayer, Arrays.asList(new Integer[] { 2, 3, 4 }), 7, true);
    this.event.convertToLocal(this.viewportLayer);
    Collection<StructuralDiff> columnDiffs = this.event.getColumnDiffs();
    Assert.assertNotNull(columnDiffs);
    Assert.assertEquals(2, columnDiffs.size());
    Iterator<StructuralDiff> iterator = columnDiffs.iterator();
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.DELETE, new Range(0, 3), new Range(0, 0)), iterator.next());
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(5, 5), new Range(2, 5)), iterator.next());
}
Also used : StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) ColumnReorderEvent(org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Aggregations

ColumnReorderEvent (org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent)9 Test (org.junit.Test)6 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)5 StructuralDiff (org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)4 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)3 ILayerEvent (org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent)3 HashSet (java.util.HashSet)2 ColumnReorderLayer (org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer)2 BaseDataLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.BaseDataLayerFixture)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 Collection (java.util.Collection)1 ColumnHeaderSelectionEvent (org.eclipse.nebula.widgets.nattable.grid.layer.event.ColumnHeaderSelectionEvent)1