Search in sources :

Example 41 with IEditorReference

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

the class CustomFilterDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    gray = parent.getDisplay().getSystemColor(SWT.COLOR_GRAY);
    black = parent.getDisplay().getSystemColor(SWT.COLOR_BLACK);
    tParent = (Composite) super.createDialogArea(parent);
    GridLayoutFactory.swtDefaults().extendedMargins(5, 5, 10, 0).numColumns(2).equalWidth(false).applyTo(tParent);
    tParent.setLayoutData(new GridData(GridData.FILL_BOTH));
    Composite cmpLeft = new Composite(tParent, SWT.BORDER);
    cmpLeft.setLayout(new GridLayout(2, false));
    GridDataFactory.swtDefaults().applyTo(cmpLeft);
    Composite cmpList = new Composite(cmpLeft, SWT.NONE);
    cmpList.setLayout(new GridLayout(1, true));
    cmpList.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    new Label(cmpList, SWT.NONE).setText(Messages.getString("dialog.CustomFilterDialog.c1Lbl"));
    initCustomFilterList(cmpList);
    Composite cmpBtn = new Composite(cmpLeft, SWT.None);
    cmpBtn.setLayout(new GridLayout());
    cmpBtn.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
    Button addCustom = new Button(cmpBtn, SWT.PUSH);
    addCustom.setText(Messages.getString("dialog.CustomFilterDialog.addCustom"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(addCustom);
    addCustom.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (isChange()) {
                if (!MessageDialog.openConfirm(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg1"))) {
                    return;
                }
            }
            refresh();
        }
    });
    Button delCustom = new Button(cmpBtn, SWT.PUSH);
    delCustom.setText(Messages.getString("dialog.CustomFilterDialog.delCustom"));
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).applyTo(delCustom);
    delCustom.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String[] filters = customFilterList.getSelection();
            if (filters != null && filters.length > 0) {
                if (MessageDialog.openConfirm(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg2"))) {
                    for (int i = 0; i < filters.length; i++) {
                        customFilters.remove(filters[i]);
                        customFiltersAddition.remove(filters[i]);
                        customFiltersIndex.remove(filters[i]);
                        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                        if (window != null) {
                            IWorkbenchPage page = window.getActivePage();
                            if (page != null) {
                                IEditorReference[] editors = page.getEditorReferences();
                                for (IEditorReference ef : editors) {
                                    IEditorPart editor = ef.getEditor(false);
                                    if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) {
                                        Combo cb = ((XLIFFEditorImplWithNatTable) editor).getFilterCombo();
                                        if (cb != null && !cb.isDisposed()) {
                                            cb.remove(filters[i]);
                                        }
                                    }
                                }
                            }
                        }
                        //							cmbFilter.remove(filters[i]);
                        customFilterList.remove(filters[i]);
                        XLFHandler.getFilterMap().remove(filters[i]);
                    }
                    PreferenceStore.saveMap(IPreferenceConstants.FILTER_CONDITION, customFilters);
                    PreferenceStore.saveCustomCondition(IPreferenceConstants.FILTER_CONDITION_INDEX, customFiltersIndex);
                }
            } else {
                MessageDialog.openInformation(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg3"));
            }
        }
    });
    Button editCustom = new Button(cmpBtn, SWT.PUSH);
    editCustom.setText(Messages.getString("dialog.CustomFilterDialog.editCustom"));
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).applyTo(editCustom);
    editCustom.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            edit();
        }
    });
    Composite cmpRight = new Composite(tParent, SWT.NONE);
    cmpRight.setLayout(new GridLayout(1, true));
    cmpRight.setLayoutData(new GridData(GridData.FILL_BOTH));
    Composite top = new Composite(cmpRight, SWT.NONE);
    top.setLayout(new GridLayout(2, false));
    top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    new Label(top, SWT.NONE).setText(Messages.getString("dialog.CustomFilterDialog.topLbl"));
    filterNameTxt = new Text(top, SWT.BORDER);
    filterNameTxt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    filterNameTxt.forceFocus();
    top = new Composite(cmpRight, SWT.NONE);
    top.setLayout(new GridLayout(2, false));
    top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    andBtn = new Button(top, SWT.RADIO);
    andBtn.setText(Messages.getString("dialog.CustomFilterDialog.andBtn"));
    andBtn.setSelection(true);
    orBtn = new Button(top, SWT.RADIO);
    orBtn.setText(Messages.getString("dialog.CustomFilterDialog.orBtn"));
    scroll = new ScrolledComposite(cmpRight, SWT.V_SCROLL | SWT.BORDER);
    scroll.setAlwaysShowScrollBars(true);
    scroll.setLayoutData(new GridData(GridData.FILL_BOTH));
    scroll.setExpandHorizontal(true);
    scroll.setExpandVertical(true);
    //		scroll.setSize(500, 200);
    dynaComp = new Composite(scroll, SWT.None);
    scroll.setContent(dynaComp);
    dynaComp.setLayout(new GridLayout(1, true));
    new DynaComposite(dynaComp, SWT.NONE);
    return parent;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) IEditorPart(org.eclipse.ui.IEditorPart) GridLayout(org.eclipse.swt.layout.GridLayout) IEditorReference(org.eclipse.ui.IEditorReference) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite)

Example 42 with IEditorReference

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

the class CustomFilterDialog method okPressed.

