Search in sources :

Example 21 with PositionCoordinate

use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.

the class EditUtils method allCellsEditable.

public static boolean allCellsEditable(SelectionLayer selectionLayer, IConfigRegistry configRegistry) {
    PositionCoordinate[] selectedCells = selectionLayer.getSelectedCells();
    for (PositionCoordinate cell : selectedCells) {
        LabelStack labelStack = selectionLayer.getConfigLabelsByPosition(cell.columnPosition, cell.rowPosition);
        IEditableRule editableRule = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, DisplayMode.EDIT, labelStack.getLabels());
        int columnIndex = selectionLayer.getColumnIndexByPosition(cell.columnPosition);
        int rowIndex = selectionLayer.getRowIndexByPosition(cell.rowPosition);
        if (!editableRule.isEditable(columnIndex, rowIndex)) {
            return false;
        }
    }
    return true;
}
Also used : LabelStack(net.sourceforge.nattable.layer.LabelStack) IEditableRule(net.sourceforge.nattable.config.IEditableRule) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate)

Example 22 with PositionCoordinate

use of net.sourceforge.nattable.coordinate.PositionCoordinate 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 23 with PositionCoordinate

use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.

the class FreezeEventHandler method handleLayerEvent.

public void handleLayerEvent(IStructuralChangeEvent event) {
    PositionCoordinate topLeftPosition = freezeLayer.getTopLeftPosition();
    PositionCoordinate bottomRightPosition = freezeLayer.getBottomRightPosition();
    Collection<StructuralDiff> columnDiffs = event.getColumnDiffs();
    if (columnDiffs != null) {
        int leftOffset = 0;
        int rightOffset = 0;
        for (StructuralDiff columnDiff : columnDiffs) {
            switch(columnDiff.getDiffType()) {
                case ADD:
                    Range afterPositionRange = columnDiff.getAfterPositionRange();
                    if (afterPositionRange.start < topLeftPosition.columnPosition) {
                        leftOffset += afterPositionRange.size();
                    }
                    if (afterPositionRange.start <= bottomRightPosition.columnPosition) {
                        rightOffset += afterPositionRange.size();
                    }
                    break;
                case DELETE:
                    Range beforePositionRange = columnDiff.getBeforePositionRange();
                    if (beforePositionRange.start < topLeftPosition.columnPosition) {
                        leftOffset -= Math.min(beforePositionRange.end, topLeftPosition.columnPosition + 1) - beforePositionRange.start;
                    }
                    if (beforePositionRange.start <= bottomRightPosition.columnPosition) {
                        rightOffset -= Math.min(beforePositionRange.end, bottomRightPosition.columnPosition + 1) - beforePositionRange.start;
                    }
                    break;
            }
        }
        topLeftPosition.columnPosition += leftOffset;
        bottomRightPosition.columnPosition += rightOffset;
    }
    Collection<StructuralDiff> rowDiffs = event.getRowDiffs();
    if (rowDiffs != null) {
        int leftOffset = 0;
        int rightOffset = 0;
        for (StructuralDiff rowDiff : rowDiffs) {
            switch(rowDiff.getDiffType()) {
                case ADD:
                    Range afterPositionRange = rowDiff.getAfterPositionRange();
                    if (afterPositionRange.start < topLeftPosition.rowPosition) {
                        leftOffset += afterPositionRange.size();
                    }
                    if (afterPositionRange.start <= bottomRightPosition.rowPosition) {
                        rightOffset += afterPositionRange.size();
                    }
                    break;
                case DELETE:
                    Range beforePositionRange = rowDiff.getBeforePositionRange();
                    if (beforePositionRange.start < topLeftPosition.rowPosition) {
                        leftOffset -= Math.min(beforePositionRange.end, topLeftPosition.rowPosition + 1) - beforePositionRange.start;
                    }
                    if (beforePositionRange.start <= bottomRightPosition.rowPosition) {
                        rightOffset -= Math.min(beforePositionRange.end, bottomRightPosition.rowPosition + 1) - beforePositionRange.start;
                    }
                    break;
            }
        }
        topLeftPosition.rowPosition += leftOffset;
        bottomRightPosition.rowPosition += rightOffset;
    }
}
Also used : PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) StructuralDiff(net.sourceforge.nattable.layer.event.StructuralDiff) Range(net.sourceforge.nattable.coordinate.Range)

Example 24 with PositionCoordinate

use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.

the class FreezeCommandHandler method handleFreezeCommand.

protected void handleFreezeCommand(IFreezeCoordinatesProvider coordinatesProvider) {
    // if not already frozen
    if (freezeLayer.getColumnCount() == 0 && freezeLayer.getRowCount() == 0) {
        final PositionCoordinate topLeftPosition = coordinatesProvider.getTopLeftPosition();
        final PositionCoordinate bottomRightPosition = coordinatesProvider.getBottomRightPosition();
        freezeLayer.setTopLeftPosition(topLeftPosition.columnPosition, topLeftPosition.rowPosition);
        freezeLayer.setBottomRightPosition(bottomRightPosition.columnPosition, bottomRightPosition.rowPosition);
        viewportLayer.setMinimumOriginPosition(bottomRightPosition.columnPosition + 1, bottomRightPosition.rowPosition + 1);
        viewportLayer.fireLayerEvent(new FreezeEvent(viewportLayer));
    }
}
Also used : PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) FreezeEvent(net.sourceforge.nattable.freeze.event.FreezeEvent)

Example 25 with PositionCoordinate

use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.

the class FreezeSelectionStrategy method getTopLeftPosition.

public PositionCoordinate getTopLeftPosition() {
    PositionCoordinate lastSelectedCellPosition = selectionLayer.getLastSelectedCellPosition();
    int columnPosition = viewportLayer.getOriginColumnPosition();
    if (columnPosition >= lastSelectedCellPosition.columnPosition) {
        columnPosition = lastSelectedCellPosition.columnPosition - 1;
    }
    int rowPosition = viewportLayer.getOriginRowPosition();
    if (rowPosition >= lastSelectedCellPosition.rowPosition) {
        rowPosition = lastSelectedCellPosition.rowPosition - 1;
    }
    return new PositionCoordinate(freezeLayer, columnPosition, rowPosition);
}
Also used : PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate)

Aggregations

PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)28 SelectionLayer (net.sourceforge.nattable.selection.SelectionLayer)5 ArrayList (java.util.ArrayList)4 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)4 CellRegion (net.heartsome.cat.ts.ui.xliffeditor.nattable.search.coordinate.CellRegion)3 IDisplayConverter (net.sourceforge.nattable.data.convert.IDisplayConverter)3 ICellEditor (net.sourceforge.nattable.edit.editor.ICellEditor)3 ILayer (net.sourceforge.nattable.layer.ILayer)3 LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)3 SelectCellCommand (net.sourceforge.nattable.selection.command.SelectCellCommand)3 ViewportLayer (net.sourceforge.nattable.viewport.ViewportLayer)3 Point (org.eclipse.swt.graphics.Point)3 StyledTextCellEditor (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)2 ActiveCellRegion (net.heartsome.cat.ts.ui.xliffeditor.nattable.search.coordinate.ActiveCellRegion)2 Range (net.sourceforge.nattable.coordinate.Range)2 LabelStack (net.sourceforge.nattable.layer.LabelStack)2 IRegion (org.eclipse.jface.text.IRegion)2 MessageFormat (java.text.MessageFormat)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1