mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 18:56:02 +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.IStatus;
|
||||||
import org.eclipse.core.runtime.Plugin;
|
import org.eclipse.core.runtime.Plugin;
|
||||||
import org.eclipse.core.runtime.Status;
|
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;
|
import org.osgi.framework.BundleContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,6 +22,10 @@ public class CodanCorePlugin extends Plugin {
|
||||||
public CodanCorePlugin() {
|
public CodanCorePlugin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEclipsePreferences getStorePreferences() {
|
||||||
|
return new InstanceScope().getNode(PLUGIN_ID);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
|
|
|
@ -8,11 +8,12 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Alena Laskavaia - initial API and implementation
|
* 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
|
* Constant definitions for plug-in preferences
|
||||||
*/
|
*/
|
||||||
public class PreferenceConstants {
|
public class PreferenceConstants {
|
||||||
public static final String P_RUN_ON_BUILD = "booleanPreference";
|
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.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
@ -35,8 +36,10 @@ public abstract class AbstractIndexAstChecker extends AbstractChecker implements
|
||||||
void processFile(IFile file) throws CoreException, InterruptedException {
|
void processFile(IFile file) throws CoreException, InterruptedException {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
// create translation unit and access index
|
// create translation unit and access index
|
||||||
ITranslationUnit tu = (ITranslationUnit) CoreModel.getDefault().create(
|
ICElement model = CoreModel.getDefault().create(file);
|
||||||
file);
|
if (!(model instanceof ITranslationUnit))
|
||||||
|
return;
|
||||||
|
ITranslationUnit tu = (ITranslationUnit) model;
|
||||||
if (tu == null)
|
if (tu == null)
|
||||||
return; // not a C/C++ file
|
return; // not a C/C++ file
|
||||||
IIndex index = CCorePlugin.getIndexManager().getIndex(tu.getCProject());
|
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.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
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.CoreException;
|
||||||
import org.eclipse.core.runtime.IConfigurationElement;
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
import org.eclipse.core.runtime.IExtensionPoint;
|
import org.eclipse.core.runtime.IExtensionPoint;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||||
|
|
||||||
public class CheckersRegisry implements Iterable<IChecker> {
|
public class CheckersRegisry implements Iterable<IChecker> {
|
||||||
private static final String EXTENSION_POINT_NAME = "checkers";
|
private static final String EXTENSION_POINT_NAME = "checkers";
|
||||||
private static final String CHECKER_ELEMENT = "checker";
|
private static final String CHECKER_ELEMENT = "checker";
|
||||||
private static final String PROBLEM_ELEMENT = "problem";
|
private static final String PROBLEM_ELEMENT = "problem";
|
||||||
|
private static final Object DEFAULT = "DEFAULT";
|
||||||
private Collection<IChecker> checkers = new ArrayList<IChecker>();
|
private Collection<IChecker> checkers = new ArrayList<IChecker>();
|
||||||
private static CheckersRegisry instance;
|
private static CheckersRegisry instance;
|
||||||
private IProblemCategory rootCategory = new CodanProblemCategory("root",
|
private HashMap<Object, IProblemsProfile> profiles = new HashMap<Object, IProblemsProfile>();
|
||||||
"root");
|
|
||||||
private Collection<IProblem> problems = new ArrayList<IProblem>();
|
|
||||||
|
|
||||||
private CheckersRegisry() {
|
private CheckersRegisry() {
|
||||||
instance = this;
|
instance = this;
|
||||||
|
profiles.put(DEFAULT, new ProblemsProfile());
|
||||||
readCheckersRegistry();
|
readCheckersRegistry();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,13 +99,13 @@ public class CheckersRegisry implements Iterable<IChecker> {
|
||||||
if (children1 != null) {
|
if (children1 != null) {
|
||||||
for (IConfigurationElement ref : children1) {
|
for (IConfigurationElement ref : children1) {
|
||||||
hasRef = true;
|
hasRef = true;
|
||||||
IProblem p = getProblemById(ref.getAttribute("refId"),
|
IProblem p = getDefaultProfile().findProblem(
|
||||||
null);
|
ref.getAttribute("refId"));
|
||||||
addRefProblem(checkerObj, p);
|
addRefProblem(checkerObj, p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!hasRef) {
|
if (!hasRef) {
|
||||||
addProblem(new CodanProblem(id, name));
|
addProblem(new CodanProblem(id, name), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -120,7 +127,8 @@ public class CheckersRegisry implements Iterable<IChecker> {
|
||||||
if (name == null)
|
if (name == null)
|
||||||
name = id;
|
name = id;
|
||||||
CodanProblem p = new CodanProblem(id, name);
|
CodanProblem p = new CodanProblem(id, name);
|
||||||
addProblem(p);
|
String category = getAtt(configurationElement, "category");
|
||||||
|
addProblem(p, category);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -156,28 +164,68 @@ public class CheckersRegisry implements Iterable<IChecker> {
|
||||||
checkers.add(checker);
|
checkers.add(checker);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addProblem(IProblem p) {
|
public void addProblem(IProblem p, String category) {
|
||||||
problems.add(p); // TODO category
|
((ProblemsProfile) getDefaultProfile()).addProblem(p,
|
||||||
((CodanProblemCategory) rootCategory).addChild(p);
|
getDefaultProfile().getRoot());
|
||||||
}
|
|
||||||
|
|
||||||
public Object getProblemsTree() {
|
|
||||||
return rootCategory;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addRefProblem(IChecker c, IProblem p) {
|
public void addRefProblem(IChecker c, IProblem p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IProblem findProblem(String id) {
|
/**
|
||||||
for (Iterator iterator = problems.iterator(); iterator.hasNext();) {
|
* @return
|
||||||
IProblem p = (IProblem) iterator.next();
|
*/
|
||||||
if (p.getId().equals(id))
|
public IProblemsProfile getDefaultProfile() {
|
||||||
return p;
|
return profiles.get(DEFAULT);
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
public void setEnabled(boolean checked) {
|
||||||
this.enabled = 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;
|
package org.eclipse.cdt.codan.core.model;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
public class CodanProblemCategory implements IProblemCategory, Cloneable {
|
||||||
public class CodanProblemCategory implements IProblemCategory {
|
|
||||||
private String id;
|
private String id;
|
||||||
private String name;
|
private String name;
|
||||||
|
private ArrayList<IProblemElement> list = new ArrayList<IProblemElement>();
|
||||||
|
|
||||||
private ArrayList list = new ArrayList();
|
|
||||||
public CodanProblemCategory(String id, String name) {
|
public CodanProblemCategory(String id, String name) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -35,6 +35,7 @@ public class CodanProblemCategory implements IProblemCategory {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] getChildren() {
|
public Object[] getChildren() {
|
||||||
return list.toArray();
|
return list.toArray();
|
||||||
}
|
}
|
||||||
|
@ -43,10 +44,56 @@ public class CodanProblemCategory implements IProblemCategory {
|
||||||
list.add(p);
|
list.add(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IProblemCategory getParent() {
|
public IProblem findProblem(String id) {
|
||||||
// TODO Auto-generated method stub
|
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;
|
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");
|
throw new NullPointerException("file");
|
||||||
if (id == null)
|
if (id == null)
|
||||||
throw new NullPointerException("id");
|
throw new NullPointerException("id");
|
||||||
IProblem problem = CheckersRegisry.getInstance().getProblemById(id,
|
IProblem problem = CheckersRegisry.getInstance()
|
||||||
file);
|
.getResourceProfile(file).findProblem(id);
|
||||||
if (problem == null)
|
if (problem == null)
|
||||||
throw new IllegalArgumentException("Id is not registered");
|
throw new IllegalArgumentException("Id is not registered");
|
||||||
if (problem.isEnabled() == false)
|
if (problem.isEnabled() == false)
|
||||||
|
|
|
@ -10,8 +10,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.core.model;
|
package org.eclipse.cdt.codan.core.model;
|
||||||
|
|
||||||
|
public interface IProblem extends IProblemElement {
|
||||||
public interface IProblem {
|
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
String getId();
|
String getId();
|
||||||
|
|
|
@ -10,12 +10,22 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.core.model;
|
package org.eclipse.cdt.codan.core.model;
|
||||||
|
|
||||||
public interface IProblemCategory {
|
public interface IProblemCategory extends IProblemElement {
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
String getId();
|
String getId();
|
||||||
|
|
||||||
Object[] getChildren();
|
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;
|
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.cdt.codan.ui.actions.ToggleNatureAction;
|
||||||
import org.eclipse.core.resources.IProject;
|
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.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.BooleanFieldEditor;
|
||||||
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
||||||
import org.eclipse.ui.IWorkbenchPropertyPage;
|
import org.eclipse.ui.IWorkbenchPropertyPage;
|
||||||
|
import org.eclipse.ui.preferences.ScopedPreferenceStore;
|
||||||
|
|
||||||
public class BuildPropertyPage extends FieldEditorPreferencePage implements
|
public class BuildPropertyPage extends FieldEditorPreferencePage implements
|
||||||
IWorkbenchPropertyPage {
|
IWorkbenchPropertyPage {
|
||||||
|
@ -77,9 +82,13 @@ public class BuildPropertyPage extends FieldEditorPreferencePage implements
|
||||||
*/
|
*/
|
||||||
public void setElement(IAdaptable element) {
|
public void setElement(IAdaptable element) {
|
||||||
this.element = element;
|
this.element = element;
|
||||||
setPreferenceStore(new PropertyStore((IResource) getElement(),
|
ProjectScope ps = new ProjectScope((IProject) getElement());
|
||||||
org.eclipse.cdt.codan.ui.Activator.getDefault()
|
ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps,
|
||||||
.getPreferenceStore(), getPageId()));
|
CodanCorePlugin.PLUGIN_ID);
|
||||||
|
scoped
|
||||||
|
.setSearchContexts(new IScopeContext[] { ps,
|
||||||
|
new InstanceScope() });
|
||||||
|
setPreferenceStore(scoped);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getPageId() {
|
protected String getPageId() {
|
||||||
|
|
|
@ -10,10 +10,6 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
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.preference.FieldEditor;
|
||||||
import org.eclipse.jface.viewers.CheckStateChangedEvent;
|
import org.eclipse.jface.viewers.CheckStateChangedEvent;
|
||||||
import org.eclipse.jface.viewers.CheckboxTreeViewer;
|
import org.eclipse.jface.viewers.CheckboxTreeViewer;
|
||||||
|
@ -40,7 +36,7 @@ import org.eclipse.swt.widgets.Tree;
|
||||||
* <code>getListSeparator</code> framework methods.
|
* <code>getListSeparator</code> framework methods.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class CheckedTreeEditor extends FieldEditor implements
|
public abstract class CheckedTreeEditor extends FieldEditor implements
|
||||||
ICheckStateListener {
|
ICheckStateListener {
|
||||||
/**
|
/**
|
||||||
* The list widget; <code>null</code> if none (before creation or after
|
* 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 CheckboxTreeViewer treeViewer;
|
||||||
private Composite listParent;
|
private Composite listParent;
|
||||||
private boolean isValid;
|
private boolean isValid;
|
||||||
private static String LIST_SEP = ",";
|
|
||||||
private boolean emptySelectionAllowed = false;
|
private boolean emptySelectionAllowed = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,10 +116,16 @@ public class CheckedTreeEditor extends FieldEditor implements
|
||||||
protected void doLoad() {
|
protected void doLoad() {
|
||||||
if (getTreeControl() != null) {
|
if (getTreeControl() != null) {
|
||||||
String s = getPreferenceStore().getString(getPreferenceName());
|
String s = getPreferenceStore().getString(getPreferenceName());
|
||||||
setTreeData(parseString(s));
|
getViewer().setInput(modelFromString(s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param s
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected abstract Object modelFromString(String s);
|
||||||
|
|
||||||
Control getTreeControl() {
|
Control getTreeControl() {
|
||||||
if (treeViewer == null)
|
if (treeViewer == null)
|
||||||
return null;
|
return null;
|
||||||
|
@ -135,23 +136,6 @@ public class CheckedTreeEditor extends FieldEditor implements
|
||||||
return treeViewer;
|
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
|
* @Override
|
||||||
* @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent)
|
* @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent)
|
||||||
|
@ -206,7 +190,7 @@ public class CheckedTreeEditor extends FieldEditor implements
|
||||||
treeViewer.refresh();
|
treeViewer.refresh();
|
||||||
String s = getPreferenceStore().getDefaultString(
|
String s = getPreferenceStore().getDefaultString(
|
||||||
getPreferenceName());
|
getPreferenceName());
|
||||||
setTreeData(parseString(s));
|
getViewer().setInput(modelFromString(s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,7 +198,7 @@ public class CheckedTreeEditor extends FieldEditor implements
|
||||||
* (non-Javadoc) Method declared on FieldEditor.
|
* (non-Javadoc) Method declared on FieldEditor.
|
||||||
*/
|
*/
|
||||||
protected void doStore() {
|
protected void doStore() {
|
||||||
String s = unparseTree();
|
String s = modelToString(getViewer().getInput());
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
getPreferenceStore().setValue(getPreferenceName(), s);
|
getPreferenceStore().setValue(getPreferenceName(), s);
|
||||||
}
|
}
|
||||||
|
@ -266,35 +250,6 @@ public class CheckedTreeEditor extends FieldEditor implements
|
||||||
return treeViewer.getControl().getShell();
|
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.
|
* (non-Javadoc) Method declared on FieldEditor.
|
||||||
*/
|
*/
|
||||||
|
@ -320,49 +275,9 @@ public class CheckedTreeEditor extends FieldEditor implements
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @return the combined string
|
* @return the combined string
|
||||||
* @see #parseString
|
* @see #stringToModel
|
||||||
*/
|
*/
|
||||||
protected String unparseTree() {
|
protected abstract String modelToString(Object model);
|
||||||
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 void createControl(Composite parent) {
|
protected void createControl(Composite parent) {
|
||||||
GridLayout ly = (GridLayout) parent.getLayout();
|
GridLayout ly = (GridLayout) parent.getLayout();
|
||||||
|
@ -406,7 +321,6 @@ public class CheckedTreeEditor extends FieldEditor implements
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public final boolean isEmptySelectionAllowed() {
|
public final boolean isEmptySelectionAllowed() {
|
||||||
return emptySelectionAllowed;
|
return emptySelectionAllowed;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
package org.eclipse.cdt.codan.internal.ui.preferences;
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
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.core.runtime.preferences.InstanceScope;
|
||||||
import org.eclipse.ui.IWorkbench;
|
import org.eclipse.ui.IWorkbench;
|
||||||
import org.eclipse.ui.IWorkbenchPreferencePage;
|
import org.eclipse.ui.IWorkbenchPreferencePage;
|
||||||
|
@ -46,7 +48,10 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
*/
|
*/
|
||||||
public void createFieldEditors() {
|
public void createFieldEditors() {
|
||||||
CheckedTreeEditor checkedTreeEditor = new ProblemsTreeEditor(
|
CheckedTreeEditor checkedTreeEditor = new ProblemsTreeEditor(
|
||||||
getFieldEditorParent());
|
getFieldEditorParent(), isPropertyPage() ? CheckersRegisry
|
||||||
|
.getInstance().getResourceProfile(
|
||||||
|
(IResource) getElement()) : CheckersRegisry
|
||||||
|
.getInstance().getWorkspaceProfile());
|
||||||
addField(checkedTreeEditor);
|
addField(checkedTreeEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,15 @@ import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
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.IResource;
|
||||||
|
import org.eclipse.core.resources.ProjectScope;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IAdaptable;
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
import org.eclipse.core.runtime.QualifiedName;
|
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.FieldEditor;
|
||||||
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
||||||
import org.eclipse.jface.preference.IPreferenceNode;
|
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.Composite;
|
||||||
import org.eclipse.swt.widgets.Control;
|
import org.eclipse.swt.widgets.Control;
|
||||||
import org.eclipse.ui.IWorkbenchPropertyPage;
|
import org.eclipse.ui.IWorkbenchPropertyPage;
|
||||||
|
import org.eclipse.ui.preferences.ScopedPreferenceStore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Berthold Daum
|
* @author Berthold Daum
|
||||||
*/
|
*/
|
||||||
public abstract class FieldEditorOverlayPage
|
public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
|
||||||
extends FieldEditorPreferencePage
|
|
||||||
implements IWorkbenchPropertyPage {
|
implements IWorkbenchPropertyPage {
|
||||||
|
/***
|
||||||
/*** Name of resource property for the selection of workbench or project settings ***/
|
* Name of resource property for the selection of workbench or project
|
||||||
|
* settings
|
||||||
|
***/
|
||||||
public static final String USEPROJECTSETTINGS = "useProjectSettings"; //$NON-NLS-1$
|
public static final String USEPROJECTSETTINGS = "useProjectSettings"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static final String FALSE = "false"; //$NON-NLS-1$
|
private static final String FALSE = "false"; //$NON-NLS-1$
|
||||||
private static final String TRUE = "true"; //$NON-NLS-1$
|
private static final String TRUE = "true"; //$NON-NLS-1$
|
||||||
|
|
||||||
// Stores all created field editors
|
// Stores all created field editors
|
||||||
private List editors = new ArrayList();
|
private List editors = new ArrayList();
|
||||||
|
|
||||||
// Stores owning element of properties
|
// Stores owning element of properties
|
||||||
private IAdaptable element;
|
private IAdaptable element;
|
||||||
|
|
||||||
// Additional buttons for property pages
|
// Additional buttons for property pages
|
||||||
private Button useWorkspaceSettingsButton,
|
private Button useWorkspaceSettingsButton, useProjectSettingsButton,
|
||||||
useProjectSettingsButton,
|
|
||||||
configureButton;
|
configureButton;
|
||||||
|
|
||||||
// Overlay preference store for property pages
|
// Overlay preference store for property pages
|
||||||
private IPreferenceStore overlayStore;
|
private IPreferenceStore overlayStore;
|
||||||
|
|
||||||
// The image descriptor of this pages title image
|
// The image descriptor of this pages title image
|
||||||
private ImageDescriptor image;
|
private ImageDescriptor image;
|
||||||
|
|
||||||
// Cache for page id
|
// Cache for page id
|
||||||
private String pageId;
|
private String pageId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param style - layout style
|
*
|
||||||
|
* @param style
|
||||||
|
* - layout style
|
||||||
*/
|
*/
|
||||||
public FieldEditorOverlayPage(int style) {
|
public FieldEditorOverlayPage(int style) {
|
||||||
super(style);
|
super(style);
|
||||||
|
@ -81,8 +82,11 @@ public abstract class FieldEditorOverlayPage
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param title - title string
|
*
|
||||||
* @param style - layout style
|
* @param title
|
||||||
|
* - title string
|
||||||
|
* @param style
|
||||||
|
* - layout style
|
||||||
*/
|
*/
|
||||||
public FieldEditorOverlayPage(String title, int style) {
|
public FieldEditorOverlayPage(String title, int style) {
|
||||||
super(title, style);
|
super(title, style);
|
||||||
|
@ -90,14 +94,15 @@ public abstract class FieldEditorOverlayPage
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param title - title string
|
*
|
||||||
* @param image - title image
|
* @param title
|
||||||
* @param style - layout style
|
* - title string
|
||||||
|
* @param image
|
||||||
|
* - title image
|
||||||
|
* @param style
|
||||||
|
* - layout style
|
||||||
*/
|
*/
|
||||||
public FieldEditorOverlayPage(
|
public FieldEditorOverlayPage(String title, ImageDescriptor image, int style) {
|
||||||
String title,
|
|
||||||
ImageDescriptor image,
|
|
||||||
int style) {
|
|
||||||
super(title, image, style);
|
super(title, image, style);
|
||||||
this.image = image;
|
this.image = image;
|
||||||
}
|
}
|
||||||
|
@ -112,6 +117,7 @@ public abstract class FieldEditorOverlayPage
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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)
|
* @see org.eclipse.ui.IWorkbenchPropertyPage#setElement(org.eclipse.core.runtime.IAdaptable)
|
||||||
*/
|
*/
|
||||||
public void setElement(IAdaptable element) {
|
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.
|
* Delivers the object that owns the properties shown in this property page.
|
||||||
|
*
|
||||||
* @see org.eclipse.ui.IWorkbenchPropertyPage#getElement()
|
* @see org.eclipse.ui.IWorkbenchPropertyPage#getElement()
|
||||||
*/
|
*/
|
||||||
public IAdaptable getElement() {
|
public IAdaptable getElement() {
|
||||||
|
@ -128,6 +135,7 @@ public abstract class FieldEditorOverlayPage
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if this instance represents a property page
|
* Returns true if this instance represents a property page
|
||||||
|
*
|
||||||
* @return - true for property pages, false for preference pages
|
* @return - true for property pages, false for preference pages
|
||||||
*/
|
*/
|
||||||
public boolean isPropertyPage() {
|
public boolean isPropertyPage() {
|
||||||
|
@ -135,8 +143,8 @@ public abstract class FieldEditorOverlayPage
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We override the addField method. This allows us to store each field editor added by subclasses
|
* We override the addField method. This allows us to store each field
|
||||||
* in a list for later processing.
|
* editor added by subclasses in a list for later processing.
|
||||||
*
|
*
|
||||||
* @see org.eclipse.jface.preference.FieldEditorPreferencePage#addField(org.eclipse.jface.preference.FieldEditor)
|
* @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.
|
* We override the createControl method. In case of property pages we create
|
||||||
* In case of property pages we create a new PropertyStore as local preference store.
|
* a new PropertyStore as local preference store. After all control have
|
||||||
* After all control have been create, we enable/disable these controls.
|
* been create, we enable/disable these controls.
|
||||||
*
|
*
|
||||||
* @see org.eclipse.jface.preference.PreferencePage#createControl()
|
* @see org.eclipse.jface.preference.PreferencePage#createControl()
|
||||||
*/
|
*/
|
||||||
|
@ -158,11 +166,12 @@ public abstract class FieldEditorOverlayPage
|
||||||
// Cache the page id
|
// Cache the page id
|
||||||
pageId = getPageId();
|
pageId = getPageId();
|
||||||
// Create an overlay preference store and fill it with properties
|
// Create an overlay preference store and fill it with properties
|
||||||
overlayStore =
|
ProjectScope ps = new ProjectScope((IProject) getElement());
|
||||||
new PropertyStore(
|
ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps,
|
||||||
(IResource) getElement(),
|
CodanCorePlugin.PLUGIN_ID);
|
||||||
super.getPreferenceStore(),
|
scoped.setSearchContexts(new IScopeContext[] { ps,
|
||||||
pageId);
|
new InstanceScope() });
|
||||||
|
overlayStore = scoped;
|
||||||
// Set overlay store as current preference store
|
// Set overlay store as current preference store
|
||||||
}
|
}
|
||||||
super.createControl(parent);
|
super.createControl(parent);
|
||||||
|
@ -172,8 +181,8 @@ public abstract class FieldEditorOverlayPage
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We override the createContents method.
|
* We override the createContents method. In case of property pages we
|
||||||
* In case of property pages we insert two radio buttons at the top of the page.
|
* insert two radio buttons at the top of the page.
|
||||||
*
|
*
|
||||||
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
|
* @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.
|
* Creates and initializes a selection group with two choice buttons and one
|
||||||
* @param parent - the parent composite
|
* push button.
|
||||||
|
*
|
||||||
|
* @param parent
|
||||||
|
* - the parent composite
|
||||||
*/
|
*/
|
||||||
private void createSelectionGroup(Composite parent) {
|
private void createSelectionGroup(Composite parent) {
|
||||||
Composite comp = new Composite(parent, SWT.NONE);
|
Composite comp = new Composite(parent, SWT.NONE);
|
||||||
|
@ -197,10 +209,13 @@ public abstract class FieldEditorOverlayPage
|
||||||
Composite radioGroup = new Composite(comp, SWT.NONE);
|
Composite radioGroup = new Composite(comp, SWT.NONE);
|
||||||
radioGroup.setLayout(new GridLayout());
|
radioGroup.setLayout(new GridLayout());
|
||||||
radioGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
radioGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||||
useWorkspaceSettingsButton = createRadioButton(radioGroup, Messages.getString("OverlayPage.Use_Workspace_Settings")); //$NON-NLS-1$
|
useWorkspaceSettingsButton = createRadioButton(radioGroup, Messages
|
||||||
useProjectSettingsButton = createRadioButton(radioGroup, Messages.getString("OverlayPage.Use_Project_Settings")); //$NON-NLS-1$
|
.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 = 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() {
|
configureButton.addSelectionListener(new SelectionAdapter() {
|
||||||
public void widgetSelected(SelectionEvent e) {
|
public void widgetSelected(SelectionEvent e) {
|
||||||
configureWorkspaceSettings();
|
configureWorkspaceSettings();
|
||||||
|
@ -208,9 +223,9 @@ public abstract class FieldEditorOverlayPage
|
||||||
});
|
});
|
||||||
// Set workspace/project radio buttons
|
// Set workspace/project radio buttons
|
||||||
try {
|
try {
|
||||||
String use =
|
String use = ((IResource) getElement())
|
||||||
((IResource) getElement()).getPersistentProperty(
|
.getPersistentProperty(new QualifiedName(pageId,
|
||||||
new QualifiedName(pageId, USEPROJECTSETTINGS));
|
USEPROJECTSETTINGS));
|
||||||
if (TRUE.equals(use)) {
|
if (TRUE.equals(use)) {
|
||||||
useProjectSettingsButton.setSelection(true);
|
useProjectSettingsButton.setSelection(true);
|
||||||
configureButton.setEnabled(false);
|
configureButton.setEnabled(false);
|
||||||
|
@ -223,8 +238,11 @@ public abstract class FieldEditorOverlayPage
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method creating a radio button
|
* 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
|
* @return - the new button
|
||||||
*/
|
*/
|
||||||
private Button createRadioButton(Composite parent, String label) {
|
private Button createRadioButton(Composite parent, String label) {
|
||||||
|
@ -232,8 +250,8 @@ public abstract class FieldEditorOverlayPage
|
||||||
button.setText(label);
|
button.setText(label);
|
||||||
button.addSelectionListener(new SelectionAdapter() {
|
button.addSelectionListener(new SelectionAdapter() {
|
||||||
public void widgetSelected(SelectionEvent e) {
|
public void widgetSelected(SelectionEvent e) {
|
||||||
configureButton.setEnabled(
|
configureButton
|
||||||
button == useWorkspaceSettingsButton);
|
.setEnabled(button == useWorkspaceSettingsButton);
|
||||||
updateFieldEditors();
|
updateFieldEditors();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -241,8 +259,9 @@ public abstract class FieldEditorOverlayPage
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns in case of property pages the overlay store,
|
* Returns in case of property pages the overlay store, in case of
|
||||||
* in case of preference pages the standard preference store
|
* preference pages the standard preference store
|
||||||
|
*
|
||||||
* @see org.eclipse.jface.preference.PreferencePage#getPreferenceStore()
|
* @see org.eclipse.jface.preference.PreferencePage#getPreferenceStore()
|
||||||
*/
|
*/
|
||||||
public IPreferenceStore getPreferenceStore() {
|
public IPreferenceStore getPreferenceStore() {
|
||||||
|
@ -261,9 +280,11 @@ public abstract class FieldEditorOverlayPage
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables or disables the field editors and buttons of this page
|
* Enables or disables the field editors and buttons of this page Subclasses
|
||||||
* Subclasses may override.
|
* may override.
|
||||||
* @param enabled - true if enabled
|
*
|
||||||
|
* @param enabled
|
||||||
|
* - true if enabled
|
||||||
*/
|
*/
|
||||||
protected void updateFieldEditors(boolean enabled) {
|
protected void updateFieldEditors(boolean enabled) {
|
||||||
Composite parent = getFieldEditorParent();
|
Composite parent = getFieldEditorParent();
|
||||||
|
@ -275,9 +296,9 @@ public abstract class FieldEditorOverlayPage
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We override the performOk method. In case of property pages we copy the values in the
|
* We override the performOk method. In case of property pages we copy the
|
||||||
* overlay store into the property values of the selected project.
|
* values in the overlay store into the property values of the selected
|
||||||
* We also save the state of the radio buttons.
|
* project. We also save the state of the radio buttons.
|
||||||
*
|
*
|
||||||
* @see org.eclipse.jface.preference.IPreferencePage#performOk()
|
* @see org.eclipse.jface.preference.IPreferencePage#performOk()
|
||||||
*/
|
*/
|
||||||
|
@ -287,11 +308,10 @@ public abstract class FieldEditorOverlayPage
|
||||||
// Save state of radiobuttons in project properties
|
// Save state of radiobuttons in project properties
|
||||||
IResource resource = (IResource) getElement();
|
IResource resource = (IResource) getElement();
|
||||||
try {
|
try {
|
||||||
String value =
|
String value = (useProjectSettingsButton.getSelection()) ? TRUE
|
||||||
(useProjectSettingsButton.getSelection()) ? TRUE : FALSE;
|
: FALSE;
|
||||||
resource.setPersistentProperty(
|
resource.setPersistentProperty(new QualifiedName(pageId,
|
||||||
new QualifiedName(pageId, USEPROJECTSETTINGS),
|
USEPROJECTSETTINGS), value);
|
||||||
value);
|
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -320,8 +340,8 @@ public abstract class FieldEditorOverlayPage
|
||||||
protected void configureWorkspaceSettings() {
|
protected void configureWorkspaceSettings() {
|
||||||
try {
|
try {
|
||||||
// create a new instance of the current class
|
// create a new instance of the current class
|
||||||
IPreferencePage page =
|
IPreferencePage page = (IPreferencePage) this.getClass()
|
||||||
(IPreferencePage) this.getClass().newInstance();
|
.newInstance();
|
||||||
page.setTitle(getTitle());
|
page.setTitle(getTitle());
|
||||||
page.setImageDescriptor(image);
|
page.setImageDescriptor(image);
|
||||||
// and show it
|
// and show it
|
||||||
|
@ -335,15 +355,18 @@ public abstract class FieldEditorOverlayPage
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a single preference pages
|
* 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) {
|
protected void showPreferencePage(String id, IPreferencePage page) {
|
||||||
final IPreferenceNode targetNode = new PreferenceNode(id, page);
|
final IPreferenceNode targetNode = new PreferenceNode(id, page);
|
||||||
PreferenceManager manager = new PreferenceManager();
|
PreferenceManager manager = new PreferenceManager();
|
||||||
manager.addToRoot(targetNode);
|
manager.addToRoot(targetNode);
|
||||||
final PreferenceDialog dialog =
|
final PreferenceDialog dialog = new PreferenceDialog(getControl()
|
||||||
new PreferenceDialog(getControl().getShell(), manager);
|
.getShell(), manager);
|
||||||
BusyIndicator.showWhile(getControl().getDisplay(), new Runnable() {
|
BusyIndicator.showWhile(getControl().getDisplay(), new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
dialog.create();
|
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;
|
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.core.runtime.preferences.AbstractPreferenceInitializer;
|
||||||
import org.eclipse.jface.preference.IPreferenceStore;
|
import org.eclipse.jface.preference.IPreferenceStore;
|
||||||
|
|
||||||
|
|
|
@ -10,14 +10,16 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
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.CodanProblem;
|
||||||
import org.eclipse.cdt.codan.core.model.CodanSeverity;
|
|
||||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblemCategory;
|
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.BaseLabelProvider;
|
||||||
import org.eclipse.jface.viewers.CheckStateChangedEvent;
|
import org.eclipse.jface.viewers.CheckStateChangedEvent;
|
||||||
import org.eclipse.jface.viewers.IBaseLabelProvider;
|
import org.eclipse.jface.viewers.IBaseLabelProvider;
|
||||||
|
import org.eclipse.jface.viewers.ICheckStateProvider;
|
||||||
import org.eclipse.jface.viewers.IContentProvider;
|
import org.eclipse.jface.viewers.IContentProvider;
|
||||||
import org.eclipse.jface.viewers.ITableLabelProvider;
|
import org.eclipse.jface.viewers.ITableLabelProvider;
|
||||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||||
|
@ -28,9 +30,70 @@ import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.TreeColumn;
|
import org.eclipse.swt.widgets.TreeColumn;
|
||||||
|
|
||||||
public class ProblemsTreeEditor extends CheckedTreeEditor {
|
public class ProblemsTreeEditor extends CheckedTreeEditor {
|
||||||
|
private CodanPreferencesLoader codanPreferencesLoader = new CodanPreferencesLoader();
|
||||||
|
|
||||||
public ProblemsTreeEditor() {
|
public ProblemsTreeEditor() {
|
||||||
super();
|
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,
|
class ProblemsContentProvider implements IContentProvider,
|
||||||
|
@ -49,6 +112,10 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
|
||||||
if (parentElement instanceof IProblemCategory) {
|
if (parentElement instanceof IProblemCategory) {
|
||||||
return ((IProblemCategory) parentElement).getChildren();
|
return ((IProblemCategory) parentElement).getChildren();
|
||||||
}
|
}
|
||||||
|
if (parentElement instanceof IProblemsProfile) {
|
||||||
|
return ((IProblemsProfile) parentElement).getRoot()
|
||||||
|
.getChildren();
|
||||||
|
}
|
||||||
return new Object[0];
|
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) {
|
public void checkStateChanged(CheckStateChangedEvent event) {
|
||||||
Object element = event.getElement();
|
Object element = event.getElement();
|
||||||
if (element instanceof CodanProblem) {
|
if (element instanceof CodanProblem) {
|
||||||
|
@ -125,13 +163,14 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProblemsTreeEditor(Composite parent) {
|
public ProblemsTreeEditor(Composite parent, IProblemsProfile profile) {
|
||||||
super("problems", "Problems", parent);
|
super(PreferenceConstants.P_PROBLEMS, "Problems", parent);
|
||||||
setEmptySelectionAllowed(true);
|
setEmptySelectionAllowed(true);
|
||||||
getTreeViewer().getTree().setHeaderVisible(true);
|
getTreeViewer().getTree().setHeaderVisible(true);
|
||||||
// getTreeViewer().getTree().
|
// getTreeViewer().getTree().
|
||||||
getTreeViewer().setContentProvider(new ProblemsContentProvider());
|
getTreeViewer().setContentProvider(new ProblemsContentProvider());
|
||||||
getTreeViewer().setLabelProvider(new ProblemsLabelProvider());
|
getTreeViewer().setLabelProvider(new ProblemsLabelProvider());
|
||||||
|
getTreeViewer().setCheckStateProvider(new ProblemsCheckStateProvider());
|
||||||
// column Name
|
// column Name
|
||||||
TreeColumn column = new TreeColumn(getTreeViewer().getTree(), SWT.NONE);
|
TreeColumn column = new TreeColumn(getTreeViewer().getTree(), SWT.NONE);
|
||||||
column.setWidth(300);
|
column.setWidth(300);
|
||||||
|
@ -140,7 +179,30 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
|
||||||
TreeColumn column2 = new TreeColumn(getTreeViewer().getTree(), SWT.NONE);
|
TreeColumn column2 = new TreeColumn(getTreeViewer().getTree(), SWT.NONE);
|
||||||
column2.setWidth(100);
|
column2.setWidth(100);
|
||||||
column2.setText("Severity");
|
column2.setText("Severity");
|
||||||
getTreeViewer().setInput(
|
codanPreferencesLoader.setInput(profile);
|
||||||
CheckersRegisry.getInstance().getProblemsTree());
|
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.cdt.codan.core.builder.CodanBuilder;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.jface.action.IAction;
|
import org.eclipse.jface.action.IAction;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
|
@ -25,7 +26,6 @@ public class RunCodeAnalysis implements IObjectActionDelegate {
|
||||||
|
|
||||||
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run(IAction action) {
|
public void run(IAction action) {
|
||||||
|
@ -34,14 +34,17 @@ public class RunCodeAnalysis implements IObjectActionDelegate {
|
||||||
Object o = iterator.next();
|
Object o = iterator.next();
|
||||||
if (o instanceof IResource) {
|
if (o instanceof IResource) {
|
||||||
IResource res = (IResource) o;
|
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) {
|
public void selectionChanged(IAction action, ISelection selection) {
|
||||||
this.sel = selection;
|
this.sel = selection;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue