Search in sources :

Example 1 with MergeSegmentOperation

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.undoable.MergeSegmentOperation in project translationstudio8 by heartsome.

the class NattableUtil method mergeSegment.

/**
	 * 合并文本段 ;
	 */
public void mergeSegment() {
    XLFHandler handler = xliffEditor.getXLFHandler();
    List<String> lstRowId = xliffEditor.getSelectedRowIds();
    List<String> lstAllRowId = xliffEditor.getXLFHandler().getAllRowIds();
    Shell shell = xliffEditor.getSite().getShell();
    if (lstRowId.size() < 2) {
        MessageDialog.openInformation(shell, Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"), Messages.getString("utils.NattableUtil.mergeSegment.msg1"));
        return;
    }
    Collections.sort(lstRowId, new SortRowIdComparator());
    Collections.sort(lstAllRowId, new SortRowIdComparator());
    String rowId1 = lstRowId.get(0);
    String fileName = RowIdUtil.getFileNameByRowId(rowId1);
    if (fileName == null) {
        return;
    }
    if (handler.isLocked(rowId1)) {
        MessageDialog.openInformation(shell, Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"), Messages.getString("utils.NattableUtil.mergeSegment.msg3"));
        return;
    }
    for (int i = 1; i < lstRowId.size(); i++) {
        String rowId = lstRowId.get(i);
        if (handler.isLocked(rowId)) {
            MessageDialog.openInformation(shell, Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"), Messages.getString("utils.NattableUtil.mergeSegment.msg3"));
            return;
        }
        String fileName2 = RowIdUtil.getFileNameByRowId(rowId);
        // 数组集合必须在一个文件中才能合并
        if (fileName2 == null || !fileName.equals(fileName2)) {
            MessageDialog.openInformation(shell, Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"), Messages.getString("utils.NattableUtil.mergeSegment.msg4"));
            return;
        }
        // 判断所选文本段是否连续
        String strCurTuId = RowIdUtil.getTUIdByRowId(rowId);
        String strPreTuId = RowIdUtil.getTUIdByRowId(lstRowId.get(i - 1));
        if (strCurTuId == null || strPreTuId == null) {
            return;
        }
        if ((lstAllRowId.indexOf(rowId) - lstAllRowId.indexOf(lstRowId.get(i - 1))) != 1) {
            MessageDialog.openInformation(shell, Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"), Messages.getString("utils.NattableUtil.mergeSegment.msg5"));
            return;
        } else {
            String curOriginal = RowIdUtil.getOriginalByRowId(rowId);
            String preOriginal = RowIdUtil.getOriginalByRowId(lstRowId.get(i - 1));
            if (!curOriginal.equals(preOriginal)) {
                MessageDialog.openInformation(shell, Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"), Messages.getString("utils.NattableUtil.mergeSegment.msg5"));
                return;
            }
        }
    }
    // Bug #2373:选择全部文本段合并后,无显示内容
    if (lstRowId.size() == xliffEditor.getXLFHandler().getRowIds().size()) {
        xliffEditor.jumpToRow(0);
    }
    MergeSegmentOperation mergeOper = new MergeSegmentOperation("merge segment", xliffEditor, handler, lstRowId);
    IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
    try {
        operationHistory.execute(mergeOper, null, null);
    } catch (Exception e) {
        LOGGER.error("", e);
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IOperationHistory(org.eclipse.core.commands.operations.IOperationHistory) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler) MergeSegmentOperation(net.heartsome.cat.ts.ui.xliffeditor.nattable.undoable.MergeSegmentOperation) ImportException(net.heartsome.cat.common.core.exception.ImportException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

ImportException (net.heartsome.cat.common.core.exception.ImportException)1 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)1 MergeSegmentOperation (net.heartsome.cat.ts.ui.xliffeditor.nattable.undoable.MergeSegmentOperation)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IOperationHistory (org.eclipse.core.commands.operations.IOperationHistory)1 Shell (org.eclipse.swt.widgets.Shell)1