Search in sources :

Example 36 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project translationstudio8 by heartsome.

the class ApplicationWorkbenchWindowAdvisor method restorEditorHistory.

/**
	 * 重新恢复产品上次退时出所保存的编辑器,此修复针对 mac 下的 bug 2998 启动:某客户安装的软件只能使用一次.		robert	2013-05-21
	 */
private void restorEditorHistory() {
    // 只针对 mac 下的用户
    if (System.getProperty("os.name").indexOf("Mac") == -1) {
        return;
    }
    final WorkbenchPage page = (WorkbenchPage) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitor.beginTask("", 10);
            String tempEditorHistoryLC = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(Constant.TEMP_EDITOR_HISTORY).toOSString();
            File tempEditorHistoryFile = new File(tempEditorHistoryLC);
            if (!tempEditorHistoryFile.exists()) {
                return;
            }
            monitor.worked(1);
            IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
            VTDGen vg = new VTDGen();
            try {
                boolean parseResult = vg.parseFile(tempEditorHistoryLC, true);
                if (!parseResult) {
                    return;
                }
                VTDNav vn = vg.getNav();
                AutoPilot ap = new AutoPilot(vn);
                int storeFileSum = 0;
                ap.selectXPath("count(/editors/editor)");
                storeFileSum = (int) ap.evalXPathToNumber();
                IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 9, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
                subMonitor.beginTask("", storeFileSum);
                ap.selectXPath("/editors/editor");
                String editorId = null;
                String localFilePath = null;
                boolean activate = false;
                IEditorReference activateEditorRefe = null;
                IEditorReference firstEditor = null;
                IFile curIFile = null;
                int index = -1;
                while (ap.evalXPath() != -1) {
                    activate = false;
                    editorId = null;
                    localFilePath = null;
                    if ((index = vn.getAttrVal("id")) != -1) {
                        editorId = vn.toRawString(index);
                    }
                    if ((index = vn.getAttrVal("path")) != -1) {
                        localFilePath = vn.toRawString(index);
                    }
                    if (editorId == null || editorId.trim().length() <= 0 || localFilePath == null || localFilePath.trim().length() <= 0) {
                        continue;
                    }
                    if ((index = vn.getAttrVal("active")) != -1) {
                        if ("true".equals(vn.toRawString(index))) {
                            activate = true;
                        }
                    }
                    curIFile = root.getFileForLocation(new Path(localFilePath));
                    if (!curIFile.exists()) {
                        subMonitor.worked(1);
                        continue;
                    }
                    if (activate) {
                        activateEditorRefe = page.getEditorManager().openEditor(editorId, new FileEditorInput(curIFile), false, null);
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().setActivePage(page);
                    } else {
                        if (firstEditor == null) {
                            firstEditor = page.getEditorManager().openEditor(editorId, new FileEditorInput(curIFile), false, null);
                        } else {
                            page.getEditorManager().openEditor(editorId, new FileEditorInput(curIFile), false, null);
                        }
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().setActivePage(page);
                    }
                    subMonitor.worked(1);
                }
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().setActivePage(page);
                if (activateEditorRefe != null) {
                    if (firstEditor != null) {
                        page.activate(firstEditor.getEditor(true));
                    }
                    page.activate(activateEditorRefe.getEditor(true));
                }
                subMonitor.done();
                monitor.done();
            } catch (Exception e) {
                LOGGER.error("restore editor file error", e);
            }
        }
    };
    try {
        new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run(true, true, runnable);
    } catch (Exception e) {
        LOGGER.error("restore editor file error", e);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) VTDGen(com.ximpleware.VTDGen) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) WorkbenchPage(org.eclipse.ui.internal.WorkbenchPage) IEditorReference(org.eclipse.ui.IEditorReference) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) AutoPilot(com.ximpleware.AutoPilot) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IFile(org.eclipse.core.resources.IFile) File(java.io.File) VTDNav(com.ximpleware.VTDNav)

