Search in sources :

Example 6 with IViewPart

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

the class ExportProjectWizard method addPages.

@Override
public void addPages() {
    // TODO Auto-generated method stub
    super.addPages();
    IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IViewPart viewPart = workbenchPage.findView("net.heartsome.cat.common.ui.navigator.view");
    if (viewPart != null) {
        this.selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
    }
    page = new ExportProjectWizardPage("", selection);
    addPage(page);
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 7 with IViewPart

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

the class SplitXliffHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    final String navegatorID = "net.heartsome.cat.common.ui.navigator.view";
    final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    final Shell shell = window.getShell();
    IFile selectFile = null;
    XLIFFEditorImplWithNatTable xliffEditor = null;
    List<Integer> splitXlfPointsIndex = new LinkedList<Integer>();
    List<String> splitXlfPointsRowId = new LinkedList<String>();
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    // 如果是导航视图,那么就获取导航视图中选中的文件
    if (activePart instanceof IViewPart) {
        if (navegatorID.equals(activePart.getSite().getId())) {
            IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(navegatorID);
            ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
            if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {
                IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
                Object object = structuredSelection.getFirstElement();
                if (object instanceof IFile) {
                    selectFile = (IFile) object;
                    String fileExtension = selectFile.getFileExtension();
                    // 如果后缀名不是xlf,那么就退出操作
                    if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
                        MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg1"));
                        return null;
                    }
                    FileEditorInput fileInput = new FileEditorInput(selectFile);
                    IEditorReference[] editorRefer = window.getActivePage().findEditors(fileInput, XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
                    IEditorPart editorPart = null;
                    if (editorRefer.length >= 1) {
                        editorPart = editorRefer[0].getEditor(true);
                        xliffEditor = (XLIFFEditorImplWithNatTable) editorPart;
                        if (window.getActivePage().getActiveEditor() != editorPart) {
                            window.getActivePage().activate(editorPart);
                        }
                    } else {
                        try {
                            xliffEditor = (XLIFFEditorImplWithNatTable) window.getActivePage().openEditor(fileInput, XLIFF_EDITOR_ID, true, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
                        } catch (PartInitException e) {
                            LOGGER.error("", e);
                            e.printStackTrace();
                        }
                    }
                } else {
                    MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg1"));
                    return null;
                }
            }
        }
    } else if (activePart instanceof IEditorPart) {
        if (XLIFF_EDITOR_ID.equals(activePart.getSite().getId())) {
            xliffEditor = (XLIFFEditorImplWithNatTable) activePart;
            selectFile = ((FileEditorInput) xliffEditor.getEditorInput()).getFile();
        }
    }
    // 根据每个tu节点的rowId获取其具体的位置,才好进行排序
    Map<Integer, String> pointIndexRowIdMap = new HashMap<Integer, String>();
    for (String rowId : xliffEditor.getSplitXliffPoints()) {
        // 获取指定tu节点所处其他结点的序列号
        int tuPostion = xliffEditor.getXLFHandler().getTUPositionByRowId(rowId);
        if (tuPostion >= 1) {
            splitXlfPointsIndex.add(tuPostion);
            pointIndexRowIdMap.put(tuPostion, rowId);
        }
    }
    if (splitXlfPointsIndex.size() <= 0) {
        MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg2"));
        return null;
    }
    // 对切割点集合进行排序
    for (int i = 0; i < splitXlfPointsIndex.size(); i++) {
        int point1 = splitXlfPointsIndex.get(i);
        for (int j = i + 1; j < splitXlfPointsIndex.size(); j++) {
            int point2 = splitXlfPointsIndex.get(j);
            if (point1 > point2) {
                splitXlfPointsIndex.set(i, point2);
                splitXlfPointsIndex.set(j, point1);
                point1 = point2;
            }
        }
    }
    // 向存储rowId的list存放数据,这样的话,所存储的rowId就是经过排序了的。
    for (int i = 0; i < splitXlfPointsIndex.size(); i++) {
        splitXlfPointsRowId.add(pointIndexRowIdMap.get(splitXlfPointsIndex.get(i)));
    }
    SplitOrMergeXlfModel model = new SplitOrMergeXlfModel();
    model.setSplitFile(selectFile);
    model.setSplitXlfPointsIndex(splitXlfPointsIndex);
    model.setSplitXlfPointsRowId(splitXlfPointsRowId);
    model.setXliffEditor(xliffEditor);
    model.setShell(shell);
    SplitXliffWizard wizard = new SplitXliffWizard(model);
    final TSWizardDialog dialog = new NattableWizardDialog(shell, wizard);
    dialog.open();
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) SplitOrMergeXlfModel(net.heartsome.cat.ts.handlexlf.split.SplitOrMergeXlfModel) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SplitXliffWizard(net.heartsome.cat.ts.handlexlf.wizard.SplitXliffWizard) Shell(org.eclipse.swt.widgets.Shell) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) PartInitException(org.eclipse.ui.PartInitException) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) NattableWizardDialog(net.heartsome.cat.ts.handlexlf.wizard.NattableWizardDialog) IEditorPart(org.eclipse.ui.IEditorPart) LinkedList(java.util.LinkedList) FileEditorInput(org.eclipse.ui.part.FileEditorInput) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog)

