use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell 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.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class StyleInheritanceTest method shouldFallBackToSuperTypeAttributesForOddCell.
@Test
public void shouldFallBackToSuperTypeAttributesForOddCell() {
ILayerCell cell = this.natTable.getCellByPosition(2, 3);
// Test cell odd attributes
final IStyle cellInstanceStyle = this.configRegistry.getConfigAttribute(CellConfigAttributes.CELL_STYLE, cell.getDisplayMode(), cell.getConfigLabels().getLabels());
Assert.assertEquals(Display.getDefault().getSystemColor(SWT.COLOR_RED), cellInstanceStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
// Test super odd attributes
StyleProxy cellProxy = new CellStyleProxy(this.configRegistry, cell.getDisplayMode(), cell.getConfigLabels().getLabels());
final Color fontAttributeValue = cellProxy.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);
Assert.assertEquals(this.defaultBackgroundColor, fontAttributeValue);
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class TestLayer method parseCellsInfo.
public void parseCellsInfo(String cellsInfo) {
int rowPosition = 0;
StringTokenizer rowOfCellInfoTokenizer = new StringTokenizer(cellsInfo, "\n");
while (rowOfCellInfoTokenizer.hasMoreTokens()) {
String rowOfCellInfo = rowOfCellInfoTokenizer.nextToken().trim();
int columnPosition = 0;
StringTokenizer cellInfoTokenizer = new StringTokenizer(rowOfCellInfo, "|");
while (cellInfoTokenizer.hasMoreTokens()) {
String cellInfo = cellInfoTokenizer.nextToken().trim();
StringTokenizer cellInfoFieldTokenizer = new StringTokenizer(cellInfo, "~:", true);
while (cellInfoFieldTokenizer.hasMoreTokens()) {
String token = cellInfoFieldTokenizer.nextToken().trim();
if ("<".equals(token)) {
// Span from left
this.dataValues[columnPosition][rowPosition] = this.dataValues[columnPosition - 1][rowPosition];
ILayerCell cell = this.cells[columnPosition - 1][rowPosition];
Rectangle boundsRect = this.bounds[columnPosition - 1][rowPosition];
if (columnPosition >= cell.getColumnPosition() + cell.getColumnSpan()) {
boundsRect = new Rectangle(boundsRect.x, boundsRect.y, boundsRect.width + getColumnWidthByPosition(columnPosition), boundsRect.height);
final ILayerCell underlyingCell = cell;
cell = new TransformedLayerCell(cell) {
@Override
public int getColumnSpan() {
return underlyingCell.getColumnSpan() + 1;
}
};
}
this.cells[columnPosition][rowPosition] = cell;
this.bounds[columnPosition][rowPosition] = boundsRect;
if (cellInfoFieldTokenizer.hasMoreTokens()) {
System.out.println("Extra tokens detected after parsing span for cell position " + columnPosition + "," + rowPosition + "; ignoring");
}
break;
} else if ("^".equals(token)) {
// Span from above
this.dataValues[columnPosition][rowPosition] = this.dataValues[columnPosition][rowPosition - 1];
ILayerCell cell = this.cells[columnPosition][rowPosition - 1];
Rectangle boundsRect = this.bounds[columnPosition][rowPosition - 1];
if (rowPosition >= cell.getRowPosition() + cell.getRowSpan()) {
boundsRect = new Rectangle(boundsRect.x, boundsRect.y, boundsRect.width, boundsRect.height + getRowHeightByPosition(rowPosition));
final ILayerCell underlyingCell = cell;
cell = new TransformedLayerCell(cell) {
@Override
public int getRowSpan() {
return underlyingCell.getRowSpan() + 1;
}
};
}
this.cells[columnPosition][rowPosition] = cell;
this.bounds[columnPosition][rowPosition] = boundsRect;
if (cellInfoFieldTokenizer.hasMoreTokens()) {
System.out.println("Extra tokens detected after parsing span for cell position " + columnPosition + "," + rowPosition + "; ignoring");
}
break;
} else if ("~".equals(token)) {
String nextToken = cellInfoFieldTokenizer.nextToken().trim();
if ("~".equals(nextToken)) {
throw new IllegalArgumentException("Bad " + nextToken + " delimiter found when parsing display mode for cell position " + columnPosition + "," + rowPosition);
} else if (":".equals(nextToken)) {
// Parse config labels
parseConfigLabels(columnPosition, rowPosition, cellInfoFieldTokenizer, cellInfoFieldTokenizer.nextToken().trim());
break;
} else {
// Parse display mode
this.displayModes[columnPosition][rowPosition] = nextToken;
}
} else if (":".equals(token)) {
String nextToken = cellInfoFieldTokenizer.nextToken().trim();
if ("~".equals(nextToken)) {
throw new IllegalArgumentException("Bad " + nextToken + " delimiter found when parsing config labels for cell position " + columnPosition + "," + rowPosition);
} else if (":".equals(nextToken)) {
throw new IllegalArgumentException("Bad " + nextToken + " delimiter found when parsing config labels for cell position " + columnPosition + "," + rowPosition);
} else {
// Parse config labels
parseConfigLabels(columnPosition, rowPosition, cellInfoFieldTokenizer, nextToken);
break;
}
} else {
// Parse data value
this.dataValues[columnPosition][rowPosition] = token;
this.cells[columnPosition][rowPosition] = new TestLayerCell(this, columnPosition, rowPosition);
this.bounds[columnPosition][rowPosition] = new Rectangle(getStartXOfColumnPosition(columnPosition), getStartYOfRowPosition(rowPosition), getColumnWidthByPosition(columnPosition), getRowHeightByPosition(rowPosition));
}
}
columnPosition++;
}
rowPosition++;
}
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class CopyDataToClipboardSerializer method serialize.
@Override
public void serialize() {
final String cellDelimeter = this.command.getCellDelimeter();
final String rowDelimeter = this.command.getRowDelimeter();
final TextTransfer textTransfer = TextTransfer.getInstance();
final StringBuilder textData = new StringBuilder();
int currentRow = 0;
for (ILayerCell[] cells : this.copiedCells) {
int currentCell = 0;
for (ILayerCell cell : cells) {
final String delimeter = ++currentCell < cells.length ? cellDelimeter : // $NON-NLS-1$
"";
if (cell != null) {
textData.append(getTextForCell(cell) + delimeter);
} else {
textData.append(delimeter);
}
}
if (++currentRow < this.copiedCells.length) {
textData.append(rowDelimeter);
}
}
if (textData.length() > 0) {
final Clipboard clipboard = new Clipboard(Display.getDefault());
try {
clipboard.setContents(new Object[] { textData.toString() }, new Transfer[] { textTransfer });
} finally {
clipboard.dispose();
}
}
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class EditSelectionCommandHandler method doCommand.
@Override
public boolean doCommand(EditSelectionCommand command) {
Composite parent = command.getParent();
IConfigRegistry configRegistry = command.getConfigRegistry();
Character initialValue = command.getCharacter();
if (EditUtils.allCellsEditable(this.selectionLayer, configRegistry) && EditUtils.isEditorSame(this.selectionLayer, configRegistry) && EditUtils.isConverterSame(this.selectionLayer, configRegistry) && EditUtils.activateLastSelectedCellEditor(this.selectionLayer, configRegistry, command.isByTraversal())) {
// check how many cells are selected
Collection<ILayerCell> selectedCells = EditUtils.getSelectedCellsForEditing(this.selectionLayer);
if (selectedCells.size() == 1) {
// editing is triggered by key for a single cell
// we need to fire the InlineCellEditEvent here because we
// don't know the correct bounds of the cell to edit inline
// corresponding to the NatTable.
// On firing the event, a translation process is triggered,
// converting the information to the correct values
// needed for inline editing
ILayerCell cell = selectedCells.iterator().next();
this.selectionLayer.fireLayerEvent(new InlineCellEditEvent(this.selectionLayer, new PositionCoordinate(this.selectionLayer, cell.getOriginColumnPosition(), cell.getOriginRowPosition()), parent, configRegistry, (initialValue != null ? initialValue : cell.getDataValue())));
} else if (selectedCells.size() > 1) {
// determine the initial value
Object initialEditValue = initialValue;
if (initialValue == null && EditUtils.isValueSame(this.selectionLayer)) {
ILayerCell cell = selectedCells.iterator().next();
initialEditValue = this.selectionLayer.getDataValueByPosition(cell.getColumnPosition(), cell.getRowPosition());
}
EditController.editCells(selectedCells, parent, initialEditValue, configRegistry);
}
}
// successful or not
return true;
}
Aggregations