Search in sources :

Example 1 with ViewportLayer

use of net.sourceforge.nattable.viewport.ViewportLayer in project translationstudio8 by heartsome.

the class XLIFFEditorImplWithNatTable method updateStatusLine.

/**
	 * 在状态栏上显示被编辑文件的信息。
	 */
public void updateStatusLine() {
    if (table == null || table.isDisposed()) {
        return;
    }
    SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
    ViewportLayer viewportLayer = bodyLayer.getViewportLayer();
    PositionCoordinate cellPosition = selectionLayer.getLastSelectedCellPosition();
    if (cellPosition == null) {
        return;
    }
    // int order = LayerUtil.convertRowPosition(selectionLayer, cellPosition.rowPosition, viewportLayer);
    // Bug #2317:选中文本段后排序,不会刷新状态栏中的序号
    int[] selectedRowPostions = selectionLayer.getFullySelectedRowPositions();
    if (selectedRowPostions.length <= 0) {
        return;
    }
    // 刷新选中行的术语,使其排序后保持高亮显示
    // if (!isHorizontalLayout()) {
    // int rowPosition = selectedRowPostions[0];
    // rowPosition *= VerticalNatTableConfig.ROW_SPAN;
    // cellPosition.set(rowPosition, cellPosition.getColumnPosition());
    // } else {
    // cellPosition.set(selectedRowPostions[0], cellPosition.getColumnPosition());
    // }
    // if (!FindReplaceDialog.isOpen) {
    // CellRegion cellRegion = new CellRegion(cellPosition, new Region(0, selectionLayer.getWidth()));
    // ActiveCellRegion.setActiveCellRegion(cellRegion);
    // }
    int order = LayerUtil.convertRowPosition(selectionLayer, selectedRowPostions[0], viewportLayer);
    order += viewportLayer.getOriginRowPosition() + 1;
    // 垂直布局时order需要进行两行递增的处理
    if (!isHorizontalLayout) {
        order = (int) Math.ceil(order / 2.0);
    }
    MessageFormat messageFormat = null;
    if (order > 0) {
        /* 一个Xliff文件,可能有多个File节点,这里使用File结点的original属性 */
        /* 当前文件:{0} | 顺序号:{1} | 可见文本段数:{2} | 文本段总数:{3} | 当前用户名" */
        messageFormat = new MessageFormat(Messages.getString("editor.XLIFFEditorImplWithNatTable.messageFormat1"));
    } else {
        messageFormat = new MessageFormat(Messages.getString("editor.XLIFFEditorImplWithNatTable.messageFormat2"));
    }
    String fileName = "";
    // 添加 Project Name
    IEditorInput editorInput = getEditorInput();
    String filePath = "";
    if (isMultiFile()) {
        if (getSelectedRowIds().size() > 0) {
            filePath = RowIdUtil.getFileNameByRowId(getSelectedRowIds().get(0));
            fileName = ResourceUtils.toWorkspacePath(filePath);
        }
    } else {
        fileName = getEditorInput().getName();
        if (editorInput instanceof FileEditorInput) {
            FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
            filePath = fileEditorInput.getFile().getLocation().toOSString();
            fileName = fileEditorInput.getFile().getFullPath().toOSString();
        }
    }
    String systemUser = Activator.getDefault().getPreferenceStore().getString(IPreferenceConstants.SYSTEM_USER);
    int editableTuSum = handler.countEditableTransUnit();
    int tuSum = handler.countTransUnit();
    // int translatedSum1 = handler
    // .getNodeCount(filePath,
    // "/xliff/file/body/trans-unit[@approved = 'yes' and target/@state != 'translated' and target/@state != 'signed-off']");
    // int translatedSum2 = handler.getNodeCount(filePath,
    // "/xliff/file/body/trans-unit/target[@state = 'translated' or @state = 'signed-off']");
    // int approveSum1 = handler.getNodeCount(filePath,
    // "/xliff/file/body/trans-unit[not(@approved='yes') and target/@state='signed-off']");
    // int approveSum2 = handler.getNodeCount(filePath, "/xliff/file/body/trans-unit[@approved = 'yes']");
    int translatedSum = handler.getTranslatedCount();
    int approveedSum = handler.getApprovedCount();
    int approveP = (int) Math.floor(approveedSum / (double) tuSum * 100.00);
    int translatedP = (int) Math.floor(translatedSum / (double) tuSum * 100.00);
    translationItem.setProgressValue(translatedP);
    approveItem.setProgressValue(approveP);
    // 将信息显示在状态栏
    String message = messageFormat.format(new String[] { fileName, String.valueOf(order), String.valueOf(editableTuSum), String.valueOf(tuSum), systemUser });
    statusLineManager.setMessage(statusLineImage, message);
}
Also used : MessageFormat(java.text.MessageFormat) SelectionLayer(net.sourceforge.nattable.selection.SelectionLayer) FileEditorInput(org.eclipse.ui.part.FileEditorInput) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) HorizontalViewportLayer(net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.HorizontalViewportLayer) ViewportLayer(net.sourceforge.nattable.viewport.ViewportLayer) VerticalViewportLayer(net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.VerticalViewportLayer) Point(org.eclipse.swt.graphics.Point) IEditorInput(org.eclipse.ui.IEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput)

