Search in sources :

Example 16 with IXliffEditor

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

the class TerminologyViewPart method selectionChanged.

/**
	 * 监听来自IHSEditor的选中改变事件。
	 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart,
	 *      org.eclipse.jface.viewers.ISelection)
	 */
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    // UNDO 每次启动程序后,术语匹配面板无法识别出术语。 2012-06-21
    if (part == null || selection == null) {
        return;
    }
    if (part instanceof IXliffEditor) {
        if (!part.equals(tempEditor)) {
            IXliffEditor editor = (IXliffEditor) part;
            tempEditor = editor;
            tempEditor = (IXliffEditor) part;
            FileEditorInput input = (FileEditorInput) getSite().getPage().getActiveEditor().getEditorInput();
            IProject currProject = input.getFile().getProject();
            matcher.setCurrentProject(currProject);
        }
    } else {
        firstAction.setEnabled(false);
        return;
    }
    if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
        firstAction.setEnabled(false);
        return;
    }
    IStructuredSelection structuredSelecion = (IStructuredSelection) selection;
    Object object = structuredSelecion.getFirstElement();
    if (object instanceof Integer) {
        rowIndex = (Integer) object;
        IXliffEditor editor = (IXliffEditor) part;
        // handler.getTransUnit(rowId);
        TransUnitBean bean = editor.getRowTransUnitBean(rowIndex);
        String pureText = bean.getSrcText();
        srcLang = bean.getSrcLang();
        tgtLang = bean.getTgtLang();
        tgtLang = tgtLang == null || tgtLang.equals("") ? editor.getTgtColumnName() : tgtLang;
        srcLang = srcLang == null || "".equals(srcLang) ? editor.getSrcColumnName() : srcLang;
        if (srcLang == null || "".equals(srcLang) || tgtLang == null || "".equals(tgtLang)) {
            return;
        }
        Language srcLangL = LocaleService.getLanguageConfiger().getLanguageByCode(srcLang);
        Language tgtLangL = LocaleService.getLanguageConfiger().getLanguageByCode(tgtLang);
        if (srcLangL.isBidi() || tgtLangL.isBidi()) {
            gridTable.setOrientation(SWT.RIGHT_TO_LEFT);
        } else {
            gridTable.setOrientation(SWT.LEFT_TO_RIGHT);
        }
        srcTableColumn.setText(srcLang);
        tgtTableColumn.setText(tgtLang);
        loadData(pureText, srcLang, tgtLang, true);
    }
}
Also used : TransUnitBean(net.heartsome.cat.ts.core.bean.TransUnitBean) Language(net.heartsome.cat.common.locale.Language) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) IProject(org.eclipse.core.resources.IProject)

Example 17 with IXliffEditor

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

the class AddTermToTBHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (editor instanceof IXliffEditor) {
        IXliffEditor xliffEditor = (IXliffEditor) editor;
        IFile file = ((FileEditorInput) editor.getEditorInput()).getFile();
        //			ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
        //			List<DatabaseModelBean> lstDatabase = projectConfig.getTermBaseDbs(true);
        TbImporter.getInstance().setProject(file.getProject());
        if (!TbImporter.getInstance().checkImporter()) {
            MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.AddTermToTBHandler.msgTitle"), Messages.getString("handler.AddTermToTBHandler.msg"));
            return null;
        }
        StringBuffer srcTerm = new StringBuffer();
        StringBuffer tgtTerm = new StringBuffer();
        String srcAllText = xliffEditor.getRowTransUnitBean(xliffEditor.getSelectedRows()[0]).getSrcText();
        xliffEditor.getSelectSrcOrTgtPureText(srcTerm, tgtTerm);
        AddTermToTBDialog dialog = AddTermToTBDialog.getInstance(editor.getSite().getShell(), srcTerm.toString().trim(), tgtTerm.toString().trim(), AddTermToTBDialog.ADD_TYPE);
        dialog.setProject(file.getProject());
        dialog.setSrcLang(xliffEditor.getSrcColumnName());
        dialog.setTgtLang(xliffEditor.getTgtColumnName());
        dialog.setSrcAllText(srcAllText);
        dialog.open();
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) AddTermToTBDialog(net.heartsome.cat.ts.ui.term.dialog.AddTermToTBDialog) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 18 with IXliffEditor

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

the class TermViewerBodyMenu method addTerm.

