diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java index b3084a03527..625337923e1 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java @@ -11,6 +11,7 @@ import org.eclipse.cdt.core.CProjectNature; import org.eclipse.cdt.core.filetype.ICFileType; import org.eclipse.cdt.core.filetype.ICFileTypeAssociation; import org.eclipse.cdt.core.filetype.ICFileTypeResolver; +import org.eclipse.cdt.core.resources.IPathEntryStore; import org.eclipse.cdt.internal.core.model.BatchOperation; import org.eclipse.cdt.internal.core.model.CModel; import org.eclipse.cdt.internal.core.model.CModelManager; @@ -825,6 +826,14 @@ public class CoreModel { // return null; //} + public static IPathEntryStore getPathEntryStore(IProject project) throws CoreException { + return CCorePlugin.getDefault().getPathEntryStore(project); + } + + public static void setPathEntryStore(IProject project, IPathEntryStore store) { + pathEntryManager.setPathEntryStore(project, store); + } + /** * Return the singleton. */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java index ba1c163424e..9dfe42c69d7 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java @@ -40,6 +40,7 @@ import org.eclipse.cdt.core.resources.IPathEntryStoreListener; import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; @@ -375,27 +376,37 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange return; } // trigger model refresh - boolean shouldFire = false; - CModelManager mgr = CModelManager.getDefault(); - for (int i = 0; i < projectLength; i++) { - if (monitor != null && monitor.isCanceled()) { - return; - } - ICProject affectedProject = modifiedProjects[i]; - if (affectedProject == null) { - continue; // was filtered out - } - IPathEntry[] newEntries = getResolvedPathEntries(affectedProject); - ICElementDelta[] deltas = generatePathEntryDeltas(affectedProject, oldResolvedEntries[i], newEntries); - if (deltas.length > 0) { - shouldFire = true; - for (int j = 0; j < deltas.length; j++) { - mgr.registerCModelDelta(deltas[j]); + try { + //final boolean canChangeResources = !ResourcesPlugin.getWorkspace().isTreeLocked(); + CoreModel.run(new IWorkspaceRunnable() { + public void run(IProgressMonitor progressMonitor) throws CoreException { + + boolean shouldFire = false; + CModelManager mgr = CModelManager.getDefault(); + for (int i = 0; i < projectLength; i++) { + if (progressMonitor != null && progressMonitor.isCanceled()) { + return; + } + ICProject affectedProject = modifiedProjects[i]; + if (affectedProject == null) { + continue; // was filtered out + } + IPathEntry[] newEntries = getResolvedPathEntries(affectedProject); + ICElementDelta[] deltas = generatePathEntryDeltas(affectedProject, oldResolvedEntries[i], newEntries); + if (deltas.length > 0) { + shouldFire = true; + for (int j = 0; j < deltas.length; j++) { + mgr.registerCModelDelta(deltas[j]); + } + } + } + if (shouldFire) { + mgr.fire(ElementChangedEvent.POST_CHANGE); + } } - } - } - if (shouldFire) { - mgr.fire(ElementChangedEvent.POST_CHANGE); + }, monitor); + } catch (CoreException e ) { + // } } @@ -681,6 +692,21 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange return containerIDs; } + public void setPathEntryStore(IProject project, IPathEntryStore newStore) { + IPathEntryStore oldStore = null; + synchronized(this) { + oldStore = (IPathEntryStore)storeMap.remove(project); + if (newStore != null) { + storeMap.put(project, newStore); + } + } + if (oldStore != null) { + // remove are self before closing + oldStore.removePathEntryStoreListener(this); + oldStore.close(); + } + } + private synchronized IPathEntryStore getPathEntryStore(IProject project, boolean create) throws CoreException { IPathEntryStore store = (IPathEntryStore)storeMap.get(project); if (store == null && create == true) { @@ -691,13 +717,6 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange return store; } - private synchronized void removePathEntryStore(IProject project) { - IPathEntryStore store = (IPathEntryStore)storeMap.remove(project); - if (store!= null) { - store.removePathEntryStoreListener(this); - } - } - /* (non-Javadoc) * @see org.eclipse.cdt.core.resources.IPathEntryStoreListener#pathEntryStoreChanged(org.eclipse.cdt.core.resources.PathEntryChangedEvent) */ @@ -712,7 +731,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange CModelManager manager = CModelManager.getDefault(); ICProject cproject = manager.create(project); if (event.hasClosed()) { - removePathEntryStore(project); + setPathEntryStore(project, null); containerRemove(cproject); } if (project.isAccessible()) {