Search in sources :

Example 66 with ISelection

use of org.eclipse.jface.viewers.ISelection in project translationstudio8 by heartsome.

the class PluginConfigurationDialog method editPuginConfig.

public void editPuginConfig() {
    ISelection selection = tableViewer.getSelection();
    if (selection != null && !selection.isEmpty() && selection instanceof StructuredSelection) {
        StructuredSelection structuredSelection = (StructuredSelection) selection;
        Iterator<PluginConfigBean> it = structuredSelection.iterator();
        if (it.hasNext()) {
            PluginConfigBean configBean = it.next();
            PluginConfigManageDialog dialog = new PluginConfigManageDialog(getShell(), false);
            dialog.create();
            dialog.setEditInitData(configBean);
            int result = dialog.open();
            if (result == IDialogConstants.OK_ID) {
                refreshTable(dialog.getCurPluginBean());
            }
        }
    } else {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.PluginConfigurationDialog.msgTitle"), Messages.getString("dialog.PluginConfigurationDialog.msg1"));
    }
}
Also used : PluginConfigBean(net.heartsome.cat.ts.ui.plugin.bean.PluginConfigBean) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 67 with ISelection

use of org.eclipse.jface.viewers.ISelection in project translationstudio8 by heartsome.

the class PluginConfigManage method executePlugin.

/**
	 * 运行自定义的插件
	 * @param bean
	 *            ;
	 */
