use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class PositionCoordinateTest method setup.
@Before
public void setup() {
ILayer layer = new DataLayerFixture();
this.p1 = new PositionCoordinate(layer, 1, 2);
this.p2 = new PositionCoordinate(layer, 1, 2);
}
use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class CellSelectionTest method willSelectBodyCellAndShouldHaveColumnHeaderSelected.
@Test
public void willSelectBodyCellAndShouldHaveColumnHeaderSelected() {
// Select body cell
// The cell position is a grid layer position
this.gridLayer.doCommand(new SelectCellCommand(this.gridLayer, 2, 2, false, false));
// Get body layer cell corresponding to the selected body cell
ILayer bodyLayer = this.gridLayer.getBodyLayer();
// The column position is 1 because it takes into account the offset of
// the row header
ILayerCell cell = bodyLayer.getCellByPosition(1, 1);
// Assert the cell is in selected state
Assert.assertEquals(DisplayMode.SELECT, cell.getDisplayMode());
}
use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class LayerCommandUtil method convertPositionToTargetContext.
public static PositionCoordinate convertPositionToTargetContext(PositionCoordinate positionCoordinate, ILayer targetLayer) {
ILayer layer = positionCoordinate.getLayer();
if (layer == targetLayer) {
return positionCoordinate;
}
int columnPosition = positionCoordinate.getColumnPosition();
int underlyingColumnPosition = layer.localToUnderlyingColumnPosition(columnPosition);
if (underlyingColumnPosition < 0) {
return null;
}
int rowPosition = positionCoordinate.getRowPosition();
int underlyingRowPosition = layer.localToUnderlyingRowPosition(rowPosition);
if (underlyingRowPosition < 0) {
return null;
}
ILayer underlyingLayer = layer.getUnderlyingLayerByPosition(columnPosition, rowPosition);
if (underlyingLayer == null) {
return null;
}
return convertPositionToTargetContext(new PositionCoordinate(underlyingLayer, underlyingColumnPosition, underlyingRowPosition), targetLayer);
}
use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class LayerCommandUtil method convertRowPositionToTargetContext.
public static RowPositionCoordinate convertRowPositionToTargetContext(RowPositionCoordinate rowPositionCoordinate, ILayer targetLayer) {
if (rowPositionCoordinate != null) {
ILayer layer = rowPositionCoordinate.getLayer();
if (layer == targetLayer) {
return rowPositionCoordinate;
}
int rowPosition = rowPositionCoordinate.getRowPosition();
int underlyingRowPosition = layer.localToUnderlyingRowPosition(rowPosition);
if (underlyingRowPosition < 0) {
return null;
}
Collection<ILayer> underlyingLayers = layer.getUnderlyingLayersByRowPosition(rowPosition);
if (underlyingLayers != null) {
for (ILayer underlyingLayer : underlyingLayers) {
if (underlyingLayer != null) {
RowPositionCoordinate convertedRowPositionCoordinate = convertRowPositionToTargetContext(new RowPositionCoordinate(underlyingLayer, underlyingRowPosition), targetLayer);
if (convertedRowPositionCoordinate != null) {
return convertedRowPositionCoordinate;
}
}
}
}
}
return null;
}
use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class EditController method editCells.
/**
* This method is used to edit cells in a sub dialog. In every case this
* method will open a dialog for editing, regardless if the list of cells to
* edit contain several or only one value. Only if the given list of cells
* to edit is <code>null</code> or empty, there is no action performed.
*
* @param cells
* The list of cells to edit.
* @param parent
* The parent composite to access the parent shell, or
* <code>null</code> to create a top-level shell dialog. In the
* last case, the dialog will be opened as non modal.
* @param initialCanonicalValue
* The value that should be propagated to the editor control.
* Needed because for multi cell editing or editor activation by
* letter/digit key will result in a different value to populate
* for some editors than populating the value out of the
* cell/data model directly.
* @param configRegistry
* The {@link IConfigRegistry} containing the configuration of
* the current NatTable instance the command should be executed
* for. This is necessary because the edit controllers in the
* current architecture are not aware of the instance they are
* running in and therefore it is needed for activation of
* editors.
*/
public static void editCells(final Collection<ILayerCell> cells, final Composite parent, Object initialCanonicalValue, final IConfigRegistry configRegistry) {
if (cells != null && !cells.isEmpty()) {
// get the editor to use, because the editor contains information if
// it allows editing on a multi edit dialog
// Note: this works because previous to calling this method it is
// checked if all cells have the same editor configured. Otherwise
// this method will have serious issues further on.
ICellEditor cellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, cells.iterator().next().getConfigLabels().getLabels());
if (cells.size() == 1 || (cells.size() > 1 && supportMultiEdit(cells, cellEditor, configRegistry))) {
if (cellEditor.openMultiEditDialog()) {
// as the EditSelectionCommandHandler already ensured that
// all cells have the same configuration, we can simply use
// any cell for multi cell edit handling
ICellEditDialog dialog = CellEditDialogFactory.createCellEditDialog(parent != null ? parent.getShell() : null, initialCanonicalValue, cells.iterator().next(), cellEditor, configRegistry);
int returnValue = dialog.open();
if (returnValue == Window.OK) {
for (ILayerCell selectedCell : cells) {
Object editorValue = dialog.getCommittedValue();
if (!(dialog.getEditType() == EditTypeEnum.SET)) {
editorValue = dialog.calculateValue(selectedCell.getDataValue(), editorValue);
}
ILayer layer = selectedCell.getLayer();
layer.doCommand(new UpdateDataCommand(layer, selectedCell.getColumnPosition(), selectedCell.getRowPosition(), editorValue));
}
}
} else {
// directly changes the value and closes right away.
for (ILayerCell cell : cells) {
ICellEditHandler editHandler = new InlineEditHandler(cell.getLayer(), cell.getColumnPosition(), cell.getRowPosition());
cellEditor.activateCell(parent, initialCanonicalValue, EditModeEnum.INLINE, editHandler, cell, configRegistry);
}
}
}
}
}
Aggregations