use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project tdi-studio-se by Talend.
the class PaletteSettingPage method okPressed.
protected void okPressed() {
ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayUtils.getDefaultShell());
IRunnableWithProgress rwp = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
IProxyRepositoryFactory prf = CorePlugin.getDefault().getProxyRepositoryFactory();
try {
prf.saveProject(project);
ShowStandardAction.getInstance().doRun();
if (needCodeGen) {
Job refreshTemplates = CorePlugin.getDefault().getCodeGeneratorService().refreshTemplates();
refreshTemplates.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
CorePlugin.getDefault().getLibrariesService().resetModulesNeeded();
}
});
}
// ComponentUtilities.updatePalette();
} catch (Exception ex) {
ExceptionHandler.process(ex);
}
}
};
try {
pmd.run(true, false, rwp);
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
ExceptionHandler.process(e);
}
}
use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project bndtools by bndtools.
the class ResolutionView method executeAnalysis.
void executeAnalysis() {
if (inputLocked)
return;
outOfDate = false;
synchronized (this) {
Job oldJob = analysisJob;
if (oldJob != null && oldJob.getState() != Job.NONE)
oldJob.cancel();
if (!loaders.isEmpty()) {
final AnalyseBundleResolutionJob job = new AnalyseBundleResolutionJob("importExportAnalysis", loaders);
job.setSystem(true);
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void aboutToRun(IJobChangeEvent event) {
if (display != null && !display.isDisposed()) {
Runnable update = new Runnable() {
@Override
public void run() {
setContentDescription("Working...");
}
};
if (display.getThread() == Thread.currentThread())
update.run();
else
display.asyncExec(update);
}
}
@Override
public void done(IJobChangeEvent event) {
IStatus result = job.getResult();
if (result != null && result.isOK()) {
if (display != null && !display.isDisposed())
display.asyncExec(new Runnable() {
@Override
public void run() {
setInput(loaders, job.getCapabilities(), job.getRequirements());
}
});
}
}
});
analysisJob = job;
analysisJob.schedule(500);
} else {
analysisJob = null;
}
}
}
use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project bndtools by bndtools.
the class IndexerWizardPage method updateInputs.
private void updateInputs() {
if (updateInputFilesJob != null) {
updateInputFilesJob.cancel();
}
inputPaths = Collections.emptyList();
setPageComplete(false);
vwrInputs.setInput(inputPaths);
lblInputCount.setText(String.format("%d resources found", inputPaths.size()));
lblInputCount.getParent().layout(new Control[] { lblInputCount });
final String resourcePattern = this.resourcePattern;
final Display display = getShell().getDisplay();
if (baseDir == null)
return;
updateInputFilesJob = new SearchFilesJob(baseDir, resourcePattern);
updateInputFilesJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
final IStatus status = updateInputFilesJob.getSearchResult();
display.syncExec(new Runnable() {
@Override
public void run() {
inputPaths = updateInputFilesJob.getPaths();
if (inputPaths == null)
inputPaths = Collections.emptyList();
if (status.isOK())
vwrInputs.setInput(updateInputFilesJob.getPaths());
else
// The error/warning status is displayed in the table instead of the path list
vwrInputs.setInput(Collections.singleton(status));
lblInputCount.setText(String.format("%d resources found", inputPaths.size()));
lblInputCount.getParent().layout(new Control[] { lblInputCount });
validate();
}
});
}
});
updateInputFilesJob.setSystem(true);
updateInputFilesJob.schedule(500);
vwrInputs.setInput(Collections.singleton(new Status(IStatus.INFO, Plugin.PLUGIN_ID, 0, Messages.IndexerWizardPage_checking, null)));
lblInputCount.setText("...");
lblInputCount.getParent().layout(new Control[] { lblInputCount });
}
use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project bndtools by bndtools.
the class RepositoriesView method createContextMenu.
void createContextMenu() {
MenuManager mgr = new MenuManager();
Menu menu = mgr.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
mgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
getSite().registerContextMenu(mgr, viewer);
mgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
try {
manager.removeAll();
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (!selection.isEmpty()) {
final Object firstElement = selection.getFirstElement();
if (firstElement instanceof Actionable) {
final RepositoryPlugin rp = getRepositoryPlugin(firstElement);
//
// Use the Actionable interface to fill the menu
// Should extend this to allow other menu entries
// from the view, but currently there are none
//
final Actionable act = (Actionable) firstElement;
Map<String, Runnable> actions = act.actions();
if (actions != null) {
for (final Entry<String, Runnable> e : actions.entrySet()) {
String label = e.getKey();
boolean enabled = true;
boolean checked = false;
String description = null;
Matcher m = LABEL_PATTERN.matcher(label);
if (m.matches()) {
if (m.group(1) != null)
enabled = false;
if (m.group(2) != null)
checked = true;
label = m.group(3);
description = m.group(4);
}
Action a = new Action(label.replace("&", "&&")) {
@Override
public void run() {
Job backgroundJob = new Job("Repository Action '" + getText() + "'") {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
e.getValue().run();
if (rp != null && rp instanceof Refreshable)
Central.refreshPlugin((Refreshable) rp);
} catch (final Exception e) {
IStatus status = new Status(IStatus.ERROR, Plugin.PLUGIN_ID, "Error executing: " + getName(), e);
Plugin.getDefault().getLog().log(status);
}
monitor.done();
return Status.OK_STATUS;
}
};
backgroundJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
if (event.getResult().isOK()) {
viewer.getTree().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
viewer.refresh();
}
});
}
}
});
backgroundJob.setUser(true);
backgroundJob.setPriority(Job.SHORT);
backgroundJob.schedule();
}
};
a.setEnabled(enabled);
if (description != null)
a.setDescription(description);
a.setChecked(checked);
manager.add(a);
}
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project translationstudio8 by heartsome.
the class ExportTmxDialog method okPressed.
@Override
protected void okPressed() {
String encoding = "UTF-8";
if (hasChangedCodingCbtn.getSelection()) {
encoding = this.encodingComboViewer.getCombo().getText();
}
String exportPath = this.tmxFileText.getText();
boolean isTopLevelTmx = this.isTopLevelTmxCbtn.getSelection();
boolean isTagLevelTmx = this.isTagCbtn.getSelection();
ExportFilterBean filterBean = null;
if (this.hasfilterCbtn.getSelection()) {
IStructuredSelection sel = (IStructuredSelection) filterComboViewer.getSelection();
filterBean = (ExportFilterBean) sel.getFirstElement();
if (filterBean.equals(filterList.get(0))) {
filterBean = null;
}
}
if (this.dbList.size() == 0) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg3"));
return;
}
for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
ExportDatabaseBean dbBean = iterator.next();
String dbType = dbBean.getDbBean().getDbType();
String name = dbBean.getDbBean().getDatabaseName();
if (dbBean.getHasSelectedLangs().size() < 2) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg4"), dbType, name));
return;
}
if (dbBean.getSrcLang().equals("")) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg5"), dbType, name));
return;
}
}
if (exportPath == null || exportPath.equals("")) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg6"));
return;
}
if (this.dbList.size() > 1) {
File f = new File(exportPath);
if (!f.isDirectory()) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg8"));
return;
}
}
if (this.dbList.size() == 1) {
File f = new File(exportPath);
if (f.isDirectory()) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg9"));
return;
}
}
if (this.dbList.size() == 1) {
dbList.get(0).setExportFilePath(exportPath);
File file = new File(exportPath);
if (file.exists()) {
if (!MessageDialog.openConfirm(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg7"), exportPath))) {
return;
}
}
} else {
for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
ExportDatabaseBean db = iterator.next();
String databaseName = db.getDbBean().getDatabaseName();
String path = exportPath + System.getProperty("file.separator") + databaseName + db.getDbBean().getDbType() + ".tmx";
File file = new File(path);
if (file.exists()) {
if (!MessageDialog.openConfirm(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg7"), path))) {
return;
}
}
db.setExportFilePath(path);
}
}
final ExportAbstract tmxExport = new ExportTmxImpl(this.dbList, filterBean, encoding, isTopLevelTmx, isTagLevelTmx);
Job job = new Job(Messages.getString("dialog.ExportTmxDialog.job")) {
@Override
protected IStatus run(IProgressMonitor monitor) {
final String result = DatabaseService.executeExport(tmxExport, monitor);
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), result);
}
});
return Status.OK_STATUS;
}
};
// 当程序退出时,检测当前 job 是否正常关闭
CommonFunction.jobCantCancelTip(job);
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void running(IJobChangeEvent event) {
ProgressIndicatorManager.displayProgressIndicator();
super.running(event);
}
@Override
public void done(IJobChangeEvent event) {
ProgressIndicatorManager.hideProgressIndicator();
super.done(event);
}
});
job.setUser(true);
job.schedule();
super.okPressed();
}
Aggregations