// BUG 178598 - If the resource is shared, and it's possible to
// get the workbench Display, the UI thread is asked to execute the
// format of the file when it can
monitor.beginTask("", 20); //$NON-NLS-1$
try {
ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
ITextFileBuffer buffer = null;
try {
if(manager != null) {
manager.connect(file.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(monitor, 1));
buffer = manager.getTextFileBuffer(resource.getFullPath(), LocationKind.IFILE);
}
if(buffer != null && buffer.isShared()) {
Display display = getDisplay();
if (display != null) {
display.syncExec(new Runnable() {
public void run() {
format(new SubProgressMonitor(monitor, 18), file);
}
});
}
}
else
format(new SubProgressMonitor(monitor, 18), file);
}
finally {
if(manager != null)
manager.disconnect(file.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(monitor, 1));
}
monitor.done();
}
catch(CoreException e) {
String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[]{file.getFullPath().toString()});