Search in sources :

Example 36 with IWorkbenchWindow

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

the class ShowPreviousUntranslatedHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
    int[] selectedRows = xliffEditor.getSelectedRows();
    if (selectedRows.length < 1) {
        return null;
    }
    Arrays.sort(selectedRows);
    int firstSelectedRow = selectedRows[0];
    XLFHandler handler = xliffEditor.getXLFHandler();
    int row = handler.getPreviousUntranslatedSegmentIndex(firstSelectedRow);
    if (row != -1) {
        xliffEditor.jumpToRow(row);
    } else {
        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
        MessageDialog.openWarning(window.getShell(), "", "不存在上一未翻译文本段。");
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 37 with IWorkbenchWindow

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

Example 38 with IWorkbenchWindow

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

the class SplitXliff method splitTheXliff.

/**
	 * 切割Xliff文件 注意:源文本没有解析,因为xlfhandler是从xlfeditor取过来的,因此不用再解析一次。
	 */
public boolean splitTheXliff(IProgressMonitor monitor) {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    monitor.beginTask(Messages.getString("splitAndMergeXliff.SplitXliff.task1"), splitPointsIndex.size());
    String xlfPath = splitFile.getLocation().toOSString();
    if (xlfPath != null) {
        File f = new File(xlfPath);
        // 如果文件不存在,提示并退出操作
        if (!f.exists()) {
            f = null;
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    MessageDialog.openInformation(shell, Messages.getString("splitAndMergeXliff.SplitXliff.msgTitle1"), MessageFormat.format(Messages.getString("splitAndMergeXliff.SplitXliff.msg1"), new Object[] { splitFile.getFullPath().toOSString() }));
                }
            });
            return false;
        } else {
            Map<String, String> newInfo = null;
            File src = new File(xlfPath);
            String fileName = null;
            String splitXliffName = null;
            try {
                splitXliffName = src.getName();
                // 源文件的文件名
                fileName = new String(splitXliffName.getBytes("UTF-8"));
            } catch (UnsupportedEncodingException e1) {
                LOGGER.error("", e1);
                e1.printStackTrace();
            }
            // 判断分割后生成的子文件是否重复,如果重复就进行提示
            String copyFiles = "";
            LinkedList<String> newSplitedFilesName = model.getNewSplitedFilesName();
            for (int i = 0; i < newSplitedFilesName.size(); i++) {
                final String newXlfPath = model.getSplitXlfsContainer().getLocation().append(newSplitedFilesName.get(i)).toOSString();
                File newXlfFile = new File(newXlfPath);
                if (newXlfFile.exists()) {
                    copyFiles += getFullPath(newXlfPath) + "\n";
                    repeateFileList.add(ResourceUtils.fileToIFile(newXlfPath));
                }
            }
            final String copyFilesTip = copyFiles.substring(0, copyFiles.length());
            // 如果新生成的文件已经存在,那么提示是否覆盖
            if (copyFiles.length() > 0) {
                try {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            boolean response = MessageDialog.openConfirm(shell, Messages.getString("splitAndMergeXliff.SplitXliff.msgTitle2"), MessageFormat.format(Messages.getString("splitAndMergeXliff.SplitXliff.msg2"), new Object[] { copyFilesTip }));
                            if (!response) {
                                needCover = true;
                            }
                        }
                    });
                } catch (Exception e) {
                    LOGGER.error("", e);
                    e.printStackTrace();
                }
                if (needCover) {
                    return false;
                }
            }
            // 先删除重复的文件,再关闭已经打开的重复文件的编辑器
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                    try {
                        IEditorReference[] refrences = window.getActivePage().getEditorReferences();
                        for (IEditorReference refrence : refrences) {
                            if (refrence.getEditor(true).getEditorSite().getId().equals(NATABLE_ID)) {
                                XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) refrence.getEditor(true);
                                if (nattable.isMultiFile()) {
                                    for (File file : nattable.getMultiFileList()) {
                                        if (repeateFileList.indexOf(ResourceUtils.fileToIFile(file.getAbsolutePath())) >= 0) {
                                            window.getActivePage().closeEditor(nattable, true);
                                            break;
                                        }
                                    }
                                } else {
                                    if (repeateFileList.indexOf(((FileEditorInput) nattable.getEditorInput()).getFile()) >= 0) {
                                        window.getActivePage().closeEditor(nattable, true);
                                    }
                                }
                            }
                        }
                        for (IFile iFile : repeateFileList) {
                            ResourceUtil.getFile(iFile).delete(true, null);
                        }
                        model.getSplitFile().getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
                    } catch (Exception e) {
                        LOGGER.error("", e);
                    }
                }
            });
            // 得到当前的时间, 开始进行循环切割
            long splitTime = System.currentTimeMillis();
            for (int i = CONSTANT_ONE, pointsSize = (splitPointsIndex.size() + 1); i <= pointsSize; i++) {
                newInfo = getNewSplitInfo(fileName, oldInfo, i, pointsSize, splitTime);
                monitor.subTask(Messages.getString("splitAndMergeXliff.SplitXliff.task2") + newInfo.get("name"));
                // 创建新的XLIFF的文件路径
                final String newXlfPath = model.getSplitXlfsContainer().getLocation().append(getSplitFileName(splitXliffName, oldInfo, i)).toOSString();
                String xliffNodeHeader = xlfhandler.getNodeHeader(xlfPath, "xliff", "/xliff");
                createNewSplitXliff(newXlfPath, xliffNodeHeader);
                // 打开这个新创建的xliff文件,将xliff与file,header等节点写入进去
                Map<String, Object> newResultMap = splitHandler.openFile(newXlfPath);
                if (newResultMap == null || Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) newResultMap.get(Constant.RETURNVALUE_RESULT)) {
                    Display.getDefault().asyncExec(new Runnable() {

                        public void run() {
                            MessageDialog.openError(shell, Messages.getString("splitAndMergeXliff.SplitXliff.msgTitle3"), Messages.getString("splitAndMergeXliff.SplitXliff.msg3"));
                        }
                    });
                    return false;
                }
                if (fileInfo == null) {
                    fileInfo = xlfhandler.getFileInfo(xlfPath);
                }
                // 获取当前分割段的首末rowId
                String startRowId = xlfhandler.getNextRowId(xlfPath, i == CONSTANT_ONE ? "start" : splitPointsRowId.get(i - 2));
                String endRowId = (i == pointsSize) ? xlfhandler.getNextRowId(xlfPath, "end") : splitPointsRowId.get(// 因为这里的I是从1开始的,故要减1
                i - CONSTANT_ONE);
                // 获取分割段的file,与body第一子节点的序列
                Map<String, Integer> startNodeIdxMap = xlfhandler.getSplitNodeIdx(xlfPath, i == CONSTANT_ONE ? "start" : splitPointsRowId.get(i - 2));
                Map<String, Integer> endNodeIdxMap = (i == pointsSize) ? xlfhandler.getSplitNodeIdx(xlfPath, "end") : xlfhandler.getSplitNodeIdx(xlfPath, splitPointsRowId.get(i - CONSTANT_ONE));
                // 获取当前起始rowId所在的file节点的序列号
                int startFileNodeIdx = startNodeIdxMap.get("fileNodeIdx");
                int endFileNodeIdx = endNodeIdxMap.get("fileNodeIdx");
                int startBodyChildIdx = startNodeIdxMap.get("bodyChildNodeIdx");
                // 开始循环每一个file节点,进行获取相关数据
                // 这是新生成的xliff文件中的file的序列号
                int n = 1;
                for (int fileIdx = startFileNodeIdx; fileIdx <= endFileNodeIdx; fileIdx++) {
                    // 开始将数据存入新切割的xliff文件中,先存放file节点的头
                    String fileNodeHeader = xlfhandler.getNodeHeader(xlfPath, "file", "/xliff/file[" + fileIdx + "]");
                    splitHandler.addDataToXlf(newXlfPath, fileNodeHeader, "/xliff");
                    String headerFrag = xlfhandler.getNodeFrag(xlfPath, "/xliff/file[" + fileIdx + "]/header");
                    splitHandler.addDataToXlf(newXlfPath, headerFrag, "/xliff/file[" + n + "]");
                    // 向新生成xliff文件添加body元素
                    String bodyNodeHeader = xlfhandler.getNodeHeader(xlfPath, "body", "/xliff/file[" + fileIdx + "]/body");
                    splitHandler.addDataToXlf(newXlfPath, bodyNodeHeader, "/xliff/file[" + n + "]");
                    boolean isLastOfFile = false;
                    if (i == pointsSize && fileIdx == endFileNodeIdx) {
                        isLastOfFile = true;
                    }
                    // UNDO 分割这里还要好发测试一下,针对不同情况。
                    String tuData = xlfhandler.getSplitTuData(xlfPath, fileIdx, n == 1 ? startBodyChildIdx : 1, n == 1 ? startRowId : null, endRowId, n == 1, isLastOfFile);
                    splitHandler.addDataToXlf(newXlfPath, tuData, "/xliff/file[" + n + "]/body");
                    n++;
                }
                if (monitor.isCanceled()) {
                    throw new OperationCanceledException(Messages.getString("splitAndMergeXliff.SplitXliff.msg3"));
                }
                monitor.worked(1);
                // 添加新的切割信息
                splitHandler.addNewInfoToSplitXlf(newXlfPath, newInfo);
            }
            monitor.done();
        }
    }
    return true;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IFile(org.eclipse.core.resources.IFile) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IEditorReference(org.eclipse.ui.IEditorReference) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 39 with IWorkbenchWindow

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

