use of net.sf.eclipsecs.core.projectconfig.filters.IFilter in project eclipse-cs by checkstyle.
the class CheckstylePropertyPage method createFilterArea.
/**
* Creates the filter area.
*
* @param container
* the container to add the filter area
*/
private Control createFilterArea(Composite container) {
// group composite containing the filter settings
Group filterArea = new Group(container, SWT.NULL);
filterArea.setText(Messages.CheckstylePropertyPage_titleFilterGroup);
filterArea.setLayout(new FormLayout());
this.mFilterList = CheckboxTableViewer.newCheckList(filterArea, SWT.BORDER);
this.mBtnEditFilter = new Button(filterArea, SWT.PUSH);
FormData fd = new FormData();
fd.left = new FormAttachment(0, 3);
fd.top = new FormAttachment(0, 3);
fd.right = new FormAttachment(this.mBtnEditFilter, -3, SWT.LEFT);
fd.bottom = new FormAttachment(60, -3);
this.mFilterList.getTable().setLayoutData(fd);
this.mFilterList.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
StringBuffer buf = new StringBuffer();
if (element instanceof IFilter) {
IFilter filter = (IFilter) element;
buf.append(filter.getName());
if (filter.getPresentableFilterData() != null) {
// $NON-NLS-1$
buf.append(": ").append(filter.getPresentableFilterData());
}
} else {
buf.append(super.getText(element));
}
return buf.toString();
}
});
this.mFilterList.setContentProvider(new ArrayContentProvider());
this.mFilterList.addSelectionChangedListener(this.mPageController);
this.mFilterList.addDoubleClickListener(this.mPageController);
this.mFilterList.addCheckStateListener(this.mPageController);
this.mBtnEditFilter.setText(Messages.CheckstylePropertyPage_btnChangeFilter);
this.mBtnEditFilter.addSelectionListener(this.mPageController);
fd = new FormData();
fd.top = new FormAttachment(0, 3);
fd.right = new FormAttachment(100, -3);
this.mBtnEditFilter.setLayoutData(fd);
// Description
Label lblDesc = new Label(filterArea, SWT.LEFT);
lblDesc.setText(Messages.CheckstylePropertyPage_lblDescription);
fd = new FormData();
fd.left = new FormAttachment(0, 3);
fd.top = new FormAttachment(this.mFilterList.getTable(), 3, SWT.BOTTOM);
fd.right = new FormAttachment(100, -3);
lblDesc.setLayoutData(fd);
this.mTxtFilterDescription = new Text(filterArea, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.VERTICAL);
fd = new FormData();
fd.left = new FormAttachment(0, 3);
fd.top = new FormAttachment(lblDesc, 3, SWT.BOTTOM);
fd.right = new FormAttachment(100, -3);
fd.bottom = new FormAttachment(100, -3);
this.mTxtFilterDescription.setLayoutData(fd);
// intialize filter list
List<IFilter> filterDefs = mProjectConfig.getFilters();
this.mFilterList.setInput(filterDefs);
// set the checked state
for (int i = 0; i < filterDefs.size(); i++) {
IFilter filter = filterDefs.get(i);
this.mFilterList.setChecked(filter, filter.isEnabled());
}
// set the readonly state
for (int i = 0; i < filterDefs.size(); i++) {
IFilter filter = filterDefs.get(i);
this.mFilterList.setGrayed(filter, filter.isReadonly());
}
this.mBtnEditFilter.setEnabled(false);
return filterArea;
}
use of net.sf.eclipsecs.core.projectconfig.filters.IFilter in project eclipse-cs by checkstyle.
the class CheckFileOnOpenPartListener method isFileAffected.
/**
* Checks if the given file is affected by the UnOpenedFilesFilter and needs to be handled on
* editor open/close.
*
* @param file
* the file to check
* @return <code>true</code> if the file is affected, <code>false</code> otherwise
*/
private boolean isFileAffected(IFile file) {
boolean affected = false;
IProject project = file.getProject();
try {
// check if checkstyle is enabled on the project
if (project.isAccessible() && project.hasNature(CheckstyleNature.NATURE_ID)) {
IProjectConfiguration config = ProjectConfigurationFactory.getConfiguration(project);
// now check if the UnOpenedFilesFilter is active
boolean unOpenedFilesFilterActive = false;
boolean filtered = false;
List<IFilter> filters = config.getFilters();
for (IFilter filter : filters) {
if (filter instanceof UnOpenedFilesFilter && ((UnOpenedFilesFilter) filter).isEnabled()) {
unOpenedFilesFilterActive = true;
}
// check if the file would be filtered out
if (filter.isEnabled() && !(filter instanceof UnOpenedFilesFilter)) {
filtered = filtered || !filter.accept(file);
}
}
affected = unOpenedFilesFilterActive && !filtered;
}
} catch (CoreException e) {
// should never happen, since editor cannot be open
// when project isn't
CheckstyleLog.log(e);
} catch (CheckstylePluginException e) {
CheckstyleLog.log(e);
}
return affected;
}
use of net.sf.eclipsecs.core.projectconfig.filters.IFilter in project eclipse-cs by checkstyle.
the class ProjectConfiguration method clone.
@Override
public ProjectConfiguration clone() {
ProjectConfiguration clone = null;
try {
clone = (ProjectConfiguration) super.clone();
clone.mFileSets = new LinkedList<FileSet>();
clone.mUseSimpleConfig = mUseSimpleConfig;
clone.mSyncFormatter = mSyncFormatter;
// clone file sets
List<FileSet> clonedFileSets = new ArrayList<FileSet>();
for (FileSet fileSet : getFileSets()) {
clonedFileSets.add(fileSet.clone());
}
clone.mFileSets = clonedFileSets;
// clone filters
List<IFilter> clonedFilters = new ArrayList<IFilter>();
for (IFilter filter : getFilters()) {
clonedFilters.add(filter.clone());
}
clone.mFilters = clonedFilters;
} catch (CloneNotSupportedException e) {
// should never happen
throw new InternalError();
}
return clone;
}
use of net.sf.eclipsecs.core.projectconfig.filters.IFilter in project eclipse-cs by checkstyle.
the class ProjectConfigurationWorkingCopy method clone.
@Override
public Object clone() {
ProjectConfigurationWorkingCopy clone = null;
try {
clone = (ProjectConfigurationWorkingCopy) super.clone();
clone.mFileSets = new LinkedList<>();
clone.setUseSimpleConfig(this.isUseSimpleConfig());
clone.setSyncFormatter(this.isSyncFormatter());
// clone file sets
for (FileSet fileSet : getFileSets()) {
clone.getFileSets().add(fileSet.clone());
}
// clone filters
List<IFilter> clonedFilters = new ArrayList<>();
for (IFilter filter : getFilters()) {
clonedFilters.add(filter.clone());
}
clone.mFilters = clonedFilters;
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
return clone;
}
use of net.sf.eclipsecs.core.projectconfig.filters.IFilter in project eclipse-cs by checkstyle.
the class ProjectConfigurationWorkingCopy method writeProjectConfig.
/**
* Produces the sax events to write a project configuration.
*
* @param config
* the configuration
*/
private Document writeProjectConfig(ProjectConfigurationWorkingCopy config) throws CheckstylePluginException {
Document doc = DocumentHelper.createDocument();
Element root = doc.addElement(XMLTags.FILESET_CONFIG_TAG);
root.addAttribute(XMLTags.FORMAT_VERSION_TAG, ProjectConfigurationFactory.CURRENT_FILE_FORMAT_VERSION);
root.addAttribute(XMLTags.SIMPLE_CONFIG_TAG, Boolean.toString(config.isUseSimpleConfig()));
root.addAttribute(XMLTags.SYNC_FORMATTER_TAG, Boolean.toString(config.isSyncFormatter()));
ICheckConfiguration[] workingCopies = config.getLocalCheckConfigWorkingSet().getWorkingCopies();
for (int i = 0; i < workingCopies.length; i++) {
writeLocalConfiguration(workingCopies[i], root);
}
for (FileSet fileSet : config.getFileSets()) {
writeFileSet(fileSet, config.getProject(), root);
}
// write filters
for (IFilter filter : config.getFilters()) {
writeFilter(filter, root);
}
return doc;
}
Aggregations