1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Changes in the PathEntryStore API

This commit is contained in:
Alain Magloire 2004-04-26 20:47:42 +00:00
parent 6797f7dd40
commit dc57a7a2d1
5 changed files with 131 additions and 28 deletions

View file

@ -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

View file

@ -630,12 +630,23 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
*/
public void pathEntryStoreChanged(PathEntryStoreChangedEvent event) {
IProject project = event.getProject();
if (project != null && (CoreModel.hasCNature(project) || CoreModel.hasCCNature(project))) {
// 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);
resolvedMap.remove(cproject);
IPathEntry[] newResolvedEntries = getResolvedPathEntries(cproject);
ICElementDelta[] deltas = generatePathEntryDeltas(cproject, oldResolvedEntries, newResolvedEntries);
if (deltas.length > 0) {
@ -649,6 +660,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}
}
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.IElementChangedListener#elementChanged(org.eclipse.cdt.core.model.ElementChangedEvent)
@ -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();

View file

@ -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);
}
}
}

View file

@ -20,8 +20,51 @@ import org.eclipse.core.runtime.CoreException;
*/
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);
}

View file

@ -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;
}
}