Example 37 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project translationstudio8 by heartsome.

the class ExportExternalHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Shell shell = HandlerUtil.getActiveShell(event);
    if (!initExportConfig(event)) {
        return null;
    }
    config.setShell(shell);
    ExportExternalDialog dialog = new ExportExternalDialog(config);
    if (Dialog.OK == dialog.open()) {
        if (config.getExportType() == ExportExternal.EXPORT_HSPROOF) {
            try {
                config.doExport();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(shell);
            try {
                progressDialog.run(true, true, new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        config.setMonitor(monitor);
                        try {
                            config.doExport();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                });
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    return null;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExportExternalDialog(net.heartsome.cat.ts.ui.docx.dialog.ExportExternalDialog) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 38 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project translationstudio8 by heartsome.

the class ImportConfig method doImport.

public void doImport() {
    switch(importType) {
        case ExportExternal.EXPORT_HSPROOF:
            ImportHsproof ih = new ImportHsproof();
            ih.doImport();
            break;
        case ExportExternal.EXPORT_SDLUNCLEAN:
            final UncleanImporter unclean = new UncleanImporter();
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
            try {
                dialog.run(true, true, new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            ImportConfig.this.monitor = monitor;
                            unclean.doImport();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
            } catch (InvocationTargetException e1) {
                e1.printStackTrace();
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
            break;
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) NavException(com.ximpleware.NavException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) XPathParseException(com.ximpleware.XPathParseException) InvocationTargetException(java.lang.reflect.InvocationTargetException) FlagErrorException(net.heartsome.cat.ts.ui.docx.common.FlagErrorException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 39 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project translationstudio8 by heartsome.

the class QAResultViewPart method createPropMenu.

/**
	 * 创建右键参数
	 */
private void createPropMenu() {
    Menu propMenu = new Menu(table);
    table.setMenu(propMenu);
    MenuItem deletWarnItem = new MenuItem(propMenu, SWT.NONE);
    deletWarnItem.setText(Messages.getString("views.QAResultViewPart.deletWarnItem"));
    deletWarnItem.setImage(deleteImage);
    deletWarnItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            QAResultBean bean;
            for (int i = 0; i < dataList.size(); i++) {
                bean = dataList.get(i);
                // 0为错误,1为警告
                if (1 == bean.getLevel()) {
                    dataList.remove(bean);
                    i--;
                }
            }
            tableModel.textRenderer.clearRowHeiMap();
            table.redraw();
        }
    });
    MenuItem deleteAllItem = new MenuItem(propMenu, SWT.NONE);
    deleteAllItem.setText(Messages.getString("views.QAResultViewPart.deleteAllItem"));
    deleteAllItem.setImage(deleteImage);
    deleteAllItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dataList.clear();
            tableModel.textRenderer.clearRowHeiMap();
            table.redraw();
        }
    });
    // 导出品质检查报告
    exportItem = new MenuItem(propMenu, SWT.NONE);
    exportItem.setText(Messages.getString("qa.views.QAResultViewPart.exportPopMenu"));
    exportItem.setImage(exportImg);
    exportItem.setEnabled(false);
    exportItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ExportQAResultDialog dialog = new ExportQAResultDialog(getSite().getShell());
            int result = dialog.open();
            if (result == IDialogConstants.OK_ID) {
                final String exportFilePath = dialog.getExportFilePath();
                if (exportFilePath == null || exportFilePath.isEmpty()) {
                    MessageDialog.openInformation(getSite().getShell(), Messages.getString("qa.all.dialog.info"), Messages.getString("qa.views.QAResultViewPart.msg.nullFilePath"));
                    return;
                }
                IRunnableWithProgress runnable = new IRunnableWithProgress() {

                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        monitor.beginTask("", 1);
                        while (!isQAEnd) {
                            try {
                                Thread.sleep(500);
                            } catch (Exception e2) {
                                logger.error("", e2);
                            }
                            if (monitor.isCanceled()) {
                                return;
                            }
                        }
                        List<QAResultBean> exportDataList = new ArrayList<QAResultBean>();
                        exportDataList.addAll(dataList);
                        ExportQAResult export = new ExportQAResult(isMultiFile, exportFilePath);
                        export.beginExport(dataList, filePathList, monitor);
                        monitor.done();
                    }
                };
                try {
                    new ProgressMonitorDialog(getSite().getShell()).run(true, true, runnable);
                } catch (Exception e1) {
                    logger.error("", e1);
                }
            }
        }
    });
    propMenu.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            if (deleteImage != null && !deleteImage.isDisposed()) {
                deleteImage.dispose();
            }
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) QAResultBean(net.heartsome.cat.ts.ui.qa.model.QAResultBean) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) MenuItem(org.eclipse.swt.widgets.MenuItem) DisposeEvent(org.eclipse.swt.events.DisposeEvent) InvocationTargetException(java.lang.reflect.InvocationTargetException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ExportQAResult(net.heartsome.cat.ts.ui.qa.export.ExportQAResult) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExportQAResultDialog(net.heartsome.cat.ts.ui.qa.export.ExportQAResultDialog) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) Menu(org.eclipse.swt.widgets.Menu)

