Search in sources :

Example 1 with ProjectConfiger

use of net.heartsome.cat.ts.core.file.ProjectConfiger 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)

Example 2 with ProjectConfiger

use of net.heartsome.cat.ts.core.file.ProjectConfiger in project translationstudio8 by heartsome.

the class ImportProjectWizardPage2 method resetConfigContent.

public void resetConfigContent(IProject project) {
    ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(project);
    if (null == projectConfig) {
        return;
    }
    // FIX Bug#3709 导入项目时更新库--打开XLIFF文件时无法更新同名的记忆库/术语库
    // 重新加载一次数据,如果ProjectConfigerFactory缓存中含有导入项目的名称时,有bug
    projectConfig.reloadConfig();
    ProjectInfoBean currentProjectConfig = projectConfig.getCurrentProjectConfig();
    List<DatabaseModelBean> tmDb = currentProjectConfig.getTmDb();
    int index = 0;
    for (DatabaseModelBean bean : tmDb) {
        // update tm config
        if ("SQLite".equals(bean.getDbType())) {
            resetSqliteTMNameAndPath(project, bean, index);
            index++;
        }
    }
    List<DatabaseModelBean> tbDb = currentProjectConfig.getTbDb();
    index = 0;
    for (DatabaseModelBean bean : tbDb) {
        // update tb config
        if ("SQLite".equals(bean.getDbType())) {
            resetSqliteTBNameAndPath(project, bean, index);
            index++;
        }
    }
    projectConfig.updateProjectConfig(currentProjectConfig);
    try {
        project.refreshLocal(IResource.DEPTH_ZERO, null);
    } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ProjectInfoBean(net.heartsome.cat.common.bean.ProjectInfoBean) CoreException(org.eclipse.core.runtime.CoreException) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean)

Example 3 with ProjectConfiger

use of net.heartsome.cat.ts.core.file.ProjectConfiger in project translationstudio8 by heartsome.

the class AddTermToTBDialog method initProperty.

/**
	 * 初始化各个控件的值 ;
	 */
public void initProperty() {
    if (srcText != null && !srcText.equals("")) {
        txtSrc.setText(srcText);
        txtSrc.setSelection(0, srcText.length());
        txtSrc.setFocus();
    }
    if (tgtText != null && !tgtText.equals("")) {
        txtTgt.setText(tgtText);
        txtTgt.setSelection(0, tgtText.length());
        txtTgt.setFocus();
    }
    if (getPropertyValue() != null) {
        txtProperty.setText(getPropertyValue());
    }
    ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(project);
    List<Language> rsLstSrcLangs = new ArrayList<Language>();
    List<Language> rsLstTgtLangs = null;
    try {
        rsLstSrcLangs.add(projectConfig.getSourceLanguage());
        rsLstTgtLangs = projectConfig.getTargetlanguages();
    } catch (XPathParseException e) {
        LOGGER.error(Messages.getString("dialog.AddTermToTBDialog.logger"), e);
    } catch (NavException e) {
        LOGGER.error(Messages.getString("dialog.AddTermToTBDialog.logger"), e);
    } catch (XPathEvalException e) {
        LOGGER.error(Messages.getString("dialog.AddTermToTBDialog.logger"), e);
    }
    ArrayList<String> lstTgtLangs = new ArrayList<String>();
    if (rsLstTgtLangs != null) {
        for (Language lang : rsLstTgtLangs) {
            lstTgtLangs.add(lang.getCode());
        }
    }
    cmbSrcLang.setLabelProvider(new LanguageLabelProvider());
    cmbSrcLang.setInput(rsLstSrcLangs);
    cmbSrcLang.getTableCombo().select(0);
    cmbTgtLang.setLabelProvider(new LanguageLabelProvider());
    cmbTgtLang.setInput(rsLstTgtLangs);
    if (tgtLang != null) {
        cmbTgtLang.getTableCombo().select(lstTgtLangs.indexOf(tgtLang));
    }
}
Also used : XPathParseException(com.ximpleware.XPathParseException) Language(net.heartsome.cat.common.locale.Language) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) LanguageLabelProvider(net.heartsome.cat.ts.ui.composite.LanguageLabelProvider) ArrayList(java.util.ArrayList) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException)

Example 4 with ProjectConfiger

use of net.heartsome.cat.ts.core.file.ProjectConfiger in project translationstudio8 by heartsome.

the class ProjectSettingHandler method execute.

