Search in sources :

Example 1 with IXliffEditor

use of net.heartsome.cat.ts.ui.editors.IXliffEditor 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 IXliffEditor

use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.

the class ApplicationWorkbenchWindowAdvisor method addViewPartVisibleListener.

private void addViewPartVisibleListener(final IWorkbenchWindow window) {
    final ICommandService commandService = (ICommandService) window.getService(ICommandService.class);
    window.getActivePage().addPartListener(new PartAdapter2() {

        private void setStates(String partId) {
            if ("net.heartsome.cat.common.ui.navigator.view".equals(partId)) {
                commandService.refreshElements("net.heartsome.cat.common.ui.navigator.command.OpenNavigatorView", null);
            } else if ("net.heartsome.cat.ts.ui.views.DocumentPropertiesViewPart".equals(partId)) {
                commandService.refreshElements("net.heartsome.cat.ts.ui.handlers.OpenDocumentPropertiesViewCommand", null);
            } else if ("net.heartsome.cat.ts.ui.translation.view.matchview".equals(partId)) {
                commandService.refreshElements("net.heartsome.cat.ts.ui.translation.menu.command.openMatchView", null);
            } else if ("net.heartsome.cat.ts.ui.term.view.termView".equals(partId)) {
                commandService.refreshElements("net.heartsome.cat.ts.ui.term.command.openTermView", null);
            } else if ("net.heartsome.cat.ts.ui.qa.views.QAResultViewPart".equals(partId)) {
                commandService.refreshElements("net.heartsome.cat.ts.ui.qa.handlers.OpenQAResultViewCommand", null);
            } else if ("net.heartsome.cat.ts.websearch.ui.view.BrowserViewPart".equals(partId)) {
                commandService.refreshElements("net.heartsome.cat.ts.websearch.showOrHideView", null);
            }
        }

        /**
			 * 视图打开时
			 * @see org.eclipse.ui.IPartListener2#partOpened(org.eclipse.ui.IWorkbenchPartReference)
			 */
        public void partOpened(final IWorkbenchPartReference partRef) {
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    setStates(partRef.getId());
                }
            });
        }

        /**
			 * 视图关闭时
			 * @see org.eclipse.ui.IPartListener2#partClosed(org.eclipse.ui.IWorkbenchPartReference)
			 */
        public void partClosed(IWorkbenchPartReference partRef) {
            if (!partRef.getPage().getWorkbenchWindow().getWorkbench().isClosing()) {
                setStates(partRef.getId());
            }
            // 关闭时,根据是否是合并打开的文件,如果是,标识其是否被存储--robert
            if ("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor".equals(partRef.getId())) {
                if (partRef.getPage().getWorkbenchWindow().getWorkbench().isClosing()) {
                    IXliffEditor xlfEditor = (IXliffEditor) partRef.getPart(true);
                    xlfEditor.setStore(true);
                }
            }
        }
    });
}
Also used : PartAdapter2(net.heartsome.cat.common.ui.listener.PartAdapter2) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) ICommandService(org.eclipse.ui.commands.ICommandService) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 3 with IXliffEditor

use of net.heartsome.cat.ts.ui.editors.IXliffEditor 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 4 with IXliffEditor

use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.

the class UpdateTMWizard method performFinish.