@SuppressWarnings("unchecked")
public void executePlugin(PluginConfigBean bean) {
    String commandLine = bean.getCommandLine();
    if (commandLine == null || "".equals(commandLine)) {
        MessageDialog.openInformation(shell, Messages.getString("plugin.PluginConfigManage.msgTitle"), Messages.getString("plugin.PluginConfigManage.msg1"));
        return;
    }
    try {
        // 当输出(进程)为当前文档时
        if (bean.getOutput().equals(PluginConstants.SEGMENT)) {
            // 先检查是否有已经打开的文件,若没有,退出插件执行
            XLIFFEditorImplWithNatTable nattable = XLIFFEditorImplWithNatTable.getCurrent();
            if (nattable == null) {
                MessageDialog.openInformation(shell, Messages.getString("plugin.PluginConfigManage.msgTitle"), Messages.getString("plugin.PluginConfigManage.msg2"));
                return;
            }
            XLFHandler handler = nattable.getXLFHandler();
            List<String> selectRowIds = nattable.getSelectedRowIds();
            if (selectRowIds.size() <= 0) {
                MessageDialog.openInformation(shell, Messages.getString("plugin.PluginConfigManage.msgTitle"), Messages.getString("plugin.PluginConfigManage.msg3"));
                return;
            }
            if (selectRowIds.size() > 1) {
                MessageDialog.openInformation(shell, Messages.getString("plugin.PluginConfigManage.msgTitle"), Messages.getString("plugin.PluginConfigManage.msg4"));
            }
            String rowId = selectRowIds.get(0);
            sendSegment(bean, handler, rowId);
            // 执行后返回的文件
            String returnContent = runPlugin(bean);
            // 如果返回为交换文件,则更新当前文本段
            if (bean.getInput().equals(PluginConstants.EXCHANGEFILE)) {
                handler.updateAndSave(rowId, "", returnContent);
            // 更新完后,要刷新界面。此处未做,滞留。
            }
        }
        // 当输出(进程)为当前文档时
        if (bean.getOutput().equals(PluginConstants.DOCUMENT)) {
            XLFHandler handler;
            IFile selectIFile = null;
            // 先检查是否有已经打开的文件,若没有,退出插件执行
            XLIFFEditorImplWithNatTable nattable = XLIFFEditorImplWithNatTable.getCurrent();
            if (nattable == null) {
                // 如果当前没有打开的文件,那么获取左边导航框中选中的文件
                ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
                if (selection == null || selection.isEmpty() || !(selection instanceof StructuredSelection)) {
                    MessageDialog.openInformation(shell, Messages.getString("plugin.PluginConfigManage.msgTitle"), Messages.getString("plugin.PluginConfigManage.msg5"));
                    return;
                }
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                Iterator<Object> selectIt = structuredSelection.iterator();
                if (selectIt.hasNext()) {
                    Object object = selectIt.next();
                    if (object instanceof IFile) {
                        selectIFile = (IFile) object;
                        String fileExtension = selectIFile.getFileExtension();
                        if (!CommonFunction.validXlfExtension(fileExtension)) {
                            MessageDialog.openInformation(shell, Messages.getString("plugin.PluginConfigManage.msgTitle"), Messages.getString("plugin.PluginConfigManage.msg5"));
                            return;
                        }
                    }
                }
                handler = new XLFHandler();
                // 打开该xliff文件
                Map<String, Object> resultMap = handler.openFile(selectIFile.getLocation().toOSString());
                if (resultMap == null || Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) resultMap.get(Constant.RETURNVALUE_RESULT)) {
                    MessageDialog.openInformation(shell, Messages.getString("plugin.PluginConfigManage.msgTitle"), Messages.getString("plugin.PluginConfigManage.msg5"));
                    return;
                }
            } else {
                handler = nattable.getXLFHandler();
                selectIFile = ResourceUtil.getFile(nattable.getEditorInput());
            // IEditorInput fileInput = nattable.getEditorInput();
            }
            sendDocument(bean, selectIFile);
            if (bean.getInput().equals(PluginConstants.DOCUMENT)) {
                // 重新解析该文件
                Map<String, Object> resultMap = handler.openFile(selectIFile.getLocation().toOSString());
                if (resultMap == null || Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) resultMap.get(Constant.RETURNVALUE_RESULT)) {
                    MessageDialog.openError(shell, Messages.getString("plugin.PluginConfigManage.msgTitle"), Messages.getString("plugin.PluginConfigManage.msg6"));
                    return;
                }
            }
        }
        // 当输出(进程)为空时
        if (bean.getOutput().equals(PluginConstants.NONE)) {
            runPlugin(bean);
        }
    } catch (Exception e) {
        LOGGER.error("", e);
        MessageDialog.openError(shell, Messages.getString("plugin.PluginConfigManage.msgTitle"), Messages.getString("plugin.PluginConfigManage.msg7"));
    }
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISelection(org.eclipse.jface.viewers.ISelection) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 68 with ISelection

use of org.eclipse.jface.viewers.ISelection in project translationstudio8 by heartsome.

the class BatchQAHandler method execute.

