1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 01:35:39 +02:00

Added scope preference for checkers

This commit is contained in:
Alena Laskavaia 2010-05-24 15:05:39 +00:00
parent fc70a0f70d
commit c2919ed4f9
21 changed files with 4069 additions and 59 deletions

View file

@ -63,6 +63,7 @@ public abstract class AbstractIndexAstChecker extends AbstractCheckerWithProblem
}
public synchronized boolean processResource(IResource resource) {
if (!shouldProduceProblems(resource)) return false;
if (resource instanceof IFile) {
IFile file = (IFile) resource;
try {
@ -102,7 +103,7 @@ public abstract class AbstractIndexAstChecker extends AbstractCheckerWithProblem
else
loc = getRuntime().getProblemLocationFactory()
.createProblemLocation(astFile, line);
getProblemReporter().reportProblem(id, loc, args);
reportProblem(id, loc, args);
}
@Override

View file

@ -65,9 +65,9 @@ public abstract class AbstractChecker implements IChecker {
* - file in scope
* @return problem instance
*/
public IProblem getProblemById(String id, IFile file) {
IProblem problem = CheckersRegistry.getInstance().getResourceProfile(
file).findProblem(id);
public IProblem getProblemById(String id, IResource file) {
IProblem problem = CheckersRegistry.getInstance()
.getResourceProfile(file).findProblem(id);
if (problem == null)
throw new IllegalArgumentException("Id is not registered"); //$NON-NLS-1$
return problem;
@ -144,4 +144,9 @@ public abstract class AbstractChecker implements IChecker {
public boolean runInEditor() {
return this instanceof IRunnableInEditorChecker;
}
public void reportProblem(String problemId, IProblemLocation loc,
Object... args) {
getProblemReporter().reportProblem(problemId, loc, args);
}
}

View file

@ -10,11 +10,17 @@
*******************************************************************************/
package org.eclipse.cdt.codan.core.model;
import java.util.Collection;
import java.util.Iterator;
import org.eclipse.cdt.codan.core.param.BasicProblemPreference;
import org.eclipse.cdt.codan.core.param.FileScopeProblemPreference;
import org.eclipse.cdt.codan.core.param.IProblemPreference;
import org.eclipse.cdt.codan.core.param.IProblemPreferenceDescriptor.PreferenceType;
import org.eclipse.cdt.codan.core.param.ListProblemPreference;
import org.eclipse.cdt.codan.core.param.MapProblemPreference;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
/**
* AbstarctChecker that has extra methods to simplify adding problem
@ -28,7 +34,55 @@ public abstract class AbstractCheckerWithProblemPreferences extends
* Checker that actually has parameter must override this
*/
public void initPreferences(IProblemWorkingCopy problem) {
// do nothing
// by default add file scope preference
addPreference(problem, new FileScopeProblemPreference(), null);
}
/**
* @param problem
* @return
*/
public FileScopeProblemPreference getScopePreference(IProblem problem) {
FileScopeProblemPreference scope = (FileScopeProblemPreference) getTopLevelPreferenceMap(
problem).getChildDescriptor(FileScopeProblemPreference.KEY);
return scope;
}
/**
* User can scope out some resources for this checker. Checker can use this
* call to test if it should run on this resource at all or not. Test should
* be done within processResource method not in enabledInContext.
*
* @param res
* @return
*/
public boolean shouldProduceProblems(IResource res) {
Collection<IProblem> refProblems = getRuntime().getChechersRegistry()
.getRefProblems(this);
for (Iterator<IProblem> iterator = refProblems.iterator(); iterator
.hasNext();) {
IProblem checkerProblem = iterator.next();
if (shouldProduceProblem(
getProblemById(checkerProblem.getId(), res),
res.getLocation()))
return true;
}
return false;
}
public boolean shouldProduceProblem(IProblem problem, IPath resource) {
FileScopeProblemPreference scope = getScopePreference(problem);
if (scope == null)
return true;
return scope.isInScope(resource);
}
@Override
public void reportProblem(String problemId, IProblemLocation loc,
Object... args) {
if (shouldProduceProblem(getProblemById(problemId, loc.getFile()), loc
.getFile().getLocation()))
super.reportProblem(problemId, loc, args);
}
/**
@ -102,13 +156,14 @@ public abstract class AbstractCheckerWithProblemPreferences extends
* @param problem
* @return
*/
protected MapProblemPreference getTopLevelPreferenceMap(
IProblemWorkingCopy problem) {
protected MapProblemPreference getTopLevelPreferenceMap(IProblem problem) {
MapProblemPreference map = (MapProblemPreference) problem
.getPreference();
if (map == null) {
map = new MapProblemPreference("params", ""); //$NON-NLS-1$ //$NON-NLS-2$
problem.setPreference(map);
if (problem instanceof IProblemWorkingCopy) {
((IProblemWorkingCopy) problem).setPreference(map);
}
}
return map;
}

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.codan.core.param;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
@ -150,6 +151,39 @@ public abstract class AbstractProblemPreference implements IProblemPreference {
/**
* @param tokenizer
* @return
* @throws IOException
*/
public abstract void importValue(StreamTokenizer tokenizer);
public abstract void importValue(StreamTokenizer tokenizer)
throws IOException;
public void importValue(String str) {
StreamTokenizer tokenizer = getImportTokenizer(str);
try {
importValue(tokenizer);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(str, e);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
protected String escape(String x) {
x = x.replaceAll("[\"\\\\]", "\\\\$0"); //$NON-NLS-1$//$NON-NLS-2$
return "\"" + x + "\""; //$NON-NLS-1$//$NON-NLS-2$
}
/**
* @param str
* @return
*/
protected String unescape(String str) {
StreamTokenizer tokenizer = getImportTokenizer(str);
try {
tokenizer.nextToken();
} catch (IOException e) {
return null;
}
String sval = tokenizer.sval;
return sval;
}
}

View file

@ -81,11 +81,6 @@ public class BasicProblemPreference extends AbstractProblemPreference {
return x;
}
protected String escape(String x) {
x = x.replaceAll("[\"\\\\]", "\\\\$0"); //$NON-NLS-1$//$NON-NLS-2$
return "\"" + x + "\""; //$NON-NLS-1$//$NON-NLS-2$
}
/*
* (non-Javadoc)
*
@ -93,6 +88,7 @@ public class BasicProblemPreference extends AbstractProblemPreference {
* org.eclipse.cdt.codan.core.param.IProblemPreferenceValue#importValue(
* java.lang.String)
*/
@Override
public void importValue(String str) {
if (str.startsWith("\"")) //$NON-NLS-1$
str = unescape(str);
@ -115,21 +111,6 @@ public class BasicProblemPreference extends AbstractProblemPreference {
}
}
/**
* @param str
* @return
*/
protected String unescape(String str) {
StreamTokenizer tokenizer = getImportTokenizer(str);
try {
tokenizer.nextToken();
} catch (IOException e) {
return null;
}
String sval = tokenizer.sval;
return sval;
}
@Override
public String toString() {
return "(" + type + ")" + key + ((value == null) ? "" : "=" + value); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$

View file

@ -0,0 +1,264 @@
/*******************************************************************************
* Copyright (c) 2009,2010 QNX Software Systems
* 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:
* QNX Software Systems (Alena Laskavaia) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.codan.core.param;
import java.io.IOException;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.codan.internal.core.CharOperation;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/**
* TODO: add description
*/
public class FileScopeProblemPreference extends AbstractProblemPreference {
public static final String KEY = "fileScope"; //$NON-NLS-1$
public static final String EXCLUSION = "exclusion"; //$NON-NLS-1$
public static final String INCLUSION = "inclusion"; //$NON-NLS-1$
private IResource resource;
private IPath[] inclusion = new IPath[0];
private IPath[] exclusion = new IPath[0];
public FileScopeProblemPreference() {
setKey(KEY);
setLabel("File Exclusion and Inclusion");
setType(PreferenceType.TYPE_CUSTOM);
}
/**
* @param key
* @return
*/
public IPath[] getAttribute(String key) {
if (key == EXCLUSION)
return exclusion;
if (key == INCLUSION)
return inclusion;
return null;
}
public void setAttribute(String key, IPath[] value) {
if (key == EXCLUSION)
exclusion = value.clone();
if (key == INCLUSION)
inclusion = value.clone();
}
/**
* @return
*/
public IProject getProject() {
if (resource != null)
return resource.getProject();
return null;
}
/**
* @return
*/
public IPath getPath() {
if (resource != null)
return resource.getFullPath();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
return root.getFullPath();
}
/**
* @param resource
* the resource to set
*/
public void setResource(IResource resource) {
this.resource = resource;
}
/**
* @return the resource
*/
public IResource getResource() {
return resource;
}
public String exportValue() {
return exportPathList(INCLUSION, inclusion) + "," //$NON-NLS-1$
+ exportPathList(EXCLUSION, exclusion);
}
/**
* @param inclusion2
* @param inclusion3
* @return
*/
private String exportPathList(String key, IPath[] arr) {
String res = key + "=>("; //$NON-NLS-1$
for (int i = 0; i < arr.length; i++) {
if (i != 0)
res += ","; //$NON-NLS-1$
res += escape(arr[i].toPortableString());
}
return res + ")"; //$NON-NLS-1$
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.cdt.codan.core.param.AbstractProblemPreference#importValue
* (java.io.StreamTokenizer)
*/
@Override
public void importValue(StreamTokenizer tokenizer) throws IOException {
List<IPath> inc = importPathList(tokenizer, INCLUSION);
inclusion = inc.toArray(new IPath[inc.size()]);
checkChar(tokenizer, ',');
List<IPath> exc = importPathList(tokenizer, EXCLUSION);
exclusion = exc.toArray(new IPath[exc.size()]);
}
/**
* @param tokenizer
* @param c
* @throws IOException
*/
private void checkChar(StreamTokenizer tokenizer, char c)
throws IOException {
tokenizer.nextToken();
if (tokenizer.ttype != c)
throw new IllegalArgumentException("Expected " + c); //$NON-NLS-1$
}
/**
* @param tokenizer
* @param inclusion2
* @throws IOException
* @throws IllegalAccessException
*/
private void checkKeyword(StreamTokenizer tokenizer, String keyword)
throws IOException {
tokenizer.nextToken();
if (tokenizer.sval == null || !tokenizer.sval.equals(keyword))
throw new IllegalArgumentException("Expected " + keyword); //$NON-NLS-1$
}
protected List<IPath> importPathList(StreamTokenizer tokenizer,
String keyword) throws IOException {
checkKeyword(tokenizer, keyword);
checkChar(tokenizer, '=');
checkChar(tokenizer, '>');
ArrayList<IPath> list = new ArrayList<IPath>();
int token;
int index = 0;
try {
checkChar(tokenizer, '(');
token = tokenizer.nextToken();
if (token != ')')
tokenizer.pushBack();
else
return Collections.emptyList();
while (true) {
token = tokenizer.nextToken();
if (tokenizer.sval == null)
throw new IllegalArgumentException();
list.add(new Path(tokenizer.sval));
token = tokenizer.nextToken();
if (token == ')')
break;
tokenizer.pushBack();
checkChar(tokenizer, ',');
index++;
}
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
return list;
}
@Override
public Object getValue() {
return this;
}
@Override
public void setValue(Object value) {
if (this == value)
return;
FileScopeProblemPreference scope = (FileScopeProblemPreference) value;
setAttribute(INCLUSION, scope.getAttribute(INCLUSION));
setAttribute(EXCLUSION, scope.getAttribute(EXCLUSION));
this.resource = scope.getResource();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.codan.core.param.AbstractProblemPreference#clone()
*/
@Override
public Object clone() {
FileScopeProblemPreference scope = (FileScopeProblemPreference) super
.clone();
scope.setValue(this);
return scope;
}
/**
* @param file
* @return
*/
public boolean isInScope(IPath file) {
//System.err.println("test " + file + " " + exportValue());
if (inclusion.length > 0) {
if (!matchesFilter(file, inclusion))
return false;
}
if (exclusion.length > 0) {
if (matchesFilter(file, exclusion))
return false;
}
return true;
}
/**
* @param resourcePath
* @param inclusion2
* @return
*/
private boolean matchesFilter(IPath resourcePath, IPath[] paths) {
char[] path = resourcePath.toString().toCharArray();
for (int i = 0, length = paths.length; i < length; i++) {
char[] pattern = paths[i].toString().toCharArray();
if (CharOperation.pathMatch(pattern, path, true, '/')) {
return true;
}
}
return false;
}
public static boolean isExcludedPath(IPath resourcePath, IPath[] paths) {
char[] path = resourcePath.toString().toCharArray();
for (int i = 0, length = paths.length; i < length; i++) {
char[] pattern = paths[i].toString().toCharArray();
if (CharOperation.pathMatch(pattern, path, true, '/')) {
return true;
}
}
return false;
}
}

View file

@ -36,7 +36,8 @@ public interface IProblemPreferenceDescriptor extends Cloneable {
TYPE_BOOLEAN("boolean"), //$NON-NLS-1$
TYPE_FILE("file"), //$NON-NLS-1$
TYPE_LIST("list"), //$NON-NLS-1$
TYPE_MAP("map"); //$NON-NLS-1$
TYPE_MAP("map"), //$NON-NLS-1$
TYPE_CUSTOM("custom"); //$NON-NLS-1$
private String literal;
private PreferenceType(String literal) {
@ -75,8 +76,7 @@ public interface IProblemPreferenceDescriptor extends Cloneable {
return TYPE_LIST;
if (value instanceof Map)
return TYPE_MAP;
throw new IllegalArgumentException(
"Cannot determine type for " + value.getClass()); //$NON-NLS-1$
return TYPE_CUSTOM;
}
}

View file

@ -157,11 +157,16 @@ public class ListProblemPreference extends AbstractProblemPreference implements
list.remove(index);
}
@SuppressWarnings("unchecked")
@Override
public Object clone() {
ListProblemPreference list1 = (ListProblemPreference) super.clone();
list1.list = (ArrayList<Object>) list.clone();
list1.list = new ArrayList<Object>();
list1.setChildDescriptor((IProblemPreference) getChildDescriptor()
.clone());
for (Iterator<Object> iterator = list.iterator(); iterator.hasNext();) {
Object value = iterator.next();
list1.addChildValue(value);
}
return list1;
}
@ -177,6 +182,7 @@ public class ListProblemPreference extends AbstractProblemPreference implements
return buf.toString() + ")"; //$NON-NLS-1$
}
@Override
public void importValue(String str) {
StreamTokenizer tokenizer = getImportTokenizer(str);
try {

View file

@ -98,11 +98,15 @@ public class MapProblemPreference extends AbstractProblemPreference implements
hash.remove(key);
}
@SuppressWarnings("unchecked")
@Override
public Object clone() {
MapProblemPreference map = (MapProblemPreference) super.clone();
map.hash = (LinkedHashMap<String, IProblemPreference>) hash.clone();
map.hash = new LinkedHashMap<String, IProblemPreference>();
for (Iterator<String> iterator = hash.keySet().iterator(); iterator
.hasNext();) {
String key = iterator.next();
map.hash.put(key, (IProblemPreference) hash.get(key).clone());
}
return map;
}
@ -119,6 +123,7 @@ public class MapProblemPreference extends AbstractProblemPreference implements
return buf.toString() + "}"; //$NON-NLS-1$
}
@Override
public void importValue(String str) {
StreamTokenizer tokenizer = getImportTokenizer(str);
try {

View file

@ -70,7 +70,11 @@ public class CodanProblem implements IProblemWorkingCopy {
*/
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
CodanProblem prob = (CodanProblem) super.clone();
if (preference != null) {
prob.preference = (IProblemPreference) preference.clone();
}
return prob;
}
public void setPreference(IProblemPreference value) {

View file

@ -41,6 +41,40 @@ public class CodanUIMessages extends NLS {
public static String Job_TitleRunningAnalysis;
public static String ParametersComposite_NewValue;
public static String ParametersComposite_None;
//
public static String ExclusionInclusionDialog_title;
public static String ExclusionInclusionDialog_description;
public static String ExclusionInclusionDialog_description2;
public static String ExclusionInclusionDialog_exclusion_pattern_label;
public static String ExclusionInclusionDialog_inclusion_pattern_label;
public static String ExclusionInclusionDialog_inclusion_pattern_add;
public static String ExclusionInclusionDialog_inclusion_pattern_add_multiple;
public static String ExclusionInclusionDialog_inclusion_pattern_remove;
public static String ExclusionInclusionDialog_inclusion_pattern_edit;
public static String ExclusionInclusionDialog_exclusion_pattern_add;
public static String ExclusionInclusionDialog_exclusion_pattern_add_multiple;
public static String ExclusionInclusionDialog_exclusion_pattern_remove;
public static String ExclusionInclusionDialog_exclusion_pattern_edit;
public static String ExclusionInclusionDialog_ChooseExclusionPattern_title;
public static String ExclusionInclusionDialog_ChooseExclusionPattern_description;
public static String ExclusionInclusionDialog_ChooseInclusionPattern_title;
public static String ExclusionInclusionDialog_ChooseInclusionPattern_description;
public static String ExclusionInclusionEntryDialog_exclude_add_title;
public static String ExclusionInclusionEntryDialog_exclude_edit_title;
public static String ExclusionInclusionEntryDialog_exclude_description;
public static String ExclusionInclusionEntryDialog_exclude_pattern_label;
public static String ExclusionInclusionEntryDialog_include_add_title;
public static String ExclusionInclusionEntryDialog_include_edit_title;
public static String ExclusionInclusionEntryDialog_include_description;
public static String ExclusionInclusionEntryDialog_include_pattern_label;
public static String ExclusionInclusionEntryDialog_pattern_button;
public static String ExclusionInclusionEntryDialog_error_empty;
public static String ExclusionInclusionEntryDialog_error_notrelative;
public static String ExclusionInclusionEntryDialog_error_exists;
public static String ExclusionInclusionEntryDialog_ChooseExclusionPattern_title;
public static String ExclusionInclusionEntryDialog_ChooseExclusionPattern_description;
public static String ExclusionInclusionEntryDialog_ChooseInclusionPattern_title;
public static String ExclusionInclusionEntryDialog_ChooseInclusionPattern_description;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, CodanUIMessages.class);

View file

@ -13,6 +13,8 @@ package org.eclipse.cdt.codan.internal.ui.dialogs;
import org.eclipse.cdt.codan.core.model.IProblem;
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
import org.eclipse.cdt.codan.internal.ui.widgets.CustomizeProblemComposite;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
@ -27,27 +29,37 @@ import org.eclipse.swt.widgets.Shell;
public class CustomizeProblemDialog extends TitleAreaDialog {
private CustomizeProblemComposite comp;
private IProblem problem;
private IResource resource;
/**
* @param parentShell
* @param selectedProblem
* @param iResource
*/
public CustomizeProblemDialog(Shell parentShell, IProblem selectedProblem) {
public CustomizeProblemDialog(Shell parentShell, IProblem selectedProblem,
IResource resource) {
super(parentShell);
this.problem = selectedProblem;
this.resource = resource;
setShellStyle(getShellStyle() | SWT.RESIZE);
}
/**
* Stores edit values into problem working copy
* @param problem - problem working copy
*
* @param problem
* - problem working copy
*/
public void save(IProblemWorkingCopy problem) {
comp.save(problem);
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse
* .swt.widgets.Composite)
*/
@Override
protected Control createDialogArea(Composite parent) {
@ -55,14 +67,16 @@ public class CustomizeProblemDialog extends TitleAreaDialog {
setTitle(problem.getName());
setMessage(CodanUIMessages.CustomizeProblemDialog_Message);
Composite area = (Composite) super.createDialogArea(parent);
comp = new CustomizeProblemComposite(area, problem);
comp = new CustomizeProblemComposite(area, problem, resource);
GridData ld = new GridData(GridData.FILL_BOTH);
ld.minimumHeight=300;
ld.minimumHeight = 300;
comp.setLayoutData(ld);
return area;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
*/
@Override

View file

@ -0,0 +1,274 @@
package org.eclipse.cdt.codan.internal.ui.dialogs;
import java.text.MessageFormat;
import java.util.List;
import org.eclipse.cdt.codan.core.param.FileScopeProblemPreference;
import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
import org.eclipse.cdt.codan.internal.ui.widgets.BasicElementLabels;
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.cdt.internal.ui.dialogs.TypedElementSelectionValidator;
import org.eclipse.cdt.internal.ui.dialogs.TypedViewerFilter;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.StatusDialog;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.eclipse.ui.views.navigator.ResourceComparator;
public class ExclusionInclusionEntryDialog extends StatusDialog {
private StringButtonDialogField fExclusionPatternDialog;
private StatusInfo fExclusionPatternStatus;
private IContainer fCurrSourceFolder;
private String fExclusionPattern;
private List fExistingPatterns;
private boolean fIsExclusion;
public ExclusionInclusionEntryDialog(Shell parent, boolean isExclusion,
String patternToEdit, List existingPatterns,
FileScopeProblemPreference entryToEdit) {
super(parent);
fIsExclusion = isExclusion;
fExistingPatterns = existingPatterns;
String title, message;
if (isExclusion) {
if (patternToEdit == null) {
title = CodanUIMessages.ExclusionInclusionEntryDialog_exclude_add_title;
} else {
title = CodanUIMessages.ExclusionInclusionEntryDialog_exclude_edit_title;
}
message = MessageFormat
.format(CodanUIMessages.ExclusionInclusionEntryDialog_exclude_pattern_label,
BasicElementLabels.getPathLabel(
entryToEdit.getPath(), false));
} else {
if (patternToEdit == null) {
title = CodanUIMessages.ExclusionInclusionEntryDialog_include_add_title;
} else {
title = CodanUIMessages.ExclusionInclusionEntryDialog_include_edit_title;
}
message = MessageFormat
.format(CodanUIMessages.ExclusionInclusionEntryDialog_include_pattern_label,
BasicElementLabels.getPathLabel(
entryToEdit.getPath(), false));
}
setTitle(title);
if (patternToEdit != null) {
fExistingPatterns.remove(patternToEdit);
}
IProject currProject = entryToEdit.getProject();
IWorkspaceRoot root = currProject != null ? currProject.getWorkspace()
.getRoot() : ResourcesPlugin.getWorkspace().getRoot();
IResource res = root.findMember(entryToEdit.getPath());
if (res instanceof IContainer) {
fCurrSourceFolder = (IContainer) res;
}
fExclusionPatternStatus = new StatusInfo();
ExclusionPatternAdapter adapter = new ExclusionPatternAdapter();
fExclusionPatternDialog = new StringButtonDialogField(adapter);
fExclusionPatternDialog.setLabelText(message);
fExclusionPatternDialog
.setButtonLabel(CodanUIMessages.ExclusionInclusionEntryDialog_pattern_button);
fExclusionPatternDialog.setDialogFieldListener(adapter);
fExclusionPatternDialog.enableButton(fCurrSourceFolder != null);
if (patternToEdit == null) {
fExclusionPatternDialog.setText(""); //$NON-NLS-1$
} else {
fExclusionPatternDialog.setText(patternToEdit.toString());
}
}
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
int widthHint = convertWidthInCharsToPixels(60);
Composite inner = new Composite(composite, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.numColumns = 2;
inner.setLayout(layout);
Label description = new Label(inner, SWT.WRAP);
if (fIsExclusion) {
description
.setText(CodanUIMessages.ExclusionInclusionEntryDialog_exclude_description);
} else {
description
.setText(CodanUIMessages.ExclusionInclusionEntryDialog_include_description);
}
GridData gd = new GridData();
gd.horizontalSpan = 2;
gd.widthHint = convertWidthInCharsToPixels(80);
description.setLayoutData(gd);
fExclusionPatternDialog.doFillIntoGrid(inner, 3);
LayoutUtil.setWidthHint(fExclusionPatternDialog.getLabelControl(null),
widthHint);
LayoutUtil.setHorizontalSpan(
fExclusionPatternDialog.getLabelControl(null), 2);
LayoutUtil.setWidthHint(fExclusionPatternDialog.getTextControl(null),
widthHint);
LayoutUtil.setHorizontalGrabbing(fExclusionPatternDialog
.getTextControl(null));
fExclusionPatternDialog.postSetFocusOnDialogField(parent.getDisplay());
applyDialogFont(composite);
return composite;
}
// -------- ExclusionPatternAdapter --------
private class ExclusionPatternAdapter implements IDialogFieldListener,
IStringButtonAdapter {
// -------- IDialogFieldListener
public void dialogFieldChanged(DialogField field) {
doStatusLineUpdate();
}
public void changeControlPressed(DialogField field) {
doChangeControlPressed();
}
}
protected void doChangeControlPressed() {
IPath pattern = chooseExclusionPattern();
if (pattern != null) {
fExclusionPatternDialog.setText(pattern.toString());
}
}
protected void doStatusLineUpdate() {
checkIfPatternValid();
updateStatus(fExclusionPatternStatus);
}
protected void checkIfPatternValid() {
String pattern = fExclusionPatternDialog.getText().trim();
if (pattern.length() == 0) {
fExclusionPatternStatus
.setError(CodanUIMessages.ExclusionInclusionEntryDialog_error_empty);
return;
}
IPath path = new Path(pattern);
if (path.isAbsolute() || path.getDevice() != null) {
fExclusionPatternStatus
.setError(CodanUIMessages.ExclusionInclusionEntryDialog_error_notrelative);
return;
}
if (fExistingPatterns.contains(pattern)) {
fExclusionPatternStatus
.setError(CodanUIMessages.ExclusionInclusionEntryDialog_error_exists);
return;
}
fExclusionPattern = pattern;
fExclusionPatternStatus.setOK();
}
public String getExclusionPattern() {
return fExclusionPattern;
}
/*
* @see org.eclipse.jface.window.Window#configureShell(Shell)
*/
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
}
// ---------- util method ------------
private IPath chooseExclusionPattern() {
String title, message;
if (fIsExclusion) {
title = CodanUIMessages.ExclusionInclusionEntryDialog_ChooseExclusionPattern_title;
message = CodanUIMessages.ExclusionInclusionEntryDialog_ChooseExclusionPattern_description;
} else {
title = CodanUIMessages.ExclusionInclusionEntryDialog_ChooseInclusionPattern_title;
message = CodanUIMessages.ExclusionInclusionEntryDialog_ChooseInclusionPattern_description;
}
IPath initialPath = new Path(fExclusionPatternDialog.getText());
IPath[] res = chooseExclusionPattern(getShell(), fCurrSourceFolder,
title, message, initialPath, false);
if (res == null) {
return null;
}
return res[0];
}
public static IPath[] chooseExclusionPattern(Shell shell,
IContainer currentSourceFolder, String title, String message,
IPath initialPath, boolean multiSelection) {
Class[] acceptedClasses = new Class[] { IFolder.class, IFile.class,
IProject.class };
ISelectionStatusValidator validator = new TypedElementSelectionValidator(
acceptedClasses, multiSelection);
ViewerFilter filter = new TypedViewerFilter(acceptedClasses);
ILabelProvider lp = new WorkbenchLabelProvider();
ITreeContentProvider cp = new WorkbenchContentProvider();
IResource initialElement = null;
if (initialPath != null) {
IContainer curr = currentSourceFolder;
int nSegments = initialPath.segmentCount();
for (int i = 0; i < nSegments; i++) {
IResource elem = curr.findMember(initialPath.segment(i));
if (elem != null) {
initialElement = elem;
}
if (elem instanceof IContainer) {
curr = (IContainer) elem;
} else {
break;
}
}
}
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(
shell, lp, cp);
dialog.setTitle(title);
dialog.setValidator(validator);
dialog.setMessage(message);
dialog.addFilter(filter);
dialog.setInput(currentSourceFolder);
dialog.setInitialSelection(initialElement);
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
dialog.setHelpAvailable(false);
if (dialog.open() == Window.OK) {
Object[] objects = dialog.getResult();
int existingSegments = currentSourceFolder.getFullPath()
.segmentCount();
IPath[] resArr = new IPath[objects.length];
for (int i = 0; i < objects.length; i++) {
IResource currRes = (IResource) objects[i];
IPath path = currRes.getFullPath()
.removeFirstSegments(existingSegments).makeRelative();
if (currRes instanceof IContainer) {
path = path.addTrailingSeparator();
}
resArr[i] = path;
}
return resArr;
}
return null;
}
}

View file

@ -23,3 +23,53 @@ OverlayPage_Use_Project_Settings=Use pr&oject settings
OverlayPage_Configure_Workspace_Settings=&Configure Workspace Settings...
PropertyStore_Cannot_write_resource_property=Cannot write resource property
# ------- ExclusionInclusionDialog -------
ExclusionInclusionDialog_title=Inclusion and Exclusion Patterns
ExclusionInclusionDialog_description=Included and excluded resources for ''{0}''.
ExclusionInclusionDialog_description2=Add or remove inclusion and exclusion patterns to resources for which problem is reported
ExclusionInclusionDialog_exclusion_pattern_label=E&xclusion patterns:
ExclusionInclusionDialog_inclusion_pattern_label=I&nclusion patterns:
ExclusionInclusionDialog_inclusion_pattern_add=A&dd...
ExclusionInclusionDialog_inclusion_pattern_add_multiple=Add &Multiple...
ExclusionInclusionDialog_inclusion_pattern_remove=&Remove
ExclusionInclusionDialog_inclusion_pattern_edit=&Edit...
ExclusionInclusionDialog_exclusion_pattern_add=&Add...
ExclusionInclusionDialog_exclusion_pattern_add_multiple=Add M&ultiple...
ExclusionInclusionDialog_exclusion_pattern_remove=Rem&ove
ExclusionInclusionDialog_exclusion_pattern_edit=Edi&t...
ExclusionInclusionDialog_ChooseExclusionPattern_title=Exclusion Pattern Selection
ExclusionInclusionDialog_ChooseExclusionPattern_description=&Choose folders or files to exclude:
ExclusionInclusionDialog_ChooseInclusionPattern_title=Inclusion Pattern Selection
ExclusionInclusionDialog_ChooseInclusionPattern_description=&Choose folders or files to include:
# ------- ExclusionInclusionEntryDialog -------
ExclusionInclusionEntryDialog_exclude_add_title=Add Exclusion Pattern
ExclusionInclusionEntryDialog_exclude_edit_title=Edit Exclusion Pattern
ExclusionInclusionEntryDialog_exclude_description=Enter a pattern for excluding files from the source folder. Allowed wildcards are '*', '?' and '**'. Examples: 'src/util/a*.c', 'src/util/', '**/Test*'.
ExclusionInclusionEntryDialog_exclude_pattern_label=E&xclusion pattern (Path relative to ''{0}''):
ExclusionInclusionEntryDialog_include_add_title=Add Inclusion Pattern
ExclusionInclusionEntryDialog_include_edit_title=Edit Inclusion Pattern
ExclusionInclusionEntryDialog_include_description=Enter a pattern for including files to the source folder. Allowed wildcards are '*', '?' and '**'. Examples: 'src/util/a*.c', 'src/util/', '**/Test*'.
ExclusionInclusionEntryDialog_include_pattern_label=I&nclusion pattern (Path relative to ''{0}''):
ExclusionInclusionEntryDialog_pattern_button=Bro&wse...
ExclusionInclusionEntryDialog_error_empty=Enter a pattern.
ExclusionInclusionEntryDialog_error_notrelative=Pattern must be a relative path.
ExclusionInclusionEntryDialog_error_exists=Pattern already exists.
ExclusionInclusionEntryDialog_ChooseExclusionPattern_title=Exclusion Pattern Selection
ExclusionInclusionEntryDialog_ChooseExclusionPattern_description=&Choose a folder or file to exclude:
ExclusionInclusionEntryDialog_ChooseInclusionPattern_title=Inclusion Pattern Selection
ExclusionInclusionEntryDialog_ChooseInclusionPattern_description=&Choose a folder or file to include:

View file

@ -279,7 +279,7 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
*/
protected void openCustomizeDialog() {
CustomizeProblemDialog d = new CustomizeProblemDialog(getShell(),
selectedProblem);
selectedProblem, (IResource) getElement());
d.open();
}
}

View file

@ -0,0 +1,302 @@
package org.eclipse.cdt.codan.internal.ui.preferences;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.cdt.codan.core.param.FileScopeProblemPreference;
import org.eclipse.cdt.codan.internal.ui.CodanUIActivator;
import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
import org.eclipse.cdt.codan.internal.ui.dialogs.ExclusionInclusionEntryDialog;
import org.eclipse.cdt.codan.internal.ui.widgets.BasicElementLabels;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IListAdapter;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
public class FileScopePreferencePage extends PreferencePage {
private ListDialogField fInclusionPatternList;
private ListDialogField fExclusionPatternList;
private FileScopeProblemPreference fCurrElement;
private IProject fCurrProject;
private IContainer fCurrSourceFolder;
private static final int IDX_ADD = 0;
private static final int IDX_ADD_MULTIPLE = 1;
private static final int IDX_EDIT = 2;
private static final int IDX_REMOVE = 4;
public FileScopePreferencePage(FileScopeProblemPreference entryToEdit) {
setTitle(CodanUIMessages.ExclusionInclusionDialog_title);
setDescription(CodanUIMessages.ExclusionInclusionDialog_description2);
fCurrElement = entryToEdit;
fCurrProject = entryToEdit.getProject();
IWorkspaceRoot root = fCurrProject != null ? fCurrProject
.getWorkspace().getRoot() : ResourcesPlugin.getWorkspace()
.getRoot();
IResource res = root.findMember(entryToEdit.getPath());
if (res instanceof IContainer) {
fCurrSourceFolder = (IContainer) res;
}
if (res == null)
fCurrSourceFolder = root;
String excLabel = CodanUIMessages.ExclusionInclusionDialog_exclusion_pattern_label;
ImageDescriptor excDescriptor = null; //JavaPluginImages.DESC_OBJS_EXCLUSION_FILTER_ATTRIB;
String[] excButtonLabels = new String[] {
CodanUIMessages.ExclusionInclusionDialog_exclusion_pattern_add,
CodanUIMessages.ExclusionInclusionDialog_exclusion_pattern_add_multiple,
CodanUIMessages.ExclusionInclusionDialog_exclusion_pattern_edit,
null,
CodanUIMessages.ExclusionInclusionDialog_exclusion_pattern_remove };
String incLabel = CodanUIMessages.ExclusionInclusionDialog_inclusion_pattern_label;
ImageDescriptor incDescriptor = null; //JavaPluginImages.DESC_OBJS_INCLUSION_FILTER_ATTRIB;
String[] incButtonLabels = new String[] {
CodanUIMessages.ExclusionInclusionDialog_inclusion_pattern_add,
CodanUIMessages.ExclusionInclusionDialog_inclusion_pattern_add_multiple,
CodanUIMessages.ExclusionInclusionDialog_inclusion_pattern_edit,
null,
CodanUIMessages.ExclusionInclusionDialog_inclusion_pattern_remove };
fExclusionPatternList = createListContents(entryToEdit,
FileScopeProblemPreference.EXCLUSION, excLabel, null,
excButtonLabels);
fInclusionPatternList = createListContents(entryToEdit,
FileScopeProblemPreference.INCLUSION, incLabel, null,
incButtonLabels);
}
@Override
protected Control createContents(Composite parent) {
Composite inner = new Composite(parent, SWT.NONE);
inner.setFont(parent.getFont());
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.numColumns = 2;
inner.setLayout(layout);
inner.setLayoutData(new GridData(GridData.FILL_BOTH));
fInclusionPatternList.doFillIntoGrid(inner, 3);
LayoutUtil.setHorizontalSpan(
fInclusionPatternList.getLabelControl(null), 2);
LayoutUtil.setHorizontalGrabbing(fInclusionPatternList
.getListControl(null));
fExclusionPatternList.doFillIntoGrid(inner, 3);
LayoutUtil.setHorizontalSpan(
fExclusionPatternList.getLabelControl(null), 2);
LayoutUtil.setHorizontalGrabbing(fExclusionPatternList
.getListControl(null));
setControl(inner);
Dialog.applyDialogFont(inner);
return inner;
}
private static class ExclusionInclusionLabelProvider extends LabelProvider {
private Image fElementImage;
public ExclusionInclusionLabelProvider(String descriptorPath) {
if (descriptorPath != null) {
ImageDescriptor d = CodanUIActivator
.getImageDescriptor(descriptorPath);
}
fElementImage = null; // XXX
}
@Override
public Image getImage(Object element) {
return fElementImage;
}
@Override
public String getText(Object element) {
return BasicElementLabels.getFilePattern((String) element);
}
}
private ListDialogField createListContents(
FileScopeProblemPreference entryToEdit, String key, String label,
String descriptor, String[] buttonLabels) {
ExclusionPatternAdapter adapter = new ExclusionPatternAdapter();
ListDialogField patternList = new ListDialogField(adapter,
buttonLabels, new ExclusionInclusionLabelProvider(descriptor));
patternList.setDialogFieldListener(adapter);
patternList.setLabelText(label);
patternList.enableButton(IDX_EDIT, false);
IPath[] pattern = entryToEdit.getAttribute(key);
ArrayList elements = new ArrayList(pattern.length);
for (int i = 0; i < pattern.length; i++) {
String patternName = pattern[i].toString();
if (patternName.length() > 0)
elements.add(patternName);
}
patternList.setElements(elements);
patternList.selectFirstElement();
patternList.enableButton(IDX_ADD_MULTIPLE, fCurrSourceFolder != null);
patternList.setViewerComparator(new ViewerComparator());
return patternList;
}
protected void doCustomButtonPressed(ListDialogField field, int index) {
if (index == IDX_ADD) {
addEntry(field);
} else if (index == IDX_EDIT) {
editEntry(field);
} else if (index == IDX_ADD_MULTIPLE) {
addMultipleEntries(field);
} else if (index == IDX_REMOVE) {
field.removeElements(field.getSelectedElements());
}
updateStatus();
}
private void updateStatus() {
fCurrElement.setAttribute(FileScopeProblemPreference.INCLUSION,
getInclusionPattern());
fCurrElement.setAttribute(FileScopeProblemPreference.EXCLUSION,
getExclusionPattern());
}
protected void doDoubleClicked(ListDialogField field) {
editEntry(field);
updateStatus();
}
protected void doSelectionChanged(ListDialogField field) {
List selected = field.getSelectedElements();
field.enableButton(IDX_EDIT, canEdit(selected));
}
private boolean canEdit(List selected) {
return selected.size() == 1;
}
private void editEntry(ListDialogField field) {
List selElements = field.getSelectedElements();
if (selElements.size() != 1) {
return;
}
List existing = field.getElements();
String entry = (String) selElements.get(0);
ExclusionInclusionEntryDialog dialog = new ExclusionInclusionEntryDialog(
getShell(), isExclusion(field), entry, existing, fCurrElement);
if (dialog.open() == Window.OK) {
field.replaceElement(entry, dialog.getExclusionPattern());
}
}
private boolean isExclusion(ListDialogField field) {
return field == fExclusionPatternList;
}
private void addEntry(ListDialogField field) {
List existing = field.getElements();
ExclusionInclusionEntryDialog dialog = new ExclusionInclusionEntryDialog(
getShell(), isExclusion(field), null, existing, fCurrElement);
if (dialog.open() == Window.OK) {
field.addElement(dialog.getExclusionPattern());
}
}
// -------- ExclusionPatternAdapter --------
private class ExclusionPatternAdapter implements IListAdapter,
IDialogFieldListener {
/**
* @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#customButtonPressed(org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField,
* int)
*/
public void customButtonPressed(ListDialogField field, int index) {
doCustomButtonPressed(field, index);
}
/**
* @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#selectionChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField)
*/
public void selectionChanged(ListDialogField field) {
doSelectionChanged(field);
}
/**
* @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#doubleClicked(org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField)
*/
public void doubleClicked(ListDialogField field) {
doDoubleClicked(field);
}
/**
* @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener#dialogFieldChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)
*/
public void dialogFieldChanged(DialogField field) {
}
}
protected void doStatusLineUpdate() {
}
protected void checkIfPatternValid() {
}
private IPath[] getPattern(ListDialogField field) {
Object[] arr = field.getElements().toArray();
Arrays.sort(arr);
IPath[] res = new IPath[arr.length];
for (int i = 0; i < res.length; i++) {
res[i] = new Path((String) arr[i]);
}
return res;
}
public IPath[] getExclusionPattern() {
return getPattern(fExclusionPatternList);
}
public IPath[] getInclusionPattern() {
return getPattern(fInclusionPatternList);
}
/*
* @see org.eclipse.jface.window.Window#configureShell(Shell)
*/
protected void configureShell(Shell newShell) {
}
private void addMultipleEntries(ListDialogField field) {
String title, message;
if (isExclusion(field)) {
title = CodanUIMessages.ExclusionInclusionDialog_ChooseExclusionPattern_title;
message = CodanUIMessages.ExclusionInclusionDialog_ChooseExclusionPattern_description;
} else {
title = CodanUIMessages.ExclusionInclusionDialog_ChooseInclusionPattern_title;
message = CodanUIMessages.ExclusionInclusionDialog_ChooseInclusionPattern_description;
}
IPath[] res = ExclusionInclusionEntryDialog.chooseExclusionPattern(
getShell(), fCurrSourceFolder, title, message, null, true);
if (res != null) {
for (int i = 0; i < res.length; i++) {
field.addElement(res[i].toString());
}
}
}
@Override
public void noDefaultAndApplyButton() {
super.noDefaultAndApplyButton();
}
}

View file

@ -0,0 +1,147 @@
package org.eclipse.cdt.codan.internal.ui.widgets;
import java.io.File;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.osgi.util.TextProcessor;
import org.eclipse.ui.IWorkingSet;
/**
* A label provider for basic elements like paths. The label provider will make
* sure that the labels are correctly
* shown in RTL environments.
*
* @since 3.4
*/
public class BasicElementLabels {
// TextProcessor delimiters
private static final String CODE_DELIMITERS = TextProcessor
.getDefaultDelimiters() + "<>()?,{}+-*!%=^|&;[]~"; //$NON-NLS-1$
private static final String FILE_PATTERN_DELIMITERS = TextProcessor
.getDefaultDelimiters() + "*.?"; //$NON-NLS-1$
private static final String URL_DELIMITERS = TextProcessor
.getDefaultDelimiters() + ":@?-"; //$NON-NLS-1$
/**
* Returns the label of a path.
*
* @param path
* the path
* @param isOSPath
* if <code>true</code>, the path represents an OS path, if
* <code>false</code> it is a workspace path.
* @return the label of the path to be used in the UI.
*/
public static String getPathLabel(IPath path, boolean isOSPath) {
String label;
if (isOSPath) {
label = path.toOSString();
} else {
label = path.makeRelative().toString();
}
return markLTR(label);
}
/**
* Returns the label of the path of a file.
*
* @param file
* the file
* @return the label of the file path to be used in the UI.
*/
public static String getPathLabel(File file) {
return markLTR(file.getAbsolutePath());
}
/**
* Returns the label for a file pattern like '*.java'
*
* @param name
* the pattern
* @return the label of the pattern.
*/
public static String getFilePattern(String name) {
return markLTR(name, FILE_PATTERN_DELIMITERS);
}
/**
* Returns the label for a URL, URI or URL part. Example is
* 'http://www.x.xom/s.html#1'
*
* @param name
* the URL string
* @return the label of the URL.
*/
public static String getURLPart(String name) {
return markLTR(name, URL_DELIMITERS);
}
/**
* Returns a label for a resource name.
*
* @param resource
* the resource
* @return the label of the resource name.
*/
public static String getResourceName(IResource resource) {
return markLTR(resource.getName());
}
/**
* Returns a label for a resource name.
*
* @param resourceName
* the resource name
* @return the label of the resource name.
*/
public static String getResourceName(String resourceName) {
return markLTR(resourceName);
}
/**
* Returns a label for Java code snippet used in a label. Example is 'Test
* test= new Test<? extends List>() { ...}'.
*
* @param string
* the Java code snippet
* @return the label for the Java code snippet
*/
public static String getJavaCodeString(String string) {
return markLTR(string, CODE_DELIMITERS);
}
/**
* Returns a label for a version name. Example is '1.4.1'
*
* @param name
* the version string
* @return the version label
*/
public static String getVersionName(String name) {
return markLTR(name);
}
/**
* Returns a label for a working set
*
* @param set
* the working set
* @return the label of the working set
*/
public static String getWorkingSetLabel(IWorkingSet set) {
return markLTR(set.getLabel());
}
/**
* It does not do anything now, but just in case we need to do the same as
* JDT does (see String.markLTR in JDT)
*/
private static String markLTR(String label) {
return label;
}
private static String markLTR(String label, String delim) {
return label;
}
}

View file

@ -8,16 +8,16 @@
* Contributors:
* Alena Laskavaia - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.codan.internal.ui.dialogs;
package org.eclipse.cdt.codan.internal.ui.widgets;
import org.eclipse.cdt.codan.core.model.IProblem;
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
import org.eclipse.core.resources.IResource;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
@ -29,17 +29,21 @@ public class CustomizeProblemComposite extends Composite {
private Composite parametersTab;
private IProblem problem;
private ParametersComposite problemsComposite;
private FileScopeComposite scopeComposite;
private IResource resource;
/**
* @param parent
* @param selectedProblem
* @param resource
* @param style
*/
public CustomizeProblemComposite(Composite parent, IProblem selectedProblem) {
public CustomizeProblemComposite(Composite parent,
IProblem selectedProblem, IResource resource) {
super(parent, SWT.NONE);
this.setLayout(new GridLayout(1, false));
this.problem = selectedProblem;
this.resource = resource;
final TabFolder tabFolder = new TabFolder(this, SWT.TOP);
tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
// createMainTab(tabFolder);
@ -49,6 +53,7 @@ public class CustomizeProblemComposite extends Composite {
public void save(IProblemWorkingCopy problem) {
problemsComposite.save(problem);
scopeComposite.save(problem);
}
/**
@ -61,7 +66,8 @@ public class CustomizeProblemComposite extends Composite {
tabItem1.setControl(parametersTab);
parametersTab.setLayout(new GridLayout());
problemsComposite = new ParametersComposite(parametersTab, problem);
problemsComposite.setLayoutData(new GridData(SWT.BEGINNING,SWT.BEGINNING, true, false));
problemsComposite.setLayoutData(new GridData(SWT.BEGINNING,
SWT.BEGINNING, true, false));
}
/**
@ -73,8 +79,8 @@ public class CustomizeProblemComposite extends Composite {
Composite comp = new Composite(tabFolder, SWT.NONE);
tabItem1.setControl(comp);
comp.setLayout(new GridLayout());
Label label = new Label(comp, SWT.NONE);
label.setText("Scope: TODO"); //$NON-NLS-1$
label.setLayoutData(new GridData(GridData.FILL_BOTH));
scopeComposite = new FileScopeComposite(comp, problem, resource);
scopeComposite.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING,
true, false));
}
}

View file

@ -0,0 +1,100 @@
/*******************************************************************************
* 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.internal.ui.widgets;
import org.eclipse.cdt.codan.core.model.IProblem;
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
import org.eclipse.cdt.codan.core.param.FileScopeProblemPreference;
import org.eclipse.cdt.codan.core.param.IProblemPreference;
import org.eclipse.cdt.codan.core.param.MapProblemPreference;
import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
import org.eclipse.cdt.codan.internal.ui.preferences.FileScopePreferencePage;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.preference.PreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
/**
* Composite to show problem scope
*
*/
public class FileScopeComposite extends Composite {
private FileScopePreferencePage page;
private IProblem problem;
private PreferenceStore prefStore;
private FileScopeProblemPreference scope;
/**
* @param parent
* @param problem
* @param resource
* @param style
*/
public FileScopeComposite(Composite parent, final IProblem problem,
IResource resource) {
super(parent, SWT.NONE);
if (problem == null)
throw new NullPointerException();
this.setLayout(new GridLayout(2, false));
this.problem = problem;
this.prefStore = new PreferenceStore();
IProblemPreference info = problem.getPreference();
FileScopeProblemPreference scopeIn = null;
if (info == null
|| (!(info instanceof MapProblemPreference))
|| ((scopeIn = (FileScopeProblemPreference) ((MapProblemPreference) info)
.getChildDescriptor(FileScopeProblemPreference.KEY)) == null)) {
Label label = new Label(this, 0);
label.setText(CodanUIMessages.ParametersComposite_None);
return;
}
scope = (FileScopeProblemPreference) scopeIn.clone();
scope.setResource(resource);
initPrefStore();
page = new FileScopePreferencePage(scope);
page.setPreferenceStore(prefStore);
page.noDefaultAndApplyButton();
page.createControl(parent);
page.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
}
public void save(IProblemWorkingCopy problem) {
if (page != null)
page.performOk();
savePrefStore();
}
private void savePrefStore() {
if (scope == null)
return;
String key = scope.getQualifiedKey();
((MapProblemPreference) problem.getPreference()).setChildValue(
FileScopeProblemPreference.KEY, scope);
prefStore.setValue(key, scope.exportValue());
}
private void initPrefStore() {
if (scope == null)
return;
String key = scope.getQualifiedKey();
prefStore.setValue(key, scope.exportValue());
}
/**
* @return the problem
*/
public IProblem getProblem() {
return problem;
}
}

View file

@ -8,12 +8,13 @@
* Contributors:
* Alena Laskavaia - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.codan.internal.ui.dialogs;
package org.eclipse.cdt.codan.internal.ui.widgets;
import java.io.File;
import org.eclipse.cdt.codan.core.model.IProblem;
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
import org.eclipse.cdt.codan.core.param.FileScopeProblemPreference;
import org.eclipse.cdt.codan.core.param.IProblemPreference;
import org.eclipse.cdt.codan.core.param.IProblemPreferenceCompositeDescriptor;
import org.eclipse.cdt.codan.core.param.ListProblemPreference;
@ -21,6 +22,7 @@ import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.FileFieldEditor;
import org.eclipse.jface.preference.ListEditor;
import org.eclipse.jface.preference.PreferenceStore;
import org.eclipse.jface.preference.StringFieldEditor;
@ -67,6 +69,8 @@ public class ParametersComposite extends Composite {
final IProblemPreference info) {
if (info == null)
return;
if (info.getKey() == FileScopeProblemPreference.KEY)
return; // skip the scope
switch (info.getType()) {
case TYPE_STRING: {
StringFieldEditor fe = new StringFieldEditor(
@ -103,11 +107,12 @@ public class ParametersComposite extends Composite {
@Override
protected String getNewInputObject() {
ListProblemPreference list = (ListProblemPreference) info;
String label = list
.getChildDescriptor()
String label = list.getChildDescriptor()
.getLabel();
InputDialog dialog = new InputDialog(
getShell(), CodanUIMessages.ParametersComposite_NewValue, label, "", null); //$NON-NLS-1$
getShell(),
CodanUIMessages.ParametersComposite_NewValue,
label, "", null); //$NON-NLS-1$
if (dialog.open() == Window.OK) {
return dialog.getValue();
}
@ -136,6 +141,20 @@ public class ParametersComposite extends Composite {
createFieldEditorsForParameters(desc);
}
break;
case TYPE_CUSTOM: {
StringFieldEditor fe = new StringFieldEditor(
info.getQualifiedKey(), info.getLabel(),
getFieldEditorParent());
addField(fe);
break;
}
case TYPE_FILE: {
FileFieldEditor fe = new FileFieldEditor(
info.getQualifiedKey(), info.getLabel(),
getFieldEditorParent());
addField(fe);
break;
}
default:
throw new UnsupportedOperationException(info.getType()
.toString());
@ -179,6 +198,9 @@ public class ParametersComposite extends Composite {
case TYPE_LIST:
desc.importValue(prefStore.getString(key));
break;
case TYPE_CUSTOM:
desc.importValue(prefStore.getString(key));
break;
case TYPE_MAP:
IProblemPreference[] childrenDescriptor = ((IProblemPreferenceCompositeDescriptor) desc)
.getChildDescriptors();
@ -213,6 +235,9 @@ public class ParametersComposite extends Composite {
case TYPE_LIST:
prefStore.setValue(key, desc.exportValue());
break;
case TYPE_CUSTOM:
prefStore.setValue(key, desc.exportValue());
break;
case TYPE_MAP:
IProblemPreference[] childrenDescriptor = ((IProblemPreferenceCompositeDescriptor) desc)
.getChildDescriptors();