// Check if we're being asked to close any parts that are already closed or cannot
// be closed at this time
ArrayList toClose = new ArrayList();
for (int i = 0; i < refArray.length; i++) {
IEditorReference reference = refArray[i];
// If we're in the middle of creating this part, this is a programming error. Abort the entire
// close operation. This usually occurs if someone tries to open a dialog in a method that
// isn't allowed to do so, and a *syncExec tries to close the part. If this shows up in a log
// file with a dialog's event loop on the stack, then the code that opened the dialog is usually
// at fault.
if (reference == partBeingActivated) {
WorkbenchPlugin.log(new RuntimeException("WARNING: Blocked recursive attempt to close part " //$NON-NLS-1$
+ partBeingActivated.getId() + " while still in the middle of activating it")); //$NON-NLS-1$
return false;
}
if(reference instanceof WorkbenchPartReference) {
WorkbenchPartReference ref = (WorkbenchPartReference) reference;
// If we're being asked to close a part that is disposed (ie: already closed),
// skip it and proceed with closing the remaining parts.
if (ref.isDisposed()) {
continue;
}
}
toClose.add(reference);
}
IEditorReference[] editorRefs = (IEditorReference[]) toClose.toArray(new IEditorReference[toClose.size()]);
// notify the model manager before the close
List partsToClose = new ArrayList();
for (int i = 0; i < editorRefs.length; i++) {
IEditorPart refPart = editorRefs[i].getEditor(false);
if (refPart != null) {
partsToClose.add(refPart);
}
}
SaveablesList modelManager = null;
Object postCloseInfo = null;
if(partsToClose.size()>0) {
modelManager = (SaveablesList) getWorkbenchWindow().getService(ISaveablesLifecycleListener.class);
// this may prompt for saving and return null if the user canceled:
postCloseInfo = modelManager.preCloseParts(partsToClose, save, getWorkbenchWindow());
if (postCloseInfo==null) {
return false;
}
}
// Fire pre-removal changes
for (int i = 0; i < editorRefs.length; i++) {
IEditorReference ref = editorRefs[i];
// Notify interested listeners before the close
window.firePerspectiveChanged(this, getPerspective(), ref,
CHANGE_EDITOR_CLOSE);
}
deferUpdates(true);
try {
if(modelManager!=null) {
modelManager.postClose(postCloseInfo);
}
// Close all editors.
for (int i = 0; i < editorRefs.length; i++) {
IEditorReference ref = editorRefs[i];
// Remove editor from the presentation
editorPresentation.closeEditor(ref);
partRemoved((WorkbenchPartReference)ref);