the class ImportProjectHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    ImportProjectWizard wizard = new ImportProjectWizard();
    TSWizardDialog dialog = new TSWizardDialog(window.getShell(), wizard) {

        /**
			 * 添加帮助按钮
			 * robert	2012-09-06
			 */
        @Override
        protected Control createHelpControl(Composite parent) {
            // ROBERTHELP 导入项目
            String language = CommonFunction.getSystemLanguage();
            final String helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch07s03.html#import-project", language);
            Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
            ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
            ((GridLayout) parent.getLayout()).numColumns++;
            toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
            final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
            toolBar.setCursor(cursor);
            toolBar.addDisposeListener(new DisposeListener() {

                public void widgetDisposed(DisposeEvent e) {
                    cursor.dispose();
                }
            });
            ToolItem helpItem = new ToolItem(toolBar, SWT.NONE);
            helpItem.setImage(helpImage);
            //$NON-NLS-1$
            helpItem.setToolTipText(JFaceResources.getString("helpToolTip"));
            helpItem.addSelectionListener(new SelectionAdapter() {

                public void widgetSelected(SelectionEvent e) {
                    PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
                }
            });
            return toolBar;
        }
    };
    dialog.setHelpAvailable(true);
    dialog.open();
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DisposeListener(org.eclipse.swt.events.DisposeListener) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ImportProjectWizard(net.heartsome.cat.ts.importproject.wizards.ImportProjectWizard) Image(org.eclipse.swt.graphics.Image) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 40 with IWorkbenchWindow

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

