use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class LayerCommandUtil method convertColumnPositionToTargetContext.
public static ColumnPositionCoordinate convertColumnPositionToTargetContext(ColumnPositionCoordinate columnPositionCoordinate, ILayer targetLayer) {
if (columnPositionCoordinate != null) {
ILayer layer = columnPositionCoordinate.getLayer();
if (layer == targetLayer) {
return columnPositionCoordinate;
}
int columnPosition = columnPositionCoordinate.getColumnPosition();
int underlyingColumnPosition = layer.localToUnderlyingColumnPosition(columnPosition);
if (underlyingColumnPosition < 0) {
return null;
}
Collection<ILayer> underlyingLayers = layer.getUnderlyingLayersByColumnPosition(columnPosition);
if (underlyingLayers != null) {
for (ILayer underlyingLayer : underlyingLayers) {
if (underlyingLayer != null) {
ColumnPositionCoordinate convertedColumnPositionCoordinate = convertColumnPositionToTargetContext(new ColumnPositionCoordinate(underlyingLayer, underlyingColumnPosition), targetLayer);
if (convertedColumnPositionCoordinate != null) {
return convertedColumnPositionCoordinate;
}
}
}
}
}
return null;
}
use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class EditController method editCell.
/**
* Activates the edit mode for the given cell. Will determine whether the
* editor should be opened inline or in a subdialog.
*
* @param cell
* The cell that should be put into the edit mode.
* @param parent
* The parent Composite, needed for the creation of the editor
* control.
* @param initialCanonicalValue
* The value that should be put to the activated editor control.
* Usually this value should be the same as calling
* <code>cell.getDataValue()</code>, but for the special case
* that an editor should be activated pressing a letter or digit
* key on the current selection, the initial value should be the
* Character representing that key.
* @param configRegistry
* The {@link IConfigRegistry} containing the configuration of
* the current NatTable instance the command should be executed
* for. This is necessary because the edit controllers in the
* current architecture are not aware of the instance they are
* running in.
*/
public static void editCell(final ILayerCell cell, final Composite parent, Object initialCanonicalValue, final IConfigRegistry configRegistry) {
try {
// determine the position of the cell to put into edit mode
Rectangle cellBounds = cell.getBounds();
ILayer layer = cell.getLayer();
int columnPosition = cell.getColumnPosition();
int rowPosition = cell.getRowPosition();
// read the configuration for the specified cell for
// - which editor to use for that cell
final List<String> configLabels = cell.getConfigLabels().getLabels();
// check which editor to use
final ICellEditor cellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, configLabels);
if (cellEditor.openInline(configRegistry, configLabels)) {
// edit inline
ICellEditHandler editHandler = new InlineEditHandler(layer, columnPosition, rowPosition);
Rectangle editorBounds = layer.getLayerPainter().adjustCellBounds(columnPosition, rowPosition, new Rectangle(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height));
cellEditor.activateCell(parent, initialCanonicalValue, EditModeEnum.INLINE, editHandler, cell, configRegistry);
final Control editorControl = cellEditor.getEditorControl();
editorBounds = cellEditor.calculateControlBounds(editorBounds);
// NatTableBorderOverlayPainter
if (editorBounds.x == 0) {
editorBounds.x += 1;
editorBounds.width -= 1;
}
if (editorControl != null && !editorControl.isDisposed()) {
editorControl.setBounds(editorBounds);
// We need to add the control listeners after setting the
// bounds to it because of the strange behaviour on Mac OS
// where a control loses focus if its bounds are set
cellEditor.addEditorControlListeners();
layer.fireLayerEvent(new CellEditorCreatedEvent(cellEditor));
}
} else {
List<ILayerCell> cells = new ArrayList<ILayerCell>();
cells.add(cell);
editCells(cells, parent, initialCanonicalValue, configRegistry);
}
} catch (Exception e) {
if (cell == null) {
// $NON-NLS-1$
log.error("Cell being edited is no longer available. Initial value: " + initialCanonicalValue, e);
} else {
// $NON-NLS-1$ //$NON-NLS-2$
log.error("Error while editing cell: Cell: " + cell + "; Initial value: " + initialCanonicalValue, e);
}
}
}
use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class DefaultGridLayer method init.
protected void init(IUniqueIndexLayer bodyDataLayer, IUniqueIndexLayer columnHeaderDataLayer, IUniqueIndexLayer rowHeaderDataLayer, IUniqueIndexLayer cornerDataLayer) {
// Body
this.bodyDataLayer = bodyDataLayer;
DefaultBodyLayerStack bodyLayer = new DefaultBodyLayerStack(bodyDataLayer);
SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
// Column header
this.columnHeaderDataLayer = columnHeaderDataLayer;
ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayer, selectionLayer);
// Row header
this.rowHeaderDataLayer = rowHeaderDataLayer;
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayer, selectionLayer);
// Corner
this.cornerDataLayer = cornerDataLayer;
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnHeaderLayer);
setBodyLayer(bodyLayer);
setColumnHeaderLayer(columnHeaderLayer);
setRowHeaderLayer(rowHeaderLayer);
setCornerLayer(cornerLayer);
CopyDataCommandHandler cdch = new CopyDataCommandHandler(selectionLayer, columnHeaderDataLayer, rowHeaderDataLayer);
cdch.setCopyFormattedText(true);
registerCommandHandler(cdch);
}
use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class AbstractRowHideShowLayer method cacheVisibleRowIndexes.
protected void cacheVisibleRowIndexes() {
this.cachedVisibleRowIndexOrder = new HashMap<Integer, Integer>();
this.cachedVisibleRowPositionOrder = new HashMap<Integer, Integer>();
this.cachedHiddenRowIndexToPositionMap = new HashMap<Integer, Integer>();
this.startYCache.clear();
ILayer underlyingLayer = getUnderlyingLayer();
int rowPosition = 0;
for (int parentRowPosition = 0; parentRowPosition < underlyingLayer.getRowCount(); parentRowPosition++) {
int rowIndex = underlyingLayer.getRowIndexByPosition(parentRowPosition);
if (!isRowIndexHidden(rowIndex)) {
this.cachedVisibleRowIndexOrder.put(rowIndex, rowPosition);
this.cachedVisibleRowPositionOrder.put(rowPosition, rowIndex);
rowPosition++;
} else {
this.cachedHiddenRowIndexToPositionMap.put(rowIndex, rowPosition);
}
}
}
use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class ImagePainter method paintCell.
@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
if (this.paintBg) {
super.paintCell(cell, gc, bounds, configRegistry);
}
Image image = getImage(cell, configRegistry);
if (image != null) {
Rectangle imageBounds = image.getBounds();
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
int contentHeight = imageBounds.height;
if (this.calculateByHeight && (contentHeight > bounds.height)) {
int contentToCellDiff = (cell.getBounds().height - bounds.height);
ILayer layer = cell.getLayer();
layer.doCommand(new RowResizeCommand(layer, cell.getRowPosition(), contentHeight + contentToCellDiff, true));
}
int contentWidth = imageBounds.width;
if (this.calculateByWidth && (contentWidth > bounds.width)) {
int contentToCellDiff = (cell.getBounds().width - bounds.width);
ILayer layer = cell.getLayer();
layer.doCommand(new ColumnResizeCommand(layer, cell.getColumnPosition(), contentWidth + contentToCellDiff, true));
}
gc.drawImage(image, bounds.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, imageBounds.width), bounds.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, imageBounds.height));
}
}
Aggregations