Search in sources :

Example 96 with IWorkbenchPage

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

the class ImportExternal method execute.

@SuppressWarnings("deprecation")
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    XLIFFEditorImplWithNatTable xliffEditor = null;
    final Shell shell = HandlerUtil.getActiveShell(event);
    String partId = HandlerUtil.getActivePartId(event);
    IFile file = null;
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (editor instanceof XLIFFEditorImplWithNatTable) {
        xliffEditor = (XLIFFEditorImplWithNatTable) editor;
    }
    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() && selection instanceof IStructuredSelection) {
            List<?> lstObj = ((IStructuredSelection) selection).toList();
            ArrayList<IFile> lstXliff = new ArrayList<IFile>();
            for (Object obj : lstObj) {
                if (obj instanceof IFile) {
                    IFile tempFile = (IFile) obj;
                    // Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
                    if (tempFile.getFileExtension() != null && CommonFunction.validXlfExtension(tempFile.getFileExtension())) {
                        lstXliff.add(tempFile);
                    }
                }
            }
            if (lstXliff.size() > 1) {
                MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ImportDocxHandler.msg1"));
                return null;
            }
            if (lstXliff.size() == 1) {
                file = lstXliff.get(0);
            }
        }
    } 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);
        if (xliffEditor.isMultiFile()) {
            MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ImportDocxHandler.msg2"));
            return null;
        } else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
            file = iFile;
        }
    }
    if (file != null) {
        XLFValidator.resetFlag();
        if (!XLFValidator.validateXliffFile(file)) {
            return null;
        }
        XLFValidator.resetFlag();
    }
    final ImportConfig config = new ImportConfig();
    config.setShell(shell);
    config.set_xliff(file == null ? "" : file.getFullPath().toOSString());
    config.setXliffEditor(xliffEditor);
    config.setXliffFile(file == null ? "" : ResourceUtils.iFileToOSPath(file));
    HsMultiActiveCellEditor.commit(true);
    ImportExternalDialog dialog = new ImportExternalDialog(shell, xliffEditor, config);
    if (Dialog.OK == dialog.open()) {
        config.doImport();
        if (xliffEditor != null) {
            // reopen if need
            if (xliffEditor.getXLFHandler().getVnMap().get(config.getXliffFile()) != null) {
                Map<String, Object> resultMap = xliffEditor.getXLFHandler().openFile(config.getXliffFile());
                if (resultMap == null || Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) resultMap.get(Constant.RETURNVALUE_RESULT)) {
                    // 打开文件失败。
                    MessageDialog.openWarning(shell, Messages.getString("all.dialog.warning"), MessageFormat.format(Messages.getString("ImportDocxDialog.ok.parseError"), config.get_xliff()));
                    LOGGER.error(MessageFormat.format(Messages.getString("ImportDocxDialog.ok.parseError"), config.get_xliff()));
                    return null;
                }
                xliffEditor.reloadData();
                HsMultiCellEditorControl.activeSourceAndTargetCell(xliffEditor);
            }
        }
    }
    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) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Shell(org.eclipse.swt.widgets.Shell) ImportConfig(net.heartsome.cat.ts.ui.external.ImportConfig) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput) ImportExternalDialog(net.heartsome.cat.ts.ui.docx.dialog.ImportExternalDialog)

Example 97 with IWorkbenchPage

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

the class XLIFFEditorImplWithNatTable method changeLayout.

