use of eu.esdihumboldt.hale.ui.util.jobs.ExclusiveSchedulingRule in project hale by halestudio.
the class CompilingSourceViewer method init.
@Override
protected void init() {
compileJob = new Job("Compile") {
@Override
public boolean shouldRun() {
return compilationEnabled;
}
@Override
public boolean shouldSchedule() {
return compilationEnabled;
}
@Override
protected IStatus run(IProgressMonitor monitor) {
String content;
changeLock.lock();
try {
if (!changed) {
return Status.OK_STATUS;
}
IDocument doc = getDocument();
if (doc != null) {
content = doc.get();
} else {
content = null;
}
changed = false;
} finally {
changeLock.unlock();
}
C result = null;
if (content != null) {
try {
// this is the potentially long running stuff
result = compile(content);
} catch (Exception e) {
// ignore, but log
log.warn("Error compiling document content", e);
}
}
boolean notify = false;
C previous = null;
changeLock.lock();
try {
/*
* Only notify listeners if the document was not changed in
* the meantime.
*/
notify = !changed;
if (notify) {
// set result
previous = compiled;
compiled = result;
// set result for futures
for (SettableFuture<C> future : toUpdate) {
future.set(result);
}
toUpdate.clear();
}
} finally {
changeLock.unlock();
}
if (notify) {
// notify listeners
PropertyChangeEvent event = new PropertyChangeEvent(CompilingSourceViewer.this, PROPERTY_COMPILED, previous, result);
notifyOnPropertyChange(event);
}
return Status.OK_STATUS;
}
};
compileJob.setSystem(true);
compileJob.setRule(new ExclusiveSchedulingRule(compileJob));
super.init();
}
use of eu.esdihumboldt.hale.ui.util.jobs.ExclusiveSchedulingRule in project hale by halestudio.
the class ValidatingSourceViewer method init.
/**
* Initialize the Job and listener.
*/
protected void init() {
validateJob = new Job("Source viewer validation") {
@Override
public boolean shouldRun() {
return validationEnabled.get();
}
@Override
public boolean shouldSchedule() {
return validationEnabled.get();
}
@Override
protected IStatus run(IProgressMonitor monitor) {
String content;
changeLock.lock();
try {
if (!changed) {
return Status.OK_STATUS;
}
IDocument doc = getDocument();
if (doc != null) {
content = doc.get();
} else {
content = "";
}
changed = false;
} finally {
changeLock.unlock();
}
boolean success = false;
try {
// this is the potentially long running stuff
success = validate(content);
} catch (Exception e) {
// ignore, but log
log.warn("Error validating document content", e);
success = false;
}
boolean notify = false;
changeLock.lock();
try {
/*
* Only notify listeners if the document was not changed in
* the meantime and the valid state is different than
* before.
*/
notify = !changed && valid != success;
if (notify) {
// set result
valid = success;
}
} finally {
changeLock.unlock();
}
if (notify) {
PropertyChangeEvent event = new PropertyChangeEvent(ValidatingSourceViewer.this, PROPERTY_VALID, !success, success);
notifyOnPropertyChange(event);
}
return Status.OK_STATUS;
}
};
validateJob.setUser(false);
validateJob.setRule(new ExclusiveSchedulingRule(this));
documentListener = new IDocumentListener() {
@Override
public void documentChanged(DocumentEvent event) {
scheduleValidation();
}
@Override
public void documentAboutToBeChanged(DocumentEvent event) {
// do nothing
}
};
}
Aggregations