use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class RenameColumnIntegrationTest method shouldRenameColumnHeader.
@Test
public void shouldRenameColumnHeader() {
String originalColumnHeader = this.natTableFixture.getDataValueByPosition(2, 0).toString();
assertEquals("Column 2", originalColumnHeader);
this.natTableFixture.doCommand(new RenameColumnHeaderCommand(this.natTableFixture, 2, TEST_COLUMN_NAME));
String renamedColumnHeader = this.natTableFixture.getDataValueByPosition(2, 0).toString();
assertEquals(TEST_COLUMN_NAME, renamedColumnHeader);
assertEquals(1, this.listener.getEventsCount());
RenameColumnHeaderEvent event = (RenameColumnHeaderEvent) this.listener.getReceivedEvent(RenameColumnHeaderEvent.class);
assertEquals(new Range(2, 3), event.getColumnPositionRanges().iterator().next());
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class RenameColumnIntegrationTest method shouldRenameColumnHeaderForReorderedColumnProgrammatically.
@Test
public void shouldRenameColumnHeaderForReorderedColumnProgrammatically() {
String originalColumnHeader = this.natTableFixture.getDataValueByPosition(2, 0).toString();
assertEquals("Column 2", originalColumnHeader);
this.natTableFixture.doCommand(new ColumnReorderCommand(this.natTableFixture, 1, 5));
originalColumnHeader = this.natTableFixture.getDataValueByPosition(2, 0).toString();
assertEquals("Column 3", originalColumnHeader);
this.grid.getColumnHeaderLayer().renameColumnIndex(2, TEST_COLUMN_NAME);
String renamedColumnHeader = this.natTableFixture.getDataValueByPosition(2, 0).toString();
assertEquals(TEST_COLUMN_NAME, renamedColumnHeader);
assertEquals(2, this.listener.getEventsCount());
RenameColumnHeaderEvent event = (RenameColumnHeaderEvent) this.listener.getReceivedEvent(RenameColumnHeaderEvent.class);
assertEquals(new Range(2, 3), event.getColumnPositionRanges().iterator().next());
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class NatTable method handleLayerEvent.
// Events /////////////////////////////////////////////////////////////////
@Override
public void handleLayerEvent(ILayerEvent event) {
List<ILayerListener> currentListeners;
this.eventListenerLock.readLock().lock();
try {
currentListeners = this.listeners;
} finally {
this.eventListenerLock.readLock().unlock();
}
for (ILayerListener layerListener : currentListeners) {
layerListener.handleLayerEvent(event);
}
if (event instanceof CellVisualUpdateEvent) {
CellVisualUpdateEvent update = (CellVisualUpdateEvent) event;
repaintCell(update.getColumnPosition(), update.getRowPosition());
return;
}
if (event instanceof ColumnVisualUpdateEvent) {
ColumnVisualUpdateEvent update = (ColumnVisualUpdateEvent) event;
// if more than one column has changed repaint the whole table
Collection<Range> ranges = update.getColumnPositionRanges();
if (ranges.size() == 1) {
Range range = ranges.iterator().next();
if (range.end - range.start == 1) {
repaintColumn(range.start);
return;
}
}
}
if (event instanceof RowVisualUpdateEvent) {
RowVisualUpdateEvent update = (RowVisualUpdateEvent) event;
// if more than one row has changed repaint the whole table
Collection<Range> ranges = update.getRowPositionRanges();
if (ranges.size() == 1) {
Range range = ranges.iterator().next();
if (range.end - range.start == 1) {
repaintRow(range.start);
return;
}
}
}
if (event instanceof ISelectionEvent) {
if (event instanceof CellSelectionEvent || event instanceof RowSelectionEvent) {
Event e = new Event();
e.widget = this;
try {
notifyListeners(SWT.Selection, e);
} catch (RuntimeException re) {
// $NON-NLS-1$
log.error("Error on SWT selection processing", re);
}
}
// in case of selections we redraw immediately
// this is because with Bug 440037 it was reported that
// NatTable is too lazy in handling selections which
// was caused by the EventConflaterChain that only performs
// updates every 100ms to avoid flickering when handling too
// many refresh operations in a short period
redraw();
} else if (event instanceof IVisualChangeEvent) {
this.conflaterChain.addEvent(event);
}
if (event instanceof CellEditorCreatedEvent) {
CellEditorCreatedEvent editorEvent = (CellEditorCreatedEvent) event;
this.activeCellEditor = editorEvent.getEditor();
Control editorControl = this.activeCellEditor.getEditorControl();
if (editorControl != null && !editorControl.isDisposed()) {
editorControl.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
NatTable.this.activeCellEditor = null;
ActiveCellEditorRegistry.unregisterActiveCellEditor();
}
});
} else {
this.activeCellEditor = null;
ActiveCellEditorRegistry.unregisterActiveCellEditor();
}
ActiveCellEditorRegistry.registerActiveCellEditor(this.activeCellEditor);
}
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class RenameColumnHelper method handleStructuralChanges.
/**
* Handle the given collection of {@link StructuralDiff} objects to update
* the indexes of the renamed column labels.
*
* @param columnDiffs
* The {@link StructuralDiff}s to handle
* @since 1.4
*/
public void handleStructuralChanges(Collection<StructuralDiff> columnDiffs) {
// the number of all deleted columns that don't have a corresponding
// index anymore (last column cases)
List<Integer> toRemove = new ArrayList<Integer>();
for (StructuralDiff columnDiff : columnDiffs) {
if (columnDiff.getDiffType() != null && columnDiff.getDiffType().equals(DiffTypeEnum.DELETE)) {
Range beforePositionRange = columnDiff.getBeforePositionRange();
for (int i = beforePositionRange.start; i < beforePositionRange.end; i++) {
int index = i;
if (index >= 0)
toRemove.add(index);
}
}
}
// remove the column indexes that are deleted
for (Integer r : toRemove) {
this.renamedColumnsLabelsByIndex.remove(r);
}
// modify column indexes regarding the deleted columns
List<Integer> indices = new ArrayList<Integer>(this.renamedColumnsLabelsByIndex.keySet());
Collections.sort(indices);
Map<Integer, String> modified = new TreeMap<Integer, String>();
for (Integer column : indices) {
// check number of removed indexes that are lower than the current
// one
int deletedBefore = 0;
for (Integer removed : toRemove) {
if (removed < column) {
deletedBefore++;
}
}
int modColumn = column - deletedBefore;
if (modColumn >= 0)
modified.put(modColumn, this.renamedColumnsLabelsByIndex.get(column));
}
this.renamedColumnsLabelsByIndex.clear();
this.renamedColumnsLabelsByIndex.putAll(modified);
for (StructuralDiff columnDiff : columnDiffs) {
if (columnDiff.getDiffType() != null && columnDiff.getDiffType().equals(DiffTypeEnum.ADD)) {
indices = new ArrayList<Integer>(this.renamedColumnsLabelsByIndex.keySet());
Collections.sort(indices);
Range beforePositionRange = columnDiff.getBeforePositionRange();
Range afterPositionRange = columnDiff.getAfterPositionRange();
Map<Integer, String> modifiedColumns = new TreeMap<Integer, String>();
int beforeIndex = this.columnHeaderLayer.getColumnIndexByPosition(beforePositionRange.start);
for (Integer column : indices) {
if (column >= beforeIndex) {
modifiedColumns.put(column + (afterPositionRange.end - afterPositionRange.start), this.renamedColumnsLabelsByIndex.get(column));
} else {
modifiedColumns.put(column, this.renamedColumnsLabelsByIndex.get(column));
}
}
this.renamedColumnsLabelsByIndex.clear();
this.renamedColumnsLabelsByIndex.putAll(modifiedColumns);
}
}
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class CopyDataCommandHandler method assembleCopiedDataStructure.
/**
* Collects and assembles the selected data that should be copied to the
* clipboard.
*
* @return A two dimensional array containing the selected cells to copy to
* the clipboard. The first level of this array represent the row
* positions of the cells, while the second level contains the cells
* itself based on the column position.
*/
protected ILayerCell[][] assembleCopiedDataStructure() {
final Set<Range> selectedRows = this.selectionLayer.getSelectedRowPositions();
final ILayerCell[][] copiedCells = assembleColumnHeaders();
// cleanup the row positions to copy
// this is needed because taking only the Range.start into account leads
// to overriding values in the array instead of adding if there are
// multiple Ranges returned
List<Integer> selectedRowPositions = new ArrayList<Integer>();
for (Range range : selectedRows) {
for (int rowPosition = range.start; rowPosition < range.end; rowPosition++) {
selectedRowPositions.add(rowPosition);
}
}
// ensure the correct order as a Set is not ordered at all and we want
// to paste the values in the same order we copied them.
Collections.sort(selectedRowPositions);
final int rowOffset = this.columnHeaderDataLayer != null ? this.columnHeaderDataLayer.getRowCount() : 0;
for (int i = 0; i < selectedRowPositions.size(); i++) {
Integer rowPos = selectedRowPositions.get(i);
copiedCells[i + rowOffset] = assembleBody(rowPos);
}
return copiedCells;
}
Aggregations