Search in sources :

Example 16 with LayerCell

use of net.sourceforge.nattable.layer.cell.LayerCell in project translationstudio8 by heartsome.

the class RowHeightCalculator method getPreferredRowHeight.

private int getPreferredRowHeight(int rowPosition, IConfigRegistry configRegistry, int clientAreaHeight) {
    int maxHeight = 0;
    ICellPainter painter;
    LayerCell cell;
    SelectionLayer layer = bodyLayer.getSelectionLayer();
    for (int columnPosition = 0; columnPosition < layer.getColumnCount(); columnPosition++) {
        cell = layer.getCellByPosition(columnPosition, rowPosition);
        if (cell != null) {
            painter = configRegistry.getConfigAttribute(CellConfigAttributes.CELL_PAINTER, cell.getDisplayMode(), bodyLayer.getConfigLabelsByPosition(columnPosition, rowPosition).getLabels());
            if (painter != null) {
                int preferedHeight = painter.getPreferredHeight(cell, null, configRegistry);
                maxHeight = (preferedHeight > maxHeight) ? preferedHeight : maxHeight;
            }
        }
    }
    if (maxHeight > clientAreaHeight) {
        return clientAreaHeight;
    }
    return maxHeight;
}
Also used : SelectionLayer(net.sourceforge.nattable.selection.SelectionLayer) LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) ICellPainter(net.sourceforge.nattable.painter.cell.ICellPainter)

Example 17 with LayerCell

use of net.sourceforge.nattable.layer.cell.LayerCell in project translationstudio8 by heartsome.

the class MultiCellEditController method editSelectedCells.

public static boolean editSelectedCells(SelectionLayer selectionLayer, Character initialEditValue, Composite parent, IConfigRegistry configRegistry) {
    LayerCell lastSelectedCell = EditUtils.getLastSelectedCell(selectionLayer);
    // IF cell is selected
    if (lastSelectedCell != null) {
        final List<String> lastSelectedCellLabelsArray = lastSelectedCell.getConfigLabels().getLabels();
        PositionCoordinate[] selectedCells = selectionLayer.getSelectedCells();
        // AND selected cell count > 1
        if (selectedCells.length > 1) {
            ICellEditor lastSelectedCellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, lastSelectedCellLabelsArray);
            // AND all selected cells are editable
            if (EditUtils.isEditorSame(selectionLayer, configRegistry, lastSelectedCellEditor) && EditUtils.allCellsEditable(selectionLayer, configRegistry)) {
                // THEN use multi commit handler and populate editor in popup
                ICellEditor cellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, lastSelectedCellLabelsArray);
                IDisplayConverter dataTypeConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.EDIT, lastSelectedCellLabelsArray);
                IStyle cellStyle = new CellStyleProxy(configRegistry, DisplayMode.EDIT, lastSelectedCellLabelsArray);
                IDataValidator dataValidator = configRegistry.getConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, DisplayMode.EDIT, lastSelectedCellLabelsArray);
                Object originalCanonicalValue = lastSelectedCell.getDataValue();
                for (PositionCoordinate selectedCell : selectedCells) {
                    Object cellValue = selectionLayer.getCellByPosition(selectedCell.columnPosition, selectedCell.rowPosition).getDataValue();
                    if (!cellValue.equals(originalCanonicalValue)) {
                        originalCanonicalValue = null;
                        break;
                    }
                }
                ITickUpdateHandler tickUpdateHandler = configRegistry.getConfigAttribute(TickUpdateConfigAttributes.UPDATE_HANDLER, DisplayMode.EDIT, lastSelectedCellLabelsArray);
                boolean allowIncrementDecrement = tickUpdateHandler != null && tickUpdateHandler.isApplicableFor(originalCanonicalValue);
                MultiCellEditDialog dialog = new MultiCellEditDialog(parent.getShell(), cellEditor, dataTypeConverter, cellStyle, dataValidator, originalCanonicalValue, initialEditValue, allowIncrementDecrement);
                int returnValue = dialog.open();
                ActiveCellEditor.close();
                if (returnValue == Dialog.OK) {
                    Object editorValue = dialog.getEditorValue();
                    Object newValue = editorValue;
                    if (allowIncrementDecrement) {
                        switch(dialog.getEditType()) {
                            case INCREASE:
                                newValue = tickUpdateHandler.getIncrementedValue(originalCanonicalValue);
                                break;
                            case DECREASE:
                                newValue = tickUpdateHandler.getDecrementedValue(originalCanonicalValue);
                                break;
                        }
                    }
                    for (PositionCoordinate selectedCell : selectedCells) {
                        selectionLayer.doCommand(new UpdateDataCommand(selectionLayer, selectedCell.columnPosition, selectedCell.rowPosition, newValue));
                    }
                }
            }
        } else {
            // ELSE use single commit handler and populate editor inline in cell rectangle
            selectionLayer.fireLayerEvent(new InlineCellEditEvent(selectionLayer, new PositionCoordinate(selectionLayer, lastSelectedCell.getColumnPosition(), lastSelectedCell.getRowPosition()), parent, configRegistry, initialEditValue));
        }
        return true;
    }
    return false;
}
Also used : IDataValidator(net.sourceforge.nattable.data.validate.IDataValidator) MultiCellEditDialog(net.sourceforge.nattable.edit.gui.MultiCellEditDialog) LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) UpdateDataCommand(net.sourceforge.nattable.edit.command.UpdateDataCommand) IDisplayConverter(net.sourceforge.nattable.data.convert.IDisplayConverter) ITickUpdateHandler(net.sourceforge.nattable.tickupdate.ITickUpdateHandler) IStyle(net.sourceforge.nattable.style.IStyle) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) ICellEditor(net.sourceforge.nattable.edit.editor.ICellEditor) InlineCellEditEvent(net.sourceforge.nattable.edit.event.InlineCellEditEvent) CellStyleProxy(net.sourceforge.nattable.style.CellStyleProxy)

