use of org.eclipse.core.runtime.jobs.IJobChangeListener in project polymap4-core by Polymap4.
the class OperationSupport method execute3.
/**
*@see #execute(IUndoableOperation, boolean, boolean, IJobChangeListener...)
*/
public void execute3(final IUndoableOperation op, boolean async, boolean progress, Runnable... doneHandlers) {
IJobChangeListener[] listeners = new IJobChangeListener[doneHandlers.length];
for (int i = 0; i < doneHandlers.length; i++) {
Runnable handler = doneHandlers[i];
listeners[i] = new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent ev) {
handler.run();
}
};
}
execute(op, async, progress, listeners);
}
use of org.eclipse.core.runtime.jobs.IJobChangeListener in project core by jcryptool.
the class IntegratorWizardPage method makeNewKey.
protected void makeNewKey() {
Job[] preJobs = Job.getJobManager().find(KeyStoreHelper.KEYSTOREHELPER_FAMILY);
int preJobCount = preJobs.length;
KeyStoreHelper.makeSymmetricKeyByWizard(showKeyGroup).addObserver(new Observer() {
public void update(Observable o, final Object arg) {
if (arg != null) {
keyFromKeystoreGroup.getDisplay().syncExec(new Runnable() {
public void run() {
KeyStoreAlias ref = (KeyStoreAlias) arg;
setKeyForShowcase(ref);
}
});
}
}
});
Job[] jobs = Job.getJobManager().find(KeyStoreHelper.KEYSTOREHELPER_FAMILY);
if (jobs.length > preJobCount) {
createNewKeyButton.getDisplay().syncExec(new Runnable() {
public void run() {
buttonTextBeforeJobrunningMsg = createNewKeyButton.getText();
// $NON-NLS-1$
createNewKeyButton.setText(Messages.getString("IntegratorWizardPage.generatingButtonHint"));
disableControls();
}
});
Job job = jobs[jobs.length - 1];
IJobChangeListener listener = new IJobChangeListener() {
public void sleeping(IJobChangeEvent event) {
}
public void done(IJobChangeEvent event) {
createNewKeyButton.getDisplay().syncExec(new Runnable() {
public void run() {
createNewKeyButton.setText(buttonTextBeforeJobrunningMsg);
enableControls();
}
});
}
public void awake(IJobChangeEvent event) {
}
public void aboutToRun(IJobChangeEvent event) {
}
public void running(IJobChangeEvent event) {
}
public void scheduled(IJobChangeEvent event) {
}
};
if (job.getState() != Job.NONE)
job.addJobChangeListener(listener);
else {
listener.done(null);
}
}
}
use of org.eclipse.core.runtime.jobs.IJobChangeListener in project core by jcryptool.
the class IntegratorWizardPage method makeNewKeypair.
protected void makeNewKeypair() {
Job[] preJobs = Job.getJobManager().find(KeyStoreHelper.KEYSTOREHELPER_FAMILY);
int preJobCount = preJobs.length;
KeyStoreHelper.makeKeyPairByWizard(showKeyGroup).addObserver(new Observer() {
public void update(Observable o, final Object arg) {
if (arg != null) {
keyFromKeystoreGroup.getDisplay().syncExec(new Runnable() {
public void run() {
KeyStoreAlias ref = (KeyStoreAlias) arg;
setKeyForShowcase(ref);
}
});
}
}
});
Job[] jobs = Job.getJobManager().find(KeyStoreHelper.KEYSTOREHELPER_FAMILY);
if (jobs.length > preJobCount) {
createNewKeyButton.getDisplay().syncExec(new Runnable() {
public void run() {
buttonTextBeforeJobrunningMsg = createNewKeyButton.getText();
// $NON-NLS-1$
createNewKeyButton.setText(Messages.getString("IntegratorWizardPage.generatingButtonHint"));
disableControls();
}
});
Job job = jobs[jobs.length - 1];
IJobChangeListener listener = new IJobChangeListener() {
public void sleeping(IJobChangeEvent event) {
}
public void done(IJobChangeEvent event) {
createNewKeyButton.getDisplay().syncExec(new Runnable() {
public void run() {
createNewKeyButton.setText(buttonTextBeforeJobrunningMsg);
enableControls();
}
});
}
public void awake(IJobChangeEvent event) {
}
public void aboutToRun(IJobChangeEvent event) {
}
public void running(IJobChangeEvent event) {
}
public void scheduled(IJobChangeEvent event) {
}
};
if (job.getState() != Job.NONE)
job.addJobChangeListener(listener);
else {
listener.done(null);
}
}
}
use of org.eclipse.core.runtime.jobs.IJobChangeListener in project polymap4-core by Polymap4.
the class UIJob method joinAndDispatch.
/**
* Waits until this job is finished. This method will block the calling thread
* until the job has finished executing, or until this thread has been
* interrupted, or the timeout exceeds. A job must not be joined from within the
* scope of its run method.
* <p/>
* This method must be called from the UIThread. It calls readAndDispatch() of
* the current display, so that the UI is responsive during the call is blocked.
*
* @param timeoutMillis
* @return False if the job did not finish within the given timeout or the
* calling thread was interrupted.
*/
public boolean joinAndDispatch(long timeoutMillis) {
final AtomicBoolean done = new AtomicBoolean(getState() == Job.NONE);
IJobChangeListener jobListener = new JobChangeAdapter() {
public void done(IJobChangeEvent event) {
synchronized (done) {
done.set(true);
done.notify();
}
}
};
addJobChangeListener(jobListener);
// registered; this avoids race cond. between the two
if (getState() == Job.NONE) {
removeJobChangeListener(jobListener);
return true;
}
final Display threadDisplay = Display.getCurrent();
final Timer timer = new Timer();
while (!done.get() && timer.elapsedTime() < timeoutMillis && (threadDisplay == null || !threadDisplay.isDisposed())) {
Thread.yield();
if (threadDisplay != null) {
if (!threadDisplay.readAndDispatch()) {
synchronized (done) {
try {
done.wait(300);
log.debug("wake after: " + timer.elapsedTime() + "ms");
} catch (InterruptedException e) {
}
}
// // just wait on #done blocks hangs;
// // display.sleep() might wait forever, so we need this watchdog
// Polymap.executorService().execute( new Runnable() {
// public void run() {
// synchronized (done) {
// try { done.wait( 300 ); } catch (InterruptedException e) {}
// }
// log.info( "wake ..." );
// threadDisplay.wake();
// }
// });
// threadDisplay.sleep();
}
} else {
synchronized (done) {
try {
done.wait(250);
} catch (InterruptedException e) {
}
}
}
}
removeJobChangeListener(jobListener);
return done.get();
}
Aggregations