mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
- updated property store to initialize from core
This commit is contained in:
parent
d99739839b
commit
8ebbd32496
22 changed files with 684 additions and 824 deletions
|
@ -3,6 +3,8 @@ package org.eclipse.cdt.codan.core;
|
|||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Plugin;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
/**
|
||||
|
@ -20,6 +22,10 @@ public class CodanCorePlugin extends Plugin {
|
|||
public CodanCorePlugin() {
|
||||
}
|
||||
|
||||
public IEclipsePreferences getStorePreferences() {
|
||||
return new InstanceScope().getNode(PLUGIN_ID);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
|
|
@ -8,11 +8,12 @@
|
|||
* Contributors:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
||||
package org.eclipse.cdt.codan.core;
|
||||
|
||||
/**
|
||||
* Constant definitions for plug-in preferences
|
||||
*/
|
||||
public class PreferenceConstants {
|
||||
public static final String P_RUN_ON_BUILD = "booleanPreference";
|
||||
public static final String P_PROBLEMS = "problems";
|
||||
}
|
|
@ -0,0 +1,145 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Alena Laskavaia
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.builder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.codan.core.model.CodanProblem;
|
||||
import org.eclipse.cdt.codan.core.model.CodanSeverity;
|
||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemsProfile;
|
||||
|
||||
/**
|
||||
* @author Alena
|
||||
*
|
||||
*/
|
||||
public class CodanPreferencesLoader {
|
||||
private static String LIST_SEP = ",";
|
||||
private IProblemsProfile baseModel;
|
||||
|
||||
/**
|
||||
* @param workspaceProfile
|
||||
*/
|
||||
public CodanPreferencesLoader(IProblemsProfile profile) {
|
||||
setInput(profile);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public CodanPreferencesLoader() {
|
||||
}
|
||||
|
||||
public void setInput(Object model) {
|
||||
baseModel = (IProblemsProfile) model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stored as element=true|false,...
|
||||
*
|
||||
* @param stringList
|
||||
* @return
|
||||
*/
|
||||
public Object modelFromString(String stringList) {
|
||||
String[] arr = stringList.split(LIST_SEP);
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
String elem = arr[i];
|
||||
String[] pair = elem.split("=", 2);
|
||||
if (pair.length == 0)
|
||||
continue;
|
||||
String id = pair[0];
|
||||
IProblem p = problemFromString(id);
|
||||
if (p == null) {
|
||||
System.err.println("cannot find '" + id + "'");
|
||||
continue;
|
||||
}
|
||||
if (pair.length == 1) {
|
||||
((CodanProblem) p).setEnabled(true);
|
||||
} else {
|
||||
String check = pair[1];
|
||||
Boolean c = Boolean.valueOf(check);
|
||||
((CodanProblem) p).setEnabled(c);
|
||||
}
|
||||
}
|
||||
return baseModel;
|
||||
}
|
||||
|
||||
protected String problemToString(Object element) {
|
||||
IProblem p = ((IProblem) element);
|
||||
return p.getId() + ":" + p.getSeverity();
|
||||
}
|
||||
|
||||
protected IProblem problemFromString(String string) {
|
||||
String[] pair = string.split(":");
|
||||
if (pair.length == 0)
|
||||
return null;
|
||||
String id = pair[0];
|
||||
String arg = "";
|
||||
if (pair.length > 1) {
|
||||
arg = pair[1];
|
||||
}
|
||||
CodanSeverity sev;
|
||||
try {
|
||||
sev = CodanSeverity.valueOf(arg);
|
||||
} catch (RuntimeException e) {
|
||||
sev = CodanSeverity.Warning;
|
||||
}
|
||||
IProblem prob = baseModel.findProblem(id);
|
||||
if (prob instanceof CodanProblem) {
|
||||
((CodanProblem) prob).setSeverity(sev);
|
||||
}
|
||||
return prob;
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines the given list of items into a single string. This method is the
|
||||
* converse of <code>parseString</code>.
|
||||
* <p>
|
||||
* Subclasses may implement this method.
|
||||
* </p>
|
||||
*
|
||||
* @return the combined string
|
||||
* @see #parseString
|
||||
*/
|
||||
public String modelToString(Object model) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
Map<Object, Boolean> map = fillChecked(model,
|
||||
new HashMap<Object, Boolean>());
|
||||
for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
|
||||
Object element = iterator.next();
|
||||
buf.append(problemToString(element));
|
||||
buf.append('=');
|
||||
buf.append(map.get(element));
|
||||
if (iterator.hasNext())
|
||||
buf.append(LIST_SEP);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param input
|
||||
* @param hashMap
|
||||
* @return
|
||||
*/
|
||||
private Map<Object, Boolean> fillChecked(Object element,
|
||||
HashMap<Object, Boolean> hashMap) {
|
||||
if (element instanceof IProblemsProfile) {
|
||||
IProblemsProfile profile = (IProblemsProfile) element;
|
||||
IProblem[] problems = profile.getProblems();
|
||||
for (IProblem iProblem : problems) {
|
||||
hashMap.put(iProblem, iProblem.isEnabled());
|
||||
}
|
||||
}
|
||||
return hashMap;
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
@ -35,8 +36,10 @@ public abstract class AbstractIndexAstChecker extends AbstractChecker implements
|
|||
void processFile(IFile file) throws CoreException, InterruptedException {
|
||||
this.file = file;
|
||||
// create translation unit and access index
|
||||
ITranslationUnit tu = (ITranslationUnit) CoreModel.getDefault().create(
|
||||
file);
|
||||
ICElement model = CoreModel.getDefault().create(file);
|
||||
if (!(model instanceof ITranslationUnit))
|
||||
return;
|
||||
ITranslationUnit tu = (ITranslationUnit) model;
|
||||
if (tu == null)
|
||||
return; // not a C/C++ file
|
||||
IIndex index = CCorePlugin.getIndexManager().getIndex(tu.getCProject());
|
||||
|
|
|
@ -12,27 +12,34 @@ package org.eclipse.cdt.codan.core.model;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.cdt.codan.core.PreferenceConstants;
|
||||
import org.eclipse.cdt.codan.core.builder.CodanPreferencesLoader;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ProjectScope;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.IExtensionPoint;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
|
||||
public class CheckersRegisry implements Iterable<IChecker> {
|
||||
private static final String EXTENSION_POINT_NAME = "checkers";
|
||||
private static final String CHECKER_ELEMENT = "checker";
|
||||
private static final String PROBLEM_ELEMENT = "problem";
|
||||
private static final Object DEFAULT = "DEFAULT";
|
||||
private Collection<IChecker> checkers = new ArrayList<IChecker>();
|
||||
private static CheckersRegisry instance;
|
||||
private IProblemCategory rootCategory = new CodanProblemCategory("root",
|
||||
"root");
|
||||
private Collection<IProblem> problems = new ArrayList<IProblem>();
|
||||
private HashMap<Object, IProblemsProfile> profiles = new HashMap<Object, IProblemsProfile>();
|
||||
|
||||
private CheckersRegisry() {
|
||||
instance = this;
|
||||
profiles.put(DEFAULT, new ProblemsProfile());
|
||||
readCheckersRegistry();
|
||||
}
|
||||
|
||||
|
@ -92,13 +99,13 @@ public class CheckersRegisry implements Iterable<IChecker> {
|
|||
if (children1 != null) {
|
||||
for (IConfigurationElement ref : children1) {
|
||||
hasRef = true;
|
||||
IProblem p = getProblemById(ref.getAttribute("refId"),
|
||||
null);
|
||||
IProblem p = getDefaultProfile().findProblem(
|
||||
ref.getAttribute("refId"));
|
||||
addRefProblem(checkerObj, p);
|
||||
}
|
||||
}
|
||||
if (!hasRef) {
|
||||
addProblem(new CodanProblem(id, name));
|
||||
addProblem(new CodanProblem(id, name), null);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -120,7 +127,8 @@ public class CheckersRegisry implements Iterable<IChecker> {
|
|||
if (name == null)
|
||||
name = id;
|
||||
CodanProblem p = new CodanProblem(id, name);
|
||||
addProblem(p);
|
||||
String category = getAtt(configurationElement, "category");
|
||||
addProblem(p, category);
|
||||
return p;
|
||||
}
|
||||
return null;
|
||||
|
@ -156,28 +164,68 @@ public class CheckersRegisry implements Iterable<IChecker> {
|
|||
checkers.add(checker);
|
||||
}
|
||||
|
||||
public void addProblem(IProblem p) {
|
||||
problems.add(p); // TODO category
|
||||
((CodanProblemCategory) rootCategory).addChild(p);
|
||||
}
|
||||
|
||||
public Object getProblemsTree() {
|
||||
return rootCategory;
|
||||
public void addProblem(IProblem p, String category) {
|
||||
((ProblemsProfile) getDefaultProfile()).addProblem(p,
|
||||
getDefaultProfile().getRoot());
|
||||
}
|
||||
|
||||
public void addRefProblem(IChecker c, IProblem p) {
|
||||
}
|
||||
|
||||
public IProblem findProblem(String id) {
|
||||
for (Iterator iterator = problems.iterator(); iterator.hasNext();) {
|
||||
IProblem p = (IProblem) iterator.next();
|
||||
if (p.getId().equals(id))
|
||||
return p;
|
||||
}
|
||||
return null;
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public IProblemsProfile getDefaultProfile() {
|
||||
return profiles.get(DEFAULT);
|
||||
}
|
||||
|
||||
public IProblem getProblemById(String id, IFile file) {
|
||||
return findProblem(id);
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public IProblemsProfile getWorkspaceProfile() {
|
||||
IProblemsProfile wp = profiles.get(ResourcesPlugin.getWorkspace());
|
||||
if (wp == null) {
|
||||
try {
|
||||
wp = (IProblemsProfile) getDefaultProfile().clone();
|
||||
// load default values
|
||||
CodanPreferencesLoader loader = new CodanPreferencesLoader(wp);
|
||||
String s = CodanCorePlugin.getDefault().getStorePreferences()
|
||||
.get(PreferenceConstants.P_PROBLEMS, "");
|
||||
loader.modelFromString(s);
|
||||
} catch (CloneNotSupportedException e) {
|
||||
wp = getDefaultProfile();
|
||||
}
|
||||
}
|
||||
return wp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param element
|
||||
* @return
|
||||
*/
|
||||
public IProblemsProfile getResourceProfile(IResource element) {
|
||||
IProblemsProfile prof = profiles.get(element);
|
||||
if (prof == null) {
|
||||
if (element instanceof IProject) {
|
||||
try {
|
||||
prof = (IProblemsProfile) getWorkspaceProfile().clone();
|
||||
// load default values
|
||||
CodanPreferencesLoader loader = new CodanPreferencesLoader(
|
||||
prof);
|
||||
IEclipsePreferences node = new ProjectScope(
|
||||
(IProject) element)
|
||||
.getNode(CodanCorePlugin.PLUGIN_ID);
|
||||
String s = node.get(PreferenceConstants.P_PROBLEMS, "");
|
||||
loader.modelFromString(s);
|
||||
} catch (CloneNotSupportedException e) {
|
||||
// cant
|
||||
}
|
||||
} else if (element.getParent() != null) {
|
||||
prof = getResourceProfile(element.getParent());
|
||||
} else {
|
||||
prof = getResourceProfile(element.getProject());
|
||||
}
|
||||
}
|
||||
return prof;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,4 +56,14 @@ public class CodanProblem implements IProblem {
|
|||
public void setEnabled(boolean checked) {
|
||||
this.enabled = checked;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#clone()
|
||||
*/
|
||||
@Override
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,13 +11,13 @@
|
|||
package org.eclipse.cdt.codan.core.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
public class CodanProblemCategory implements IProblemCategory {
|
||||
public class CodanProblemCategory implements IProblemCategory, Cloneable {
|
||||
private String id;
|
||||
private String name;
|
||||
private ArrayList<IProblemElement> list = new ArrayList<IProblemElement>();
|
||||
|
||||
private ArrayList list = new ArrayList();
|
||||
public CodanProblemCategory(String id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
|
@ -35,6 +35,7 @@ public class CodanProblemCategory implements IProblemCategory {
|
|||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Object[] getChildren() {
|
||||
return list.toArray();
|
||||
}
|
||||
|
@ -43,10 +44,56 @@ public class CodanProblemCategory implements IProblemCategory {
|
|||
list.add(p);
|
||||
}
|
||||
|
||||
public IProblemCategory getParent() {
|
||||
// TODO Auto-generated method stub
|
||||
public IProblem findProblem(String id) {
|
||||
Object[] children = this.getChildren();
|
||||
for (Object object : children) {
|
||||
if (object instanceof IProblemCategory) {
|
||||
IProblemCategory cat = (IProblemCategory) object;
|
||||
IProblem found = cat.findProblem(id);
|
||||
if (found != null)
|
||||
return found;
|
||||
} else if (object instanceof IProblem) {
|
||||
IProblem p = (IProblem) object;
|
||||
if (p.getId().equals(id))
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public IProblemCategory findCategory(String id) {
|
||||
if (getId().equals(id))
|
||||
return this;
|
||||
Object[] children = getChildren();
|
||||
for (Object object : children) {
|
||||
if (object instanceof IProblemCategory) {
|
||||
IProblemCategory cat = (IProblemCategory) object;
|
||||
IProblemCategory found = cat.findCategory(id);
|
||||
if (found != null)
|
||||
return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#clone()
|
||||
*/
|
||||
@Override
|
||||
public Object clone() {
|
||||
try {
|
||||
CodanProblemCategory clone = (CodanProblemCategory) super.clone();
|
||||
clone.list = new ArrayList<IProblemElement>();
|
||||
for (Iterator<IProblemElement> iterator = this.list.iterator(); iterator
|
||||
.hasNext();) {
|
||||
IProblemElement child = iterator.next();
|
||||
clone.list.add((IProblemElement) child.clone());
|
||||
}
|
||||
return clone;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,8 +26,8 @@ public class ErrorReporter {
|
|||
throw new NullPointerException("file");
|
||||
if (id == null)
|
||||
throw new NullPointerException("id");
|
||||
IProblem problem = CheckersRegisry.getInstance().getProblemById(id,
|
||||
file);
|
||||
IProblem problem = CheckersRegisry.getInstance()
|
||||
.getResourceProfile(file).findProblem(id);
|
||||
if (problem == null)
|
||||
throw new IllegalArgumentException("Id is not registered");
|
||||
if (problem.isEnabled() == false)
|
||||
|
|
|
@ -10,8 +10,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.model;
|
||||
|
||||
|
||||
public interface IProblem {
|
||||
public interface IProblem extends IProblemElement {
|
||||
String getName();
|
||||
|
||||
String getId();
|
||||
|
|
|
@ -10,12 +10,22 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.model;
|
||||
|
||||
public interface IProblemCategory {
|
||||
public interface IProblemCategory extends IProblemElement {
|
||||
String getName();
|
||||
|
||||
String getId();
|
||||
|
||||
Object[] getChildren();
|
||||
|
||||
IProblemCategory getParent();
|
||||
/**
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
IProblem findProblem(String id);
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
IProblemCategory findCategory(String id);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Alena Laskavaia
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.model;
|
||||
|
||||
/**
|
||||
* @author Alena
|
||||
*
|
||||
*/
|
||||
public interface IProblemElement extends Cloneable {
|
||||
Object clone() throws CloneNotSupportedException;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Alena Laskavaia
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.model;
|
||||
|
||||
/**
|
||||
* @author Alena
|
||||
*
|
||||
*/
|
||||
public interface IProblemsProfile extends IProblemElement {
|
||||
IProblemCategory getRoot();
|
||||
|
||||
IProblem findProblem(String id);
|
||||
|
||||
IProblem[] getProblems();
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Alena Laskavaia
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author Alena
|
||||
*
|
||||
*/
|
||||
public class ProblemsProfile implements IProblemsProfile, Cloneable {
|
||||
private IProblemCategory rootCategory = new CodanProblemCategory("root",
|
||||
"root");
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.cdt.codan.core.model.IProblemsProfile#getProblem(java.lang
|
||||
* .String)
|
||||
*/
|
||||
@Override
|
||||
public IProblem findProblem(String id) {
|
||||
return getRoot().findProblem(id);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.codan.core.model.IProblemsProfile#getProblems()
|
||||
*/
|
||||
@Override
|
||||
public IProblem[] getProblems() {
|
||||
Collection<IProblem> problems = new ArrayList<IProblem>();
|
||||
collectProblems(getRoot(), problems);
|
||||
return problems.toArray(new IProblem[problems.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param root
|
||||
* @param problems
|
||||
*/
|
||||
protected void collectProblems(IProblemCategory parent,
|
||||
Collection<IProblem> problems) {
|
||||
Object[] children = parent.getChildren();
|
||||
for (Object object : children) {
|
||||
if (object instanceof IProblemCategory) {
|
||||
IProblemCategory cat = (IProblemCategory) object;
|
||||
collectProblems(cat, problems);
|
||||
} else if (object instanceof IProblem) {
|
||||
problems.add((IProblem) object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.codan.core.model.IProblemsProfile#getRoot()
|
||||
*/
|
||||
@Override
|
||||
public IProblemCategory getRoot() {
|
||||
return rootCategory;
|
||||
}
|
||||
|
||||
public void addProblem(IProblem p, IProblemCategory cat) {
|
||||
if (cat == null)
|
||||
cat = getRoot();
|
||||
((CodanProblemCategory) cat).addChild(p);
|
||||
}
|
||||
|
||||
public IProblemCategory findCategory(String id) {
|
||||
return getRoot().findCategory(id);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#clone()
|
||||
*/
|
||||
@Override
|
||||
public Object clone() {
|
||||
try {
|
||||
ProblemsProfile clone = (ProblemsProfile) super.clone();
|
||||
clone.rootCategory = (IProblemCategory) ((CodanProblemCategory) this.rootCategory)
|
||||
.clone();
|
||||
return clone;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +1,17 @@
|
|||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
||||
import org.eclipse.cdt.codan.core.PreferenceConstants;
|
||||
import org.eclipse.cdt.codan.ui.actions.ToggleNatureAction;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ProjectScope;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.core.runtime.preferences.IScopeContext;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.eclipse.jface.preference.BooleanFieldEditor;
|
||||
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
||||
import org.eclipse.ui.IWorkbenchPropertyPage;
|
||||
import org.eclipse.ui.preferences.ScopedPreferenceStore;
|
||||
|
||||
public class BuildPropertyPage extends FieldEditorPreferencePage implements
|
||||
IWorkbenchPropertyPage {
|
||||
|
@ -77,9 +82,13 @@ public class BuildPropertyPage extends FieldEditorPreferencePage implements
|
|||
*/
|
||||
public void setElement(IAdaptable element) {
|
||||
this.element = element;
|
||||
setPreferenceStore(new PropertyStore((IResource) getElement(),
|
||||
org.eclipse.cdt.codan.ui.Activator.getDefault()
|
||||
.getPreferenceStore(), getPageId()));
|
||||
ProjectScope ps = new ProjectScope((IProject) getElement());
|
||||
ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps,
|
||||
CodanCorePlugin.PLUGIN_ID);
|
||||
scoped
|
||||
.setSearchContexts(new IScopeContext[] { ps,
|
||||
new InstanceScope() });
|
||||
setPreferenceStore(scoped);
|
||||
}
|
||||
|
||||
protected String getPageId() {
|
||||
|
|
|
@ -10,10 +10,6 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jface.preference.FieldEditor;
|
||||
import org.eclipse.jface.viewers.CheckStateChangedEvent;
|
||||
import org.eclipse.jface.viewers.CheckboxTreeViewer;
|
||||
|
@ -40,7 +36,7 @@ import org.eclipse.swt.widgets.Tree;
|
|||
* <code>getListSeparator</code> framework methods.
|
||||
* </p>
|
||||
*/
|
||||
public class CheckedTreeEditor extends FieldEditor implements
|
||||
public abstract class CheckedTreeEditor extends FieldEditor implements
|
||||
ICheckStateListener {
|
||||
/**
|
||||
* The list widget; <code>null</code> if none (before creation or after
|
||||
|
@ -49,7 +45,6 @@ public class CheckedTreeEditor extends FieldEditor implements
|
|||
private CheckboxTreeViewer treeViewer;
|
||||
private Composite listParent;
|
||||
private boolean isValid;
|
||||
private static String LIST_SEP = ",";
|
||||
private boolean emptySelectionAllowed = false;
|
||||
|
||||
/**
|
||||
|
@ -121,10 +116,16 @@ public class CheckedTreeEditor extends FieldEditor implements
|
|||
protected void doLoad() {
|
||||
if (getTreeControl() != null) {
|
||||
String s = getPreferenceStore().getString(getPreferenceName());
|
||||
setTreeData(parseString(s));
|
||||
getViewer().setInput(modelFromString(s));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param s
|
||||
* @return
|
||||
*/
|
||||
protected abstract Object modelFromString(String s);
|
||||
|
||||
Control getTreeControl() {
|
||||
if (treeViewer == null)
|
||||
return null;
|
||||
|
@ -135,23 +136,6 @@ public class CheckedTreeEditor extends FieldEditor implements
|
|||
return treeViewer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param map
|
||||
*/
|
||||
private void setTreeData(Map<Object, Boolean> checked) {
|
||||
for (Iterator iter = checked.keySet().iterator(); iter.hasNext();) {
|
||||
Object element = iter.next();
|
||||
if (element != null) {
|
||||
Boolean state = checked.get(element);
|
||||
treeViewer.setChecked(element, state);
|
||||
checkStateChanged(new CheckStateChangedEvent(treeViewer,
|
||||
element, state));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @Override
|
||||
* @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent)
|
||||
|
@ -206,7 +190,7 @@ public class CheckedTreeEditor extends FieldEditor implements
|
|||
treeViewer.refresh();
|
||||
String s = getPreferenceStore().getDefaultString(
|
||||
getPreferenceName());
|
||||
setTreeData(parseString(s));
|
||||
getViewer().setInput(modelFromString(s));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,7 +198,7 @@ public class CheckedTreeEditor extends FieldEditor implements
|
|||
* (non-Javadoc) Method declared on FieldEditor.
|
||||
*/
|
||||
protected void doStore() {
|
||||
String s = unparseTree();
|
||||
String s = modelToString(getViewer().getInput());
|
||||
if (s != null) {
|
||||
getPreferenceStore().setValue(getPreferenceName(), s);
|
||||
}
|
||||
|
@ -266,35 +250,6 @@ public class CheckedTreeEditor extends FieldEditor implements
|
|||
return treeViewer.getControl().getShell();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stored as element=true|false,...
|
||||
*
|
||||
* @param stringList
|
||||
* @return
|
||||
*/
|
||||
public Map<Object, Boolean> parseString(String stringList) {
|
||||
Map<Object, Boolean> data = new HashMap<Object, Boolean>();
|
||||
String[] arr = stringList.split(LIST_SEP);
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
String elem = arr[i];
|
||||
String[] pair = elem.split("=", 2);
|
||||
if (pair.length == 0)
|
||||
continue;
|
||||
String id = pair[0];
|
||||
if (pair.length == 1) {
|
||||
data.put(parseObject(id), true);
|
||||
continue;
|
||||
}
|
||||
String check = pair[1];
|
||||
data.put(parseObject(id), Boolean.valueOf(check));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
protected Object parseObject(String string) {
|
||||
return string;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc) Method declared on FieldEditor.
|
||||
*/
|
||||
|
@ -320,49 +275,9 @@ public class CheckedTreeEditor extends FieldEditor implements
|
|||
* </p>
|
||||
*
|
||||
* @return the combined string
|
||||
* @see #parseString
|
||||
* @see #stringToModel
|
||||
*/
|
||||
protected String unparseTree() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
Map<Object, Boolean> map = fillElementsFromUi(treeViewer.getInput(),
|
||||
new HashMap<Object, Boolean>());
|
||||
for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
|
||||
Object element = iterator.next();
|
||||
buf.append(unparseElement(element));
|
||||
buf.append('=');
|
||||
buf.append(map.get(element));
|
||||
if (iterator.hasNext())
|
||||
buf.append(LIST_SEP);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param element
|
||||
* @return
|
||||
*/
|
||||
protected String unparseElement(Object element) {
|
||||
return element.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param root
|
||||
*/
|
||||
public Map<Object, Boolean> fillElementsFromUi(Object root,
|
||||
Map<Object, Boolean> checked) {
|
||||
|
||||
Object[] children = getContentProvider().getChildren(root);
|
||||
if (children.length == 0) {
|
||||
checked.put(root, treeViewer.getChecked(root));
|
||||
} else {
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
Object object = children[i];
|
||||
fillElementsFromUi(object, checked);
|
||||
}
|
||||
}
|
||||
|
||||
return checked;
|
||||
}
|
||||
protected abstract String modelToString(Object model);
|
||||
|
||||
protected void createControl(Composite parent) {
|
||||
GridLayout ly = (GridLayout) parent.getLayout();
|
||||
|
@ -406,7 +321,6 @@ public class CheckedTreeEditor extends FieldEditor implements
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
public final boolean isEmptySelectionAllowed() {
|
||||
return emptySelectionAllowed;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
||||
import org.eclipse.cdt.codan.core.model.CheckersRegisry;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
import org.eclipse.ui.IWorkbenchPreferencePage;
|
||||
|
@ -46,7 +48,10 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
|||
*/
|
||||
public void createFieldEditors() {
|
||||
CheckedTreeEditor checkedTreeEditor = new ProblemsTreeEditor(
|
||||
getFieldEditorParent());
|
||||
getFieldEditorParent(), isPropertyPage() ? CheckersRegisry
|
||||
.getInstance().getResourceProfile(
|
||||
(IResource) getElement()) : CheckersRegisry
|
||||
.getInstance().getWorkspaceProfile());
|
||||
addField(checkedTreeEditor);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,10 +14,15 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ProjectScope;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.core.runtime.QualifiedName;
|
||||
import org.eclipse.core.runtime.preferences.IScopeContext;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.eclipse.jface.preference.FieldEditor;
|
||||
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
||||
import org.eclipse.jface.preference.IPreferenceNode;
|
||||
|
@ -37,43 +42,39 @@ import org.eclipse.swt.widgets.Button;
|
|||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.ui.IWorkbenchPropertyPage;
|
||||
import org.eclipse.ui.preferences.ScopedPreferenceStore;
|
||||
|
||||
/**
|
||||
* @author Berthold Daum
|
||||
*/
|
||||
public abstract class FieldEditorOverlayPage
|
||||
extends FieldEditorPreferencePage
|
||||
implements IWorkbenchPropertyPage {
|
||||
|
||||
/*** Name of resource property for the selection of workbench or project settings ***/
|
||||
public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
|
||||
implements IWorkbenchPropertyPage {
|
||||
/***
|
||||
* Name of resource property for the selection of workbench or project
|
||||
* settings
|
||||
***/
|
||||
public static final String USEPROJECTSETTINGS = "useProjectSettings"; //$NON-NLS-1$
|
||||
|
||||
private static final String FALSE = "false"; //$NON-NLS-1$
|
||||
private static final String TRUE = "true"; //$NON-NLS-1$
|
||||
|
||||
// Stores all created field editors
|
||||
private List editors = new ArrayList();
|
||||
|
||||
// Stores owning element of properties
|
||||
private IAdaptable element;
|
||||
|
||||
// Additional buttons for property pages
|
||||
private Button useWorkspaceSettingsButton,
|
||||
useProjectSettingsButton,
|
||||
configureButton;
|
||||
|
||||
private Button useWorkspaceSettingsButton, useProjectSettingsButton,
|
||||
configureButton;
|
||||
// Overlay preference store for property pages
|
||||
private IPreferenceStore overlayStore;
|
||||
|
||||
// The image descriptor of this pages title image
|
||||
private ImageDescriptor image;
|
||||
|
||||
// Cache for page id
|
||||
private String pageId;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param style - layout style
|
||||
*
|
||||
* @param style
|
||||
* - layout style
|
||||
*/
|
||||
public FieldEditorOverlayPage(int style) {
|
||||
super(style);
|
||||
|
@ -81,8 +82,11 @@ public abstract class FieldEditorOverlayPage
|
|||
|
||||
/**
|
||||
* Constructor
|
||||
* @param title - title string
|
||||
* @param style - layout style
|
||||
*
|
||||
* @param title
|
||||
* - title string
|
||||
* @param style
|
||||
* - layout style
|
||||
*/
|
||||
public FieldEditorOverlayPage(String title, int style) {
|
||||
super(title, style);
|
||||
|
@ -90,28 +94,30 @@ public abstract class FieldEditorOverlayPage
|
|||
|
||||
/**
|
||||
* Constructor
|
||||
* @param title - title string
|
||||
* @param image - title image
|
||||
* @param style - layout style
|
||||
*
|
||||
* @param title
|
||||
* - title string
|
||||
* @param image
|
||||
* - title image
|
||||
* @param style
|
||||
* - layout style
|
||||
*/
|
||||
public FieldEditorOverlayPage(
|
||||
String title,
|
||||
ImageDescriptor image,
|
||||
int style) {
|
||||
public FieldEditorOverlayPage(String title, ImageDescriptor image, int style) {
|
||||
super(title, image, style);
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id of the current preference page as defined in plugin.xml
|
||||
* Subclasses must implement.
|
||||
* Subclasses must implement.
|
||||
*
|
||||
* @return - the qualifier
|
||||
*/
|
||||
protected abstract String getPageId();
|
||||
|
||||
/**
|
||||
* Receives the object that owns the properties shown in this property page.
|
||||
* Receives the object that owns the properties shown in this property page.
|
||||
*
|
||||
* @see org.eclipse.ui.IWorkbenchPropertyPage#setElement(org.eclipse.core.runtime.IAdaptable)
|
||||
*/
|
||||
public void setElement(IAdaptable element) {
|
||||
|
@ -120,6 +126,7 @@ public abstract class FieldEditorOverlayPage
|
|||
|
||||
/**
|
||||
* Delivers the object that owns the properties shown in this property page.
|
||||
*
|
||||
* @see org.eclipse.ui.IWorkbenchPropertyPage#getElement()
|
||||
*/
|
||||
public IAdaptable getElement() {
|
||||
|
@ -128,15 +135,16 @@ public abstract class FieldEditorOverlayPage
|
|||
|
||||
/**
|
||||
* Returns true if this instance represents a property page
|
||||
*
|
||||
* @return - true for property pages, false for preference pages
|
||||
*/
|
||||
public boolean isPropertyPage() {
|
||||
return getElement() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* We override the addField method. This allows us to store each field editor added by subclasses
|
||||
* in a list for later processing.
|
||||
/**
|
||||
* We override the addField method. This allows us to store each field
|
||||
* editor added by subclasses in a list for later processing.
|
||||
*
|
||||
* @see org.eclipse.jface.preference.FieldEditorPreferencePage#addField(org.eclipse.jface.preference.FieldEditor)
|
||||
*/
|
||||
|
@ -146,9 +154,9 @@ public abstract class FieldEditorOverlayPage
|
|||
}
|
||||
|
||||
/**
|
||||
* We override the createControl method.
|
||||
* In case of property pages we create a new PropertyStore as local preference store.
|
||||
* After all control have been create, we enable/disable these controls.
|
||||
* We override the createControl method. In case of property pages we create
|
||||
* a new PropertyStore as local preference store. After all control have
|
||||
* been create, we enable/disable these controls.
|
||||
*
|
||||
* @see org.eclipse.jface.preference.PreferencePage#createControl()
|
||||
*/
|
||||
|
@ -158,11 +166,12 @@ public abstract class FieldEditorOverlayPage
|
|||
// Cache the page id
|
||||
pageId = getPageId();
|
||||
// Create an overlay preference store and fill it with properties
|
||||
overlayStore =
|
||||
new PropertyStore(
|
||||
(IResource) getElement(),
|
||||
super.getPreferenceStore(),
|
||||
pageId);
|
||||
ProjectScope ps = new ProjectScope((IProject) getElement());
|
||||
ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps,
|
||||
CodanCorePlugin.PLUGIN_ID);
|
||||
scoped.setSearchContexts(new IScopeContext[] { ps,
|
||||
new InstanceScope() });
|
||||
overlayStore = scoped;
|
||||
// Set overlay store as current preference store
|
||||
}
|
||||
super.createControl(parent);
|
||||
|
@ -171,9 +180,9 @@ public abstract class FieldEditorOverlayPage
|
|||
updateFieldEditors();
|
||||
}
|
||||
|
||||
/**
|
||||
* We override the createContents method.
|
||||
* In case of property pages we insert two radio buttons at the top of the page.
|
||||
/**
|
||||
* We override the createContents method. In case of property pages we
|
||||
* insert two radio buttons at the top of the page.
|
||||
*
|
||||
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
|
||||
*/
|
||||
|
@ -184,8 +193,11 @@ public abstract class FieldEditorOverlayPage
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes a selection group with two choice buttons and one push button.
|
||||
* @param parent - the parent composite
|
||||
* Creates and initializes a selection group with two choice buttons and one
|
||||
* push button.
|
||||
*
|
||||
* @param parent
|
||||
* - the parent composite
|
||||
*/
|
||||
private void createSelectionGroup(Composite parent) {
|
||||
Composite comp = new Composite(parent, SWT.NONE);
|
||||
|
@ -197,10 +209,13 @@ public abstract class FieldEditorOverlayPage
|
|||
Composite radioGroup = new Composite(comp, SWT.NONE);
|
||||
radioGroup.setLayout(new GridLayout());
|
||||
radioGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
useWorkspaceSettingsButton = createRadioButton(radioGroup, Messages.getString("OverlayPage.Use_Workspace_Settings")); //$NON-NLS-1$
|
||||
useProjectSettingsButton = createRadioButton(radioGroup, Messages.getString("OverlayPage.Use_Project_Settings")); //$NON-NLS-1$
|
||||
useWorkspaceSettingsButton = createRadioButton(radioGroup, Messages
|
||||
.getString("OverlayPage.Use_Workspace_Settings")); //$NON-NLS-1$
|
||||
useProjectSettingsButton = createRadioButton(radioGroup, Messages
|
||||
.getString("OverlayPage.Use_Project_Settings")); //$NON-NLS-1$
|
||||
configureButton = new Button(comp, SWT.PUSH);
|
||||
configureButton.setText(Messages.getString("OverlayPage.Configure_Workspace_Settings")); //$NON-NLS-1$
|
||||
configureButton.setText(Messages
|
||||
.getString("OverlayPage.Configure_Workspace_Settings")); //$NON-NLS-1$
|
||||
configureButton.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
configureWorkspaceSettings();
|
||||
|
@ -208,9 +223,9 @@ public abstract class FieldEditorOverlayPage
|
|||
});
|
||||
// Set workspace/project radio buttons
|
||||
try {
|
||||
String use =
|
||||
((IResource) getElement()).getPersistentProperty(
|
||||
new QualifiedName(pageId, USEPROJECTSETTINGS));
|
||||
String use = ((IResource) getElement())
|
||||
.getPersistentProperty(new QualifiedName(pageId,
|
||||
USEPROJECTSETTINGS));
|
||||
if (TRUE.equals(use)) {
|
||||
useProjectSettingsButton.setSelection(true);
|
||||
configureButton.setEnabled(false);
|
||||
|
@ -223,8 +238,11 @@ public abstract class FieldEditorOverlayPage
|
|||
|
||||
/**
|
||||
* Convenience method creating a radio button
|
||||
* @param parent - the parent composite
|
||||
* @param label - the button label
|
||||
*
|
||||
* @param parent
|
||||
* - the parent composite
|
||||
* @param label
|
||||
* - the button label
|
||||
* @return - the new button
|
||||
*/
|
||||
private Button createRadioButton(Composite parent, String label) {
|
||||
|
@ -232,8 +250,8 @@ public abstract class FieldEditorOverlayPage
|
|||
button.setText(label);
|
||||
button.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
configureButton.setEnabled(
|
||||
button == useWorkspaceSettingsButton);
|
||||
configureButton
|
||||
.setEnabled(button == useWorkspaceSettingsButton);
|
||||
updateFieldEditors();
|
||||
}
|
||||
});
|
||||
|
@ -241,8 +259,9 @@ public abstract class FieldEditorOverlayPage
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns in case of property pages the overlay store,
|
||||
* in case of preference pages the standard preference store
|
||||
* Returns in case of property pages the overlay store, in case of
|
||||
* preference pages the standard preference store
|
||||
*
|
||||
* @see org.eclipse.jface.preference.PreferencePage#getPreferenceStore()
|
||||
*/
|
||||
public IPreferenceStore getPreferenceStore() {
|
||||
|
@ -255,15 +274,17 @@ public abstract class FieldEditorOverlayPage
|
|||
* Enables or disables the field editors and buttons of this page
|
||||
*/
|
||||
private void updateFieldEditors() {
|
||||
// We iterate through all field editors
|
||||
// We iterate through all field editors
|
||||
boolean enabled = useProjectSettingsButton.getSelection();
|
||||
updateFieldEditors(enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables the field editors and buttons of this page
|
||||
* Subclasses may override.
|
||||
* @param enabled - true if enabled
|
||||
* Enables or disables the field editors and buttons of this page Subclasses
|
||||
* may override.
|
||||
*
|
||||
* @param enabled
|
||||
* - true if enabled
|
||||
*/
|
||||
protected void updateFieldEditors(boolean enabled) {
|
||||
Composite parent = getFieldEditorParent();
|
||||
|
@ -274,10 +295,10 @@ public abstract class FieldEditorOverlayPage
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* We override the performOk method. In case of property pages we copy the values in the
|
||||
* overlay store into the property values of the selected project.
|
||||
* We also save the state of the radio buttons.
|
||||
/**
|
||||
* We override the performOk method. In case of property pages we copy the
|
||||
* values in the overlay store into the property values of the selected
|
||||
* project. We also save the state of the radio buttons.
|
||||
*
|
||||
* @see org.eclipse.jface.preference.IPreferencePage#performOk()
|
||||
*/
|
||||
|
@ -287,11 +308,10 @@ public abstract class FieldEditorOverlayPage
|
|||
// Save state of radiobuttons in project properties
|
||||
IResource resource = (IResource) getElement();
|
||||
try {
|
||||
String value =
|
||||
(useProjectSettingsButton.getSelection()) ? TRUE : FALSE;
|
||||
resource.setPersistentProperty(
|
||||
new QualifiedName(pageId, USEPROJECTSETTINGS),
|
||||
value);
|
||||
String value = (useProjectSettingsButton.getSelection()) ? TRUE
|
||||
: FALSE;
|
||||
resource.setPersistentProperty(new QualifiedName(pageId,
|
||||
USEPROJECTSETTINGS), value);
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
}
|
||||
|
@ -320,8 +340,8 @@ public abstract class FieldEditorOverlayPage
|
|||
protected void configureWorkspaceSettings() {
|
||||
try {
|
||||
// create a new instance of the current class
|
||||
IPreferencePage page =
|
||||
(IPreferencePage) this.getClass().newInstance();
|
||||
IPreferencePage page = (IPreferencePage) this.getClass()
|
||||
.newInstance();
|
||||
page.setTitle(getTitle());
|
||||
page.setImageDescriptor(image);
|
||||
// and show it
|
||||
|
@ -335,15 +355,18 @@ public abstract class FieldEditorOverlayPage
|
|||
|
||||
/**
|
||||
* Show a single preference pages
|
||||
* @param id - the preference page identification
|
||||
* @param page - the preference page
|
||||
*
|
||||
* @param id
|
||||
* - the preference page identification
|
||||
* @param page
|
||||
* - the preference page
|
||||
*/
|
||||
protected void showPreferencePage(String id, IPreferencePage page) {
|
||||
final IPreferenceNode targetNode = new PreferenceNode(id, page);
|
||||
PreferenceManager manager = new PreferenceManager();
|
||||
manager.addToRoot(targetNode);
|
||||
final PreferenceDialog dialog =
|
||||
new PreferenceDialog(getControl().getShell(), manager);
|
||||
final PreferenceDialog dialog = new PreferenceDialog(getControl()
|
||||
.getShell(), manager);
|
||||
BusyIndicator.showWhile(getControl().getDisplay(), new Runnable() {
|
||||
public void run() {
|
||||
dialog.create();
|
||||
|
@ -352,5 +375,4 @@ public abstract class FieldEditorOverlayPage
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,334 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003 Berthold Daum.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Berthold Daum
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.QualifiedName;
|
||||
import org.eclipse.jface.preference.IPreferenceNode;
|
||||
import org.eclipse.jface.preference.IPreferencePage;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.preference.PreferenceDialog;
|
||||
import org.eclipse.jface.preference.PreferenceManager;
|
||||
import org.eclipse.jface.preference.PreferenceNode;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.BusyIndicator;
|
||||
import org.eclipse.swt.custom.CTabFolder;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.TabFolder;
|
||||
import org.eclipse.ui.dialogs.PropertyPage;
|
||||
import org.eclipse.ui.part.PageBook;
|
||||
|
||||
/**
|
||||
* @author Berthold Daum
|
||||
*/
|
||||
public abstract class OverlayPage extends PropertyPage {
|
||||
|
||||
/*** Name of resource property for the selection of workbench or project settings ***/
|
||||
public static final String USEPROJECTSETTINGS = "useProjectSettings"; //$NON-NLS-1$
|
||||
|
||||
private static final String FALSE = "false"; //$NON-NLS-1$
|
||||
private static final String TRUE = "true"; //$NON-NLS-1$
|
||||
|
||||
// Additional buttons for property pages
|
||||
private Button useWorkspaceSettingsButton,
|
||||
useProjectSettingsButton,
|
||||
configureButton;
|
||||
|
||||
// Overlay preference store for property pages
|
||||
private PropertyStore overlayStore;
|
||||
|
||||
// The image descriptor of this pages title image
|
||||
private ImageDescriptor image;
|
||||
|
||||
// Cache for page id
|
||||
private String pageId;
|
||||
|
||||
// Container for subclass controls
|
||||
private Composite contents;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public OverlayPage() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param title - title string
|
||||
*/
|
||||
public OverlayPage(String title) {
|
||||
super();
|
||||
setTitle(title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param title - title string
|
||||
* @param image - title image
|
||||
*/
|
||||
public OverlayPage(String title, ImageDescriptor image) {
|
||||
super();
|
||||
setTitle(title);
|
||||
setImageDescriptor(image);
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id of the current preference page as defined in plugin.xml
|
||||
* Subclasses must implement.
|
||||
*
|
||||
* @return - the qualifier
|
||||
*/
|
||||
protected abstract String getPageId();
|
||||
|
||||
/**
|
||||
* Returns true if this instance represents a property page
|
||||
* @return - true for property pages, false for preference pages
|
||||
*/
|
||||
public boolean isPropertyPage() {
|
||||
return getElement() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* We need to implement createContents method. In case of property pages we insert two radio buttons
|
||||
* and a push button at the top of the page. Below this group we create a new composite for the contents
|
||||
* created by subclasses.
|
||||
*
|
||||
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
|
||||
*/
|
||||
protected Control createContents(Composite parent) {
|
||||
if (isPropertyPage())
|
||||
createSelectionGroup(parent);
|
||||
contents = new Composite(parent, SWT.NONE);
|
||||
GridLayout layout = new GridLayout();
|
||||
layout.marginHeight = 0;
|
||||
layout.marginWidth = 0;
|
||||
contents.setLayout(layout);
|
||||
contents.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
return contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes a selection group with two choice buttons and one push button.
|
||||
* @param parent - the parent composite
|
||||
*/
|
||||
private void createSelectionGroup(Composite parent) {
|
||||
Composite comp = new Composite(parent, SWT.NONE);
|
||||
GridLayout layout = new GridLayout(2, false);
|
||||
layout.marginHeight = 0;
|
||||
layout.marginWidth = 0;
|
||||
comp.setLayout(layout);
|
||||
comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
Composite radioGroup = new Composite(comp, SWT.NONE);
|
||||
radioGroup.setLayout(new GridLayout());
|
||||
radioGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
useWorkspaceSettingsButton = createRadioButton(radioGroup, Messages.getString("OverlayPage.Use_Workspace_Settings")); //$NON-NLS-1$
|
||||
useProjectSettingsButton = createRadioButton(radioGroup, Messages.getString("OverlayPage.Use_Project_Settings")); //$NON-NLS-1$
|
||||
configureButton = new Button(comp, SWT.PUSH);
|
||||
configureButton.setText(Messages.getString("OverlayPage.Configure_Workspace_Settings")); //$NON-NLS-1$
|
||||
configureButton.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
configureWorkspaceSettings();
|
||||
}
|
||||
});
|
||||
// Set workspace/project radio buttons
|
||||
try {
|
||||
String use =
|
||||
((IResource) getElement()).getPersistentProperty(
|
||||
new QualifiedName(pageId, USEPROJECTSETTINGS));
|
||||
if (TRUE.equals(use)) {
|
||||
useProjectSettingsButton.setSelection(true);
|
||||
configureButton.setEnabled(false);
|
||||
} else
|
||||
useWorkspaceSettingsButton.setSelection(true);
|
||||
} catch (CoreException e) {
|
||||
useWorkspaceSettingsButton.setSelection(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method creating a radio button
|
||||
* @param parent - the parent composite
|
||||
* @param label - the button label
|
||||
* @return - the new button
|
||||
*/
|
||||
private Button createRadioButton(Composite parent, String label) {
|
||||
final Button button = new Button(parent, SWT.RADIO);
|
||||
button.setText(label);
|
||||
button.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
configureButton.setEnabled(
|
||||
button == useWorkspaceSettingsButton);
|
||||
setControlsEnabled();
|
||||
}
|
||||
});
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* In case of property pages we create a new PropertyStore as local overlay store.
|
||||
* After all controls have been create, we enable/disable these controls
|
||||
*
|
||||
* @see org.eclipse.jface.preference.PreferencePage#createControl()
|
||||
*/
|
||||
public void createControl(Composite parent) {
|
||||
// Special treatment for property pages
|
||||
if (isPropertyPage()) {
|
||||
// Cache the page id
|
||||
pageId = getPageId();
|
||||
// Create an overlay preference store and fill it with properties
|
||||
overlayStore =
|
||||
new PropertyStore(
|
||||
(IResource) getElement(),
|
||||
super.getPreferenceStore(),
|
||||
pageId);
|
||||
// Set overlay store as current preference store
|
||||
}
|
||||
super.createControl(parent);
|
||||
// Update enablement of all subclass controls
|
||||
if (isPropertyPage())
|
||||
setControlsEnabled();
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns in case of property pages the overlay store - otherwise the standard preference store
|
||||
* @see org.eclipse.jface.preference.PreferencePage#getPreferenceStore()
|
||||
*/
|
||||
public IPreferenceStore getPreferenceStore() {
|
||||
if (isPropertyPage())
|
||||
return overlayStore;
|
||||
return super.getPreferenceStore();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables the controls of this page
|
||||
*/
|
||||
private void setControlsEnabled() {
|
||||
boolean enabled = useProjectSettingsButton.getSelection();
|
||||
setControlsEnabled(enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables the controls of this page
|
||||
* Subclasses may override.
|
||||
*
|
||||
* @param enabled - true if controls shall be enabled
|
||||
*/
|
||||
protected void setControlsEnabled(boolean enabled) {
|
||||
setControlsEnabled(contents, enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables a tree of controls starting at the specified root.
|
||||
* We spare tabbed notebooks and pagebooks to allow for user navigation.
|
||||
*
|
||||
* @param root - the root composite
|
||||
* @param enabled - true if controls shall be enabled
|
||||
*/
|
||||
private void setControlsEnabled(Composite root, boolean enabled) {
|
||||
Control[] children = root.getChildren();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
Control child = children[i];
|
||||
if (!(child instanceof CTabFolder) && !(child instanceof TabFolder) && !(child instanceof PageBook))
|
||||
child.setEnabled(enabled);
|
||||
if (child instanceof Composite)
|
||||
setControlsEnabled((Composite) child, enabled);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* We override the performOk method. In case of property pages
|
||||
* we save the state of the radio buttons.
|
||||
*
|
||||
* @see org.eclipse.jface.preference.IPreferencePage#performOk()
|
||||
*/
|
||||
public boolean performOk() {
|
||||
boolean result = super.performOk();
|
||||
if (result && isPropertyPage()) {
|
||||
// Save state of radiobuttons in project properties
|
||||
IResource resource = (IResource) getElement();
|
||||
try {
|
||||
String value =
|
||||
(useProjectSettingsButton.getSelection()) ? TRUE : FALSE;
|
||||
resource.setPersistentProperty(
|
||||
new QualifiedName(pageId, USEPROJECTSETTINGS),
|
||||
value);
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* We override the performDefaults method. In case of property pages we
|
||||
* switch back to the workspace settings and disable the page controls.
|
||||
*
|
||||
* @see org.eclipse.jface.preference.PreferencePage#performDefaults()
|
||||
*/
|
||||
protected void performDefaults() {
|
||||
if (isPropertyPage()) {
|
||||
useWorkspaceSettingsButton.setSelection(true);
|
||||
useProjectSettingsButton.setSelection(false);
|
||||
configureButton.setEnabled(true);
|
||||
setControlsEnabled();
|
||||
}
|
||||
super.performDefaults();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new preferences page and opens it
|
||||
*/
|
||||
protected void configureWorkspaceSettings() {
|
||||
try {
|
||||
// create a new instance of the current class
|
||||
IPreferencePage page =
|
||||
(IPreferencePage) this.getClass().newInstance();
|
||||
page.setTitle(getTitle());
|
||||
page.setImageDescriptor(image);
|
||||
// and show it
|
||||
showPreferencePage(pageId, page);
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a single preference pages
|
||||
* @param id - the preference page identification
|
||||
* @param page - the preference page
|
||||
*/
|
||||
protected void showPreferencePage(String id, IPreferencePage page) {
|
||||
final IPreferenceNode targetNode = new PreferenceNode(id, page);
|
||||
PreferenceManager manager = new PreferenceManager();
|
||||
manager.addToRoot(targetNode);
|
||||
final PreferenceDialog dialog =
|
||||
new PreferenceDialog(getControl().getShell(), manager);
|
||||
BusyIndicator.showWhile(getControl().getDisplay(), new Runnable() {
|
||||
public void run() {
|
||||
dialog.create();
|
||||
dialog.setMessage(targetNode.getLabelText());
|
||||
dialog.open();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.cdt.codan.core.PreferenceConstants;
|
||||
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
|
||||
|
|
|
@ -10,14 +10,16 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.cdt.codan.core.model.CheckersRegisry;
|
||||
import org.eclipse.cdt.codan.core.PreferenceConstants;
|
||||
import org.eclipse.cdt.codan.core.builder.CodanPreferencesLoader;
|
||||
import org.eclipse.cdt.codan.core.model.CodanProblem;
|
||||
import org.eclipse.cdt.codan.core.model.CodanSeverity;
|
||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemCategory;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemsProfile;
|
||||
import org.eclipse.jface.viewers.BaseLabelProvider;
|
||||
import org.eclipse.jface.viewers.CheckStateChangedEvent;
|
||||
import org.eclipse.jface.viewers.IBaseLabelProvider;
|
||||
import org.eclipse.jface.viewers.ICheckStateProvider;
|
||||
import org.eclipse.jface.viewers.IContentProvider;
|
||||
import org.eclipse.jface.viewers.ITableLabelProvider;
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
|
@ -28,9 +30,70 @@ import org.eclipse.swt.widgets.Composite;
|
|||
import org.eclipse.swt.widgets.TreeColumn;
|
||||
|
||||
public class ProblemsTreeEditor extends CheckedTreeEditor {
|
||||
private CodanPreferencesLoader codanPreferencesLoader = new CodanPreferencesLoader();
|
||||
|
||||
public ProblemsTreeEditor() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
class ProblemsCheckStateProvider implements ICheckStateProvider {
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.jface.viewers.ICheckStateProvider#isChecked(java.lang
|
||||
* .Object)
|
||||
*/
|
||||
public boolean isChecked(Object element) {
|
||||
if (element instanceof IProblem) {
|
||||
IProblem p = (IProblem) element;
|
||||
return p.isEnabled();
|
||||
}
|
||||
if (element instanceof IProblemCategory) {
|
||||
// checked if at least one is checked (buy grayed)
|
||||
IProblemCategory p = (IProblemCategory) element;
|
||||
Object[] children = p.getChildren();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
Object object = children[i];
|
||||
if (isChecked(object)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.jface.viewers.ICheckStateProvider#isGrayed(java.lang.
|
||||
* Object)
|
||||
*/
|
||||
public boolean isGrayed(Object element) {
|
||||
if (element instanceof IProblem) {
|
||||
return false;
|
||||
}
|
||||
if (element instanceof IProblemCategory) {
|
||||
// checked if at least one is checked (buy grayed)
|
||||
IProblemCategory p = (IProblemCategory) element;
|
||||
Object[] children = p.getChildren();
|
||||
boolean all_checked = true;
|
||||
boolean all_unchecked = true;
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
Object object = children[i];
|
||||
if (isChecked(object)) {
|
||||
all_unchecked = false;
|
||||
} else {
|
||||
all_checked = false;
|
||||
}
|
||||
}
|
||||
if (all_checked || all_unchecked)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class ProblemsContentProvider implements IContentProvider,
|
||||
|
@ -49,6 +112,10 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
|
|||
if (parentElement instanceof IProblemCategory) {
|
||||
return ((IProblemCategory) parentElement).getChildren();
|
||||
}
|
||||
if (parentElement instanceof IProblemsProfile) {
|
||||
return ((IProblemsProfile) parentElement).getRoot()
|
||||
.getChildren();
|
||||
}
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
|
@ -89,35 +156,6 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String unparseElement(Object element) {
|
||||
IProblem p = ((IProblem) element);
|
||||
return p.getId() + ":" + p.getSeverity();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object parseObject(String string) {
|
||||
String[] pair = string.split(":");
|
||||
if (pair.length == 0)
|
||||
return null;
|
||||
String id = pair[0];
|
||||
String arg = "";
|
||||
if (pair.length > 1) {
|
||||
arg = pair[1];
|
||||
}
|
||||
CodanSeverity sev;
|
||||
try {
|
||||
sev = CodanSeverity.valueOf(arg);
|
||||
} catch (RuntimeException e) {
|
||||
sev = CodanSeverity.Warning;
|
||||
}
|
||||
IProblem prob = CheckersRegisry.getInstance().findProblem(id);
|
||||
if (prob instanceof CodanProblem) {
|
||||
((CodanProblem) prob).setSeverity(sev);
|
||||
}
|
||||
return prob;
|
||||
}
|
||||
|
||||
public void checkStateChanged(CheckStateChangedEvent event) {
|
||||
Object element = event.getElement();
|
||||
if (element instanceof CodanProblem) {
|
||||
|
@ -125,13 +163,14 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
|
|||
}
|
||||
}
|
||||
|
||||
public ProblemsTreeEditor(Composite parent) {
|
||||
super("problems", "Problems", parent);
|
||||
public ProblemsTreeEditor(Composite parent, IProblemsProfile profile) {
|
||||
super(PreferenceConstants.P_PROBLEMS, "Problems", parent);
|
||||
setEmptySelectionAllowed(true);
|
||||
getTreeViewer().getTree().setHeaderVisible(true);
|
||||
// getTreeViewer().getTree().
|
||||
getTreeViewer().setContentProvider(new ProblemsContentProvider());
|
||||
getTreeViewer().setLabelProvider(new ProblemsLabelProvider());
|
||||
getTreeViewer().setCheckStateProvider(new ProblemsCheckStateProvider());
|
||||
// column Name
|
||||
TreeColumn column = new TreeColumn(getTreeViewer().getTree(), SWT.NONE);
|
||||
column.setWidth(300);
|
||||
|
@ -140,7 +179,30 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
|
|||
TreeColumn column2 = new TreeColumn(getTreeViewer().getTree(), SWT.NONE);
|
||||
column2.setWidth(100);
|
||||
column2.setText("Severity");
|
||||
getTreeViewer().setInput(
|
||||
CheckersRegisry.getInstance().getProblemsTree());
|
||||
codanPreferencesLoader.setInput(profile);
|
||||
getViewer().setInput(profile);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @seeorg.eclipse.cdt.codan.internal.ui.preferences.CheckedTreeEditor#
|
||||
* modelFromString(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
protected Object modelFromString(String s) {
|
||||
return codanPreferencesLoader.modelFromString(s);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.cdt.codan.internal.ui.preferences.CheckedTreeEditor#modelToString
|
||||
* (java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
protected String modelToString(Object model) {
|
||||
return codanPreferencesLoader.modelToString(model);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,234 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003 Berthold Daum.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Berthold Daum
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.QualifiedName;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.preference.PreferenceStore;
|
||||
|
||||
/**
|
||||
* @author Berthold Daum
|
||||
*
|
||||
*/
|
||||
public class PropertyStore extends PreferenceStore {
|
||||
|
||||
private IResource resource;
|
||||
private IPreferenceStore workbenchStore;
|
||||
private String pageId;
|
||||
private boolean inserting = false;
|
||||
|
||||
public PropertyStore(
|
||||
IResource resource,
|
||||
IPreferenceStore workbenchStore,
|
||||
String pageId) {
|
||||
this.resource = resource;
|
||||
this.workbenchStore = workbenchStore;
|
||||
this.pageId = pageId;
|
||||
}
|
||||
|
||||
/*** Write modified values back to properties ***/
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPersistentPreferenceStore#save()
|
||||
*/
|
||||
public void save() throws IOException {
|
||||
writeProperties();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.PreferenceStore#save(java.io.OutputStream, java.lang.String)
|
||||
*/
|
||||
public void save(OutputStream out, String header) throws IOException {
|
||||
writeProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes modified preferences into resource properties.
|
||||
*/
|
||||
private void writeProperties() throws IOException {
|
||||
String[] preferences = super.preferenceNames();
|
||||
for (int i = 0; i < preferences.length; i++) {
|
||||
String name = preferences[i];
|
||||
try {
|
||||
setProperty(name, getString(name));
|
||||
} catch (CoreException e) {
|
||||
throw new IOException(Messages.getString("PropertyStore.Cannot_write_resource_property") + name); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to set a property
|
||||
* @param name - the preference name
|
||||
* @param value - the property value or null to delete the property
|
||||
* @throws CoreException
|
||||
*/
|
||||
private void setProperty(String name, String value) throws CoreException {
|
||||
resource.setPersistentProperty(new QualifiedName(pageId, name), value);
|
||||
}
|
||||
|
||||
/*** Get default values (Delegate to workbench store) ***/
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#getDefaultBoolean(java.lang.String)
|
||||
*/
|
||||
public boolean getDefaultBoolean(String name) {
|
||||
return workbenchStore.getDefaultBoolean(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#getDefaultDouble(java.lang.String)
|
||||
*/
|
||||
public double getDefaultDouble(String name) {
|
||||
return workbenchStore.getDefaultDouble(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#getDefaultFloat(java.lang.String)
|
||||
*/
|
||||
public float getDefaultFloat(String name) {
|
||||
return workbenchStore.getDefaultFloat(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#getDefaultInt(java.lang.String)
|
||||
*/
|
||||
public int getDefaultInt(String name) {
|
||||
return workbenchStore.getDefaultInt(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#getDefaultLong(java.lang.String)
|
||||
*/
|
||||
public long getDefaultLong(String name) {
|
||||
return workbenchStore.getDefaultLong(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#getDefaultString(java.lang.String)
|
||||
*/
|
||||
public String getDefaultString(String name) {
|
||||
return workbenchStore.getDefaultString(name);
|
||||
}
|
||||
|
||||
/*** Get property values ***/
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#getBoolean(java.lang.String)
|
||||
*/
|
||||
public boolean getBoolean(String name) {
|
||||
insertValue(name);
|
||||
return super.getBoolean(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#getDouble(java.lang.String)
|
||||
*/
|
||||
public double getDouble(String name) {
|
||||
insertValue(name);
|
||||
return super.getDouble(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#getFloat(java.lang.String)
|
||||
*/
|
||||
public float getFloat(String name) {
|
||||
insertValue(name);
|
||||
return super.getFloat(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#getInt(java.lang.String)
|
||||
*/
|
||||
public int getInt(String name) {
|
||||
insertValue(name);
|
||||
return super.getInt(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#getLong(java.lang.String)
|
||||
*/
|
||||
public long getLong(String name) {
|
||||
insertValue(name);
|
||||
return super.getLong(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#getString(java.lang.String)
|
||||
*/
|
||||
public String getString(String name) {
|
||||
insertValue(name);
|
||||
return super.getString(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
private synchronized void insertValue(String name) {
|
||||
if (inserting)
|
||||
return;
|
||||
if (super.contains(name))
|
||||
return;
|
||||
inserting = true;
|
||||
String prop = null;
|
||||
try {
|
||||
prop = getProperty(name);
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
if (prop == null)
|
||||
prop = workbenchStore.getString(name);
|
||||
if (prop != null)
|
||||
setValue(name, prop);
|
||||
inserting = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to fetch a property
|
||||
* @param name - the preference name
|
||||
* @return - the property value
|
||||
* @throws CoreException
|
||||
*/
|
||||
private String getProperty(String name) throws CoreException {
|
||||
return resource.getPersistentProperty(new QualifiedName(pageId, name));
|
||||
}
|
||||
|
||||
/*** Misc ***/
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#contains(java.lang.String)
|
||||
*/
|
||||
public boolean contains(String name) {
|
||||
return workbenchStore.contains(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#setToDefault(java.lang.String)
|
||||
*/
|
||||
public void setToDefault(String name) {
|
||||
setValue(name, getDefaultString(name));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#isDefault(java.lang.String)
|
||||
*/
|
||||
public boolean isDefault(String name) {
|
||||
String defaultValue = getDefaultString(name);
|
||||
if (defaultValue == null) return false;
|
||||
return defaultValue.equals(getString(name));
|
||||
}
|
||||
|
||||
}
|
|
@ -14,6 +14,7 @@ import java.util.Iterator;
|
|||
|
||||
import org.eclipse.cdt.codan.core.builder.CodanBuilder;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
|
@ -25,7 +26,6 @@ public class RunCodeAnalysis implements IObjectActionDelegate {
|
|||
|
||||
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void run(IAction action) {
|
||||
|
@ -34,14 +34,17 @@ public class RunCodeAnalysis implements IObjectActionDelegate {
|
|||
Object o = iterator.next();
|
||||
if (o instanceof IResource) {
|
||||
IResource res = (IResource) o;
|
||||
new CodanBuilder().new CodanResourceVisitor().visit(res);
|
||||
try {
|
||||
res.accept(new CodanBuilder().new CodanResourceVisitor());
|
||||
} catch (CoreException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
this.sel = selection;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue