Search in sources :

Example 41 with ProgressMonitorDialog

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

the class PreMachineTransUitls method executeTranslation.

public static void executeTranslation(List<IFile> list, final Shell shell) {
    HsMultiActiveCellEditor.commit(true);
    try {
        if (list.size() == 0) {
            MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg1"));
            return;
        }
        List<IFile> lstFiles = new ArrayList<IFile>();
        XLFValidator.resetFlag();
        for (IFile iFile : list) {
            if (!XLFValidator.validateXliffFile(iFile)) {
                lstFiles.add(iFile);
            }
        }
        XLFValidator.resetFlag();
        list = new ArrayList<IFile>(list);
        list.removeAll(lstFiles);
        if (list.size() == 0) {
            return;
        }
        final IProject project = list.get(0).getProject();
        final List<String> filesWithOsPath = ResourceUtils.IFilesToOsPath(list);
        final XLFHandler xlfHandler = new XLFHandler();
        Map<String, Object> resultMap = xlfHandler.openFiles(filesWithOsPath);
        if (resultMap == null || Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) resultMap.get(Constant.RETURNVALUE_RESULT)) {
            // 打开文件失败。			
            MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg2"));
            return;
        }
        Map<String, List<XliffBean>> map = xlfHandler.getXliffInfo();
        final PreMachineTransParameters parameters = new PreMachineTransParameters();
        PreMachineTranslationDialog dialog = new PreMachineTranslationDialog(shell, map, parameters);
        if (dialog.open() == Window.OK) {
            if (project == null) {
                MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg3"));
                return;
            }
            if (filesWithOsPath == null || filesWithOsPath.size() == 0) {
                MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg4"));
                return;
            }
            final List<IFile> lstFile = list;
            IRunnableWithProgress runnable = new IRunnableWithProgress() {

                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    PreMachineTranslation pt = new PreMachineTranslation(xlfHandler, filesWithOsPath, project, parameters);
                    try {
                        final List<PreMachineTranslationCounter> result = pt.executeTranslation(monitor);
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                            //PreMachineTranslationResultDialog dialog = new PreMachineTranslationResultDialog(shell, result);
                            //dialog.open();
                            }
                        });
                        project.refreshLocal(IResource.DEPTH_INFINITE, null);
                        result.clear();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } catch (CoreException e) {
                        logger.error("", e);
                        e.printStackTrace();
                    } finally {
                        pt.clearResources();
                    }
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                            for (IFile file : lstFile) {
                                FileEditorInput editorInput = new FileEditorInput(file);
                                IEditorPart editorPart = page.findEditor(editorInput);
                                // 选择所有语言
                                XLFHandler handler = null;
                                if (editorPart != null && editorPart instanceof IXliffEditor) {
                                    // xliff 文件已用 XLIFF 编辑器打开
                                    IXliffEditor xliffEditor = (IXliffEditor) editorPart;
                                    handler = xliffEditor.getXLFHandler();
                                    handler.resetCache();
                                    VTDGen vg = new VTDGen();
                                    String path = ResourceUtils.iFileToOSPath(file);
                                    if (vg.parseFile(path, true)) {
                                        handler.getVnMap().put(path, vg.getNav());
                                        xliffEditor.refresh();
                                    }
                                }
                            }
                        }
                    });
                }
            };
            try {
                new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run(true, true, runnable);
                MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.result.msg"));
            } catch (InvocationTargetException e) {
                logger.error("", e);
            } catch (InterruptedException e) {
                logger.error("", e);
            }
        }
    } finally {
        HsMultiCellEditorControl.activeSourceAndTargetCell(XLIFFEditorImplWithNatTable.getCurrent());
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) PreMachineTransParameters(net.heartsome.cat.ts.machinetranslation.bean.PreMachineTransParameters) PreMachineTranslationDialog(net.heartsome.cat.ts.machinetranslation.dialog.PreMachineTranslationDialog) ArrayList(java.util.ArrayList) List(java.util.List) PreMachineTranslationCounter(net.heartsome.cat.ts.machinetranslation.bean.PreMachineTranslationCounter) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) VTDGen(com.ximpleware.VTDGen) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 42 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project pentaho-kettle by pentaho.

the class TextFileCSVImportProgressDialog method open.

public String open() {
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                message = doScan(monitor);
            } catch (Exception e) {
                e.printStackTrace();
                throw new InvocationTargetException(e, BaseMessages.getString(PKG, "TextFileCSVImportProgressDialog.Exception.ErrorScanningFile", "" + rownumber, debug, e.toString()));
            }
        }
    };
    try {
        ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
        pmd.run(true, true, op);
    } catch (InvocationTargetException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "TextFileCSVImportProgressDialog.ErrorScanningFile.Title"), BaseMessages.getString(PKG, "TextFileCSVImportProgressDialog.ErrorScanningFile.Message"), e);
    } catch (InterruptedException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "TextFileCSVImportProgressDialog.ErrorScanningFile.Title"), BaseMessages.getString(PKG, "TextFileCSVImportProgressDialog.ErrorScanningFile.Message"), e);
    }
    return message;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) KettleException(org.pentaho.di.core.exception.KettleException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 43 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project archi by archimatetool.

the class ExportJasperReportsWizard method performFinish.

@Override
public boolean performFinish() {
    fPage1.storePreferences();
    final File mainTemplateFile = fPage2.getMainTemplateFile();
    // Check this exists
    if (mainTemplateFile == null || !mainTemplateFile.exists()) {
        MessageDialog.openError(getShell(), Messages.ExportJasperReportsWizard_1, Messages.ExportJasperReportsWizard_2);
        return false;
    }
    final Locale locale = fPage2.getLocale();
    final File exportFolder = fPage1.getExportFolder();
    final String exportFileName = fPage1.getExportFilename();
    final String reportTitle = fPage1.getReportTitle();
    final int exportOptions = fPage1.getExportOptions();
    // Check valid dir and file name
    try {
        File exportFile = new File(exportFolder, exportFileName);
        exportFile.getCanonicalPath();
        exportFolder.mkdirs();
    } catch (Exception ex) {
        MessageDialog.openError(getShell(), Messages.ExportJasperReportsWizard_3, Messages.ExportJasperReportsWizard_4);
        return false;
    }
    Display.getCurrent().asyncExec(new Runnable() {

        @Override
        public void run() {
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
            try {
                dialog.run(false, true, new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            JasperReportsExporter exporter = new JasperReportsExporter(fModel, exportFolder, exportFileName, mainTemplateFile, reportTitle, locale, exportOptions);
                            exporter.export(monitor);
                        } catch (Exception ex) {
                            ex.printStackTrace();
                            MessageDialog.openError(getShell(), Messages.ExportJasperReportsWizard_5, ex.getMessage());
                        } finally {
                            monitor.done();
                        }
                    }
                });
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });
    return true;
}
Also used : Locale(java.util.Locale) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 44 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project xtext-eclipse by eclipse.