@SuppressWarnings("unchecked")
public Object execute(ExecutionEvent event) throws ExecutionException {
    isMultiFile = false;
    preferenceStore = Activator.getDefault().getPreferenceStore();
    // UNDO 如果焦点在其他视图上时,获取的文件错误。
    IFile multiTempIFile = null;
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    final Shell shell = window.getShell();
    //		ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
    IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.common.ui.navigator.view");
    ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
    if (HandlerUtil.getActivePart(event) instanceof IViewPart) {
        ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
        if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {
            IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
            Iterator<Object> selectIt = structuredSelection.iterator();
            while (selectIt.hasNext()) {
                Object object = selectIt.next();
                if (object instanceof IFile) {
                    IFile selectFile = (IFile) object;
                    String fileExtension = selectFile.getFileExtension();
                    // 如果后缀名不是xlf,那么就进行提示
                    if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
                        boolean isSure = MessageDialog.openConfirm(shell, Messages.getString("qa.all.dialog.warning"), MessageFormat.format(Messages.getString("qa.all.tip.notXliff"), new Object[] { selectFile.getFullPath() }));
                        if (!isSure) {
                            return null;
                        }
                        continue;
                    }
                    selectIFiles.add(selectFile);
                } else if (object instanceof IProject) {
                    IProject selectProject = (IProject) object;
                    try {
                        ResourceUtils.getXliffs(selectProject, selectIFiles);
                    } catch (Exception e) {
                        e.printStackTrace();
                        logger.error(Messages.getString("qa.handlers.BatchQAHandler.log1"), e);
                    }
                } else if (object instanceof IContainer) {
                    IContainer selectContainer = (IContainer) object;
                    try {
                        ResourceUtils.getXliffs(selectContainer, selectIFiles);
                    } catch (Exception e) {
                        logger.error(Messages.getString("qa.handlers.BatchQAHandler.log1"), e);
                        e.printStackTrace();
                    }
                }
            }
        }
    } else {
        //如果左边未选择品质检查的类型,那么,获取nattable中打开的文件
        IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
        String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
        if (activeEditor != null && !activeEditor.getSite().getId().equals(XLIFF_EDITOR_ID)) {
            MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.BatchQAHandler.tip2"));
            return null;
        }
        XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) activeEditor;
        isMultiFile = nattable.isMultiFile();
        multiTempIFile = ((FileEditorInput) nattable.getEditorInput()).getFile();
        if (isMultiFile) {
            List<String> multiFilesList = new XLFHandler().getMultiFiles(multiTempIFile);
            for (String multiFileStr : multiFilesList) {
                selectIFiles.add(ResourceUtils.fileToIFile(multiFileStr));
            }
        } else {
            selectIFiles.add(multiTempIFile);
        }
    }
    CommonFunction.removeRepeateSelect(selectIFiles);
    if (selectIFiles.size() == 0) {
        MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.BatchQAHandler.tip1"));
        return null;
    }
    List<IFile> lstFiles = new ArrayList<IFile>();
    XLFValidator.resetFlag();
    for (IFile iFile : selectIFiles) {
        if (!XLFValidator.validateXliffFile(iFile)) {
            lstFiles.add(iFile);
        }
    }
    XLFValidator.resetFlag();
    selectIFiles.removeAll(lstFiles);
    if (selectIFiles.size() == 0) {
        return null;
    }
    model = new QAModel();
    model.setQaXlfList(selectIFiles);
    quality = new QualityAssurance(model);
    BatchQADialog dialog = new BatchQADialog(shell, model, isMultiFile);
    int result = dialog.open();
    if (result == IDialogConstants.OK_ID) {
        // 先调用方法,查看品质检查结果视图是否处于显示状态,如果显示了的。删除数据
        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));
        // 将当前所处理的文件传至 qaResult
        List<String> fileList = new ArrayList<String>();
        for (IFile iFIle : model.getQaXlfList()) {
            fileList.add(iFIle.getLocation().toOSString());
        }
        qaResult.setFilePathList(fileList);
        HsMultiActiveCellEditor.commit(true);
        if (isMultiFile) {
            model.setMuliFiles(true);
            model.setMultiOper(new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
            qaResult.setMultiOper(model.getMultiOper());
            quality.beginMultiFileQA(qaResult);
        } else {
            model.setMuliFiles(false);
            qaResult.setMultiOper(model.getMultiOper());
            quality.beginQA(qaResult);
        }
    }
    return null;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) QualityAssurance(net.heartsome.cat.ts.ui.qa.QualityAssurance) QAModel(net.heartsome.cat.ts.ui.qa.model.QAModel) BatchQADialog(net.heartsome.cat.ts.ui.qa.dialogs.BatchQADialog) Shell(org.eclipse.swt.widgets.Shell) ISelection(org.eclipse.jface.viewers.ISelection) IContainer(org.eclipse.core.resources.IContainer) MultiFilesOper(net.heartsome.cat.ts.ui.util.MultiFilesOper) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEditorPart(org.eclipse.ui.IEditorPart) QAResult(net.heartsome.cat.ts.ui.qa.model.QAResult) QAResultViewPart(net.heartsome.cat.ts.ui.qa.views.QAResultViewPart) IProject(org.eclipse.core.resources.IProject) ExecutionException(org.eclipse.core.commands.ExecutionException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 69 with ISelection

use of org.eclipse.jface.viewers.ISelection in project translationstudio8 by heartsome.

the class NonTranslationQAPage method editNontransElement.

/**
	 * 编辑非译元素
	 */
private void editNontransElement() {
    NontransElementBean bean = null;
    ISelection selection = tableViewer.getSelection();
    if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        if (structuredSelection.getFirstElement() instanceof NontransElementBean) {
            bean = (NontransElementBean) structuredSelection.getFirstElement();
            if (validIsInternalElementNonTip(bean)) {
                return;
            }
            AddOrEditNontransElementDialog dialog = new AddOrEditNontransElementDialog(getShell(), false, tableViewer, bean);
            int result = dialog.open();
            if (result == IDialogConstants.OK_ID) {
                tableViewer.refresh();
            }
        }
    }
}
Also used : NontransElementBean(net.heartsome.cat.ts.ui.qa.model.NontransElementBean) AddOrEditNontransElementDialog(net.heartsome.cat.ts.ui.qa.dialogs.AddOrEditNontransElementDialog) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Point(org.eclipse.swt.graphics.Point)

