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());
}
}
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;
}
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;
}
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();
}
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();
}
}
Aggregations