Search in sources :

Example 46 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project translationstudio8 by heartsome.

the class UpdateTMWizard method performFinish.

public boolean performFinish() {
    final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final boolean isDraft = page.isDraft();
    final boolean isApproved = page.isApproved();
    final boolean isSignedOff = page.isSignedOff();
    final boolean isTranslated = page.isTranslated();
    final boolean isLocked = page.isLocked();
    if (!isDraft && !isApproved && !isSignedOff && !isTranslated && !isLocked) {
        MessageDialog.openInformation(getShell(), Messages.getString("wizard.UpdateTMWizard.msgTitle"), Messages.getString("wizard.UpdateTMWizard.msg"));
        return false;
    }
    IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
    final int contextSize = ps.getInt(TMPreferenceConstants.CONTEXT_MATCH);
    final int tmxImportStrategy = ps.getInt(TMPreferenceConstants.TM_UPDATE);
    IRunnableWithProgress progress = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) {
            monitor.setTaskName(Messages.getString("dialog.UpdateTMDialog.jobTask1"));
            monitor.beginTask(Messages.getString("dialog.UpdateTMDialog.jobTask1"), lstXLIFF.size() * 2);
            for (final IFile xliffFile : lstXLIFF) {
                ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(xliffFile.getProject());
                DatabaseModelBean modelBean = projectConfig.getDefaultTMDb();
                FileEditorInput editorInput = new FileEditorInput(xliffFile);
                IEditorPart editorPart = activePage.findEditor(editorInput);
                // 选择所有语言
                XLFHandler handler = null;
                if (editorPart != null && editorPart instanceof IXliffEditor) {
                    // xliff 文件已用 XLIFF 编辑器打开
                    IXliffEditor xliffEditor = (IXliffEditor) editorPart;
                    handler = xliffEditor.getXLFHandler();
                } else {
                    // xliff 文件未打开
                    handler = new XLFHandler();
                }
                monitor.subTask(Messages.getString("dialog.UpdateTMDialog.jobTask2"));
                // 修改获取系统用户方式/*System.getProperty("user.name");*/
                String systemUser = PlatformUI.getPreferenceStore().getString(IPreferenceConstants.SYSTEM_USER);
                String[] arrTempTMX = handler.generateTMXToUpdateTM(xliffFile, isApproved, isSignedOff, isTranslated, isDraft, isLocked, contextSize, systemUser);
                monitor.worked(1);
                if (arrTempTMX != null) {
                    monitor.subTask(Messages.getString("dialog.UpdateTMDialog.jobTask3"));
                    // }
                    try {
                        DatabaseService.importTmxWithString(modelBean.toDbMetaData(), arrTempTMX[1], new SubProgressMonitor(monitor, 1), tmxImportStrategy, false, arrTempTMX[0]);
                    } catch (ImportException e) {
                        final String msg = e.getMessage();
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                MessageDialog.openInformation(getShell(), Messages.getString("dialog.UpdateTMDialog.job.msgTitle"), msg);
                            }
                        });
                        canFinish = false;
                        return;
                    }
                }
            }
            monitor.done();
            // 刷新项目
            ResourceUtils.refreshCurentSelectProject();
            canFinish = true;
        }
    };
    try {
        getContainer().run(true, true, progress);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return canFinish;
}
Also used : IFile(org.eclipse.core.resources.IFile) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ImportException(net.heartsome.cat.common.core.exception.ImportException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 47 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project translationstudio8 by heartsome.

the class ImportProjectWizardPage2 method updateProjectsList.

public void updateProjectsList(final String path) {
    if (path == null || path.length() == 0) {
        setMessage(Messages.getString("wizard.ImportProjectWizardPage.desc"));
        selectedProjects = new ProjectRecord[0];
        setPageComplete(selectElementTree.getCheckedElements().length > 0);
        lastPath = path;
        return;
    }
    final File directory = new File(path);
    long modified = directory.lastModified();
    if (path.equals(lastPath) && lastModified == modified && lastCopyFiles == copyFiles) {
        // change, no refreshing is required
        return;
    }
    lastPath = path;
    lastModified = modified;
    lastCopyFiles = copyFiles;
    // We can't access the radio button from the inner class so get the
    // status beforehand
    final boolean dirSelected = false;
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {

            @SuppressWarnings({ "rawtypes", "restriction" })
            public void run(IProgressMonitor monitor) {
                monitor.beginTask(Messages.getString("importProjectWizardPage.searchingMessage"), 100);
                selectedProjects = new ProjectRecord[0];
                Collection files = new ArrayList();
                monitor.worked(10);
                if (!dirSelected && ArchiveFileManipulations.isTarFile(path)) {
                    TarFile sourceTarFile = getSpecifiedTarSourceFile(path);
                    if (sourceTarFile == null) {
                        return;
                    }
                    structureProvider = new TarLeveledStructureProvider(sourceTarFile);
                    Object child = structureProvider.getRoot();
                    if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
                        return;
                    }
                    Iterator filesIterator = files.iterator();
                    selectedProjects = new ProjectRecord[files.size()];
                    int index = 0;
                    monitor.worked(50);
                    monitor.subTask(Messages.getString("importProjectWizardPage.processingMessage"));
                    while (filesIterator.hasNext()) {
                        selectedProjects[index++] = (ProjectRecord) filesIterator.next();
                    }
                } else if (!dirSelected && ArchiveFileManipulations.isZipFile(path)) {
                    ZipFile sourceFile = getSpecifiedZipSourceFile(path);
                    if (sourceFile == null) {
                        return;
                    }
                    structureProvider = new ZipLeveledStructureProvider(sourceFile);
                    Object child = structureProvider.getRoot();
                    if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
                        return;
                    }
                    Iterator filesIterator = files.iterator();
                    selectedProjects = new ProjectRecord[files.size()];
                    int index = 0;
                    monitor.worked(50);
                    monitor.subTask(Messages.getString("importProjectWizardPage.processingMessage"));
                    while (filesIterator.hasNext()) {
                        selectedProjects[index++] = (ProjectRecord) filesIterator.next();
                    }
                } else {
                    monitor.worked(60);
                }
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (InterruptedException e) {
        LOGGER.error(e.getMessage(), e);
    }
    // 开始处理导入项目中的项目名称不合法的情况
    String projectName = "";
    StringBuffer errorProjectNameSB = new StringBuffer();
    StringBuffer errorCharSB = new StringBuffer();
    List<ProjectRecord> tempList = new ArrayList<ProjectRecord>();
    boolean isError = false;
    for (int i = 0; i < selectedProjects.length; i++) {
        projectName = selectedProjects[i].getProjectName();
        isError = false;
        for (int j = 0; j < Constant.RESOURCE_ERRORCHAR.length; j++) {
            if (projectName.indexOf(Constant.RESOURCE_ERRORCHAR[j]) != -1) {
                errorCharSB.append(Constant.RESOURCE_ERRORCHAR[j]);
                errorProjectNameSB.append(projectName + ", ");
                isError = true;
            }
        }
        if (!isError) {
            tempList.add(selectedProjects[i]);
        }
    }
    if (errorProjectNameSB.length() > 0) {
        final String errorTip = MessageFormat.format(Messages.getString("importProjectWizardPage.projectError"), new Object[] { errorProjectNameSB.toString().substring(0, errorProjectNameSB.toString().length() - 2), errorCharSB.toString() });
        Display.getDefault().asyncExec(new Runnable() {

            public void run() {
                MessageDialog.openWarning(getShell(), Messages.getString("importProject.all.dialog.warning"), errorTip);
            }
        });
    }
    selectedProjects = tempList.toArray(new ProjectRecord[tempList.size()]);
    setPageComplete(selectElementTree.getCheckedElements().length > 0);
    selectElementTree.refresh(true);
}
Also used : ZipLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TarLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) Iterator(java.util.Iterator) Collection(java.util.Collection) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 48 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress 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 49 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress 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 50 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress 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)

Aggregations

IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)417 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)397 InvocationTargetException (java.lang.reflect.InvocationTargetException)386 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)194 CoreException (org.eclipse.core.runtime.CoreException)123 ArrayList (java.util.ArrayList)86 IStatus (org.eclipse.core.runtime.IStatus)67 IOException (java.io.IOException)65 List (java.util.List)54 Status (org.eclipse.core.runtime.Status)53 IFile (org.eclipse.core.resources.IFile)51 File (java.io.File)47 Shell (org.eclipse.swt.widgets.Shell)44 IProject (org.eclipse.core.resources.IProject)40 PartInitException (org.eclipse.ui.PartInitException)32 IPath (org.eclipse.core.runtime.IPath)26 Display (org.eclipse.swt.widgets.Display)26 IResource (org.eclipse.core.resources.IResource)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)24 Path (org.eclipse.core.runtime.Path)23