Search in sources :

Example 1 with UpdateDataCommand

use of net.sourceforge.nattable.edit.command.UpdateDataCommand 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 2 with UpdateDataCommand

use of net.sourceforge.nattable.edit.command.UpdateDataCommand in project translationstudio8 by heartsome.

the class SingleEditHandler method commit.

/**
	 * {@inheritDoc}
 	 * Note: Assumes that the value is valid.<br/>
	 */
public boolean commit(MoveDirectionEnum direction, boolean closeEditorAfterCommit) {
    Object canonicalValue = cellEditor.getCanonicalValue();
    switch(direction) {
        case LEFT:
            layer.doCommand(new MoveSelectionCommand(MoveDirectionEnum.LEFT, 1, false, false));
            break;
        case RIGHT:
            layer.doCommand(new MoveSelectionCommand(MoveDirectionEnum.RIGHT, 1, false, false));
            break;
    }
    boolean committed = layer.doCommand(new UpdateDataCommand(layer, columnPosition, rowPosition, canonicalValue));
    if (committed && closeEditorAfterCommit) {
        cellEditor.close();
        return true;
    }
    return committed;
}
Also used : UpdateDataCommand(net.sourceforge.nattable.edit.command.UpdateDataCommand) MoveSelectionCommand(net.sourceforge.nattable.selection.command.MoveSelectionCommand)

Example 3 with UpdateDataCommand

use of net.sourceforge.nattable.edit.command.UpdateDataCommand in project translationstudio8 by heartsome.

the class TickUpdateCommandHandler method updateSingleCell.

private void updateSingleCell(TickUpdateCommand command, PositionCoordinate selectedPosition) {
    LayerCell cell = selectionLayer.getCellByPosition(selectedPosition.columnPosition, selectedPosition.rowPosition);
    IEditableRule editableRule = command.getConfigRegistry().getConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, DisplayMode.EDIT, cell.getConfigLabels().getLabels());
    if (editableRule.isEditable(selectedPosition.columnPosition, selectedPosition.rowPosition)) {
        selectionLayer.doCommand(new UpdateDataCommand(selectionLayer, selectedPosition.columnPosition, selectedPosition.rowPosition, getNewCellValue(command, cell)));
    }
}
Also used : IEditableRule(net.sourceforge.nattable.config.IEditableRule) LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) UpdateDataCommand(net.sourceforge.nattable.edit.command.UpdateDataCommand)

Aggregations

UpdateDataCommand (net.sourceforge.nattable.edit.command.UpdateDataCommand)3 LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)2 IEditableRule (net.sourceforge.nattable.config.IEditableRule)1 PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)1 IDisplayConverter (net.sourceforge.nattable.data.convert.IDisplayConverter)1 IDataValidator (net.sourceforge.nattable.data.validate.IDataValidator)1 ICellEditor (net.sourceforge.nattable.edit.editor.ICellEditor)1 InlineCellEditEvent (net.sourceforge.nattable.edit.event.InlineCellEditEvent)1 MultiCellEditDialog (net.sourceforge.nattable.edit.gui.MultiCellEditDialog)1 MoveSelectionCommand (net.sourceforge.nattable.selection.command.MoveSelectionCommand)1 CellStyleProxy (net.sourceforge.nattable.style.CellStyleProxy)1 IStyle (net.sourceforge.nattable.style.IStyle)1 ITickUpdateHandler (net.sourceforge.nattable.tickupdate.ITickUpdateHandler)1