Search in sources :

Example 86 with ILayerCell

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

Example 87 with ILayerCell

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

Example 88 with ILayerCell

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++;
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) TransformedLayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.TransformedLayerCell)

Example 89 with ILayerCell

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

Example 90 with ILayerCell

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;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) InlineCellEditEvent(org.eclipse.nebula.widgets.nattable.edit.event.InlineCellEditEvent) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

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