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;
}
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;
}
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);
}
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;
}
}
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;
}
Aggregations