Search in sources :

Example 11 with ExecutionException

use of org.eclipse.core.commands.ExecutionException in project translationstudio8 by heartsome.

the class ConcordanceSearchHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    if (!isEnabled()) {
        return null;
    }
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (editor instanceof IXliffEditor) {
        IXliffEditor xliffEditor = (IXliffEditor) editor;
        String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
        IEditorPart editorRefer = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
        if (editorRefer.getSite().getId().equals(XLIFF_EDITOR_ID)) {
            // IProject project = ((FileEditorInput) editorRefer.getEditorInput()).getFile().getProject();
            IFile file = ((FileEditorInput) editorRefer.getEditorInput()).getFile();
            ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
            List<DatabaseModelBean> lstDatabase = projectConfig.getAllTmDbs();
            if (lstDatabase.size() == 0) {
                MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.ConcordanceSearchHandler.msgTitle"), Messages.getString("handler.ConcordanceSearchHandler.msg"));
                return null;
            }
            String selectText = xliffEditor.getSelectPureText();
            if ((selectText == null || selectText.equals("")) && xliffEditor.getSelectedRowIds().size() == 1) {
                selectText = xliffEditor.getXLFHandler().getSrcPureText(xliffEditor.getSelectedRowIds().get(0));
            } else if (selectText == null) {
                selectText = "";
            }
            String srcLang = xliffEditor.getSrcColumnName();
            String tgtLang = xliffEditor.getTgtColumnName();
            ConcordanceSearchDialog dialog = new ConcordanceSearchDialog(editorRefer.getSite().getShell(), file, srcLang, tgtLang, selectText.trim());
            Language srcLangL = LocaleService.getLanguageConfiger().getLanguageByCode(srcLang);
            Language tgtLangL = LocaleService.getLanguageConfiger().getLanguageByCode(tgtLang);
            dialog.open();
            if (srcLangL.isBidi() || tgtLangL.isBidi()) {
                dialog.getShell().setOrientation(SWT.RIGHT_TO_LEFT);
            }
            if (selectText != null && !selectText.trim().equals("")) {
                dialog.initGroupIdAndSearch();
                IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite();
                ICommandService commandService = (ICommandService) site.getService(ICommandService.class);
                Command command = commandService.getCommand(ActionFactory.COPY.getCommandId());
                IEvaluationService evalService = (IEvaluationService) site.getService(IEvaluationService.class);
                IEvaluationContext currentState = evalService.getCurrentState();
                ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, currentState);
                try {
                    command.executeWithChecks(executionEvent);
                } catch (Exception e1) {
                }
            }
        }
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) ConcordanceSearchDialog(net.heartsome.cat.database.ui.tm.dialog.ConcordanceSearchDialog) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) ICommandService(org.eclipse.ui.commands.ICommandService) ExecutionException(org.eclipse.core.commands.ExecutionException) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) Language(net.heartsome.cat.common.locale.Language) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IEvaluationService(org.eclipse.ui.services.IEvaluationService)

Example 12 with ExecutionException

use of org.eclipse.core.commands.ExecutionException in project translationstudio8 by heartsome.

the class DeleteAllSegmentTranslationsHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    boolean res = MessageDialog.openConfirm(window.getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle1"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg3"));
    if (res) {
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        try {
            XLFHandler handler = xliffEditor.getXLFHandler();
            int count = xliffEditor.getAllRowCount();
            int[] selectedRows = new int[count];
            for (int i = 0; i < count; i++) {
                selectedRows[i] = i;
            }
            List<Integer> rows = new ArrayList<Integer>();
            boolean exitFlag = false;
            for (int i = 0; i < selectedRows.length; i++) {
                String tgt = handler.getCaseTgtContent(handler.getRowId(selectedRows[i]));
                if (null != tgt) {
                    if (tgt.equals("no")) {
                        exitFlag = true;
                        continue;
                    }
                }
                rows.add(selectedRows[i]);
            }
            if (rows.size() != 0) {
                int columnIndex = xliffEditor.getTgtColumnIndex();
                StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
                if (cellEditor != null && cellEditor.getColumnIndex() == columnIndex) {
                    cellEditor.getSegmentViewer().getTextWidget().forceFocus();
                }
                int[] updateRows = new int[rows.size()];
                for (int i = 0; i < rows.size(); i++) {
                    int ri = rows.get(i);
                    updateRows[i] = ri;
                }
                xliffEditor.updateCells(updateRows, columnIndex, "");
                if (exitFlag) {
                    MessageDialog.openInformation(xliffEditor.getSite().getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg2"));
                }
            }
        } catch (Exception e) {
            LOGGER.error("", e);
            e.printStackTrace();
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) ExecutionException(org.eclipse.core.commands.ExecutionException) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 13 with ExecutionException

use of org.eclipse.core.commands.ExecutionException in project translationstudio8 by heartsome.

the class DeleteSelectionSegmentTranslationsHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    boolean res = MessageDialog.openConfirm(window.getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle1"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg1"));
    if (res) {
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        try {
            XLFHandler handler = xliffEditor.getXLFHandler();
            int[] selectedRows = xliffEditor.getSelectedRows();
            List<Integer> rows = new ArrayList<Integer>();
            boolean exitFlag = false;
            for (int i = 0; i < selectedRows.length; i++) {
                String tgt = handler.getCaseTgtContent(handler.getRowId(selectedRows[i]));
                if (null != tgt) {
                    if (tgt.equals("no")) {
                        exitFlag = true;
                        continue;
                    }
                }
                rows.add(selectedRows[i]);
            }
            if (rows.size() != 0) {
                int columnIndex = xliffEditor.getTgtColumnIndex();
                StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
                if (cellEditor != null && cellEditor.getColumnIndex() == columnIndex) {
                    cellEditor.getSegmentViewer().getTextWidget().forceFocus();
                }
                int[] updateRows = new int[rows.size()];
                for (int i = 0; i < rows.size(); i++) {
                    int ri = rows.get(i);
                    updateRows[i] = ri;
                }
                xliffEditor.updateCells(updateRows, columnIndex, "");
                if (exitFlag) {
                    MessageDialog.openInformation(xliffEditor.getSite().getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg2"));
                }
            }
        } catch (Exception e) {
            LOGGER.error("", e);
            e.printStackTrace();
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) ExecutionException(org.eclipse.core.commands.ExecutionException) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 14 with ExecutionException

use of org.eclipse.core.commands.ExecutionException in project translationstudio8 by heartsome.

the class SplitSegmentHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
    StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
    if (cellEditor == null) {
        return null;
    }
    if (!cellEditor.getCellType().equals(NatTableConstant.SOURCE)) {
        showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg1"));
        return null;
    }
    int rowIndex = cellEditor.getRowIndex();
    // 如果是垂直布局,那么 rowIndex 要除以2 --robert
    if (!xliffEditor.isHorizontalLayout()) {
        rowIndex = rowIndex / 2;
    }
    int caretOffset = cellEditor.getRealSplitOffset();
    if (caretOffset < 0) {
        // 文本框已经关闭时
        showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg1"));
        return null;
    }
    // 不能选择多个字符进行分割
    String selText = cellEditor.getSegmentViewer().getTextWidget().getSelectionText();
    if (selText.length() != 0) {
        showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg1"));
        return null;
    }
    XLFHandler handler = xliffEditor.getXLFHandler();
    String rowId = handler.getRowId(rowIndex);
    /* burke 修改锁定文本段不能被分割和光标在文本段段首或者段末时,不能进行分割的BUG 添加代码 起 */
    String tgt = handler.getCaseTgtContent(rowId);
    if (null != tgt) {
        if (tgt.equals("no")) {
            showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg2"));
            return null;
        }
    }
    int cellTextLength = ((UpdateDataBean) cellEditor.getCanonicalValue()).getText().length();
    if (caretOffset <= 0 || caretOffset >= cellTextLength) {
        showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg3"));
        return null;
    }
    /* burke 修改锁定文本段不能被分割和光标在文本段段首或者段末时,不能进行分割的BUG 添加代码 终 */
    // 关闭Editor
    cellEditor.close();
    IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
    try {
        operationHistory.execute(new SplitSegmentOperation("Split Segment", xliffEditor, handler, rowIndex, caretOffset), null, null);
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IOperationHistory(org.eclipse.core.commands.operations.IOperationHistory) IEditorPart(org.eclipse.ui.IEditorPart) SplitSegmentOperation(net.heartsome.cat.ts.ui.xliffeditor.nattable.undoable.SplitSegmentOperation) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor) ExecutionException(org.eclipse.core.commands.ExecutionException) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 15 with ExecutionException

use of org.eclipse.core.commands.ExecutionException in project translationstudio8 by heartsome.

the class UpdateDataAndAutoResizeCommandHandler method doCommand.

@Override
protected boolean doCommand(UpdateDataAndAutoResizeCommand command) {
    try {
        // int columnPosition = command.getColumnPosition();
        // int rowPosition = command.getRowPosition();
        // dataLayer.getDataProvider().setDataValue(columnPosition, rowPosition, command.getNewValue());
        // dataLayer.fireLayerEvent(new CellVisualChangeEvent(dataLayer, columnPosition, rowPosition));
        //
        // int currentRow = command.getRowPosition() + 1; // 修改行在当前一屏显示的几行中的相对位置
        // table.doCommand(new AutoResizeCurrentRowsCommand(table, new int[] { currentRow },
        // table.getConfigRegistry(), new GC(table)));
        IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
        operationHistory.execute(new UpdateDataOperation(table, dataLayer, command), null, null);
        return true;
    } catch (UnsupportedOperationException e) {
        LOGGER.error(MessageFormat.format(Messages.getString("handler.UpdateDataAndAutoResizeCommandHandler.logger1"), command.getNewValue()), e);
        e.printStackTrace(System.err);
        System.err.println("Failed to update value to: " + command.getNewValue());
    } catch (ExecutionException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    }
    return false;
}
Also used : UpdateDataOperation(net.heartsome.cat.ts.ui.xliffeditor.nattable.undoable.UpdateDataOperation) IOperationHistory(org.eclipse.core.commands.operations.IOperationHistory) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

ExecutionException (org.eclipse.core.commands.ExecutionException)47 CoreException (org.eclipse.core.runtime.CoreException)18 IFile (org.eclipse.core.resources.IFile)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)12 ArrayList (java.util.ArrayList)11 IEditorPart (org.eclipse.ui.IEditorPart)11 IStatus (org.eclipse.core.runtime.IStatus)9 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)9 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)8 IProject (org.eclipse.core.resources.IProject)8 Status (org.eclipse.core.runtime.Status)8 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)8 List (java.util.List)7 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 ISelection (org.eclipse.jface.viewers.ISelection)7 FileEditorInput (org.eclipse.ui.part.FileEditorInput)7 PartInitException (org.eclipse.ui.PartInitException)5