the class MultiOrganizeImportsHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchSite activeSite = HandlerUtil.getActiveSite(event);
    MultiOrganizeImportAction javaDelegate = new MultiOrganizeImportAction(activeSite);
    ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
    if (currentSelection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
        if (shouldRunJavaOrganizeImports()) {
            ICompilationUnit[] compilationUnits = javaDelegate.getCompilationUnits(structuredSelection);
            if (compilationUnits.length > 0) {
                javaDelegate.run(structuredSelection);
            }
        }
        final Multimap<IProject, IFile> files = collectFiles(structuredSelection);
        Shell shell = activeSite.getShell();
        IRunnableWithProgress op = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor mon) throws InvocationTargetException, InterruptedException {
                mon.beginTask(Messages.OrganizeImports, files.size() * 2);
                mon.setTaskName(Messages.OrganizeImports + " - Calculating Import optimisations for " + files.size() + " Xtend files");
                final List<Change> organizeImports = importOrganizerProvider.get().organizeImports(files, mon);
                for (int i = 0; !mon.isCanceled() && i < organizeImports.size(); i++) {
                    Change change = organizeImports.get(i);
                    mon.setTaskName("Performing changes - Xtend " + (i + 1) + " of " + files.size() + "");
                    try {
                        mon.subTask(change.getName());
                        change.perform(SubMonitor.convert(mon, 1));
                    } catch (CoreException e) {
                        throw new InvocationTargetException(e);
                    }
                    if (mon.isCanceled()) {
                        throw new InterruptedException();
                    }
                }
            }
        };
        try {
            new ProgressMonitorDialog(shell).run(true, true, op);
        } catch (InvocationTargetException e) {
            handleException(e);
        } catch (InterruptedException e) {
        // user cancelled, ok
        }
    }
    return event.getApplicationContext();
}
Also used : IWorkbenchSite(org.eclipse.ui.IWorkbenchSite) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IFile(org.eclipse.core.resources.IFile) MultiOrganizeImportAction(org.eclipse.jdt.internal.ui.actions.MultiOrganizeImportAction) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Change(org.eclipse.ltk.core.refactoring.Change) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ISelection(org.eclipse.jface.viewers.ISelection)

Example 45 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project azure-tools-for-java by Microsoft.

the class SrvPriCreationStatusDialog method createServicePrincipalAsync.

private void createServicePrincipalAsync() {
    try {
        class StatusTask implements IRunnableWithProgress, IListener<Status> {

            IProgressMonitor progressIndicator = null;

            @Override
            public void listen(Status status) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (progressIndicator != null) {
                            progressIndicator.setTaskName(status.getAction());
                        }
                        // if only action was set in the status - the info for progress indicator only - igonre for table
                        if (status.getResult() != null) {
                            TableItem item = new TableItem(table, SWT.NULL);
                            item.setText(new String[] { status.getAction(), status.getResult().toString(), status.getDetails() });
                        }
                    }
                });
            }

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                progressIndicator = monitor;
                monitor.beginTask("Creating Service Principal...", IProgressMonitor.UNKNOWN);
                for (String tid : tidSidsMap.keySet()) {
                    if (monitor.isCanceled()) {
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                TableItem item = new TableItem(table, SWT.NULL);
                                item.setText(new String[] { "!!! Canceled by user" });
                            }
                        });
                        return;
                    }
                    List<String> sidList = tidSidsMap.get(tid);
                    if (!sidList.isEmpty()) {
                        try {
                            Display.getDefault().asyncExec(new Runnable() {

                                @Override
                                public void run() {
                                    TableItem item = new TableItem(table, SWT.NULL);
                                    item.setText(new String[] { "tenant ID: " + tid + " ===" });
                                }
                            });
                            Date now = new Date();
                            String suffix = new SimpleDateFormat("yyyyMMddHHmmss").format(now);
                            ;
                            String authFilepath = SrvPriManager.createSp(tid, sidList, suffix, this, destinationFolder);
                            if (authFilepath != null) {
                                Display.getDefault().asyncExec(new Runnable() {

                                    @Override
                                    public void run() {
                                        listCreatedFiles.add(authFilepath);
                                        listCreatedFiles.setSelection(0);
                                    }
                                });
                            }
                        } catch (Exception ex) {
                            ex.printStackTrace();
                            LOG.log(new org.eclipse.core.runtime.Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@ProgressDialog@createServicePrincipalAsync@SrvPriCreationStatusDialog", ex));
                        }
                    }
                }
            }
        }
        new ProgressMonitorDialog(this.getShell()).run(true, true, new StatusTask());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(com.microsoft.azuretools.authmanage.srvpri.step.Status) TableItem(org.eclipse.swt.widgets.TableItem) IListener(com.microsoft.azuretools.authmanage.srvpri.report.IListener) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Date(java.util.Date) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SimpleDateFormat(java.text.SimpleDateFormat)

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