Example 8 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)

Example 9 with IViewPart

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

the class ExecuteQuickTranslation method execute.

/** (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    if (TranslateParameter.getInstance().isAutoQuickTrans()) {
        return null;
    }
    final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    final IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof IXliffEditor)) {
        return null;
    }
    final IXliffEditor xliffEditor = (IXliffEditor) editor;
    final int[] selectedRowIndexs = xliffEditor.getSelectedRows();
    if (selectedRowIndexs.length == 0) {
        return null;
    }
    //		TransUnitBean transUnitBean = xliffEditor.getRowTransUnitBean(selectedRowIndexs[selectedRowIndexs.length - 1]);
    IComplexMatch matcher = new QuickTranslationImpl();
    //		FileEditorInput input = (FileEditorInput) editor.getEditorInput();
    //		IProject project = input.getFile().getProject();
    //		List<AltTransBean> newAltTrans = matcher.executeTranslation(transUnitBean, project);
    //		if(newAltTrans.size() == 0){
    //			return null;
    //		}
    IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
    if (viewPart != null && viewPart instanceof MatchViewPart) {
        MatchViewPart matchView = (MatchViewPart) viewPart;
        matchView.manualExecComplexTranslation(selectedRowIndexs[0], xliffEditor, matcher);
    //			matchView.replaceMatchs(newAltTrans);
    //			matchView.refreshView(xliffEditor, selectedRowIndexs[selectedRowIndexs.length - 1]);
    }
    //		}
    return null;
}
Also used : MatchViewPart(net.heartsome.cat.ts.ui.translation.view.MatchViewPart) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IComplexMatch(net.heartsome.cat.ts.tm.complexMatch.IComplexMatch) QuickTranslationImpl(net.heartsome.cat.ts.quicktranslation.QuickTranslationImpl) IViewPart(org.eclipse.ui.IViewPart) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 10 with IViewPart

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

the class AbstractExportHandler method initExportConfig.

public boolean initExportConfig(ExecutionEvent event) throws ExecutionException {
    config = new ExportConfig();
    Shell shell = HandlerUtil.getActiveShell(event);
    String partId = HandlerUtil.getActivePartId(event);
    if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
        // 导航视图处于激活状态
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
        StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
        if (selection != null && !selection.isEmpty()) {
            for (Object obj : selection.toList()) {
                if (obj instanceof IFile) {
                    addXLFFile((IFile) obj);
                } else if (obj instanceof IFolder) {
                    traversalFile((IFolder) obj);
                } else if (obj instanceof IProject) {
                    IProject proj = (IProject) obj;
                    traversalFile(proj.getFolder(XLF));
                }
            }
            if (config.getProjects() == null || config.getProjects().size() < 1) {
                MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("xlf2tmx.info.notfoundxlf"));
                return false;
            }
        }
    } else if (partId.equals("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor")) {
        // nattable 处于激活状态
        IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
        IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
        IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
        IEditorPart editor = HandlerUtil.getActiveEditor(event);
        IXliffEditor xliffEditor = (IXliffEditor) editor;
        if (xliffEditor.isMultiFile()) {
            MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxHandler.msg2"));
            return false;
        } else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
            addXLFFile(iFile);
        }
    }
    return true;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ExportConfig(net.heartsome.cat.ts.ui.external.ExportConfig) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IViewPart (org.eclipse.ui.IViewPart)95 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)52 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)38 IEditorPart (org.eclipse.ui.IEditorPart)31 PartInitException (org.eclipse.ui.PartInitException)25 IViewReference (org.eclipse.ui.IViewReference)23 IFile (org.eclipse.core.resources.IFile)15 ArrayList (java.util.ArrayList)14 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)14 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)14 IEditorInput (org.eclipse.ui.IEditorInput)11 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 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)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