1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-20 23:45:23 +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 * Add a listener for profile changes
*
* @param listener * @param listener
* @since 2.0 * @since 2.0
*/ */
@ -75,8 +76,17 @@ public interface IProblemProfile extends IProblemElement {
/** /**
* Remove a lister for profile changes * Remove a lister for profile changes
*
* @param listener * @param listener
* @since 2.0 * @since 2.0
*/ */
public void removeProfileChangeListener(IProblemProfileChangeListener listener); 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 java.util.EventObject;
import org.eclipse.core.resources.IResource;
/** /**
* An event object describing the details of a change to a preference * An event object describing the details of a change to a preference
* in the preference store. * in the preference store.
@ -29,7 +27,7 @@ public final class ProblemProfileChangeEvent extends EventObject {
private String key; private String key;
private Object newValue; private Object newValue;
private Object oldValue; private Object oldValue;
private IResource resourse; private Object resource;
private IProblemProfile profile; private IProblemProfile profile;
public static final String PROBLEM_KEY = "problem"; //$NON-NLS-1$ public static final String PROBLEM_KEY = "problem"; //$NON-NLS-1$
public static final String PROBLEM_PREF_KEY = "problem_params"; //$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 oldValue the old preference value
* @param newValue the new preference value * @param newValue the new preference value
*/ */
public ProblemProfileChangeEvent(IProblemProfile profile, IResource resource, String key, Object oldValue, Object newValue) { public ProblemProfileChangeEvent(IProblemProfile profile, Object resource, String key, Object oldValue, Object newValue) {
super(profile); super(resource);
this.key = key; this.key = key;
this.newValue = newValue; this.newValue = newValue;
this.oldValue = oldValue; this.oldValue = oldValue;
this.profile = profile; this.profile = profile;
this.resourse = resource; this.resource = resource;
} }
/** /**
@ -59,8 +57,8 @@ public final class ProblemProfileChangeEvent extends EventObject {
* *
* @return the node * @return the node
*/ */
public IResource getResource() { public Object getResource() {
return resourse; return resource;
} }
/** /**

View file

@ -59,7 +59,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
private CheckersRegistry() { private CheckersRegistry() {
instance = this; instance = this;
profiles.put(DEFAULT, new ProblemProfile()); profiles.put(DEFAULT, new ProblemProfile(DEFAULT));
readCheckersRegistry(); readCheckersRegistry();
initialized = true; initialized = true;
} }
@ -331,6 +331,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
if (wp == null) { if (wp == null) {
try { try {
wp = (IProblemProfile) getDefaultProfile().clone(); wp = (IProblemProfile) getDefaultProfile().clone();
((ProblemProfile) wp).setResource(ResourcesPlugin.getWorkspace());
// load default values // load default values
CodanPreferencesLoader loader = new CodanPreferencesLoader(wp); CodanPreferencesLoader loader = new CodanPreferencesLoader(wp);
loader.load(CodanPreferencesLoader.getWorkspaceNode()); loader.load(CodanPreferencesLoader.getWorkspaceNode());
@ -364,6 +365,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
if (element instanceof IProject) { if (element instanceof IProject) {
try { try {
prof = (IProblemProfile) getWorkspaceProfile().clone(); prof = (IProblemProfile) getWorkspaceProfile().clone();
((ProblemProfile) prof).setResource(element);
// load default values // load default values
CodanPreferencesLoader loader = new CodanPreferencesLoader(prof); CodanPreferencesLoader loader = new CodanPreferencesLoader(prof);
Preferences projectNode = CodanPreferencesLoader.getProjectNode((IProject) element); Preferences projectNode = CodanPreferencesLoader.getProjectNode((IProject) element);

View file

@ -90,7 +90,7 @@ public class CodanProblemElement implements IProblemElement {
*/ */
protected void notifyChanged(String key) { protected void notifyChanged(String key) {
if (getProfile() instanceof ProblemProfile) { 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.IProblemProfile;
import org.eclipse.cdt.codan.core.model.IProblemProfileChangeListener; import org.eclipse.cdt.codan.core.model.IProblemProfileChangeListener;
import org.eclipse.cdt.codan.core.model.ProblemProfileChangeEvent; 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.ISafeRunnable;
import org.eclipse.core.runtime.ListenerList; import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.SafeRunner; import org.eclipse.core.runtime.SafeRunner;
@ -29,8 +28,12 @@ import org.eclipse.core.runtime.SafeRunner;
*/ */
public class ProblemProfile implements IProblemProfile, Cloneable { public class ProblemProfile implements IProblemProfile, Cloneable {
private CodanProblemCategory rootCategory; 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 = new CodanProblemCategory("root", "root"); //$NON-NLS-1$ //$NON-NLS-2$
rootCategory.setProfile(this); rootCategory.setProfile(this);
} }
@ -158,11 +161,11 @@ public class ProblemProfile implements IProblemProfile, Cloneable {
/* /*
* Convenience method for notifying preference change listeners. * 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) if (preferenceChangeListeners == null)
return; return;
Object[] listeners = preferenceChangeListeners.getListeners(); 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++) { for (int i = 0; i < listeners.length; i++) {
final IProblemProfileChangeListener listener = (IProblemProfileChangeListener) listeners[i]; final IProblemProfileChangeListener listener = (IProblemProfileChangeListener) listeners[i];
ISafeRunnable job = new ISafeRunnable() { ISafeRunnable job = new ISafeRunnable() {
@ -177,4 +180,17 @@ public class ProblemProfile implements IProblemProfile, Cloneable {
SafeRunner.run(job); 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;
}
} }