Search in sources :

Example 41 with XLIFFEditorImplWithNatTable

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable in project translationstudio8 by heartsome.

the class LineNumberPainter method checkSplit.

/**
	 * 通过LayerCell得到行号确定所要得到的TU对象,通过TU对象的各种属性确定其状态图片
	 * @param cell
	 * @param configRegistry
	 * @return ;
	 */
protected boolean checkSplit(LayerCell cell, IConfigRegistry configRegistry) {
    int index = cell.getLayer().getRowIndexByPosition(cell.getRowPosition());
    // 添加分割点的图标,--robert
    XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
    if (editor != null) {
        if (!editor.isHorizontalLayout()) {
            index = index / 2;
        }
        String rowId = editor.getXLFHandler().getRowId(index);
        List<String> splitPoints = editor.getSplitXliffPoints();
        if (splitPoints.indexOf(rowId) != -1) {
            return true;
        }
    }
    return false;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)

Example 42 with XLIFFEditorImplWithNatTable

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable 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 43 with XLIFFEditorImplWithNatTable

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable in project translationstudio8 by heartsome.

the class AddSelectionSegmentNotesHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
    if (editorPart instanceof XLIFFEditorImplWithNatTable) {
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editorPart;
        AddOrUpdateNoteDialog dialog = new AddOrUpdateNoteDialog(xliffEditor.getSite().getShell(), xliffEditor, AddOrUpdateNoteDialog.DIALOG_ADD, null);
        dialog.open();
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) AddOrUpdateNoteDialog(net.heartsome.cat.ts.ui.xliffeditor.nattable.dialog.AddOrUpdateNoteDialog) IEditorPart(org.eclipse.ui.IEditorPart)

Example 44 with XLIFFEditorImplWithNatTable

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable in project translationstudio8 by heartsome.

the class ShowPreviousSegmentHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
    int[] selectedRows = xliffEditor.getSelectedRows();
    if (selectedRows.length < 1) {
        return null;
    }
    Arrays.sort(selectedRows);
    int firstSelectedRow = selectedRows[0];
    if (firstSelectedRow == 0) {
        firstSelectedRow = 1;
    }
    xliffEditor.jumpToRow(firstSelectedRow - 1);
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IEditorPart(org.eclipse.ui.IEditorPart)

Example 45 with XLIFFEditorImplWithNatTable

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable in project translationstudio8 by heartsome.

the class ShowPreviousUnapprovedHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
    int[] selectedRows = xliffEditor.getSelectedRows();
    if (selectedRows.length < 1) {
        return null;
    }
    Arrays.sort(selectedRows);
    int firstSelectedRow = selectedRows[0];
    XLFHandler handler = xliffEditor.getXLFHandler();
    int row = handler.getPreviousUnapprovedSegmentIndex(firstSelectedRow);
    if (row != -1) {
        xliffEditor.jumpToRow(row);
    } else {
        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
        MessageDialog.openWarning(window.getShell(), "", "不存在上一未批准文本段。");
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Aggregations

XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)71 IEditorPart (org.eclipse.ui.IEditorPart)53 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)36 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)27 ArrayList (java.util.ArrayList)16 IFile (org.eclipse.core.resources.IFile)13 FileEditorInput (org.eclipse.ui.part.FileEditorInput)11 StyledTextCellEditor (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)9 Shell (org.eclipse.swt.widgets.Shell)9 NattableUtil (net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil)8 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)8 IViewPart (org.eclipse.ui.IViewPart)8 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)8 ExecutionException (org.eclipse.core.commands.ExecutionException)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 IEditorReference (org.eclipse.ui.IEditorReference)7 HashMap (java.util.HashMap)6 IEditorInput (org.eclipse.ui.IEditorInput)6 ISelection (org.eclipse.jface.viewers.ISelection)5 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)5