the class NextSplitPointHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    final Shell shell = window.getShell();
    XLIFFEditorImplWithNatTable xliffEditor = null;
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart instanceof IEditorPart) {
        if (XLIFF_EDITOR_ID.equals(activePart.getSite().getId())) {
            xliffEditor = (XLIFFEditorImplWithNatTable) activePart;
            List<String> splitPointList = xliffEditor.getSplitXliffPoints();
            if (splitPointList.size() <= 0) {
                MessageDialog.openInformation(shell, Messages.getString("all.dialog.info"), Messages.getString("NextSplitPointHandler.msg.nullSplitPoint"));
                return null;
            }
            final XLFHandler xlfHander = xliffEditor.getXLFHandler();
            // 先对 splitPointList 进行排序
            Collections.sort(splitPointList, new Comparator<String>() {

                public int compare(String rowId1, String rowId2) {
                    int rowIndex1 = xlfHander.getRowIndex(rowId1);
                    int rowIndex2 = xlfHander.getRowIndex(rowId2);
                    return rowIndex1 > rowIndex2 ? 1 : -1;
                }
            });
            List<String> selectionRowIdList = xliffEditor.getSelectedRowIds();
            if (selectionRowIdList != null && selectionRowIdList.size() > 0) {
                curSelectionRowId = selectionRowIdList.get(0);
            }
            // 开始定位,定位之前让 nattable 恢复默认布局
            xliffEditor.resetOrder();
            if (curSelectionRowId == null) {
                curSelectionRowId = splitPointList.get(0);
            } else {
                int curSelectionRowIndex = xlfHander.getRowIndex(curSelectionRowId);
                for (String curRowId : splitPointList) {
                    int pointRowIndex = xlfHander.getRowIndex(curRowId);
                    if (pointRowIndex > curSelectionRowIndex) {
                        curSelectionRowId = curRowId;
                        xliffEditor.jumpToRow(curSelectionRowId);
                        break;
                    }
                }
            }
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Shell(org.eclipse.swt.widgets.Shell) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Aggregations

IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)363 IEditorPart (org.eclipse.ui.IEditorPart)136 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)102 PartInitException (org.eclipse.ui.PartInitException)81 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)41 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)39 IViewPart (org.eclipse.ui.IViewPart)39 ArrayList (java.util.ArrayList)37 IEditorReference (org.eclipse.ui.IEditorReference)35 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)32 IWorkbench (org.eclipse.ui.IWorkbench)32 IFile (org.eclipse.core.resources.IFile)30 ISelection (org.eclipse.jface.viewers.ISelection)29 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)27 Shell (org.eclipse.swt.widgets.Shell)26 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)24 CoreException (org.eclipse.core.runtime.CoreException)23 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)21 IProject (org.eclipse.core.resources.IProject)20 QueryUnit (com.cubrid.common.ui.query.editor.QueryUnit)19