Search in sources :

Example 11 with IViewPart

use of org.eclipse.ui.IViewPart in project translationstudio8 by heartsome.

the class AcceptTerm8 method execute.

/** (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.ts.ui.term.view.termView");
    if (viewPart != null && viewPart instanceof ITermViewPart) {
        ITermViewPart matchView = (ITermViewPart) viewPart;
        matchView.acceptTermByIndex(7);
    }
    return null;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) ITermViewPart(net.heartsome.cat.ts.ui.view.ITermViewPart)

Example 12 with IViewPart

use of org.eclipse.ui.IViewPart in project translationstudio8 by heartsome.

the class AcceptTerm9 method execute.

/** (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.ts.ui.term.view.termView");
    if (viewPart != null && viewPart instanceof ITermViewPart) {
        ITermViewPart matchView = (ITermViewPart) viewPart;
        matchView.acceptTermByIndex(8);
    }
    return null;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) ITermViewPart(net.heartsome.cat.ts.ui.view.ITermViewPart)

Example 13 with IViewPart

use of org.eclipse.ui.IViewPart 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)

Example 14 with IViewPart

use of org.eclipse.ui.IViewPart in project translationstudio8 by heartsome.

the class MultiSelectionPropertyTester method test.

public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    IProject curProject = null;
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
        IWorkbenchPage page = window.getActivePage();
        if (page != null) {
            if (page.getActivePartReference() == null) {
                return false;
            }
            String partId = page.getActivePartReference().getId();
            if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
                // 导航视图处于激活状态
                IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
                StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
                ArrayList<IFile> selectedIFileList = new ArrayList<IFile>();
                if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
                    List<?> lstObj = ((IStructuredSelection) selection).toList();
                    for (Object obj : lstObj) {
                        if (obj instanceof IFile) {
                            IFile file = (IFile) obj;
                            // Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
                            if (file.getFileExtension() == null || !CommonFunction.validXlfExtension(file.getFileExtension())) {
                                return false;
                            } else {
                                String xlfFolderPath = file.getProject().getFullPath().append(Constant.FOLDER_XLIFF).toOSString();
                                if (!file.getFullPath().toOSString().startsWith(xlfFolderPath)) {
                                    return false;
                                }
                                if (curProject == null) {
                                    curProject = file.getProject();
                                } else {
                                    if (curProject != file.getProject()) {
                                        return false;
                                    }
                                }
                                selectedIFileList.add(file);
                            }
                        } else if (obj instanceof IFolder) {
                            IFolder folder = (IFolder) obj;
                            String xlfFolderPath = folder.getProject().getFullPath().append(Constant.FOLDER_XLIFF).toOSString();
                            if (!folder.getFullPath().toOSString().startsWith(xlfFolderPath)) {
                                return false;
                            }
                            try {
                                ResourceUtils.getXliffs(folder, selectedIFileList);
                            } catch (CoreException e) {
                                logger.error(Messages.getString("propertyTester.MultiSelectionPropertyTester.logger1"), folder.getFullPath().toOSString(), e);
                            }
                            if (curProject == null) {
                                curProject = folder.getProject();
                            } else {
                                if (curProject != folder.getProject()) {
                                    return false;
                                }
                            }
                        }
                    }
                    CommonFunction.removeRepeateSelect(selectedIFileList);
                    if (selectedIFileList.size() < 2) {
                        return false;
                    }
                } else {
                    return false;
                }
            }
        } else {
            return false;
        }
    } else {
        return false;
    }
    return true;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IFolder(org.eclipse.core.resources.IFolder)

Example 15 with IViewPart

use of org.eclipse.ui.IViewPart 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

IViewPart (org.eclipse.ui.IViewPart)104 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)58 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)39 IEditorPart (org.eclipse.ui.IEditorPart)34 PartInitException (org.eclipse.ui.PartInitException)28 IViewReference (org.eclipse.ui.IViewReference)26 ArrayList (java.util.ArrayList)16 IFile (org.eclipse.core.resources.IFile)15 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)15 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)15 IEditorInput (org.eclipse.ui.IEditorInput)13 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)13 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)10 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)10 ITermViewPart (net.heartsome.cat.ts.ui.view.ITermViewPart)10 Shell (org.eclipse.swt.widgets.Shell)9 IEditorReference (org.eclipse.ui.IEditorReference)9 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)8 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)8 IProject (org.eclipse.core.resources.IProject)8