Example 40 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project translationstudio8 by heartsome.

the class OpenMultiXliffHandler method execute.

@SuppressWarnings("unchecked")
public Object execute(ExecutionEvent event) throws ExecutionException {
    IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.common.ui.navigator.view");
    ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
    if (currentSelection.isEmpty() || !(currentSelection instanceof IStructuredSelection)) {
        return null;
    }
    IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
    Iterator<Object> selectIt = structuredSelection.iterator();
    final ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    shell = window.getShell();
    // 先验证是否跨项目
    IProject selectedProject = null;
    while (selectIt.hasNext()) {
        Object object = selectIt.next();
        if (object instanceof IFile) {
            IFile iFile = (IFile) object;
            if (!CommonFunction.validXlfExtension(iFile.getFileExtension())) {
                MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), MessageFormat.format(Messages.getString("handlers.OpenMultiXliffHandler.msg1"), iFile.getFullPath().toOSString()));
                continue;
            }
            selectIFiles.add(iFile);
            if (selectedProject == null) {
                selectedProject = iFile.getProject();
            } else {
                if (selectedProject != iFile.getProject()) {
                    MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg2"));
                    return null;
                }
            }
        } else if (object instanceof IContainer) {
            IContainer selectContainer = (IContainer) object;
            if (selectedProject == null) {
                selectedProject = selectContainer.getProject();
            }
            // 判断当前文件夹是否处于 XLIFF 文件夹下
            try {
                ResourceUtils.getXliffs(selectContainer, selectIFiles);
            } catch (CoreException e) {
                logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger1"), selectContainer.getFullPath().toOSString(), e);
            }
        }
    }
    // 过滤重复选择文件
    CommonFunction.removeRepeateSelect(selectIFiles);
    if (selectIFiles.size() < 2) {
        MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg3"));
        return null;
    }
    MultiFilesOper oper = new MultiFilesOper(selectedProject, selectIFiles);
    // 先验证这些文件是否已经合并打开,如果是,则退出
    if (oper.validExist()) {
        return null;
    }
    // 判断是否有重复打开的文件,并删除缓存中要合并打开的文件。
    if (oper.hasOpenedIFile()) {
        if (oper.getSelectIFiles().size() <= 0) {
            MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg4"));
            return null;
        } else {
            boolean isResponse = MessageDialog.openConfirm(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle2"), Messages.getString("handlers.OpenMultiXliffHandler.msg5"));
            if (isResponse) {
                if (oper.getSelectIFiles().size() < 2) {
                    MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg6"));
                    return null;
                }
            } else {
                return null;
            }
        }
    }
    final IFile multiIFile = oper.createMultiTempFile();
    if (multiIFile != null && multiIFile.exists()) {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(Messages.getString("handler.OpenMultiXliffHandler.tip1"), 10);
                IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 7, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
                // 进行判断所选择文件的语言对是否符合标准,先解析文件
                final XLFHandler xlfHander = new XLFHandler();
                final Map<String, Object> newResultMap = xlfHander.openFiles(ResourceUtils.iFilesToFiles(selectIFiles), subMonitor);
                // 针对解析失败
                if (newResultMap == null || QAConstant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) newResultMap.get(QAConstant.RETURNVALUE_RESULT)) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), (String) newResultMap.get(Constant.RETURNVALUE_MSG));
                        }
                    });
                    return;
                }
                // 验证是否有多个语言
                boolean hasDiffrentLangPair = false;
                Map<String, ArrayList<String>> langMap = xlfHander.getLanguages();
                if (langMap.size() > 1) {
                    hasDiffrentLangPair = true;
                } else {
                    for (Entry<String, ArrayList<String>> entry : langMap.entrySet()) {
                        if (entry.getValue().size() > 1) {
                            hasDiffrentLangPair = true;
                        }
                    }
                }
                if (monitor.isCanceled()) {
                    return;
                }
                monitor.worked(1);
                if (hasDiffrentLangPair) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg7"));
                        }
                    });
                    // 先删除临时文件,再退出
                    try {
                        multiIFile.delete(true, monitor);
                    } catch (CoreException e) {
                        logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger2"), e);
                    }
                    return;
                }
                final boolean[] validateResult = new boolean[] { false };
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        validateResult[0] = XLFValidator.validateXlifIFiles(selectIFiles);
                    }
                });
                if (!validateResult[0]) {
                    try {
                        multiIFile.delete(true, monitor);
                    } catch (CoreException e) {
                        logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger2"), e);
                    }
                    return;
                }
                final FileEditorInput input = new FileEditorInput(multiIFile);
                if (monitor.isCanceled()) {
                    return;
                }
                monitor.worked(1);
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        try {
                            // UNDO 这里合并打开时,要考虑传入参数xlfHandler,以防多次解析文件带来的消耗。
                            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, XLIFF_EDITOR_ID, true);
                        } catch (PartInitException e) {
                            e.printStackTrace();
                        }
                    }
                });
                if (monitor.isCanceled()) {
                    return;
                }
                monitor.worked(1);
                monitor.done();
            }
        };
        try {
            new ProgressMonitorDialog(shell).run(true, true, runnable);
        } catch (Exception e) {
            logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger3"), e);
        }
    } else {
        MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg8"));
        return null;
    }
    return null;
}
Also used : 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) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ISelection(org.eclipse.jface.viewers.ISelection) PartInitException(org.eclipse.ui.PartInitException) IContainer(org.eclipse.core.resources.IContainer) MultiFilesOper(net.heartsome.cat.ts.ui.util.MultiFilesOper) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IProject(org.eclipse.core.resources.IProject) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Aggregations

ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)315 InvocationTargetException (java.lang.reflect.InvocationTargetException)250 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)241 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)207 CoreException (org.eclipse.core.runtime.CoreException)79 IOException (java.io.IOException)68 ArrayList (java.util.ArrayList)66 Shell (org.eclipse.swt.widgets.Shell)55 PartInitException (org.eclipse.ui.PartInitException)49 List (java.util.List)44 HashMap (java.util.HashMap)41 IResource (org.eclipse.core.resources.IResource)38 WorkspaceModifyOperation (org.eclipse.ui.actions.WorkspaceModifyOperation)37 LinkedHashMap (java.util.LinkedHashMap)34 Display (org.eclipse.swt.widgets.Display)32 EventObject (java.util.EventObject)30 BasicCommandStack (org.eclipse.emf.common.command.BasicCommandStack)30 Resource (org.eclipse.emf.ecore.resource.Resource)30 IFile (org.eclipse.core.resources.IFile)25 File (java.io.File)23