void addTerm() {
    IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (editor instanceof IXliffEditor) {
        IXliffEditor xliffEditor = (IXliffEditor) editor;
        IFile file = ((FileEditorInput) editor.getEditorInput()).getFile();
        TbImporter.getInstance().setProject(file.getProject());
        if (!TbImporter.getInstance().checkImporter()) {
            MessageDialog.openInformation(editor.getSite().getShell(), Messages.getString("handler.AddTermToTBHandler.msgTitle"), Messages.getString("handler.AddTermToTBHandler.msg"));
            return;
        }
        StringBuffer srcTerm = new StringBuffer();
        StringBuffer tgtTerm = new StringBuffer();
        String srcAllText = xliffEditor.getRowTransUnitBean(xliffEditor.getSelectedRows()[0]).getSrcText();
        xliffEditor.getSelectSrcOrTgtPureText(srcTerm, tgtTerm);
        AddTermToTBDialog dialog = AddTermToTBDialog.getInstance(editor.getSite().getShell(), srcTerm.toString().trim(), tgtTerm.toString().trim(), AddTermToTBDialog.ADD_TYPE);
        dialog.setProject(file.getProject());
        dialog.setSrcLang(xliffEditor.getSrcColumnName());
        dialog.setTgtLang(xliffEditor.getTgtColumnName());
        dialog.setSrcAllText(srcAllText);
        dialog.open();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) AddTermToTBDialog(net.heartsome.cat.ts.ui.term.dialog.AddTermToTBDialog) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 19 with IXliffEditor

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

the class ColorConfigLoader method loadColor.

private void loadColor() {
    Device device = Activator.getDefault().getWorkbench().getDisplay();
    if (pfStore == null) {
        pfStore = Activator.getDefault().getPreferenceStore();
        pfStore.addPropertyChangeListener(this);
    }
    colorConfigBean.release();
    colorConfigBean.setPtColor(getColor(device, IColorPreferenceConstant.PT_COLOR));
    colorConfigBean.setQtColor(getColor(device, IColorPreferenceConstant.QT_COLOR));
    colorConfigBean.setMtColor(getColor(device, IColorPreferenceConstant.MT_COLOR));
    colorConfigBean.setTm101Color(getColor(device, IColorPreferenceConstant.TM_MATCH101_COLOR));
    colorConfigBean.setTm100Color(getColor(device, IColorPreferenceConstant.TM_MATCH100_COLOR));
    colorConfigBean.setTm90Color(getColor(device, IColorPreferenceConstant.TM_MATCH90_COLOR));
    colorConfigBean.setTm80Color(getColor(device, IColorPreferenceConstant.TM_MATCH80_COLOR));
    colorConfigBean.setTm70Color(getColor(device, IColorPreferenceConstant.TM_MATCH70_COLOR));
    colorConfigBean.setTm0Color(getColor(device, IColorPreferenceConstant.TM_MATCH0_COLOR));
    colorConfigBean.setSrcDiffFgColor(getColor(device, IColorPreferenceConstant.DIFFERENCE_FG_COLOR));
    colorConfigBean.setSrcDiffBgColor(getColor(device, IColorPreferenceConstant.DIFFERENCE_BG_COLOR));
    colorConfigBean.setTagFgColor(getColor(device, IColorPreferenceConstant.TAG_FG_COLOR));
    colorConfigBean.setTagBgColor(getColor(device, IColorPreferenceConstant.TAG_BG_COLOR));
    colorConfigBean.setWrongTagColor(getColor(device, IColorPreferenceConstant.WRONG_TAG_COLOR));
    colorConfigBean.setErrorWordColor(getColor(device, IColorPreferenceConstant.WRONG_TAG_COLOR));
    String strColor = colorConfigBean.toString();
    IXliffEditor xliffEditor = null;
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
        IWorkbenchPage page = window.getActivePage();
        if (page != null) {
            IEditorPart editor = page.getActiveEditor();
            if (editor != null && editor instanceof IXliffEditor) {
                xliffEditor = (IXliffEditor) editor;
            }
        }
    }
    if (strCurColor != null && !strCurColor.equals(strColor)) {
        // 更改颜色设置后刷新界面
        if (xliffEditor != null) {
            xliffEditor.autoResize();
            xliffEditor.refresh();
        }
        if (window != null) {
            IWorkbenchPage page = window.getActivePage();
            if (page != null) {
                IViewPart viewPart = page.findView("net.heartsome.cat.ts.ui.translation.view.matchview");
                if (viewPart != null) {
                    IMatchViewPart part = (IMatchViewPart) viewPart;
                    part.refreshTable();
                }
            }
        }
        strCurColor = strColor;
    }
    Color highlightedTermColor = colorConfigBean.getHighlightedTermColor();
    RGB newRgb = StringConverter.asRGB(pfStore.getString(IColorPreferenceConstant.HIGHLIGHTED_TERM_COLOR));
    if (highlightedTermColor == null || highlightedTermColor.isDisposed()) {
        highlightedTermColor = new Color(device, newRgb);
    } else if (!highlightedTermColor.getRGB().equals(newRgb)) {
        highlightedTermColor.dispose();
        highlightedTermColor = new Color(device, newRgb);
        // had changed
        if (xliffEditor != null) {
            // 刷新
            xliffEditor.highlightedTerms(0, null);
        }
    }
    colorConfigBean.setHighlightedTermColor(highlightedTermColor);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) Device(org.eclipse.swt.graphics.Device) Color(org.eclipse.swt.graphics.Color) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) RGB(org.eclipse.swt.graphics.RGB) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) IMatchViewPart(net.heartsome.cat.ts.ui.view.IMatchViewPart)