Example 2 with ViewportLayer

use of net.sourceforge.nattable.viewport.ViewportLayer in project translationstudio8 by heartsome.

the class HorizontalViewportLayer method doCommand.

@Override
public boolean doCommand(ILayerCommand command) {
    boolean b = super.doCommand(command);
    if (command instanceof ClientAreaResizeCommand && command.convertToTargetLayer(this)) {
        ClientAreaResizeCommand clientAreaResizeCommand = (ClientAreaResizeCommand) command;
        // 垂直滚动条
        final ScrollBar vBar = clientAreaResizeCommand.getScrollable().getVerticalBar();
        Listener[] listeners = vBar.getListeners(SWT.Selection);
        for (Listener listener : listeners) {
            // 清除默认的 Selection 监听(在类 ScrollBarHandlerTemplate 中添加的)
            vBar.removeListener(SWT.Selection, listener);
        }
        vBar.addListener(SWT.Selection, new Listener() {

            private ViewportLayer viewportLayer = HorizontalViewportLayer.this;

            private IUniqueIndexLayer scrollableLayer = viewportLayer.getScrollableLayer();

            public void handleEvent(Event event) {
                // 滚动滚动条前提交当前处于编辑状态的文本段
                HsMultiActiveCellEditor.commit(true);
                ScrollBar scrollBar = (ScrollBar) event.widget;
                int position = scrollableLayer.getRowPositionByY(scrollBar.getSelection());
                viewportLayer.invalidateVerticalStructure();
                viewportLayer.setOriginRowPosition(position);
                vBar.setIncrement(viewportLayer.getRowHeightByPosition(0));
            //					HsMultiCellEditorControl.activeSourceAndTargetCell(XLIFFEditorImplWithNatTable.getCurrent());
            }
        });
    }
    return b;
}
Also used : Listener(org.eclipse.swt.widgets.Listener) ClientAreaResizeCommand(net.sourceforge.nattable.grid.command.ClientAreaResizeCommand) Event(org.eclipse.swt.widgets.Event) ViewportLayer(net.sourceforge.nattable.viewport.ViewportLayer) IUniqueIndexLayer(net.sourceforge.nattable.layer.IUniqueIndexLayer) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 3 with ViewportLayer

use of net.sourceforge.nattable.viewport.ViewportLayer in project translationstudio8 by heartsome.

the class LayerUtil method getLowerLayerRowPosition.

// AbstractLayerTransform
public static <T extends IUniqueIndexLayer> int getLowerLayerRowPosition(NatTable table, int sourceRowPosition, Class<T> targetLayerClass) {
    ViewportLayer viewportLayer = getLayer(table, ViewportLayer.class);
    int originRowPosition = viewportLayer.getOriginRowPosition();
    sourceRowPosition -= originRowPosition + 1;
    T t = getLayer(table, targetLayerClass);
    return convertRowPosition(viewportLayer, sourceRowPosition, t);
}
Also used : ViewportLayer(net.sourceforge.nattable.viewport.ViewportLayer)

Example 4 with ViewportLayer

use of net.sourceforge.nattable.viewport.ViewportLayer in project translationstudio8 by heartsome.

the class FindReplaceCommandHandler method doCommand.

