use of org.eclipse.core.runtime.jobs.Job in project che by eclipse.
the class WorkspaceModifyOperation method threadChange.
/* (non-Javadoc)
* @see IThreadListener#threadChange(Thread);
* @since 3.2
*/
public void threadChange(Thread thread) {
//already owns a scheduling rule because this is deadlock prone (bug 105491)
if (rule == null) {
return;
}
Job currentJob = Job.getJobManager().currentJob();
if (currentJob == null) {
return;
}
ISchedulingRule currentRule = currentJob.getRule();
if (currentRule == null) {
return;
}
//$NON-NLS-1$
throw new IllegalStateException("Cannot fork a thread from a thread owning a rule");
}
use of org.eclipse.core.runtime.jobs.Job in project che by eclipse.
the class InternalSearchUI method runSearchInBackground.
// public ISearchResultViewPart getSearchView() {
// return getSearchViewManager().getActiveSearchView();
// }
// private IWorkbenchSiteProgressService getProgressService() {
// ISearchResultViewPart view = getSearchView();
// if (view != null) {
// IWorkbenchPartSite site = view.getSite();
// if (site != null)
// return (IWorkbenchSiteProgressService)view.getSite().getAdapter(IWorkbenchSiteProgressService.class);
// }
// return null;
// }
public boolean runSearchInBackground(ISearchQuery query, ISearchResultViewPart view) {
if (isQueryRunning(query))
return false;
// // prepare view
// if (view == null) {
// getSearchViewManager().activateSearchView(true);
// } else {
// getSearchViewManager().activateSearchView(view);
// }
addQuery(query);
SearchJobRecord sjr = new SearchJobRecord(query);
fSearchJobs.put(query, sjr);
Job job = new InternalSearchJob(sjr);
job.setPriority(Job.BUILD);
job.setUser(true);
// IWorkbenchSiteProgressService service= getProgressService();
// if (service != null) {
// service.schedule(job, 0, true);
// } else {
job.schedule();
return true;
}
use of org.eclipse.core.runtime.jobs.Job in project che by eclipse.
the class Policy method debug.
/**
* Print a debug message to the console.
* Prepend the message with the current date, the name of the current thread and the current job if present.
*/
public static void debug(String message) {
StringBuilder output = new StringBuilder();
output.append(new Date(System.currentTimeMillis()));
//$NON-NLS-1$
output.append(" - [");
output.append(Thread.currentThread().getName());
//$NON-NLS-1$
output.append("] ");
Job currentJob = Job.getJobManager().currentJob();
if (currentJob != null) {
output.append(currentJob.getClass().getName());
//$NON-NLS-1$
output.append("(");
output.append(currentJob.getName());
//$NON-NLS-1$
output.append("): ");
}
output.append(message);
System.out.println(output.toString());
}
use of org.eclipse.core.runtime.jobs.Job in project translationstudio8 by heartsome.
the class TMX2TXTConverterDialog method convert.
/**
* 开始转换
*/
private void convert() {
final String tmxLocation = tmxTxt.getText();
if (tmxLocation.equals("")) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg1"));
return;
}
final String txtLocation = txtTxt.getText();
if (txtLocation.equals("")) {
//$NON-NLS-1$
MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg2"));
return;
}
File txtFile = new File(txtLocation);
if (txtFile.exists()) {
boolean response = MessageDialog.openConfirm(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle2"), MessageFormat.format(Messages.getString("dialog.TMX2TXTConverterDialog.msg3"), txtLocation));
if (!response) {
return;
}
} else if (!txtFile.getParentFile().exists()) {
txtFile.getParentFile().mkdirs();
}
Job job = new Job(Messages.getString("dialog.TMX2TXTConverterDialog.job")) {
@Override
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask(Messages.getString("dialog.TMX2TXTConverterDialog.task"), 10);
// 先解析文件,花费一格
int openResult = openFile(tmxLocation, monitor);
if (openResult == 0) {
return Status.CANCEL_STATUS;
} else if (openResult == -2) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg4"));
}
});
return Status.CANCEL_STATUS;
} else if (openResult == -1) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg5"));
}
});
return Status.CANCEL_STATUS;
}
if (!validVersion(tmxLocation)) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg6"));
}
});
return Status.CANCEL_STATUS;
}
if ((tuNodesCount = getTUCount(tmxLocation)) <= 0) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg7"));
}
});
return Status.CANCEL_STATUS;
}
try {
output = new FileOutputStream(txtLocation);
byte[] bom = new byte[3];
bom[0] = (byte) 0xEF;
bom[1] = (byte) 0xBB;
bom[2] = (byte) 0xBF;
output.write(bom);
writeHeader();
monitor.worked(1);
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 8, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
return processTU(tmxLocation, txtLocation, subMonitor);
} catch (Exception e) {
e.printStackTrace();
LOGGER.error("", e);
}
monitor.done();
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();
}
use of org.eclipse.core.runtime.jobs.Job in project translationstudio8 by heartsome.
the class DeleteResourceAndCloseEditorAction method scheduleDeleteJob.
/**
* Schedule a job to delete the resources to delete.
* @param resourcesToDelete
*/
private void scheduleDeleteJob(final IResource[] resourcesToDelete) {
// use a non-workspace job with a runnable inside so we can avoid
// periodic updates
Job deleteJob = new Job(IDEWorkbenchMessages.DeleteResourceAction_jobName) {
public IStatus run(final IProgressMonitor monitor) {
try {
final DeleteResourcesOperation op = new DeleteResourcesOperation(resourcesToDelete, IDEWorkbenchMessages.DeleteResourceAction_operationLabel, deleteContent);
op.setModelProviderIds(getModelProviderIds());
// added to the undo history.
if (deleteContent && containsOnlyProjects(resourcesToDelete)) {
// We must compute the execution status first so that any user prompting
// or validation checking occurs. Do it in a syncExec because
// we are calling this from a Job.
WorkbenchJob statusJob = new //$NON-NLS-1$
WorkbenchJob(//$NON-NLS-1$
"Status checking") {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
*/
public IStatus runInUIThread(IProgressMonitor monitor) {
return op.computeExecutionStatus(monitor);
}
};
statusJob.setSystem(true);
statusJob.schedule();
try {
// block until the status is ready
statusJob.join();
} catch (InterruptedException e) {
// Do nothing as status will be a cancel
}
if (statusJob.getResult().isOK()) {
return op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(shellProvider.getShell()));
}
return statusJob.getResult();
}
return PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(shellProvider.getShell()));
} catch (ExecutionException e) {
if (e.getCause() instanceof CoreException) {
return ((CoreException) e.getCause()).getStatus();
}
return new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, e.getMessage(), e);
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object)
*/
public boolean belongsTo(Object family) {
if (IDEWorkbenchMessages.DeleteResourceAction_jobName.equals(family)) {
return true;
}
return super.belongsTo(family);
}
};
deleteJob.setUser(true);
deleteJob.schedule();
}
Aggregations