public void changeLayout(boolean isHorizontalLayout) {
    // 同步布局状态
    this.isHorizontalLayout = isHorizontalLayout;
    // 如果当前的 table 已经存在,销毁后再重新创建。
    if (table != null && !table.isDisposed()) {
        table.dispose();
        for (Control control : parent.getChildren()) {
            control.dispose();
        }
    }
    // 构建 NatTable 的数据提供者
    bodyDataProvider = setupBodyDataProvider(isHorizontalLayout);
    // 构建 NatTable 列头的数据提供者
    DefaultColumnHeaderDataProvider colHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabels);
    // 构建 NatTable 的 body layer stack
    bodyLayer = new BodyLayerStack(bodyDataProvider, isHorizontalLayout);
    // 构建 NatTable 的 column header layout stack
    ColumnHeaderLayerStack columnHeaderLayer = new ColumnHeaderLayerStack(colHeaderDataProvider);
    // 构建 NatTable 之下的 composite layer,不使用默认的 configuration(默认的 configuration 是在点击可编辑单元格时,直接进入编辑状态)。
    CompositeLayer compositeLayer = new CompositeLayer(1, 2);
    compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, columnHeaderLayer, 0, 0);
    compositeLayer.setChildLayer(GridRegion.BODY, bodyLayer, 0, 1);
    // 标识 BodyLayer 在 CompositeLayer 上的位置
    LayerUtil.setBodyLayerPosition(0, 1);
    /* 给 composite layer 添加编辑相关的命令和 handler */
    // 添加行背景色(奇数行和偶数行不同)
    addRowBackgroundColor(compositeLayer);
    // 构建 NatTable
    table = new NatTable(parent, compositeLayer, false);
    Language srcLang = LocaleService.getLanguageConfiger().getLanguageByCode(srcColumnName);
    Language tgtLang = LocaleService.getLanguageConfiger().getLanguageByCode(tgtColumnName);
    if (srcLang.isBidi() || tgtLang.isBidi()) {
        table.setOrientation(SWT.RIGHT_TO_LEFT);
    }
    // 去除默认绘画器
    table.removePaintListener(table);
    // 使用自定义绘画器,此绘画器,具有自动计算行高功能。
    table.addPaintListener(paintListenerWithAutoRowSize);
    Listener[] ls = table.getListeners(SWT.Resize);
    for (Listener l : ls) {
        table.removeListener(SWT.Resize, l);
    }
    table.addListener(SWT.Resize, resizeListenerWithColumnResize);
    table.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            // ActiveCellEditor.commit(); // 关闭编辑时,先提交未提交的单元格,避免造成内容丢失。Bug #2685
            HsMultiActiveCellEditor.commit(true);
            table.removeListener(SWT.Resize, resizeListenerWithColumnResize);
            table.removePaintListener(paintListenerWithAutoRowSize);
        }
    });
    table.setLayoutData(new GridData(GridData.FILL_BOTH));
    // 给 NatTable 添加相应的配置
    DefaultNatTableStyleConfiguration configuration = new DefaultNatTableStyleConfiguration();
    configuration.hAlign = HorizontalAlignmentEnum.LEFT;
    table.addConfiguration(configuration);
    // To be changed 给NatTable添加选择列的功能 Add By Leakey
    /*
		 * ColumnGroupModel columnGroupModel = new ColumnGroupModel(); DisplayColumnChooserCommandHandler
		 * columnChooserCommandHandler = new DisplayColumnChooserCommandHandler( bodyLayer.getSelectionLayer(),
		 * bodyLayer.getColumnHideShowLayer(), columnHeaderLayer.getColumnHeaderLayer(),
		 * columnHeaderLayer.getColumnHeaderDataLayer(), columnHeaderLayer.getColumnGroupHeaderLayer(), columnGroupModel
		 * ); bodyLayer.registerCommandHandler(columnChooserCommandHandler);
		 */
    /*
		 * 不使用默认的表头菜单,使用自定义的菜单,因此自定义菜单在 corner 中添加了相应的菜单项,所以需要指定这些添加的 command 在哪一层进一处理
		 */
    // 表头中添加自定义菜单会引发一些不可预料的问题,故先去掉
    // table.addConfiguration(new HeaderMenuConfiguration(table));
    /*
		 * 增加表格的自定义右键菜单
		 */
    table.addConfiguration(new BodyMenuConfiguration(this));
    // 注册列头点击监听(处理排序)
    table.addConfiguration(new SingleClickSortConfiguration());
    /*
		 * 初始化“撤销/重做”历史
		 */
    initializeOperationHistory();
    table.setData(IUndoContext.class.getName(), undoContext);
    /* Weachy - 注册修改后保存内容并自适应大小的处理 handler(覆盖默认的handler:UpdateDataCommandHandler) */
    bodyLayer.getBodyDataLayer().registerCommandHandler(new UpdateDataAndAutoResizeCommandHandler(table, bodyLayer.getBodyDataLayer()));
    /* Weachy - 注册当前显示行的行高自适应处理 handler */
    compositeLayer.registerCommandHandler(new AutoResizeCurrentRowsCommandHandler(compositeLayer));
    /* Weachy - 移除系统默认的查找 handler,添加自定义的查找替换 handler */
    bodyLayer.getSelectionLayer().unregisterCommandHandler(SearchCommand.class);
    bodyLayer.getSelectionLayer().registerCommandHandler(new FindReplaceCommandHandler(bodyLayer.getSelectionLayer()));
    /*
		 * 下面给 NatTable 添加可编辑单元格的配置
		 */
    table.addConfiguration(editableGridConfiguration());
    // 添加标记的自定义显示样式
    IConfigRegistry configRegistry = new ConfigRegistry();
    /*
		 * 如果是水平布局,则使用 ColumnOverrideLabelAccumulator 实现指定列都使用相同的显示样式;否则使用 CellOverrideLabelAccumulator 实现根据显示的内容来显示样式。
		 */
    if (isHorizontalLayout) {
        // 第一步:创建一个标签累加器,给需要绘制会不同效果的 cells 添加自定义的标签。在这里是第三列的标签列。
        ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyLayer);
        columnLabelAccumulator.registerColumnOverrides(0, "LINENUMBER_CELL_LABEL");
        columnLabelAccumulator.registerColumnOverrides(1, SOURCE_EDIT_CELL_LABEL);
        columnLabelAccumulator.registerColumnOverrides(2, FLAG_CELL_LABEL);
        columnLabelAccumulator.registerColumnOverrides(3, TARGET_EDIT_CELL_LABEL);
        // 第二步:注册这个标签累加器。
        bodyLayer.setConfigLabelAccumulator(columnLabelAccumulator);
        // 第三步:把自定义的 cell painter,cell style 与自定义的标签进行关联。
        addFlagLableToColumn(configRegistry);
        addLineNumberToColumn(configRegistry);
    } else {
        ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyLayer);
        columnLabelAccumulator.registerColumnOverrides(0, "LINENUMBER_CELL_LABEL");
        columnLabelAccumulator.registerColumnOverrides(1, FLAG_CELL_LABEL);
        columnLabelAccumulator.registerColumnOverrides(VerticalNatTableConfig.TARGET_COL_INDEX, SOURCE_EDIT_CELL_LABEL);
        columnLabelAccumulator.registerColumnOverrides(VerticalNatTableConfig.TARGET_COL_INDEX, TARGET_EDIT_CELL_LABEL);
        bodyLayer.setConfigLabelAccumulator(columnLabelAccumulator);
        // CellOverrideLabelAccumulator<TransUnitDummy> cellLabelAccumulator = new
        // CellOverrideLabelAccumulator<TransUnitDummy>(
        // (IRowDataProvider) bodyDataProvider);
        // CellOverrideLabelAccumulator<TransUnitBean> cellLabelAccumulator = new
        // CellOverrideLabelAccumulator<TransUnitBean>(
        // (IRowDataProvider) bodyDataProvider);
        // cellLabelAccumulator.registerOverride("flag", VerticalNatTableConfig.SOURCE_COL_INDEX,
        // FOCUS_CELL_LABEL);
        //
        // bodyLayer.getBodyDataLayer().setConfigLabelAccumulator(cellLabelAccumulator);
        addFlagLableToColumn(configRegistry);
        addLineNumberToColumn(configRegistry);
    }
    table.setConfigRegistry(configRegistry);
    // configure manually
    table.configure();
    /* Weachy - 垂直布局下,注册使键盘方向键以 2 行为一个单位移动选中行的处理 handler(覆盖默认的handler:MoveRowSelectionCommandHandler) */
    if (!isHorizontalLayout) {
    // SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
    // selectionLayer.registerCommandHandler(new VerticalMoveRowSelectionCommandHandler(selectionLayer));
    }
    if (bodyLayer.selectionLayer.getRowCount() > 0) {
        // 默认选中第一行
        HsMultiActiveCellEditor.commit(true);
        bodyLayer.selectionLayer.doCommand(new SelectCellCommand(bodyLayer.getSelectionLayer(), getTgtColumnIndex(), isHorizontalLayout ? 0 : 1, false, false));
        HsMultiCellEditorControl.activeSourceAndTargetCell(this);
    }
    IWorkbenchPage page = getSite().getPage();
    IViewReference[] viewReferences = page.getViewReferences();
    IViewPart view;
    for (int i = 0; i < viewReferences.length; i++) {
        view = viewReferences[i].getView(false);
        if (view == null) {
            continue;
        }
        // 切换到其他视图,再切换回来,解决NatTable改变布局后其他视图无法监听到的问题。
        view.setFocus();
    // break;
    }
    // 改变布局方式后,把焦点给 NatTable
    table.setFocus();
    RowHeightCalculator rowHeightCalculator = new RowHeightCalculator(bodyLayer, table, 32);
    ILayer lay = bodyLayer.getViewportLayer();
    if (lay instanceof HorizontalViewportLayer) {
        ((HorizontalViewportLayer) bodyLayer.getViewportLayer()).setRowHeightCalculator(rowHeightCalculator);
    } else if (lay instanceof VerticalViewportLayer) {
        ((VerticalViewportLayer) bodyLayer.getViewportLayer()).setRowHeightCalculator(rowHeightCalculator);
    }
    parent.layout();
    NoteToolTip toolTip = new NoteToolTip(table);
    toolTip.setPopupDelay(10);
    toolTip.activate();
    toolTip.setShift(new Point(10, 10));
    StateToolTip stateTip = new StateToolTip(table);
    stateTip.setPopupDelay(10);
    stateTip.activate();
    stateTip.setShift(new Point(10, 10));
    NotSendToTmToolTip notSendToTMToolTip = new NotSendToTmToolTip(table);
    notSendToTMToolTip.setPopupDelay(10);
    notSendToTMToolTip.activate();
    notSendToTMToolTip.setShift(new Point(10, 10));
    HasQustionToolTip hasqustionTooltip = new HasQustionToolTip(table);
    hasqustionTooltip.setPopupDelay(10);
    hasqustionTooltip.activate();
    hasqustionTooltip.setShift(new Point(10, 10));
    // 在状态栏上显示当前文本段的信息。
    updateStatusLine();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) IViewPart(org.eclipse.ui.IViewPart) PaintListener(org.eclipse.swt.events.PaintListener) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) DisposeListener(org.eclipse.swt.events.DisposeListener) Listener(org.eclipse.swt.widgets.Listener) IPropertyListener(org.eclipse.ui.IPropertyListener) VerifyListener(org.eclipse.swt.events.VerifyListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FindReplaceCommandHandler(net.heartsome.cat.ts.ui.xliffeditor.nattable.search.command.FindReplaceCommandHandler) DisposeEvent(org.eclipse.swt.events.DisposeEvent) BodyMenuConfiguration(net.heartsome.cat.ts.ui.xliffeditor.nattable.menu.BodyMenuConfiguration) IUndoContext(org.eclipse.core.commands.operations.IUndoContext) IConfigRegistry(net.sourceforge.nattable.config.IConfigRegistry) ConfigRegistry(net.sourceforge.nattable.config.ConfigRegistry) Control(org.eclipse.swt.widgets.Control) Language(net.heartsome.cat.common.locale.Language) DefaultNatTableStyleConfiguration(net.sourceforge.nattable.config.DefaultNatTableStyleConfiguration) IViewReference(org.eclipse.ui.IViewReference) NatTable(net.sourceforge.nattable.NatTable) ColumnOverrideLabelAccumulator(net.sourceforge.nattable.layer.cell.ColumnOverrideLabelAccumulator) UpdateDataAndAutoResizeCommandHandler(net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.UpdateDataAndAutoResizeCommandHandler) SelectCellCommand(net.sourceforge.nattable.selection.command.SelectCellCommand) ILayer(net.sourceforge.nattable.layer.ILayer) Point(org.eclipse.swt.graphics.Point) CompositeLayer(net.sourceforge.nattable.layer.CompositeLayer) Point(org.eclipse.swt.graphics.Point) RowHeightCalculator(net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.RowHeightCalculator) VerticalViewportLayer(net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.VerticalViewportLayer) HorizontalViewportLayer(net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.HorizontalViewportLayer) SingleClickSortConfiguration(net.sourceforge.nattable.sort.config.SingleClickSortConfiguration) IConfigRegistry(net.sourceforge.nattable.config.IConfigRegistry) GridData(org.eclipse.swt.layout.GridData) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) DefaultColumnHeaderDataProvider(net.sourceforge.nattable.grid.data.DefaultColumnHeaderDataProvider) AutoResizeCurrentRowsCommandHandler(net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.AutoResizeCurrentRowsCommandHandler)