public boolean doCommand(ILayer targetLayer, FindReplaceCommand findReplaceCommand) {
    findReplaceCommand.convertToTargetLayer(targetLayer);
    ISearchStrategy searchStrategy = findReplaceCommand.getSearchStrategy();
    if (findReplaceCommand.getSearchEventListener() != null) {
        selectionLayer.addLayerListener(findReplaceCommand.getSearchEventListener());
    }
    PositionCoordinate anchor = selectionLayer.getSelectionAnchor();
    if (anchor.columnPosition < 0 || anchor.rowPosition < 0) {
        anchor = new PositionCoordinate(selectionLayer, 0, 0);
    }
    searchStrategy.setContextLayer(targetLayer);
    Object dataValueToFind = null;
    if ((dataValueToFind = findReplaceCommand.getSearchText()) == null) {
        dataValueToFind = selectionLayer.getDataValueByPosition(anchor.columnPosition, anchor.rowPosition);
    }
    ICellSearchStrategy cellSearchStrategy = findReplaceCommand.getCellSearchStrategy();
    searchStrategy.setCellSearchStrategy(cellSearchStrategy);
    DefaultCellSearchStrategy defaultCellSearchStrategy = null;
    if (cellSearchStrategy instanceof DefaultCellSearchStrategy) {
        defaultCellSearchStrategy = (DefaultCellSearchStrategy) cellSearchStrategy;
    }
    searchResultCellRegion = searchStrategy.executeSearch(dataValueToFind);
    if (searchResultCellRegion != null) {
        PositionCoordinate searchResultCellCoordinate = searchResultCellRegion.getPositionCoordinate();
        int rowPosition = searchResultCellCoordinate.rowPosition;
        XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
        ViewportLayer viewportLayer = LayerUtil.getLayer(editor.getTable(), ViewportLayer.class);
        HsMultiActiveCellEditor.commit(true);
        if (!editor.isHorizontalLayout()) {
            viewportLayer.doCommand(new SelectCellCommand(selectionLayer, searchResultCellCoordinate.columnPosition, rowPosition / 2 * 2, false, false));
        } else {
            viewportLayer.doCommand(new SelectCellCommand(selectionLayer, searchResultCellCoordinate.columnPosition, rowPosition, false, false));
        }
        HsMultiCellEditorControl.activeSourceAndTargetCell(editor);
        HsMultiActiveCellEditor.setCellEditorForceFocusByIndex(searchResultCellCoordinate.columnPosition, rowPosition);
        StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
        if (cellEditor != null) {
            String dataValue = cellEditor.getSegmentViewer().getDocument().get();
            if (dataValue != null) {
                int startOffset = -1;
                if (defaultCellSearchStrategy != null) {
                    startOffset = defaultCellSearchStrategy.getStartOffset();
                }
                defaultCellSearchStrategy.setStartOffset(startOffset);
                String findString = dataValueToFind.toString();
                if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
                    findString = findString.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n");
                    findString = findString.replaceAll("\\t", Constants.TAB_CHARACTER + "​");
                    findString = findString.replaceAll(" ", Constants.SPACE_CHARACTER + "​");
                }
                IRegion region = defaultCellSearchStrategy.executeSearch(findString, dataValue);
                if (region != null) {
                    HsMultiActiveCellEditor.setSelectionText(cellEditor, region.getOffset(), region.getLength());
                }
                defaultCellSearchStrategy.setStartOffset(-1);
            }
        }
    }
    selectionLayer.fireLayerEvent(new FindReplaceEvent(searchResultCellRegion));
    if (findReplaceCommand.getSearchEventListener() != null) {
        selectionLayer.removeLayerListener(findReplaceCommand.getSearchEventListener());
    }
    return true;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) ICellSearchStrategy(net.heartsome.cat.ts.ui.xliffeditor.nattable.search.strategy.ICellSearchStrategy) SelectCellCommand(net.sourceforge.nattable.selection.command.SelectCellCommand) FindReplaceEvent(net.heartsome.cat.ts.ui.xliffeditor.nattable.search.event.FindReplaceEvent) ViewportLayer(net.sourceforge.nattable.viewport.ViewportLayer) IRegion(org.eclipse.jface.text.IRegion) DefaultCellSearchStrategy(net.heartsome.cat.ts.ui.xliffeditor.nattable.search.strategy.DefaultCellSearchStrategy) ISearchStrategy(net.heartsome.cat.ts.ui.xliffeditor.nattable.search.strategy.ISearchStrategy) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)

Example 5 with ViewportLayer

use of net.sourceforge.nattable.viewport.ViewportLayer in project translationstudio8 by heartsome.

the class XLIFFEditorImplWithNatTable method refresh.

/**
	 * 刷新编辑器 ;
	 */
public void refresh() {
    if (table != null && !table.isDisposed()) {
        ViewportLayer viewportLayer = bodyLayer.getViewportLayer();
        viewportLayer.invalidateVerticalStructure();
        viewportLayer.recalculateScrollBars();
        table.redraw();
    }
}
Also used : HorizontalViewportLayer(net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.HorizontalViewportLayer) ViewportLayer(net.sourceforge.nattable.viewport.ViewportLayer) VerticalViewportLayer(net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.VerticalViewportLayer)

Aggregations

ViewportLayer (net.sourceforge.nattable.viewport.ViewportLayer)10 HorizontalViewportLayer (net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.HorizontalViewportLayer)3 VerticalViewportLayer (net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.VerticalViewportLayer)3 PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)3 SelectCellCommand (net.sourceforge.nattable.selection.command.SelectCellCommand)3 StyledTextCellEditor (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)2 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)2 SelectionLayer (net.sourceforge.nattable.selection.SelectionLayer)2 Point (org.eclipse.swt.graphics.Point)2 MessageFormat (java.text.MessageFormat)1 FindReplaceEvent (net.heartsome.cat.ts.ui.xliffeditor.nattable.search.event.FindReplaceEvent)1 DefaultCellSearchStrategy (net.heartsome.cat.ts.ui.xliffeditor.nattable.search.strategy.DefaultCellSearchStrategy)1 ICellSearchStrategy (net.heartsome.cat.ts.ui.xliffeditor.nattable.search.strategy.ICellSearchStrategy)1 ISearchStrategy (net.heartsome.cat.ts.ui.xliffeditor.nattable.search.strategy.ISearchStrategy)1 NatTable (net.sourceforge.nattable.NatTable)1 IConfigRegistry (net.sourceforge.nattable.config.IConfigRegistry)1 ClientAreaResizeCommand (net.sourceforge.nattable.grid.command.ClientAreaResizeCommand)1 IUniqueIndexLayer (net.sourceforge.nattable.layer.IUniqueIndexLayer)1 LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)1 IRegion (org.eclipse.jface.text.IRegion)1