Search in sources :

Example 56 with ILayerCell

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;
}
Also used : NullComparator(org.eclipse.nebula.widgets.nattable.config.NullComparator) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 57 with ILayerCell

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());
    }
}
Also used : InputStream(java.io.InputStream) Color(org.eclipse.swt.graphics.Color) FontData(org.eclipse.swt.graphics.FontData) Calendar(java.util.Calendar) IOException(java.io.IOException) Date(java.util.Date) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter) CellStyle(org.apache.poi.ss.usermodel.CellStyle) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Row(org.apache.poi.ss.usermodel.Row) ParseException(java.text.ParseException) Cell(org.apache.poi.ss.usermodel.Cell) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) CellStyleProxy(org.eclipse.nebula.widgets.nattable.style.CellStyleProxy)

Example 58 with ILayerCell

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;
}
Also used : ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 59 with ILayerCell

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;
}
Also used : NullComparator(org.eclipse.nebula.widgets.nattable.config.NullComparator) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 60 with ILayerCell

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());
}
Also used : ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Test(org.junit.Test)

Aggregations

ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)118 Test (org.junit.Test)45 Rectangle (org.eclipse.swt.graphics.Rectangle)23 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)14 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)14 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)11 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)10 LabelStack (org.eclipse.nebula.widgets.nattable.layer.LabelStack)10 Color (org.eclipse.swt.graphics.Color)10 EditCellCommand (org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand)9 ICellPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)9 DataProviderFixture (org.eclipse.nebula.widgets.nattable.test.fixture.data.DataProviderFixture)9 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)8 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)5 Point (org.eclipse.swt.graphics.Point)5 HashSet (java.util.HashSet)4 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)4 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)4 IEditableRule (org.eclipse.nebula.widgets.nattable.config.IEditableRule)4 ICellEditor (org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor)4