use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class NatColumnTableFormat method getColumnComparator.
@Override
public Comparator<?> getColumnComparator(final int col) {
ILayerCell cell = this.columnHeaderDataLayer.getCellByPosition(col, 0);
if (cell == null) {
return null;
}
Comparator<?> comparator = this.configRegistry.getConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, cell.getDisplayMode(), cell.getConfigLabels().getLabels());
return (comparator instanceof NullComparator) ? null : comparator;
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class PoiExcelExporter method exportCell.
@Override
public void exportCell(OutputStream outputStream, Object exportDisplayValue, ILayerCell cell, IConfigRegistry configRegistry) throws IOException {
int columnPosition = cell.getColumnPosition();
int rowPosition = cell.getRowPosition();
if (columnPosition != cell.getOriginColumnPosition() || rowPosition != cell.getOriginRowPosition()) {
return;
}
if (this.applyColumnWidths && cell.getColumnSpan() == 1) {
this.xlSheet.setColumnWidth(columnPosition, getPoiColumnWidth(cell.getBounds().width) + getPoiColumnWidth(5));
}
if (this.applyRowHeights && cell.getRowSpan() == 1) {
this.xlRow.setHeight(getPoiRowHeight(cell.getBounds().height));
}
// check if cell was already created because of spanning
Cell xlCell = this.xlRow.getCell(columnPosition);
if (xlCell == null) {
xlCell = this.xlRow.createCell(columnPosition);
}
CellStyleProxy cellStyle = new CellStyleProxy(configRegistry, DisplayMode.NORMAL, cell.getConfigLabels().getLabels());
Color fg = cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR);
Color bg = cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);
org.eclipse.swt.graphics.Font font = cellStyle.getAttributeValue(CellStyleAttributes.FONT);
FontData fontData = font.getFontData()[0];
String dataFormat = null;
if (exportDisplayValue instanceof Calendar || exportDisplayValue instanceof Date) {
dataFormat = getDataFormatString(cell, configRegistry);
}
int hAlign = HorizontalAlignmentEnum.getSWTStyle(cellStyle);
int vAlign = VerticalAlignmentEnum.getSWTStyle(cellStyle);
ICellPainter cellPainter = configRegistry.getConfigAttribute(CellConfigAttributes.CELL_PAINTER, DisplayMode.NORMAL, cell.getConfigLabels().getLabels());
boolean vertical = this.applyVerticalTextConfiguration ? isVertical(cellPainter) : false;
boolean wrap = this.applyTextWrapping ? wrapText(cellPainter) : false;
CellStyle xlCellStyle = getExcelCellStyle(fg, bg, fontData, dataFormat, hAlign, vAlign, vertical, wrap, this.applyCellBorders);
xlCell.setCellStyle(xlCellStyle);
int columnSpan = cell.getColumnSpan();
int rowSpan = cell.getRowSpan();
if (columnSpan > 1 || rowSpan > 1) {
int lastRow = rowPosition + rowSpan - 1;
int lastColumn = columnPosition + columnSpan - 1;
this.xlSheet.addMergedRegion(new CellRangeAddress(rowPosition, lastRow, columnPosition, lastColumn));
// apply style to all cells that get merged
Row tempRow = null;
Cell tempCell = null;
for (int i = rowPosition; i <= lastRow; i++) {
tempRow = this.xlSheet.getRow(i);
if (tempRow == null) {
tempRow = this.xlSheet.createRow(i);
}
for (int j = columnPosition; j <= lastColumn; j++) {
tempCell = tempRow.getCell(j);
if (tempCell == null) {
tempCell = tempRow.createCell(j);
}
tempCell.setCellStyle(xlCellStyle);
}
}
}
if (exportDisplayValue == null)
// $NON-NLS-1$
exportDisplayValue = "";
if (exportDisplayValue instanceof Boolean) {
xlCell.setCellValue((Boolean) exportDisplayValue);
} else if (exportDisplayValue instanceof Calendar) {
xlCell.setCellValue((Calendar) exportDisplayValue);
} else if (exportDisplayValue instanceof Date) {
xlCell.setCellValue((Date) exportDisplayValue);
} else if (exportDisplayValue instanceof Number) {
xlCell.setCellValue(((Number) exportDisplayValue).doubleValue());
} else if (exportDisplayValue instanceof InputStream) {
exportImage((InputStream) exportDisplayValue, xlCell);
} else if (this.formulaParser != null) {
// formula export is enabled, so we perform checks on the cell
// values
String cellValue = exportDisplayValue.toString();
if (this.formulaParser.isFunction(cellValue)) {
String functionString = this.formulaParser.getFunctionOnly(cellValue);
// POI expects the formula parameters to be separated by ,
// instead of ;
// also localized decimal separators need to be modified for
// export
functionString = functionString.replace(',', '.');
functionString = functionString.replace(';', ',');
xlCell.setCellFormula(functionString);
} else if (this.formulaParser.isNumber(cellValue)) {
try {
xlCell.setCellValue(this.nf.parse(cellValue).doubleValue());
} catch (ParseException e) {
// $NON-NLS-1$
throw new IOException("Error on parsing number value: " + cellValue, e);
}
} else {
xlCell.setCellValue(exportDisplayValue.toString());
}
} else {
xlCell.setCellValue(exportDisplayValue.toString());
}
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class GroupByComparator method isTreeColumn.
/**
* @param columnIndex
* The column index of the column that should be checked.
* @return <code>true</code> if the column at the given index is the tree
* column, <code>false</code> if not or if no treeLayer reference is
* set to this {@link GroupByComparator}
*/
protected boolean isTreeColumn(int columnIndex) {
if (this.treeLayer != null) {
int columnPosition = this.treeLayer.getColumnPositionByIndex(columnIndex);
ILayerCell cell = this.treeLayer.getCellByPosition(columnPosition, 0);
if (cell != null) {
return cell.getConfigLabels().hasLabel(TreeLayer.TREE_COLUMN_CELL);
}
}
// tree column and therefore no column is treated that way
return false;
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class HierarchicalWrapperSortModel method getColumnComparator.
@Override
public Comparator<?> getColumnComparator(int columnIndex) {
ILayerCell cell = this.columnHeaderDataLayer.getCellByPosition(columnIndex, 0);
if (cell == null) {
return null;
}
Comparator<?> comparator = this.configRegistry.getConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, cell.getDisplayMode(), cell.getConfigLabels().getLabels());
return (comparator instanceof NullComparator) ? null : comparator;
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class EditUtilsTest method testGetLastSelectedCellWithMultiSelection.
@Test
public void testGetLastSelectedCellWithMultiSelection() {
this.selectionLayer.selectCell(1, 1, false, true);
this.selectionLayer.selectCell(2, 2, false, true);
this.selectionLayer.selectCell(3, 3, false, true);
ILayerCell cell = EditUtils.getLastSelectedCell(this.selectionLayer);
assertNotNull(cell);
assertEquals(3, cell.getColumnIndex());
assertEquals(3, cell.getRowIndex());
}
Aggregations