Search in sources :

Example 21 with LayerCell

use of net.sourceforge.nattable.layer.cell.LayerCell 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)

Example 22 with LayerCell

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

the class BodyCellEditorMouseEventMatcher method matches.

public boolean matches(NatTable natTable, MouseEvent event, LabelStack regionLabels) {
    if (regionLabels != null && regionLabels.hasLabel(GridRegion.BODY)) {
        LayerCell cell = natTable.getCellByPosition(natTable.getColumnPositionByX(event.x), natTable.getRowPositionByY(event.y));
        ICellEditor cellEditor = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.CELL_EDITOR, cell.getDisplayMode(), cell.getConfigLabels().getLabels());
        if (cellEditorClass.isInstance(cellEditor)) {
            return true;
        }
    }
    return false;
}
Also used : LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) ICellEditor(net.sourceforge.nattable.edit.editor.ICellEditor)

Example 23 with LayerCell

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

the class MouseEditAction method run.

public void run(NatTable natTable, MouseEvent event) {
    XLIFFEditorImplWithNatTable xliffEditor = XLIFFEditorImplWithNatTable.getCurrent();
    if (xliffEditor == null) {
        return;
    }
    int columnPosition = natTable.getColumnPositionByX(event.x);
    int rowPosition = natTable.getRowPositionByY(event.y);
    boolean withShiftMask = (event.stateMask & SWT.SHIFT) != 0;
    boolean withCtrlMask = (event.stateMask & SWT.CTRL) != 0;
    if (!xliffEditor.isHorizontalLayout() && rowPosition != HsMultiActiveCellEditor.targetRowPosition && (rowPosition != HsMultiActiveCellEditor.sourceRowPosition || columnPosition != xliffEditor.getSrcColumnIndex())) {
        HsMultiActiveCellEditor.commit(true);
        natTable.doCommand(new SelectCellCommand(natTable, columnPosition, rowPosition, withShiftMask, withCtrlMask));
        if (columnPosition == xliffEditor.getTgtColumnIndex()) {
            HsMultiCellEditorControl.activeSourceAndTargetCell(xliffEditor);
        }
    } else if (rowPosition != HsMultiActiveCellEditor.targetRowPosition || columnPosition != xliffEditor.getSrcColumnIndex() || columnPosition != xliffEditor.getTgtColumnIndex()) {
        HsMultiActiveCellEditor.commit(true);
        natTable.doCommand(new SelectCellCommand(natTable, columnPosition, rowPosition, withShiftMask, withCtrlMask));
        if (columnPosition == xliffEditor.getSrcColumnIndex() || columnPosition == xliffEditor.getTgtColumnIndex()) {
            HsMultiCellEditorControl.activeSourceAndTargetCell(xliffEditor);
        }
    }
    // 点击批注图片时打开编辑批注对话框
    Image image = XliffEditorGUIHelper.getImage(ImageName.HAS_NOTE);
    // int columnPosition = natTable.getColumnPositionByX(event.x);
    // int rowPosition = natTable.getRowPositionByY(event.y);
    LayerCell cell = natTable.getCellByPosition(columnPosition, rowPosition);
    Rectangle imageBounds = image.getBounds();
    if (cell == null) {
        return;
    }
    Rectangle cellBounds = cell.getBounds();
    int x = cellBounds.x + imageBounds.width * 3 + 20;
    int y = cellBounds.y + CellStyleUtil.getVerticalAlignmentPadding(CellStyleUtil.getCellStyle(cell, natTable.getConfigRegistry()), cellBounds, imageBounds.height);
    if (columnPosition == xliffEditor.getStatusColumnIndex() && event.x >= x && event.x <= (x + imageBounds.width) && event.y >= y && event.y <= (y + imageBounds.height)) {
        if ((xliffEditor.isHorizontalLayout() && columnPosition == 2) || (!xliffEditor.isHorizontalLayout() && columnPosition == 1)) {
            Vector<NoteBean> noteBeans = null;
            try {
                int rowIndex = natTable.getRowIndexByPosition(rowPosition);
                if (!xliffEditor.isHorizontalLayout()) {
                    rowIndex = rowIndex / VerticalNatTableConfig.ROW_SPAN;
                }
                noteBeans = xliffEditor.getXLFHandler().getNotes(xliffEditor.getXLFHandler().getRowId(rowIndex));
                if (noteBeans != null && noteBeans.size() > 0) {
                    UpdateNoteDialog dialog = new UpdateNoteDialog(xliffEditor.getSite().getShell(), xliffEditor, rowIndex);
                    dialog.open();
                }
            } catch (NavException e) {
                e.printStackTrace();
            } catch (XPathParseException e) {
                e.printStackTrace();
            } catch (XPathEvalException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) SelectCellCommand(net.sourceforge.nattable.selection.command.SelectCellCommand) LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) Rectangle(org.eclipse.swt.graphics.Rectangle) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) Image(org.eclipse.swt.graphics.Image) XPathParseException(com.ximpleware.XPathParseException) NoteBean(net.heartsome.cat.ts.core.bean.NoteBean) UpdateNoteDialog(net.heartsome.cat.ts.ui.xliffeditor.nattable.dialog.UpdateNoteDialog)

Example 24 with LayerCell

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

the class HsMultiActiveCellEditor method recalculateCellsBounds.

public static void recalculateCellsBounds() {
    if (parent == null) {
        return;
    }
    ViewportLayer vLayer = LayerUtil.getLayer(parent, ViewportLayer.class);
    if (vLayer == null) {
        return;
    }
    StyledTextCellEditor fc = getFocusCellEditor();
    if (sourceEditor != null && sourceEditor.isValid()) {
        int rowPosition = vLayer.getRowPositionByIndex(sourceEditor.getRowIndex());
        int columnPosition = vLayer.getColumnPositionByIndex(sourceEditor.getColumnIndex());
        rowPosition += 1;
        if (rowPosition < 1) {
            return;
        }
        LayerCell cell = parent.getCellByPosition(columnPosition, rowPosition);
        if (cell == null) {
            return;
        }
        Rectangle cellBounds = cell.getBounds();
        if (cellBounds != null) {
            Rectangle adjustedCellBounds = parent.getLayerPainter().adjustCellBounds(cellBounds);
            sourceEditor.setEditorBounds(adjustedCellBounds, true);
            sourceEditor.setColumnPosition(columnPosition);
            sourceEditor.setRowPosition(rowPosition);
            if (fc == sourceEditor.getCellEditor()) {
                sourceEditor.forceFocus();
            }
        }
    }
    if (targetEditor != null && targetEditor.isValid()) {
        int rowPosition = vLayer.getRowPositionByIndex(targetEditor.getRowIndex());
        int columnPosition = vLayer.getColumnPositionByIndex(targetEditor.getColumnIndex());
        rowPosition += 1;
        if (rowPosition < 1) {
            return;
        }
        LayerCell cell = parent.getCellByPosition(columnPosition, rowPosition);
        if (cell == null) {
            return;
        }
        Rectangle cellBounds = cell.getBounds();
        if (cellBounds != null) {
            Rectangle adjustedCellBounds = parent.getLayerPainter().adjustCellBounds(cellBounds);
            targetEditor.setEditorBounds(adjustedCellBounds, true);
            targetEditor.setColumnPosition(columnPosition);
            targetEditor.setRowPosition(rowPosition);
            if (fc == targetEditor.getCellEditor()) {
                targetEditor.forceFocus();
            }
        }
    }
}
Also used : LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) Rectangle(org.eclipse.swt.graphics.Rectangle) ViewportLayer(net.sourceforge.nattable.viewport.ViewportLayer)

Aggregations

LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)24 Rectangle (org.eclipse.swt.graphics.Rectangle)8 ICellPainter (net.sourceforge.nattable.painter.cell.ICellPainter)4 PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)3 IDisplayConverter (net.sourceforge.nattable.data.convert.IDisplayConverter)3 IStyle (net.sourceforge.nattable.style.IStyle)3 IDataValidator (net.sourceforge.nattable.data.validate.IDataValidator)2 UpdateDataCommand (net.sourceforge.nattable.edit.command.UpdateDataCommand)2 ICellEditor (net.sourceforge.nattable.edit.editor.ICellEditor)2 CellStyleProxy (net.sourceforge.nattable.style.CellStyleProxy)2 Point (org.eclipse.swt.graphics.Point)2 NavException (com.ximpleware.NavException)1 XPathEvalException (com.ximpleware.XPathEvalException)1 XPathParseException (com.ximpleware.XPathParseException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 InnerTagBean (net.heartsome.cat.common.innertag.InnerTagBean)1 XliffInnerTagFactory (net.heartsome.cat.common.innertag.factory.XliffInnerTagFactory)1 NoteBean (net.heartsome.cat.ts.core.bean.NoteBean)1