Example 98 with IWorkbenchPage

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

the class ExportAsTextHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    String elementName = event.getParameter("elementName");
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    Shell shell = activeEditor.getEditorSite().getShell();
    if (activeEditor == null || !(activeEditor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) activeEditor;
    if (xliffEditor.isMultiFile()) {
        MessageDialog.openInformation(shell, "", "当前编辑器打开了多个文件,无法执行该操作。");
    }
    IEditorInput input = xliffEditor.getEditorInput();
    URI uri = null;
    if (input instanceof FileEditorInput) {
        uri = ((FileEditorInput) input).getURI();
    } else if (input instanceof FileStoreEditorInput) {
        uri = ((FileStoreEditorInput) input).getURI();
    } else {
        return null;
    }
    File xliff = new File(uri);
    FileDialog fd = new FileDialog(shell, SWT.SAVE);
    String[] names = { "Plain Text Files [*.txt]", "All Files [*.*]" };
    //$NON-NLS-1$ //$NON-NLS-2$
    String[] extensions = { "*.txt", "*.*" };
    fd.setFilterExtensions(extensions);
    fd.setFilterNames(names);
    //$NON-NLS-1$
    fd.setFileName(xliff.getName() + ".txt");
    String out = fd.open();
    if (out == null) {
        return null;
    }
    XLFHandler handler = xliffEditor.getXLFHandler();
    boolean result = handler.saveAsText(xliff.getAbsolutePath(), out, elementName);
    if (result) {
        IWorkbenchPage page = xliffEditor.getEditorSite().getPage();
        OpenEditorUtil.OpenFileWithSystemEditor(page, out);
    } else {
        MessageDialog.openInformation(shell, "", "文件 “" + out + "” 保存失败!请重试。");
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IEditorPart(org.eclipse.ui.IEditorPart) URI(java.net.URI) Shell(org.eclipse.swt.widgets.Shell) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog) IEditorInput(org.eclipse.ui.IEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 99 with IWorkbenchPage

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

the class NumberOrTagConsisQAHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    boolean isMultiFile = false;
    IFile multiTempIFile = null;
    IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
    // 改为布局
    if (editorPart != null && editorPart instanceof XLIFFEditorImplWithNatTable) {
        String qaItem = event.getParameter("qaItemId");
        XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) editorPart;
        ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
        FileEditorInput input = (FileEditorInput) nattable.getEditorInput();
        // 首先判断是否是合并打开的文件
        if (nattable.isMultiFile()) {
            isMultiFile = true;
        }
        if (isMultiFile) {
            multiTempIFile = input.getFile();
            List<String> multiFilesList = new XLFHandler().getMultiFiles(multiTempIFile);
            for (String filePath : multiFilesList) {
                selectIFiles.add(ResourceUtils.fileToIFile(filePath));
            }
        } else {
            selectIFiles.add(input.getFile());
        }
        QAModel model = new QAModel();
        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
        shell = window.getShell();
        // 先调用方法,查看品质检查结果视图是否处于显示状态,如果是显示的,就删除数据
        IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IViewPart view = workbenchPage.findView(QAResultViewPart.ID);
        if (view != null) {
            // 运行时,将结果视图中列表的数据清除
            ((QAResultViewPart) view).clearTableData();
        }
        QAResult qaResult = new QAResult();
        // 存储品质检查的检查项
        // model.setBatchQAItemIdList(getBatchQAItems());
        // 存储品质检查的检查时不包括的文本段
        model.setNotInclude(getNotIncludePara());
        // 给品质检查结果视图发出通告,本次检查对象为合并打开文件
        qaResult.firePropertyChange(isMultiFile, new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
        if (isMultiFile) {
            model.setMuliFiles(true);
            model.setMultiOper(new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
        } else {
            model.setMuliFiles(false);
        }
        boolean isNumberQA = false;
        if (QAConstant.QA_NUMBER.equals(qaItem)) {
            isNumberQA = true;
        } else if (QAConstant.QA_TAG.equals(qaItem)) {
            isNumberQA = false;
        }
        List<String> fileList = new ArrayList<String>();
        for (IFile iFIle : selectIFiles) {
            fileList.add(iFIle.getLocation().toOSString());
        }
        qaResult.setFilePathList(fileList);
        HsMultiActiveCellEditor.commit(true);
        beginQA(selectIFiles, model, isNumberQA, qaResult);
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) QAResult(net.heartsome.cat.ts.ui.qa.model.QAResult) QAResultViewPart(net.heartsome.cat.ts.ui.qa.views.QAResultViewPart) QAModel(net.heartsome.cat.ts.ui.qa.model.QAModel) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) MultiFilesOper(net.heartsome.cat.ts.ui.util.MultiFilesOper) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 100 with IWorkbenchPage

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

the class CommonFunction method closePointEditor.

/**
	 * 关闭指定文件的编辑器		-- robert 2013-04-01
	 * 备注:这里面的方法,是不能获取 nattable 的实例,故,在处理 合并打开的情况时,是通过 vtd 进行解析 合并临时文件从而获取相关文件的
	 * @param iFileList
	 */
public static void closePointEditor(List<IFile> iFileList) {
    Map<IFile, IEditorPart> openedIfileMap = new HashMap<IFile, IEditorPart>();
    IEditorReference[] referenceArray = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
    for (IEditorReference reference : referenceArray) {
        IEditorPart editor = reference.getEditor(true);
        IFile iFile = ((FileEditorInput) editor.getEditorInput()).getFile();
        // 如果这是一个 nattable 编辑器
        if (XLIFF_EDITOR_ID.equals(editor.getSite().getId())) {
            String iFilePath = iFile.getLocation().toOSString();
            String extension = iFile.getFileExtension();
            if ("hsxliff".equals(extension)) {
                openedIfileMap.put(iFile, editor);
            } else if ("xlp".equals(extension)) {
                // 这是合并打开的情况
                // 开始解析这个合并打开临时文件,获取合并打开的文件。
                VTDGen vg = new VTDGen();
                if (vg.parseFile(iFilePath, true)) {
                    VTDNav vn = vg.getNav();
                    AutoPilot ap = new AutoPilot(vn);
                    try {
                        ap.selectXPath("/mergerFiles/mergerFile/@filePath");
                        int index = -1;
                        while ((index = ap.evalXPath()) != -1) {
                            String fileLC = vn.toString(index + 1);
                            if (fileLC != null && !"".equals(fileLC)) {
                                openedIfileMap.put(ResourceUtils.fileToIFile(fileLC), editor);
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        } else {
            // 其他情况,直接将文件丢进去就行了
            openedIfileMap.put(iFile, editor);
        }
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        for (IFile curIfile : iFileList) {
            if (openedIfileMap.containsKey(curIfile)) {
                page.closeEditor(openedIfileMap.get(curIfile), false);
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) VTDGen(com.ximpleware.VTDGen) IEditorPart(org.eclipse.ui.IEditorPart) IOException(java.io.IOException) IEditorReference(org.eclipse.ui.IEditorReference) AutoPilot(com.ximpleware.AutoPilot) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) VTDNav(com.ximpleware.VTDNav)

Aggregations

IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)189 IEditorPart (org.eclipse.ui.IEditorPart)80 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)68 PartInitException (org.eclipse.ui.PartInitException)57 IViewPart (org.eclipse.ui.IViewPart)52 IFile (org.eclipse.core.resources.IFile)39 IEditorReference (org.eclipse.ui.IEditorReference)34 ArrayList (java.util.ArrayList)26 IViewReference (org.eclipse.ui.IViewReference)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)24 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)18 CoreException (org.eclipse.core.runtime.CoreException)18 IEditorInput (org.eclipse.ui.IEditorInput)17 IWorkbench (org.eclipse.ui.IWorkbench)17 IRepositoryNode (org.talend.repository.model.IRepositoryNode)15 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)14 FileEditorInput (org.eclipse.ui.part.FileEditorInput)13 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)12 IProject (org.eclipse.core.resources.IProject)11 ISelection (org.eclipse.jface.viewers.ISelection)11