Search in sources :

Example 1 with PrefrenceParameters

use of net.heartsome.cat.ts.machinetranslation.bean.PrefrenceParameters 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.isBingState()) {
        MessageDialog.openError(window.getShell(), Messages.getString("handler.ExecuteBingTransHandler.msgTitle"), Messages.getString("handler.ExecuteBingTransHandler.msg"));
        return null;
    }
    final IXliffEditor xliffEditor = (IXliffEditor) editor;
    final int[] selectedRowIndexs = xliffEditor.getSelectedRows();
    if (selectedRowIndexs.length == 0) {
        return null;
    }
    ISimpleMatcher matcher = new SimpleMatcherBingImpl();
    IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
    if (viewPart != null && viewPart instanceof MatchViewPart) {
        MatchViewPart matchView = (MatchViewPart) viewPart;
        matchView.manualExecSimpleTranslation(selectedRowIndexs[0], xliffEditor, matcher);
    }
    return null;
}
Also used : MatchViewPart(net.heartsome.cat.ts.ui.translation.view.MatchViewPart) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) SimpleMatcherBingImpl(net.heartsome.cat.ts.machinetranslation.SimpleMatcherBingImpl) IViewPart(org.eclipse.ui.IViewPart) ISimpleMatcher(net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher) PrefrenceParameters(net.heartsome.cat.ts.machinetranslation.bean.PrefrenceParameters) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 2 with PrefrenceParameters

use of net.heartsome.cat.ts.machinetranslation.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;
    }
    PrefrenceParameters ps = PrefrenceParameters.getInstance();
    if (!ps.isGoogleState()) {
        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;
    }
    ISimpleMatcher matcher = new SimpleMatcherGoogleImpl();
    IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
    if (viewPart != null && viewPart instanceof MatchViewPart) {
        MatchViewPart matchView = (MatchViewPart) viewPart;
        matchView.manualExecSimpleTranslation(selectedRowIndexs[0], xliffEditor, matcher);
    }
    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.machinetranslation.bean.PrefrenceParameters) SimpleMatcherGoogleImpl(net.heartsome.cat.ts.machinetranslation.SimpleMatcherGoogleImpl) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Aggregations

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