@Override
protected void okPressed() {
    String filterNameStr = filterNameTxt.getText();
    if (filterNameStr == null || "".equals(filterNameStr)) {
        MessageDialog.openInformation(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg6"));
        return;
    }
    StringBuilder xpath = new StringBuilder();
    String link = andBtn.getSelection() ? " and " : " or ";
    ArrayList<String[]> tempValue = new ArrayList<String[]>();
    for (DynaComposite comp : conditionList) {
        // 得到所有自定义条件组合的xpath
        String tempXpath = comp.getXpath(true);
        if (RESULT_FAILED.equals(tempXpath)) {
            return;
        }
        xpath.append(tempXpath).append(link);
        tempValue.add(comp.getTempIndex());
    }
    if (xpath.length() > 0) {
        if (isAdd()) {
            IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            if (window != null) {
                IWorkbenchPage page = window.getActivePage();
                if (page != null) {
                    IEditorReference[] editors = page.getEditorReferences();
                    for (IEditorReference e : editors) {
                        IEditorPart editor = e.getEditor(false);
                        if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) {
                            Combo cb = ((XLIFFEditorImplWithNatTable) editor).getFilterCombo();
                            if (cb != null && !cb.isDisposed()) {
                                cb.add(filterNameTxt.getText());
                            }
                        }
                    }
                }
            }
        //				cmbFilter.add(filterNameTxt.getText());
        } else {
            XLFHandler.getFilterMap().put(filterNameTxt.getText(), xpath.substring(0, xpath.lastIndexOf(link)));
        }
        customFilters.put(filterNameStr, xpath.substring(0, xpath.lastIndexOf(link)));
        customFiltersAddition.put(filterNameStr, link.trim());
        customFiltersIndex.put(filterNameStr, tempValue);
        PreferenceStore.saveMap(IPreferenceConstants.FILTER_CONDITION, new TreeMap<String, String>(customFilters));
        PreferenceStore.saveMap(IPreferenceConstants.FILTER_CONDITION_ADDITION, customFiltersAddition);
        PreferenceStore.saveCustomCondition(IPreferenceConstants.FILTER_CONDITION_INDEX, customFiltersIndex);
        reload();
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) ArrayList(java.util.ArrayList) Combo(org.eclipse.swt.widgets.Combo) IEditorPart(org.eclipse.ui.IEditorPart) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 43 with IEditorReference

use of org.eclipse.ui.IEditorReference 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 44 with IEditorReference

use of org.eclipse.ui.IEditorReference 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 45 with IEditorReference

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

the class LockRepeatedSegmentHandler method lockTU.

/**
	 * 概据内部匹配结果,锁定文本段。
	 * @param xlfHandler
	 * @param rowIdMap
	 */
private void lockTU(final XLFHandler xlfHandler, Map<String, List<String>> rowIdMap) {
    Iterator<Entry<String, List<String>>> it = rowIdMap.entrySet().iterator();
    while (it.hasNext()) {
        isLocked = false;
        final Entry<String, List<String>> rowIdsEntry = it.next();
        final String fileLC = rowIdsEntry.getKey();
        // 查看该文件是否打开,若打开,则获editor的handler,若未打开,则直接使用当前handler
        final IEditorInput input = new FileEditorInput(ResourceUtils.fileToIFile(fileLC));
        final IEditorReference[] editorRefes = window.getActivePage().getEditorReferences();
        Display.getDefault().syncExec(new Runnable() {

            public void run() {
                for (int i = 0; i < editorRefes.length; i++) {
                    if (XLIFF_EDITOR_ID.equals(editorRefes[i].getId())) {
                        // 先判断打开单个文件的情况
                        XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) (editorRefes[i].getEditor(true));
                        if (!nattable.isMultiFile()) {
                            if (nattable.getEditorInput().equals(input)) {
                                nattable.getXLFHandler().lockTransUnits(rowIdsEntry.getValue(), true);
                                isLocked = true;
                                nattable.getTable().redraw();
                            }
                        } else {
                            // 这是合并打开的情况
                            if (nattable.getMultiFileList().indexOf(new File(fileLC)) >= 0) {
                                nattable.getXLFHandler().lockTransUnits(rowIdsEntry.getValue(), true);
                                isLocked = true;
                                nattable.getTable().redraw();
                            }
                            ;
                        }
                    }
                }
                // 如果未被锁定(当前文件没有打开),就调用当前XLFHandler去锁定所有文本段
                if (!isLocked) {
                    xlfHandler.lockTransUnits(rowIdsEntry.getValue(), true);
                }
            }
        });
    }
}
Also used : Entry(java.util.Map.Entry) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IEditorReference(org.eclipse.ui.IEditorReference) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ArrayList(java.util.ArrayList) List(java.util.List) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

IEditorReference (org.eclipse.ui.IEditorReference)174 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)83 IEditorPart (org.eclipse.ui.IEditorPart)78 PartInitException (org.eclipse.ui.PartInitException)59 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)55 IFile (org.eclipse.core.resources.IFile)50 IEditorInput (org.eclipse.ui.IEditorInput)49 ArrayList (java.util.ArrayList)34 FileEditorInput (org.eclipse.ui.part.FileEditorInput)28 Item (org.talend.core.model.properties.Item)17 IWorkbench (org.eclipse.ui.IWorkbench)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 PersistenceException (org.talend.commons.exception.PersistenceException)13 IOException (java.io.IOException)12 CoreException (org.eclipse.core.runtime.CoreException)12 ProcessItem (org.talend.core.model.properties.ProcessItem)11 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)10 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)10 Path (org.eclipse.core.runtime.Path)10 IProcess2 (org.talend.core.model.process.IProcess2)10