Search in sources :

Example 1 with ICellEditor

use of net.sourceforge.nattable.edit.editor.ICellEditor in project translationstudio8 by heartsome.

the class ChangeSourceEditableHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) {
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        ICellEditor cellEditor = xliffEditor.getTable().getConfigRegistry().getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, XLIFFEditorImplWithNatTable.SOURCE_EDIT_CELL_LABEL);
        if (cellEditor == null || !(cellEditor instanceof StyledTextCellEditor)) {
            return null;
        }
        HsMultiActiveCellEditor.commit(false);
        StyledTextCellEditor sce = (StyledTextCellEditor) cellEditor;
        EditableManager editableManager = sce.getEditableManager();
        //			SourceEditMode nextMode = editableManager.getSourceEditMode().getNextMode();
        SourceEditMode nextMode = getSourceEditMode(editableManager);
        editableManager.setSourceEditMode(nextMode);
        //			element.setIcon(Activator.getImageDescriptor(nextMode.getImagePath()));
        if (!sce.isClosed()) {
            editableManager.judgeEditable();
            //				更新全局 Action 的可用状态,主要是更新编辑-删除功能的可用状态。
            sce.getActionHandler().updateActionsEnableState();
        }
        sce.addClosingListener(listener);
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) SourceEditMode(net.heartsome.cat.ts.ui.xliffeditor.nattable.celleditor.SourceEditMode) EditableManager(net.heartsome.cat.ts.ui.xliffeditor.nattable.celleditor.EditableManager) ICellEditor(net.sourceforge.nattable.edit.editor.ICellEditor) IEditorPart(org.eclipse.ui.IEditorPart) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)

Example 2 with ICellEditor

use of net.sourceforge.nattable.edit.editor.ICellEditor in project translationstudio8 by heartsome.

the class EditUtils method isEditorSame.

public static boolean isEditorSame(SelectionLayer selectionLayer, IConfigRegistry configRegistry, ICellEditor lastSelectedCellEditor) {
    PositionCoordinate[] selectedCells = selectionLayer.getSelectedCells();
    boolean isAllSelectedCellsHaveSameEditor = true;
    for (PositionCoordinate selectedCell : selectedCells) {
        LabelStack labelStack = selectionLayer.getConfigLabelsByPosition(selectedCell.columnPosition, selectedCell.rowPosition);
        ICellEditor cellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, labelStack.getLabels());
        if (cellEditor != lastSelectedCellEditor) {
            isAllSelectedCellsHaveSameEditor = false;
        }
    }
    return isAllSelectedCellsHaveSameEditor;
}
Also used : LabelStack(net.sourceforge.nattable.layer.LabelStack) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) ICellEditor(net.sourceforge.nattable.edit.editor.ICellEditor)

Example 3 with ICellEditor

use of net.sourceforge.nattable.edit.editor.ICellEditor 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)

Example 4 with ICellEditor

use of net.sourceforge.nattable.edit.editor.ICellEditor 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 5 with ICellEditor

use of net.sourceforge.nattable.edit.editor.ICellEditor in project translationstudio8 by heartsome.

the class TickUpdateCommandHandler method doCommand.

public boolean doCommand(TickUpdateCommand command) {
    PositionCoordinate[] selectedPositions = selectionLayer.getSelectedCells();
    IConfigRegistry configRegistry = command.getConfigRegistry();
    // Tick update for multiple cells in selection 
    if (selectedPositions.length > 1) {
        ICellEditor lastSelectedCellEditor = EditUtils.lastSelectedCellEditor(selectionLayer, configRegistry);
        // Can all cells be updated ?
        if (EditUtils.isEditorSame(selectionLayer, configRegistry, lastSelectedCellEditor) && EditUtils.allCellsEditable(selectionLayer, configRegistry)) {
            for (PositionCoordinate position : selectedPositions) {
                updateSingleCell(command, position);
            }
        }
    } else {
        // Tick update for single selected cell
        updateSingleCell(command, selectionLayer.getLastSelectedCellPosition());
    }
    return true;
}
Also used : IConfigRegistry(net.sourceforge.nattable.config.IConfigRegistry) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) ICellEditor(net.sourceforge.nattable.edit.editor.ICellEditor)

Aggregations

ICellEditor (net.sourceforge.nattable.edit.editor.ICellEditor)6 PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)3 IDisplayConverter (net.sourceforge.nattable.data.convert.IDisplayConverter)2 IDataValidator (net.sourceforge.nattable.data.validate.IDataValidator)2 LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)2 CellStyleProxy (net.sourceforge.nattable.style.CellStyleProxy)2 IStyle (net.sourceforge.nattable.style.IStyle)2 EditableManager (net.heartsome.cat.ts.ui.xliffeditor.nattable.celleditor.EditableManager)1 SourceEditMode (net.heartsome.cat.ts.ui.xliffeditor.nattable.celleditor.SourceEditMode)1 StyledTextCellEditor (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)1 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)1 IConfigRegistry (net.sourceforge.nattable.config.IConfigRegistry)1 UpdateDataCommand (net.sourceforge.nattable.edit.command.UpdateDataCommand)1 InlineCellEditEvent (net.sourceforge.nattable.edit.event.InlineCellEditEvent)1 MultiCellEditDialog (net.sourceforge.nattable.edit.gui.MultiCellEditDialog)1 ILayer (net.sourceforge.nattable.layer.ILayer)1 ILayerListener (net.sourceforge.nattable.layer.ILayerListener)1 LabelStack (net.sourceforge.nattable.layer.LabelStack)1 ITickUpdateHandler (net.sourceforge.nattable.tickupdate.ITickUpdateHandler)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1