Example 20 with IXliffEditor

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

the class ExecuteBingTransHandler method execute.

/**
	 * (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof IXliffEditor)) {
        return null;
    }
    // check the google translation state: check the key availability
    PrefrenceParameters ps = PrefrenceParameters.getInstance();
    if (!ps.getState()) {
        MessageDialog.openError(window.getShell(), Messages.getString("handler.ExecuteBingTransHandler.msgTitle"), Messages.getString("handler.ExecuteBingTransHandler.msg"));
        return null;
    }
    String tshelp = System.getProperties().getProperty("TSHelp");
    String tsstate = System.getProperties().getProperty("TSState");
    if (tshelp == null || !"true".equals(tshelp) || tsstate == null || !"true".equals(tsstate)) {
        LoggerFactory.getLogger(ExecuteBingTransHandler.class).error("Exception:key hs008 is lost.(Can't find the key)");
        System.exit(0);
    }
    final IXliffEditor xliffEditor = (IXliffEditor) editor;
    final int[] selectedRowIndexs = xliffEditor.getSelectedRows();
    if (selectedRowIndexs.length == 0) {
        return null;
    }
    //		int currentRowIndex = selectedRowIndexs[0];
    //		TransUnitBean transUnitBean = xliffEditor.getRowTransUnitBean(currentRowIndex);
    //		if (transUnitBean == null) {
    //			return null;
    //		}
    //		String srcPureText = transUnitBean.getSrcText();
    //		String tgtLanguage = xliffEditor.getTgtColumnName();
    //		String srcLanguage = xliffEditor.getSrcColumnName();
    //		TransUnitInfo2TranslationBean tuInfo2Trans = new TransUnitInfo2TranslationBean();
    //		tuInfo2Trans.setSrcPureText(srcPureText);
    //		tuInfo2Trans.setSrcLanguage(srcLanguage);
    //		tuInfo2Trans.setTgtLangugage(tgtLanguage);
    ISimpleMatcher matcher = new SimpleMatcherBingImpl();
    //		String tgtText = matcher.executeMatch(tuInfo2Trans);
    //		if (tgtText.equals("")) {
    //			return null;
    //		}
    //		AltTransBean bean = new AltTransBean(srcPureText, tgtText, srcLanguage, tgtLanguage,
    //				matcher.getMathcerOrigin(), matcher.getMathcerToolId());
    //		bean.getMatchProps().put("match-quality", "100");
    //		bean.getMatchProps().put("hs:matchType", matcher.getMatcherType());
    //		bean.setSrcContent(srcPureText);
    //		bean.setTgtContent(tgtText);
    //		List<AltTransBean> newAltTrans = new ArrayList<AltTransBean>();
    //		newAltTrans.add(bean);
    // check if need save the AltTrans to file
    //		if (CommonFunction.checkEdition("U") && matcher.isSuportPreTrans()) {
    //			List<String> oldToolIds = new ArrayList<String>();
    //			oldToolIds.add(matcher.getMathcerToolId());
    //			xliffEditor.getXLFHandler().updateAltTrans(xliffEditor.getXLFHandler().getRowId(currentRowIndex), newAltTrans, oldToolIds);
    //		}
    IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
    if (viewPart != null && viewPart instanceof MatchViewPart) {
        MatchViewPart matchView = (MatchViewPart) viewPart;
        //matchView.refreshView(xliffEditor, selectedRowIndexs[0]);
        //			matchView.refreshViewByToolId(xliffEditor, newAltTrans, matcher.getMathcerToolId());
        //			matchView.replaceMatchs(newAltTrans);
        //			newAltTrans.clear();
        matchView.manualExecSimpleTranslation(matcher);
    }
    return null;
}
Also used : MatchViewPart(net.heartsome.cat.ts.ui.translation.view.MatchViewPart) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) SimpleMatcherBingImpl(net.heartsome.cat.ts.bingtrans.SimpleMatcherBingImpl) IViewPart(org.eclipse.ui.IViewPart) ISimpleMatcher(net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher) PrefrenceParameters(net.heartsome.cat.ts.bingtrans.bean.PrefrenceParameters) IEditorPart(org.eclipse.ui.IEditorPart) 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