/**
	 * (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    runWizardPageExtension();
    ISelection curSelection = HandlerUtil.getCurrentSelection(event);
    if (curSelection != null && !curSelection.isEmpty() && curSelection instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) curSelection;
        Object obj = selection.getFirstElement();
        if (obj instanceof IProject) {
            IProject project = (IProject) obj;
            ProjectConfiger cfg = ProjectConfigerFactory.getProjectConfiger(project);
            final ProjectInfoBean cfgBean = cfg.getCurrentProjectConfig();
            cfgBean.setProjectName(project.getName());
            ProjectSettingBaseInfoPage infoPage = new ProjectSettingBaseInfoPage(cfgBean);
            ProjectSettingLanguagePage langPag = new ProjectSettingLanguagePage(cfgBean);
            final PreferenceManager mgr = new PreferenceManager();
            IPreferenceNode infoNode = new PreferenceNode("infoPage", infoPage);
            IPreferenceNode langNode = new PreferenceNode("langPag", langPag);
            mgr.addToRoot(infoNode);
            mgr.addTo("infoPage", langNode);
            AbstractProjectSettingPage pageTm = getPageByType("TM");
            if (pageTm != null) {
                pageTm.setProjectInfoBean(cfgBean);
                IPreferenceNode extensionNode = new PreferenceNode("tmInfo", pageTm);
                mgr.addTo("infoPage", extensionNode);
            }
            AbstractProjectSettingPage pageTb = getPageByType("TB");
            if (pageTb != null) {
                pageTb.setProjectInfoBean(cfgBean);
                IPreferenceNode extensionNode = new PreferenceNode("tbInfo", pageTb);
                mgr.addTo("infoPage", extensionNode);
            }
            for (AbstractProjectSettingPage page : extensionPages) {
                page.setProjectInfoBean(cfgBean);
                IPreferenceNode extensionNode = new PreferenceNode("tbInfo", page);
                mgr.addTo("infoPage", extensionNode);
            }
            ProjectSettingDialog dialog = new ProjectSettingDialog(window.getShell(), mgr);
            dialog.create();
            dialog.setMessage(infoPage.getTitle());
            if (dialog.open() == 0) {
                cfg.updateProjectConfig(cfgBean);
                try {
                    project.refreshLocal(IResource.DEPTH_INFINITE, null);
                } catch (CoreException e) {
                    logger.error("", e);
                }
            }
        } else {
            MessageDialog.openError(window.getShell(), Messages.getString("handlers.ProjectSettingHandler.msgTitle"), Messages.getString("handlers.ProjectSettingHandler.msg1"));
            return null;
        }
    } else {
        MessageDialog.openError(window.getShell(), Messages.getString("handlers.ProjectSettingHandler.msgTitle"), Messages.getString("handlers.ProjectSettingHandler.msg1"));
        return null;
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ProjectSettingBaseInfoPage(net.heartsome.cat.ts.ui.projectsetting.ProjectSettingBaseInfoPage) ProjectSettingDialog(net.heartsome.cat.ts.ui.projectsetting.ProjectSettingDialog) ProjectSettingLanguagePage(net.heartsome.cat.ts.ui.projectsetting.ProjectSettingLanguagePage) PreferenceNode(org.eclipse.jface.preference.PreferenceNode) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AbstractProjectSettingPage(net.heartsome.cat.ts.ui.extensionpoint.AbstractProjectSettingPage) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode) PreferenceManager(org.eclipse.jface.preference.PreferenceManager) IProject(org.eclipse.core.resources.IProject) ProjectInfoBean(net.heartsome.cat.common.bean.ProjectInfoBean) CoreException(org.eclipse.core.runtime.CoreException) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) ISelection(org.eclipse.jface.viewers.ISelection)

Example 5 with ProjectConfiger

use of net.heartsome.cat.ts.core.file.ProjectConfiger 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)

Aggregations

ProjectConfiger (net.heartsome.cat.ts.core.file.ProjectConfiger)11 DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)7 IFile (org.eclipse.core.resources.IFile)5 ArrayList (java.util.ArrayList)4 ProjectInfoBean (net.heartsome.cat.common.bean.ProjectInfoBean)4 Language (net.heartsome.cat.common.locale.Language)4 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)4 IProject (org.eclipse.core.resources.IProject)4 CoreException (org.eclipse.core.runtime.CoreException)4 IEditorPart (org.eclipse.ui.IEditorPart)4 FileEditorInput (org.eclipse.ui.part.FileEditorInput)3 File (java.io.File)2 List (java.util.List)2 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 NavException (com.ximpleware.NavException)1 XPathEvalException (com.ximpleware.XPathEvalException)1