Use org.eclipse.ui.ide.IDE.saveAllEditors
:
IResource [] resources = array of IFile, IFolder, IProject
boolean ok = IDE.saveAllEditors(resources, confirm);
From the JavaDoc:
Save all dirty editors in the workbench whose editor input is a child resource of one of the IResource's provided. Opens a dialog to prompt the user if confirm is true. Return true if successful. Return false if the user has canceled the command.