Example 70 with ISelection

use of org.eclipse.jface.viewers.ISelection in project translationstudio8 by heartsome.

the class NonTranslationQAPage method initListener.

/**
	 * 一些事件的添加
	 */
public void initListener() {
    // 非译元素的添加事件
    addBtn.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            addNonTransElement();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            addNonTransElement();
        }
    });
    editBtn.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent arg0) {
            editNontransElement();
        }

        public void widgetDefaultSelected(SelectionEvent arg0) {
            editNontransElement();
        }
    });
    // 删除按钮的点击操作
    deleteBtn.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            deleteElement();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            deleteElement();
        }
    });
    // 给comboViewer添加事件,同时传入内置元素
    comboViewer.getCombo().addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            addInternalElement();
            comboViewer.getCombo().setText(Messages.getString("qa.preference.NonTranslationQAPage.addInterElement"));
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            addInternalElement();
            comboViewer.getCombo().setText(Messages.getString("qa.preference.NonTranslationQAPage.addInterElement"));
        }
    });
    // 非译元素列表的点击事件
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = tableViewer.getSelection();
            if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                if (structuredSelection.getFirstElement() instanceof NontransElementBean) {
                    if (structuredSelection.size() == 1 && !validIsInternalElementNonTip((NontransElementBean) structuredSelection.getFirstElement())) {
                        editBtn.setEnabled(true);
                    } else {
                        editBtn.setEnabled(false);
                    }
                    deleteBtn.setEnabled(true);
                } else {
                    setAddModel();
                }
            } else {
                setAddModel();
            }
        }
    });
    tableViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent arg0) {
            editNontransElement();
        }
    });
}
Also used : NontransElementBean(net.heartsome.cat.ts.ui.qa.model.NontransElementBean) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ISelection (org.eclipse.jface.viewers.ISelection)951 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)595 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)173 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)113 ArrayList (java.util.ArrayList)102 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)101 IResource (org.eclipse.core.resources.IResource)89 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)88 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)85 IFile (org.eclipse.core.resources.IFile)84 GridData (org.eclipse.swt.layout.GridData)80 Composite (org.eclipse.swt.widgets.Composite)67 PartInitException (org.eclipse.ui.PartInitException)66 ITextSelection (org.eclipse.jface.text.ITextSelection)65 IEditorPart (org.eclipse.ui.IEditorPart)65 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)65 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)58 SelectionEvent (org.eclipse.swt.events.SelectionEvent)57 GridLayout (org.eclipse.swt.layout.GridLayout)57 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)52