From dc57a7a2d140d992b374a09abeb7ae150a7f382e Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Mon, 26 Apr 2004 20:47:42 +0000 Subject: [PATCH] Changes in the PathEntryStore API --- core/org.eclipse.cdt.core/ChangeLog | 8 ++++ .../internal/core/model/PathEntryManager.java | 47 ++++++++++++------- .../internal/core/model/PathEntryStore.java | 31 +++++++++--- .../cdt/core/resources/IPathEntryStore.java | 47 ++++++++++++++++++- .../resources/PathEntryStoreChangedEvent.java | 26 ++++++++-- 5 files changed, 131 insertions(+), 28 deletions(-) diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index c1749f4f167..32709347415 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -1,3 +1,11 @@ +2004-04-26 Alain Magloire + + Changes in the PathEntryStore API + * model/org/eclipse/cdt/internal/core/model/PathEntryManager.java + * model/org/eclipse/cdt/internal/core/model/PathEntryStore.java + * src/org/eclipse/cdt/core/resources/IPathEntryStore.java + * src/org/eclipse/cdt/core/resources/PathEntryStoreChangedEvent.java + 2004-04-26 Alain Magloire Move the persistency of the IPathEntry in a differenct 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 dda408decd1..8a4bceb0137 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 @@ -630,22 +630,34 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange */ public void pathEntryStoreChanged(PathEntryStoreChangedEvent event) { IProject project = event.getProject(); - if (project != null && (CoreModel.hasCNature(project) || CoreModel.hasCCNature(project))) { - CModelManager manager = CModelManager.getDefault(); - ICProject cproject = manager.create(project); - try { - IPathEntry[] oldResolvedEntries = getResolvedPathEntries(cproject); - resolvedMap.remove(cproject); - IPathEntry[] newResolvedEntries = getResolvedPathEntries(cproject); - ICElementDelta[] deltas = generatePathEntryDeltas(cproject, oldResolvedEntries, newResolvedEntries); - if (deltas.length > 0) { - cproject.close(); - for (int i = 0; i < deltas.length; i++) { - manager.registerCModelDelta(deltas[i]); + + // sanity + if (project == null) { + return; + } + + IPathEntryStore store = (IPathEntryStore)storeMap.get(project); + if (store != null) { + if (event.hasClosed()) { + storeMap.remove(project); + store.removePathEntryStoreListener(this); + } + if (project.isAccessible()) { + CModelManager manager = CModelManager.getDefault(); + ICProject cproject = manager.create(project); + try { + IPathEntry[] oldResolvedEntries = getResolvedPathEntries(cproject); + IPathEntry[] newResolvedEntries = getResolvedPathEntries(cproject); + ICElementDelta[] deltas = generatePathEntryDeltas(cproject, oldResolvedEntries, newResolvedEntries); + if (deltas.length > 0) { + cproject.close(); + for (int i = 0; i < deltas.length; i++) { + manager.registerCModelDelta(deltas[i]); + } + manager.fire(ElementChangedEvent.POST_CHANGE); } - manager.fire(ElementChangedEvent.POST_CHANGE); + } catch (CModelException e) { } - } catch (CModelException e) { } } } @@ -671,9 +683,10 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange if (((flags & ICElementDelta.F_CLOSED) != 0) || (kind == ICElementDelta.REMOVED)) { if (element.getElementType() == ICElement.C_PROJECT) { IProject project = element.getCProject().getProject(); - IPathEntryStore store = (IPathEntryStore)storeMap.remove(project); - store.removePathEntryStoreListener(this); - resolvedMap.remove(project); + IPathEntryStore store = (IPathEntryStore)storeMap.get(project); + if (store != null) { + store.fireClosedEvent(project); + } } } ICElementDelta[] affectedChildren= delta.getAffectedChildren(); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryStore.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryStore.java index 44909a73d2e..ed16ff14154 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryStore.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryStore.java @@ -344,12 +344,7 @@ public class PathEntryStore extends AbstractCExtension implements IPathEntryStor CModelManager manager = CModelManager.getDefault(); IProject project = cdesc.getProject(); // Call the listeners. - PathEntryStoreChangedEvent evt = new PathEntryStoreChangedEvent(project); - IPathEntryStoreListener[] observers = new IPathEntryStoreListener[listeners.size()]; - listeners.toArray(observers); - for (int i = 0; i < observers.length; i++) { - observers[i].pathEntryStoreChanged(evt); - } + fireContentChangedEvent(project); } } } @@ -368,4 +363,28 @@ public class PathEntryStore extends AbstractCExtension implements IPathEntryStor listeners.remove(listener); } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.resources.IPathEntryStore#fireContentChangedEvent(IProject) + */ + public void fireContentChangedEvent(IProject project) { + PathEntryStoreChangedEvent evt = new PathEntryStoreChangedEvent(this, project, PathEntryStoreChangedEvent.CONTENT_CHANGED); + IPathEntryStoreListener[] observers = new IPathEntryStoreListener[listeners.size()]; + listeners.toArray(observers); + for (int i = 0; i < observers.length; i++) { + observers[i].pathEntryStoreChanged(evt); + } + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.resources.IPathEntryStore#fireClosedChangedEvent(IProject) + */ + public void fireClosedEvent(IProject project) { + PathEntryStoreChangedEvent evt = new PathEntryStoreChangedEvent(this, project, PathEntryStoreChangedEvent.STORE_CLOSED); + IPathEntryStoreListener[] observers = new IPathEntryStoreListener[listeners.size()]; + listeners.toArray(observers); + for (int i = 0; i < observers.length; i++) { + observers[i].pathEntryStoreChanged(evt); + } + } + } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IPathEntryStore.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IPathEntryStore.java index 7c857ec47d7..98a7186e646 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IPathEntryStore.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IPathEntryStore.java @@ -19,9 +19,52 @@ import org.eclipse.core.runtime.CoreException; * IPathEntryStore */ public interface IPathEntryStore { - + + /** + * Returns the path entries save on the project. + * @param project + * @return + * @throws CoreException + */ IPathEntry[] getRawPathEntries(IProject project) throws CoreException; - void setRawPathEntries(IProject project, IPathEntry[] engries) throws CoreException; + + /** + * Save the entries on the project. + * Setting paths should fire a CONTENT_CHANGED events to the listeners. + * It is up to the listener to calculate the deltas. + * + * @param project + * @param entries + * @throws CoreException + */ + void setRawPathEntries(IProject project, IPathEntry[] entries) throws CoreException; + + /** + * Add a listener to the store. + * + * @param listener + */ void addPathEntryStoreListener(IPathEntryStoreListener listener); + + /** + * Remove the listener form the list. + * + * @param listener + */ void removePathEntryStoreListener(IPathEntryStoreListener listener); + + /** + * Fire a CONTENT_CHANGED event to the listeners. + * + * @param project + */ + void fireContentChangedEvent(IProject project); + + /** + * Fire a CLOSE_STORE event to the listeners. + * + * @param project + */ + void fireClosedEvent(IProject project); + } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/PathEntryStoreChangedEvent.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/PathEntryStoreChangedEvent.java index e3483766862..d3a2a83ba56 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/PathEntryStoreChangedEvent.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/PathEntryStoreChangedEvent.java @@ -19,15 +19,35 @@ import org.eclipse.core.resources.IProject; * PathEntryChangedEvent */ public class PathEntryStoreChangedEvent extends EventObject { + + public static final int CONTENT_CHANGED = 1; + public static final int STORE_CLOSED = 2; + + private final int flags; + private final IProject project; + /** * */ - public PathEntryStoreChangedEvent(Object object) { - super(object); + public PathEntryStoreChangedEvent(IPathEntryStore store, IProject project, int flags) { + super(store); + this.project = project; + this.flags = flags; + } + + public IPathEntryStore getPathEntryStore() { + return (IPathEntryStore)getSource(); } public IProject getProject() { - return (IProject)getSource(); + return project; } + public boolean hasContentChanged() { + return (flags & CONTENT_CHANGED) != 0; + } + + public boolean hasClosed() { + return (flags & STORE_CLOSED) != 0; + } }