Search in sources :

Example 1 with ILayerListener

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

the class InlineCellEditController method editCellInline.

public static boolean editCellInline(LayerCell cell, Character initialEditValue, Composite parent, IConfigRegistry configRegistry) {
    try {
        ActiveCellEditor.commit();
        final List<String> configLabels = cell.getConfigLabels().getLabels();
        Rectangle cellBounds = cell.getBounds();
        ILayer layer = cell.getLayer();
        int columnPosition = layer.getColumnPositionByX(cellBounds.x);
        int columnIndex = layer.getColumnIndexByPosition(columnPosition);
        int rowPosition = layer.getRowPositionByY(cellBounds.y);
        int rowIndex = layer.getRowIndexByPosition(rowPosition);
        boolean editable = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, DisplayMode.EDIT, configLabels).isEditable(columnIndex, rowIndex);
        if (!editable) {
            return false;
        }
        ICellEditor cellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, configLabels);
        IDisplayConverter displayConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.EDIT, configLabels);
        IStyle cellStyle = new CellStyleProxy(configRegistry, DisplayMode.EDIT, configLabels);
        IDataValidator dataValidator = configRegistry.getConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, DisplayMode.EDIT, configLabels);
        ICellEditHandler editHandler = new SingleEditHandler(cellEditor, layer, columnPosition, rowPosition);
        final Rectangle editorBounds = layer.getLayerPainter().adjustCellBounds(new Rectangle(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height));
        Object originalCanonicalValue = cell.getDataValue();
        ActiveCellEditor.activate(cellEditor, parent, originalCanonicalValue, initialEditValue, displayConverter, cellStyle, dataValidator, editHandler, columnPosition, rowPosition, columnIndex, rowIndex);
        Control editorControl = ActiveCellEditor.getControl();
        if (editorControl != null) {
            editorControl.setBounds(editorBounds);
            ILayerListener layerListener = layerListenerMap.get(layer);
            if (layerListener == null) {
                layerListener = new InlineCellEditLayerListener(layer);
                layerListenerMap.put(layer, layerListener);
                layer.addLayerListener(layerListener);
            }
        }
    } catch (Exception e) {
        if (cell == null) {
            System.err.println("Cell being edited is no longer available. " + "Character: " + initialEditValue);
        } else {
            System.err.println("Error while editing cell (inline): " + "Cell: " + cell + "; Character: " + initialEditValue);
            e.printStackTrace(System.err);
        }
    }
    return true;
}
Also used : IDataValidator(net.sourceforge.nattable.data.validate.IDataValidator) ILayer(net.sourceforge.nattable.layer.ILayer) Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerListener(net.sourceforge.nattable.layer.ILayerListener) IDisplayConverter(net.sourceforge.nattable.data.convert.IDisplayConverter) IStyle(net.sourceforge.nattable.style.IStyle) Control(org.eclipse.swt.widgets.Control) ICellEditor(net.sourceforge.nattable.edit.editor.ICellEditor) CellStyleProxy(net.sourceforge.nattable.style.CellStyleProxy)

Aggregations

IDisplayConverter (net.sourceforge.nattable.data.convert.IDisplayConverter)1 IDataValidator (net.sourceforge.nattable.data.validate.IDataValidator)1 ICellEditor (net.sourceforge.nattable.edit.editor.ICellEditor)1 ILayer (net.sourceforge.nattable.layer.ILayer)1 ILayerListener (net.sourceforge.nattable.layer.ILayerListener)1 CellStyleProxy (net.sourceforge.nattable.style.CellStyleProxy)1 IStyle (net.sourceforge.nattable.style.IStyle)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 Control (org.eclipse.swt.widgets.Control)1