Example 18 with LayerCell

use of net.sourceforge.nattable.layer.cell.LayerCell in project translationstudio8 by heartsome.

the class EditCellCommandHandler method doCommand.

@Override
public boolean doCommand(EditCellCommand command) {
    LayerCell cell = command.getCell();
    Composite parent = command.getParent();
    IConfigRegistry configRegistry = command.getConfigRegistry();
    return InlineCellEditController.editCellInline(cell, null, parent, configRegistry);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) IConfigRegistry(net.sourceforge.nattable.config.IConfigRegistry)

Example 19 with LayerCell

use of net.sourceforge.nattable.layer.cell.LayerCell in project translationstudio8 by heartsome.

the class ColumnGroupHeaderLayer method getCellByPosition.

// Cell features
/**
	 * If a cell belongs to a column group:
	 * 	 column position - set to the start position of the group
	 * 	 span - set to the width/size of the column group
	 *
	 * NOTE: gc.setClip() is used in the CompositeLayerPainter to ensure that partially visible
	 * Column group header cells are rendered properly.
	 */
@Override
public LayerCell getCellByPosition(int columnPosition, int rowPosition) {
    int bodyColumnIndex = getColumnIndexByPosition(columnPosition);
    // Column group header cell
    if (model.isPartOfAGroup(bodyColumnIndex)) {
        if (rowPosition == 0) {
            return new LayerCell(this, getStartPositionOfGroup(columnPosition), rowPosition, columnPosition, rowPosition, getColumnSpan(columnPosition), 1);
        } else {
            return new LayerCell(this, columnPosition, rowPosition);
        }
    } else {
        // render column header w/ rowspan = 2
        LayerCell cell = columnHeaderLayer.getCellByPosition(columnPosition, 0);
        if (cell != null) {
            cell.updateLayer(this);
            cell.updateRowSpan(2);
        }
        return cell;
    }
}
Also used : LayerCell(net.sourceforge.nattable.layer.cell.LayerCell)

Example 20 with LayerCell

use of net.sourceforge.nattable.layer.cell.LayerCell in project translationstudio8 by heartsome.

the class AbstractLayerTransform method getCellByPosition.

// Cell features
@Override
public LayerCell getCellByPosition(int columnPosition, int rowPosition) {
    int underlyingColumnPosition = localToUnderlyingColumnPosition(columnPosition);
    int underlyingRowPosition = localToUnderlyingRowPosition(rowPosition);
    LayerCell cell = underlyingLayer.getCellByPosition(underlyingColumnPosition, underlyingRowPosition);
    if (cell != null) {
        cell.updatePosition(this, underlyingToLocalColumnPosition(underlyingLayer, cell.getOriginColumnPosition()), underlyingToLocalRowPosition(underlyingLayer, cell.getOriginRowPosition()), underlyingToLocalColumnPosition(underlyingLayer, cell.getColumnPosition()), underlyingToLocalRowPosition(underlyingLayer, cell.getRowPosition()));
    }
    return cell;
}
Also used : LayerCell(net.sourceforge.nattable.layer.cell.LayerCell)

Aggregations

LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)24 Rectangle (org.eclipse.swt.graphics.Rectangle)8 ICellPainter (net.sourceforge.nattable.painter.cell.ICellPainter)4 PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)3 IDisplayConverter (net.sourceforge.nattable.data.convert.IDisplayConverter)3 IStyle (net.sourceforge.nattable.style.IStyle)3 IDataValidator (net.sourceforge.nattable.data.validate.IDataValidator)2 UpdateDataCommand (net.sourceforge.nattable.edit.command.UpdateDataCommand)2 ICellEditor (net.sourceforge.nattable.edit.editor.ICellEditor)2 CellStyleProxy (net.sourceforge.nattable.style.CellStyleProxy)2 Point (org.eclipse.swt.graphics.Point)2 NavException (com.ximpleware.NavException)1 XPathEvalException (com.ximpleware.XPathEvalException)1 XPathParseException (com.ximpleware.XPathParseException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 InnerTagBean (net.heartsome.cat.common.innertag.InnerTagBean)1 XliffInnerTagFactory (net.heartsome.cat.common.innertag.factory.XliffInnerTagFactory)1 NoteBean (net.heartsome.cat.ts.core.bean.NoteBean)1