1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-19 15:05:36 +02:00

added resource object to profile

This commit is contained in:
Alena Laskavaia 2011-03-11 03:40:48 +00:00
parent 31689d7b5d
commit dfb6654676
5 changed files with 52 additions and 26 deletions

View file

@ -68,6 +68,7 @@ public interface IProblemProfile extends IProblemElement {
/**
* Add a listener for profile changes
*
* @param listener
* @since 2.0
*/
@ -75,8 +76,17 @@ public interface IProblemProfile extends IProblemElement {
/**
* Remove a lister for profile changes
*
* @param listener
* @since 2.0
*/
public void removeProfileChangeListener(IProblemProfileChangeListener listener);
/**
* Get an object associated with profile, usually the resource
*
* @return resource of another object associated with this profile
* @since 2.0
*/
public Object getResource();
}

View file

@ -12,8 +12,6 @@ package org.eclipse.cdt.codan.core.model;
import java.util.EventObject;
import org.eclipse.core.resources.IResource;
/**
* An event object describing the details of a change to a preference
* in the preference store.
@ -29,7 +27,7 @@ public final class ProblemProfileChangeEvent extends EventObject {
private String key;
private Object newValue;
private Object oldValue;
private IResource resourse;
private Object resource;
private IProblemProfile profile;
public static final String PROBLEM_KEY = "problem"; //$NON-NLS-1$
public static final String PROBLEM_PREF_KEY = "problem_params"; //$NON-NLS-1$
@ -44,13 +42,13 @@ public final class ProblemProfileChangeEvent extends EventObject {
* @param oldValue the old preference value
* @param newValue the new preference value
*/
public ProblemProfileChangeEvent(IProblemProfile profile, IResource resource, String key, Object oldValue, Object newValue) {
super(profile);
public ProblemProfileChangeEvent(IProblemProfile profile, Object resource, String key, Object oldValue, Object newValue) {
super(resource);
this.key = key;
this.newValue = newValue;
this.oldValue = oldValue;
this.profile = profile;
this.resourse = resource;
this.resource = resource;
}
/**
@ -59,8 +57,8 @@ public final class ProblemProfileChangeEvent extends EventObject {
*
* @return the node
*/
public IResource getResource() {
return resourse;
public Object getResource() {
return resource;
}
/**

View file

@ -59,7 +59,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
private CheckersRegistry() {
instance = this;
profiles.put(DEFAULT, new ProblemProfile());
profiles.put(DEFAULT, new ProblemProfile(DEFAULT));
readCheckersRegistry();
initialized = true;
}
@ -227,7 +227,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/*
* (non-Javadoc)
*
*
* @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#iterator()
*/
public Iterator<IChecker> iterator() {
@ -247,7 +247,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/*
* (non-Javadoc)
*
*
* @see
* org.eclipse.cdt.codan.core.model.ICheckersRegistry#addChecker(org.eclipse
* .cdt.codan.core.model.IChecker)
@ -258,7 +258,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/*
* (non-Javadoc)
*
*
* @see
* org.eclipse.cdt.codan.core.model.ICheckersRegistry#addProblem(org.eclipse
* .cdt.codan.core.model.IProblem, java.lang.String)
@ -272,7 +272,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/*
* (non-Javadoc)
*
*
* @see
* org.eclipse.cdt.codan.core.model.ICheckersRegistry#addCategory(org.eclipse
* .cdt.codan.core.model.IProblemCategory, java.lang.String)
@ -286,7 +286,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/*
* (non-Javadoc)
*
*
* @see
* org.eclipse.cdt.codan.core.model.ICheckersRegistry#addRefProblem(org.
* eclipse.cdt.codan.core.model.IChecker,
@ -303,7 +303,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/**
* Returns list of problems registered for given checker
*
*
* @return collection of problems or null
*/
public Collection<IProblem> getRefProblems(IChecker checker) {
@ -312,7 +312,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/*
* (non-Javadoc)
*
*
* @see
* org.eclipse.cdt.codan.core.model.ICheckersRegistry#getDefaultProfile()
*/
@ -322,7 +322,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/*
* (non-Javadoc)
*
*
* @see
* org.eclipse.cdt.codan.core.model.ICheckersRegistry#getWorkspaceProfile()
*/
@ -331,6 +331,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
if (wp == null) {
try {
wp = (IProblemProfile) getDefaultProfile().clone();
((ProblemProfile) wp).setResource(ResourcesPlugin.getWorkspace());
// load default values
CodanPreferencesLoader loader = new CodanPreferencesLoader(wp);
loader.load(CodanPreferencesLoader.getWorkspaceNode());
@ -353,7 +354,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/*
* (non-Javadoc)
*
*
* @see
* org.eclipse.cdt.codan.core.model.ICheckersRegistry#getResourceProfile
* (org.eclipse.core.resources.IResource)
@ -364,6 +365,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
if (element instanceof IProject) {
try {
prof = (IProblemProfile) getWorkspaceProfile().clone();
((ProblemProfile) prof).setResource(element);
// load default values
CodanPreferencesLoader loader = new CodanPreferencesLoader(prof);
Preferences projectNode = CodanPreferencesLoader.getProjectNode((IProject) element);
@ -387,7 +389,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/*
* (non-Javadoc)
*
*
* @seeorg.eclipse.cdt.codan.core.model.ICheckersRegistry#
* getResourceProfileWorkingCopy(org.eclipse.core.resources.IResource)
*/
@ -405,7 +407,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
* Tests if a checker is enabled (needs to be run) or not. Checker is
* enabled
* if at least one problem it reports is enabled.
*
*
* @param checker
* @param resource
* @return <code>true</code> if the checker is enabled
@ -428,7 +430,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/**
* Tests if a checker needs to run in a specific launch mode.
*
*
* @param checker
* @param resource
* @param mode

View file

@ -90,7 +90,7 @@ public class CodanProblemElement implements IProblemElement {
*/
protected void notifyChanged(String key) {
if (getProfile() instanceof ProblemProfile) {
((ProblemProfile) getProfile()).fireProfileChangeEvent(null, key, null, this);
((ProblemProfile) getProfile()).fireProfileChangeEvent(key, null, this);
}
}
}

View file

@ -18,7 +18,6 @@ import org.eclipse.cdt.codan.core.model.IProblemCategory;
import org.eclipse.cdt.codan.core.model.IProblemProfile;
import org.eclipse.cdt.codan.core.model.IProblemProfileChangeListener;
import org.eclipse.cdt.codan.core.model.ProblemProfileChangeEvent;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.SafeRunner;
@ -29,8 +28,12 @@ import org.eclipse.core.runtime.SafeRunner;
*/
public class ProblemProfile implements IProblemProfile, Cloneable {
private CodanProblemCategory rootCategory;
private Object resource;
public ProblemProfile() {
/**
* @param resource
*/
public ProblemProfile(Object resource) {
rootCategory = new CodanProblemCategory("root", "root"); //$NON-NLS-1$ //$NON-NLS-2$
rootCategory.setProfile(this);
}
@ -158,11 +161,11 @@ public class ProblemProfile implements IProblemProfile, Cloneable {
/*
* Convenience method for notifying preference change listeners.
*/
protected void fireProfileChangeEvent(IResource resource, String key, Object oldValue, Object newValue) {
protected void fireProfileChangeEvent(String key, Object oldValue, Object newValue) {
if (preferenceChangeListeners == null)
return;
Object[] listeners = preferenceChangeListeners.getListeners();
final ProblemProfileChangeEvent event = new ProblemProfileChangeEvent(this, resource, key, oldValue, newValue);
final ProblemProfileChangeEvent event = new ProblemProfileChangeEvent(this, this.resource, key, oldValue, newValue);
for (int i = 0; i < listeners.length; i++) {
final IProblemProfileChangeListener listener = (IProblemProfileChangeListener) listeners[i];
ISafeRunnable job = new ISafeRunnable() {
@ -177,4 +180,17 @@ public class ProblemProfile implements IProblemProfile, Cloneable {
SafeRunner.run(job);
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.codan.core.model.IProblemProfile#getResource()
*/
public Object getResource() {
return resource;
}
public void setResource(Object resource) {
this.resource = resource;
}
}