Search in sources :

Example 1 with TermBaseSearchDialog

use of net.heartsome.cat.database.ui.tb.dialog.TermBaseSearchDialog in project translationstudio8 by heartsome.

the class TermBaseSearchHandler 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;
        IProject project = ((FileEditorInput) editor.getEditorInput()).getFile().getProject();
        ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(project);
        List<DatabaseModelBean> lstDatabase = projectConfig.getTermBaseDbs(false);
        if (lstDatabase == null || lstDatabase.size() == 0) {
            MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.TermBaseSearchHandler.msgTitle"), Messages.getString("handler.TermBaseSearchHandler.msg"));
            return null;
        }
        String selectText = xliffEditor.getSelectPureText();
        if ((selectText == null || selectText.equals("")) && xliffEditor.getSelectedRowIds().size() == 1) {
            selectText = xliffEditor.getXLFHandler().getSrcPureText(xliffEditor.getSelectedRowIds().get(0));
            selectText = resetCeanString(selectText);
        }
        String srcLang = xliffEditor.getSrcColumnName();
        String tgtLang = xliffEditor.getTgtColumnName();
        TermBaseSearchDialog dialog = new TermBaseSearchDialog(editor.getSite().getShell(), project, 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.search();
        }
    }
    return null;
}
Also used : Language(net.heartsome.cat.common.locale.Language) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) TermBaseSearchDialog(net.heartsome.cat.database.ui.tb.dialog.TermBaseSearchDialog) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) IProject(org.eclipse.core.resources.IProject)

Aggregations

DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)1 Language (net.heartsome.cat.common.locale.Language)1 TermBaseSearchDialog (net.heartsome.cat.database.ui.tb.dialog.TermBaseSearchDialog)1 ProjectConfiger (net.heartsome.cat.ts.core.file.ProjectConfiger)1 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)1 IProject (org.eclipse.core.resources.IProject)1 IEditorPart (org.eclipse.ui.IEditorPart)1