public boolean performFinish() {
    final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final boolean isDraft = page.isDraft();
    final boolean isApproved = page.isApproved();
    final boolean isSignedOff = page.isSignedOff();
    final boolean isTranslated = page.isTranslated();
    final boolean isLocked = page.isLocked();
    if (!isDraft && !isApproved && !isSignedOff && !isTranslated && !isLocked) {
        MessageDialog.openInformation(getShell(), Messages.getString("wizard.UpdateTMWizard.msgTitle"), Messages.getString("wizard.UpdateTMWizard.msg"));
        return false;
    }
    IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
    final int contextSize = ps.getInt(TMPreferenceConstants.CONTEXT_MATCH);
    final int tmxImportStrategy = ps.getInt(TMPreferenceConstants.TM_UPDATE);
    IRunnableWithProgress progress = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) {
            monitor.setTaskName(Messages.getString("dialog.UpdateTMDialog.jobTask1"));
            monitor.beginTask(Messages.getString("dialog.UpdateTMDialog.jobTask1"), lstXLIFF.size() * 2);
            for (final IFile xliffFile : lstXLIFF) {
                ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(xliffFile.getProject());
                DatabaseModelBean modelBean = projectConfig.getDefaultTMDb();
                FileEditorInput editorInput = new FileEditorInput(xliffFile);
                IEditorPart editorPart = activePage.findEditor(editorInput);
                // 选择所有语言
                XLFHandler handler = null;
                if (editorPart != null && editorPart instanceof IXliffEditor) {
                    // xliff 文件已用 XLIFF 编辑器打开
                    IXliffEditor xliffEditor = (IXliffEditor) editorPart;
                    handler = xliffEditor.getXLFHandler();
                } else {
                    // xliff 文件未打开
                    handler = new XLFHandler();
                }
                monitor.subTask(Messages.getString("dialog.UpdateTMDialog.jobTask2"));
                // 修改获取系统用户方式/*System.getProperty("user.name");*/
                String systemUser = PlatformUI.getPreferenceStore().getString(IPreferenceConstants.SYSTEM_USER);
                String[] arrTempTMX = handler.generateTMXToUpdateTM(xliffFile, isApproved, isSignedOff, isTranslated, isDraft, isLocked, contextSize, systemUser);
                monitor.worked(1);
                if (arrTempTMX != null) {
                    monitor.subTask(Messages.getString("dialog.UpdateTMDialog.jobTask3"));
                    // }
                    try {
                        DatabaseService.importTmxWithString(modelBean.toDbMetaData(), arrTempTMX[1], new SubProgressMonitor(monitor, 1), tmxImportStrategy, false, arrTempTMX[0]);
                    } catch (ImportException e) {
                        final String msg = e.getMessage();
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                MessageDialog.openInformation(getShell(), Messages.getString("dialog.UpdateTMDialog.job.msgTitle"), msg);
                            }
                        });
                        canFinish = false;
                        return;
                    }
                }
            }
            monitor.done();
            // 刷新项目
            ResourceUtils.refreshCurentSelectProject();
            canFinish = true;
        }
    };
    try {
        getContainer().run(true, true, progress);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return canFinish;
}
Also used : IFile(org.eclipse.core.resources.IFile) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ImportException(net.heartsome.cat.common.core.exception.ImportException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 5 with IXliffEditor

use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.

the class WebSearchHandler method execute.

/** (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    String selectPureText = "";
    if (editor instanceof IXliffEditor) {
        IXliffEditor xliffEditor = (IXliffEditor) editor;
        selectPureText = xliffEditor.getSelectPureText();
    }
    try {
        IViewPart showView = getActivePage().showView(BrowserViewPart.ID);
        if (showView instanceof BrowserViewPart) {
            BrowserViewPart browserViewPart = (BrowserViewPart) showView;
            browserViewPart.setKeyWord(selectPureText, true);
        }
    } catch (PartInitException e) {
        e.printStackTrace();
        logger.error("", e);
    }
    return null;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) BrowserViewPart(net.heartsome.cat.ts.websearch.ui.view.BrowserViewPart) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Aggregations

IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)34 IEditorPart (org.eclipse.ui.IEditorPart)24 FileEditorInput (org.eclipse.ui.part.FileEditorInput)18 IFile (org.eclipse.core.resources.IFile)17 IEditorReference (org.eclipse.ui.IEditorReference)10 IViewPart (org.eclipse.ui.IViewPart)10 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)8 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)8 PartInitException (org.eclipse.ui.PartInitException)8 ArrayList (java.util.ArrayList)7 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)7 IProject (org.eclipse.core.resources.IProject)7 CoreException (org.eclipse.core.runtime.CoreException)7 MatchViewPart (net.heartsome.cat.ts.ui.translation.view.MatchViewPart)5 ProjectConfiger (net.heartsome.cat.ts.core.file.ProjectConfiger)4 ISimpleMatcher (net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher)4 ExecutionException (org.eclipse.core.commands.ExecutionException)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 List (java.util.List)3