Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / PHPCore.java
index 52d906b..a7e866e 100644 (file)
@@ -6,12 +6,15 @@ import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.List;
 
+import net.sourceforge.phpdt.internal.core.BatchOperation;
 import net.sourceforge.phpeclipse.resourcesview.PHPFile;
 import net.sourceforge.phpeclipse.resourcesview.PHPProject;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRunnable;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -155,7 +158,7 @@ public class PHPCore {
    * @since 2.1
    */
   public static final String CLEAN = "clean"; //$NON-NLS-1$
-       
+
   /**
    * Returns a table of all known configurable options with their default values.
    * These options allow to configure the behaviour of the underlying components.
@@ -550,9 +553,7 @@ public class PHPCore {
     for (int i = 0; i < defaultPropertyNames.length; i++) {
       String propertyName = defaultPropertyNames[i];
       if (optionNames.contains(propertyName)) {
-        defaultOptions.put(
-          propertyName,
-          preferences.getDefaultString(propertyName));
+        defaultOptions.put(propertyName, preferences.getDefaultString(propertyName));
       }
     }
     // get preferences not set to their default
@@ -560,9 +561,7 @@ public class PHPCore {
     for (int i = 0; i < propertyNames.length; i++) {
       String propertyName = propertyNames[i];
       if (optionNames.contains(propertyName)) {
-        defaultOptions.put(
-          propertyName,
-          preferences.getDefaultString(propertyName));
+        defaultOptions.put(propertyName, preferences.getDefaultString(propertyName));
       }
     }
     // get encoding through resource plugin
@@ -672,8 +671,7 @@ public class PHPCore {
   }
   public static IProject[] getPHPProjects() {
     List phpProjectsList = new ArrayList();
-    IProject[] workspaceProjects =
-      PHPeclipsePlugin.getWorkspace().getRoot().getProjects();
+    IProject[] workspaceProjects = PHPeclipsePlugin.getWorkspace().getRoot().getProjects();
 
     for (int i = 0; i < workspaceProjects.length; i++) {
       IProject iProject = workspaceProjects[i];
@@ -686,8 +684,7 @@ public class PHPCore {
   }
 
   public static PHPProject getPHPProject(String name) {
-    IProject aProject =
-      PHPeclipsePlugin.getWorkspace().getRoot().getProject(name);
+    IProject aProject = PHPeclipsePlugin.getWorkspace().getRoot().getProject(name);
     if (isPHPProject(aProject)) {
       PHPProject thePHPProject = new PHPProject();
       thePHPProject.setProject(aProject);
@@ -730,15 +727,13 @@ public class PHPCore {
         return project;
       }
     } catch (CoreException e) {
-      System.err.println(
-        "Exception occurred in PHPCore#create(IProject): " + e.toString());
+      System.err.println("Exception occurred in PHPCore#create(IProject): " + e.toString());
     }
 
     return null;
   }
 
-  public static void addPHPNature(IProject project, IProgressMonitor monitor)
-    throws CoreException {
+  public static void addPHPNature(IProject project, IProgressMonitor monitor) throws CoreException {
     if (!project.hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) {
       IProjectDescription description = project.getDescription();
       String[] prevNatures = description.getNatureIds();
@@ -758,175 +753,212 @@ public class PHPCore {
   public static Plugin getPlugin() {
     return PHPeclipsePlugin.getDefault();
   }
-  
-/**
-   * Initializes the default preferences settings for this plug-in.
-   */
+
+  /**
+     * Initializes the default preferences settings for this plug-in.
+     */
   protected static void initializeDefaultPluginPreferences() {
-               
+
     Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
     HashSet optionNames = OptionNames;
-               
-//    // Compiler settings
-//    preferences.setDefault(COMPILER_LOCAL_VARIABLE_ATTR, GENERATE);
-//    optionNames.add(COMPILER_LOCAL_VARIABLE_ATTR);
-//
-//    preferences.setDefault(COMPILER_LINE_NUMBER_ATTR, GENERATE); 
-//    optionNames.add(COMPILER_LINE_NUMBER_ATTR);
-//
-//    preferences.setDefault(COMPILER_SOURCE_FILE_ATTR, GENERATE); 
-//    optionNames.add(COMPILER_SOURCE_FILE_ATTR);
-//
-//    preferences.setDefault(COMPILER_CODEGEN_UNUSED_LOCAL, PRESERVE); 
-//    optionNames.add(COMPILER_CODEGEN_UNUSED_LOCAL);
-//
-//    preferences.setDefault(COMPILER_CODEGEN_TARGET_PLATFORM, VERSION_1_1); 
-//    optionNames.add(COMPILER_CODEGEN_TARGET_PLATFORM);
-//
-//    preferences.setDefault(COMPILER_PB_UNREACHABLE_CODE, ERROR); 
-//    optionNames.add(COMPILER_PB_UNREACHABLE_CODE);
-//
-//    preferences.setDefault(COMPILER_PB_INVALID_IMPORT, ERROR); 
-//    optionNames.add(COMPILER_PB_INVALID_IMPORT);
-//
-//    preferences.setDefault(COMPILER_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD, WARNING); 
-//    optionNames.add(COMPILER_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD);
-//
-//    preferences.setDefault(COMPILER_PB_METHOD_WITH_CONSTRUCTOR_NAME, WARNING); 
-//    optionNames.add(COMPILER_PB_METHOD_WITH_CONSTRUCTOR_NAME);
-//
-//    preferences.setDefault(COMPILER_PB_DEPRECATION, WARNING);
-//    optionNames.add(COMPILER_PB_DEPRECATION);
-//
-//    preferences.setDefault(COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, DISABLED);
-//    optionNames.add(COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE);
-//
-//    preferences.setDefault(COMPILER_PB_HIDDEN_CATCH_BLOCK, WARNING); 
-//    optionNames.add(COMPILER_PB_HIDDEN_CATCH_BLOCK);
-//
-//    preferences.setDefault(COMPILER_PB_UNUSED_LOCAL, IGNORE); 
-//    optionNames.add(COMPILER_PB_UNUSED_LOCAL);
-//
-//    preferences.setDefault(COMPILER_PB_UNUSED_PARAMETER, IGNORE); 
-//    optionNames.add(COMPILER_PB_UNUSED_PARAMETER);
-//
-//    preferences.setDefault(COMPILER_PB_UNUSED_IMPORT, WARNING); 
-//    optionNames.add(COMPILER_PB_UNUSED_IMPORT);
-//
-//    preferences.setDefault(COMPILER_PB_SYNTHETIC_ACCESS_EMULATION, IGNORE); 
-//    optionNames.add(COMPILER_PB_SYNTHETIC_ACCESS_EMULATION);
-//
-//    preferences.setDefault(COMPILER_PB_NON_NLS_STRING_LITERAL, IGNORE); 
-//    optionNames.add(COMPILER_PB_NON_NLS_STRING_LITERAL);
-//
-//    preferences.setDefault(COMPILER_PB_ASSERT_IDENTIFIER, IGNORE); 
-//    optionNames.add(COMPILER_PB_ASSERT_IDENTIFIER);
-//
-//    preferences.setDefault(COMPILER_PB_STATIC_ACCESS_RECEIVER, WARNING); 
-//    optionNames.add(COMPILER_PB_STATIC_ACCESS_RECEIVER);
-//
-//    preferences.setDefault(COMPILER_PB_NO_EFFECT_ASSIGNMENT, WARNING); 
-//    optionNames.add(COMPILER_PB_NO_EFFECT_ASSIGNMENT);
-//
-//    preferences.setDefault(COMPILER_TASK_TAGS, ""); //$NON-NLS-1$
-//    optionNames.add(COMPILER_TASK_TAGS);
-//
-//    preferences.setDefault(COMPILER_TASK_PRIORITIES, ""); //$NON-NLS-1$
-//    optionNames.add(COMPILER_TASK_PRIORITIES);
-//
-//    preferences.setDefault(COMPILER_SOURCE, VERSION_1_3);
-//    optionNames.add(COMPILER_SOURCE);
-//
-//    preferences.setDefault(COMPILER_COMPLIANCE, VERSION_1_3); 
-//    optionNames.add(COMPILER_COMPLIANCE);
-//
-//    preferences.setDefault(COMPILER_PB_MAX_PER_UNIT, "100"); //$NON-NLS-1$
-//    optionNames.add(COMPILER_PB_MAX_PER_UNIT);
-//             
-//    // Builder settings
-//    preferences.setDefault(CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, ""); //$NON-NLS-1$
-//    optionNames.add(CORE_JAVA_BUILD_RESOURCE_COPY_FILTER);
-//
-//    preferences.setDefault(CORE_JAVA_BUILD_INVALID_CLASSPATH, ABORT); 
-//    optionNames.add(CORE_JAVA_BUILD_INVALID_CLASSPATH);
-//     
-//    preferences.setDefault(CORE_JAVA_BUILD_DUPLICATE_RESOURCE, WARNING); 
-//    optionNames.add(CORE_JAVA_BUILD_DUPLICATE_RESOURCE);
-//             
-//    preferences.setDefault(CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, CLEAN); 
-//    optionNames.add(CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER);
-//
-//    // JavaCore settings
-//    preferences.setDefault(CORE_JAVA_BUILD_ORDER, IGNORE); 
-//    optionNames.add(CORE_JAVA_BUILD_ORDER);
-//     
-//    preferences.setDefault(CORE_CIRCULAR_CLASSPATH, ERROR); 
-//    optionNames.add(CORE_CIRCULAR_CLASSPATH);
-//             
-//    preferences.setDefault(CORE_INCOMPLETE_CLASSPATH, ERROR); 
-//    optionNames.add(CORE_INCOMPLETE_CLASSPATH);
-               
+
+    //    // Compiler settings
+    //    preferences.setDefault(COMPILER_LOCAL_VARIABLE_ATTR, GENERATE);
+    //    optionNames.add(COMPILER_LOCAL_VARIABLE_ATTR);
+    //
+    //    preferences.setDefault(COMPILER_LINE_NUMBER_ATTR, GENERATE); 
+    //    optionNames.add(COMPILER_LINE_NUMBER_ATTR);
+    //
+    //    preferences.setDefault(COMPILER_SOURCE_FILE_ATTR, GENERATE); 
+    //    optionNames.add(COMPILER_SOURCE_FILE_ATTR);
+    //
+    //    preferences.setDefault(COMPILER_CODEGEN_UNUSED_LOCAL, PRESERVE); 
+    //    optionNames.add(COMPILER_CODEGEN_UNUSED_LOCAL);
+    //
+    //    preferences.setDefault(COMPILER_CODEGEN_TARGET_PLATFORM, VERSION_1_1); 
+    //    optionNames.add(COMPILER_CODEGEN_TARGET_PLATFORM);
+    //
+    //    preferences.setDefault(COMPILER_PB_UNREACHABLE_CODE, ERROR); 
+    //    optionNames.add(COMPILER_PB_UNREACHABLE_CODE);
+    //
+    //    preferences.setDefault(COMPILER_PB_INVALID_IMPORT, ERROR); 
+    //    optionNames.add(COMPILER_PB_INVALID_IMPORT);
+    //
+    //    preferences.setDefault(COMPILER_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD, WARNING); 
+    //    optionNames.add(COMPILER_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD);
+    //
+    //    preferences.setDefault(COMPILER_PB_METHOD_WITH_CONSTRUCTOR_NAME, WARNING); 
+    //    optionNames.add(COMPILER_PB_METHOD_WITH_CONSTRUCTOR_NAME);
+    //
+    //    preferences.setDefault(COMPILER_PB_DEPRECATION, WARNING);
+    //    optionNames.add(COMPILER_PB_DEPRECATION);
+    //
+    //    preferences.setDefault(COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, DISABLED);
+    //    optionNames.add(COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE);
+    //
+    //    preferences.setDefault(COMPILER_PB_HIDDEN_CATCH_BLOCK, WARNING); 
+    //    optionNames.add(COMPILER_PB_HIDDEN_CATCH_BLOCK);
+    //
+    //    preferences.setDefault(COMPILER_PB_UNUSED_LOCAL, IGNORE); 
+    //    optionNames.add(COMPILER_PB_UNUSED_LOCAL);
+    //
+    //    preferences.setDefault(COMPILER_PB_UNUSED_PARAMETER, IGNORE); 
+    //    optionNames.add(COMPILER_PB_UNUSED_PARAMETER);
+    //
+    //    preferences.setDefault(COMPILER_PB_UNUSED_IMPORT, WARNING); 
+    //    optionNames.add(COMPILER_PB_UNUSED_IMPORT);
+    //
+    //    preferences.setDefault(COMPILER_PB_SYNTHETIC_ACCESS_EMULATION, IGNORE); 
+    //    optionNames.add(COMPILER_PB_SYNTHETIC_ACCESS_EMULATION);
+    //
+    //    preferences.setDefault(COMPILER_PB_NON_NLS_STRING_LITERAL, IGNORE); 
+    //    optionNames.add(COMPILER_PB_NON_NLS_STRING_LITERAL);
+    //
+    //    preferences.setDefault(COMPILER_PB_ASSERT_IDENTIFIER, IGNORE); 
+    //    optionNames.add(COMPILER_PB_ASSERT_IDENTIFIER);
+    //
+    //    preferences.setDefault(COMPILER_PB_STATIC_ACCESS_RECEIVER, WARNING); 
+    //    optionNames.add(COMPILER_PB_STATIC_ACCESS_RECEIVER);
+    //
+    //    preferences.setDefault(COMPILER_PB_NO_EFFECT_ASSIGNMENT, WARNING); 
+    //    optionNames.add(COMPILER_PB_NO_EFFECT_ASSIGNMENT);
+    //
+    //    preferences.setDefault(COMPILER_TASK_TAGS, ""); //$NON-NLS-1$
+    //    optionNames.add(COMPILER_TASK_TAGS);
+    //
+    //    preferences.setDefault(COMPILER_TASK_PRIORITIES, ""); //$NON-NLS-1$
+    //    optionNames.add(COMPILER_TASK_PRIORITIES);
+    //
+    //    preferences.setDefault(COMPILER_SOURCE, VERSION_1_3);
+    //    optionNames.add(COMPILER_SOURCE);
+    //
+    //    preferences.setDefault(COMPILER_COMPLIANCE, VERSION_1_3); 
+    //    optionNames.add(COMPILER_COMPLIANCE);
+    //
+    //    preferences.setDefault(COMPILER_PB_MAX_PER_UNIT, "100"); //$NON-NLS-1$
+    //    optionNames.add(COMPILER_PB_MAX_PER_UNIT);
+    //         
+    //    // Builder settings
+    //    preferences.setDefault(CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, ""); //$NON-NLS-1$
+    //    optionNames.add(CORE_JAVA_BUILD_RESOURCE_COPY_FILTER);
+    //
+    //    preferences.setDefault(CORE_JAVA_BUILD_INVALID_CLASSPATH, ABORT); 
+    //    optionNames.add(CORE_JAVA_BUILD_INVALID_CLASSPATH);
+    // 
+    //    preferences.setDefault(CORE_JAVA_BUILD_DUPLICATE_RESOURCE, WARNING); 
+    //    optionNames.add(CORE_JAVA_BUILD_DUPLICATE_RESOURCE);
+    //         
+    //    preferences.setDefault(CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, CLEAN); 
+    //    optionNames.add(CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER);
+    //
+    //    // JavaCore settings
+    //    preferences.setDefault(CORE_JAVA_BUILD_ORDER, IGNORE); 
+    //    optionNames.add(CORE_JAVA_BUILD_ORDER);
+    // 
+    //    preferences.setDefault(CORE_CIRCULAR_CLASSPATH, ERROR); 
+    //    optionNames.add(CORE_CIRCULAR_CLASSPATH);
+    //         
+    //    preferences.setDefault(CORE_INCOMPLETE_CLASSPATH, ERROR); 
+    //    optionNames.add(CORE_INCOMPLETE_CLASSPATH);
+
     // encoding setting comes from resource plug-in
     optionNames.add(CORE_ENCODING);
-               
+
     // Formatter settings
-    preferences.setDefault(FORMATTER_NEWLINE_OPENING_BRACE, DO_NOT_INSERT); 
+    preferences.setDefault(FORMATTER_NEWLINE_OPENING_BRACE, DO_NOT_INSERT);
     optionNames.add(FORMATTER_NEWLINE_OPENING_BRACE);
 
     preferences.setDefault(FORMATTER_NEWLINE_CONTROL, DO_NOT_INSERT);
     optionNames.add(FORMATTER_NEWLINE_CONTROL);
 
-    preferences.setDefault(FORMATTER_CLEAR_BLANK_LINES, PRESERVE_ONE); 
+    preferences.setDefault(FORMATTER_CLEAR_BLANK_LINES, PRESERVE_ONE);
     optionNames.add(FORMATTER_CLEAR_BLANK_LINES);
 
     preferences.setDefault(FORMATTER_NEWLINE_ELSE_IF, DO_NOT_INSERT);
     optionNames.add(FORMATTER_NEWLINE_ELSE_IF);
 
-    preferences.setDefault(FORMATTER_NEWLINE_EMPTY_BLOCK, INSERT); 
+    preferences.setDefault(FORMATTER_NEWLINE_EMPTY_BLOCK, INSERT);
     optionNames.add(FORMATTER_NEWLINE_EMPTY_BLOCK);
 
     preferences.setDefault(FORMATTER_LINE_SPLIT, "80"); //$NON-NLS-1$
     optionNames.add(FORMATTER_LINE_SPLIT);
 
-    preferences.setDefault(FORMATTER_COMPACT_ASSIGNMENT, NORMAL); 
+    preferences.setDefault(FORMATTER_COMPACT_ASSIGNMENT, NORMAL);
     optionNames.add(FORMATTER_COMPACT_ASSIGNMENT);
 
-    preferences.setDefault(FORMATTER_TAB_CHAR, TAB); 
+    preferences.setDefault(FORMATTER_TAB_CHAR, TAB);
     optionNames.add(FORMATTER_TAB_CHAR);
 
     preferences.setDefault(FORMATTER_TAB_SIZE, "4"); //$NON-NLS-1$ 
     optionNames.add(FORMATTER_TAB_SIZE);
-               
+
     // CodeAssist settings
-//    preferences.setDefault(CODEASSIST_VISIBILITY_CHECK, DISABLED); //$NON-NLS-1$
-//    optionNames.add(CODEASSIST_VISIBILITY_CHECK);
-//
-//    preferences.setDefault(CODEASSIST_IMPLICIT_QUALIFICATION, DISABLED); //$NON-NLS-1$
-//    optionNames.add(CODEASSIST_IMPLICIT_QUALIFICATION);
-//             
-//    preferences.setDefault(CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$
-//    optionNames.add(CODEASSIST_FIELD_PREFIXES);
-//             
-//    preferences.setDefault(CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$
-//    optionNames.add(CODEASSIST_STATIC_FIELD_PREFIXES);
-//             
-//    preferences.setDefault(CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$
-//    optionNames.add(CODEASSIST_LOCAL_PREFIXES);
-//             
-//    preferences.setDefault(CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$
-//    optionNames.add(CODEASSIST_ARGUMENT_PREFIXES);
-//             
-//    preferences.setDefault(CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$
-//    optionNames.add(CODEASSIST_FIELD_SUFFIXES);
-//             
-//    preferences.setDefault(CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$
-//    optionNames.add(CODEASSIST_STATIC_FIELD_SUFFIXES);
-//             
-//    preferences.setDefault(CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$
-//    optionNames.add(CODEASSIST_LOCAL_SUFFIXES);
-//             
-//    preferences.setDefault(CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$
-//    optionNames.add(CODEASSIST_ARGUMENT_SUFFIXES);
-               
+    //    preferences.setDefault(CODEASSIST_VISIBILITY_CHECK, DISABLED); //$NON-NLS-1$
+    //    optionNames.add(CODEASSIST_VISIBILITY_CHECK);
+    //
+    //    preferences.setDefault(CODEASSIST_IMPLICIT_QUALIFICATION, DISABLED); //$NON-NLS-1$
+    //    optionNames.add(CODEASSIST_IMPLICIT_QUALIFICATION);
+    //         
+    //    preferences.setDefault(CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$
+    //    optionNames.add(CODEASSIST_FIELD_PREFIXES);
+    //         
+    //    preferences.setDefault(CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$
+    //    optionNames.add(CODEASSIST_STATIC_FIELD_PREFIXES);
+    //         
+    //    preferences.setDefault(CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$
+    //    optionNames.add(CODEASSIST_LOCAL_PREFIXES);
+    //         
+    //    preferences.setDefault(CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$
+    //    optionNames.add(CODEASSIST_ARGUMENT_PREFIXES);
+    //         
+    //    preferences.setDefault(CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$
+    //    optionNames.add(CODEASSIST_FIELD_SUFFIXES);
+    //         
+    //    preferences.setDefault(CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$
+    //    optionNames.add(CODEASSIST_STATIC_FIELD_SUFFIXES);
+    //         
+    //    preferences.setDefault(CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$
+    //    optionNames.add(CODEASSIST_LOCAL_SUFFIXES);
+    //         
+    //    preferences.setDefault(CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$
+    //    optionNames.add(CODEASSIST_ARGUMENT_SUFFIXES);
+
+  }
+  /**
+        * Runs the given action as an atomic Java model operation.
+        * <p>
+        * After running a method that modifies Java elements,
+        * registered listeners receive after-the-fact notification of
+        * what just transpired, in the form of a element changed event.
+        * This method allows clients to call a number of
+        * methods that modify java elements and only have element
+        * changed event notifications reported at the end of the entire
+        * batch.
+        * </p>
+        * <p>
+        * If this method is called outside the dynamic scope of another such
+        * call, this method runs the action and then reports a single
+        * element changed event describing the net effect of all changes
+        * done to java elements by the action.
+        * </p>
+        * <p>
+        * If this method is called in the dynamic scope of another such
+        * call, this method simply runs the action.
+        * </p>
+        *
+        * @param action the action to perform
+        * @param monitor a progress monitor, or <code>null</code> if progress
+        *    reporting and cancellation are not desired
+        * @exception CoreException if the operation failed.
+        * @since 2.1
+        */
+  public static void run(IWorkspaceRunnable action, IProgressMonitor monitor) throws CoreException {
+    IWorkspace workspace = ResourcesPlugin.getWorkspace();
+    if (workspace.isTreeLocked()) {
+      new BatchOperation(action).run(monitor);
+    } else {
+      // use IWorkspace.run(...) to ensure that a build will be done in autobuild mode
+      workspace.run(new BatchOperation(action), monitor);
+    }
   }
 }
\ No newline at end of file