Search in sources :

Example 1 with PrefrenceParameters

use of net.heartsome.cat.ts.googletrans.bean.PrefrenceParameters in project translationstudio8 by heartsome.

the class ExecuteGoogleTransHandler 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.ExecuteGoogleTransHandler.msgTitle"), Messages.getString("handler.ExecuteGoogleTransHandler.msg"));
        return null;
    }
    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);
    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(ExecuteGoogleTransHandler.class).error("Exception:key hs008 is lost.(Can't find the key)");
        System.exit(0);
    }
    ISimpleMatcher matcher = new SimpleMatcherGoogleImpl();
    //		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.manualExecSimpleTranslation(matcher);
    //matchView.refreshView(xliffEditor, selectedRowIndexs[0]);
    //			matchView.replaceMatchs(newAltTrans);
    //			matchView.refreshViewByToolId(xliffEditor, newAltTrans, matcher.getMathcerToolId());
    //			newAltTrans.clear();
    }
    return null;
}
Also used : MatchViewPart(net.heartsome.cat.ts.ui.translation.view.MatchViewPart) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) ISimpleMatcher(net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher) PrefrenceParameters(net.heartsome.cat.ts.googletrans.bean.PrefrenceParameters) SimpleMatcherGoogleImpl(net.heartsome.cat.ts.googletrans.SimpleMatcherGoogleImpl) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Aggregations

SimpleMatcherGoogleImpl (net.heartsome.cat.ts.googletrans.SimpleMatcherGoogleImpl)1 PrefrenceParameters (net.heartsome.cat.ts.googletrans.bean.PrefrenceParameters)1 ISimpleMatcher (net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher)1 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)1 MatchViewPart (net.heartsome.cat.ts.ui.translation.view.MatchViewPart)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IViewPart (org.eclipse.ui.IViewPart)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1