Search in sources :

Example 6 with IFilter

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;
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Group(org.eclipse.swt.widgets.Group) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Button(org.eclipse.swt.widgets.Button) IFilter(net.sf.eclipsecs.core.projectconfig.filters.IFilter) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 7 with IFilter

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;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IFilter(net.sf.eclipsecs.core.projectconfig.filters.IFilter) IProjectConfiguration(net.sf.eclipsecs.core.projectconfig.IProjectConfiguration) UnOpenedFilesFilter(net.sf.eclipsecs.core.projectconfig.filters.UnOpenedFilesFilter) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) IProject(org.eclipse.core.resources.IProject)

Example 8 with IFilter

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;
}
Also used : IFilter(net.sf.eclipsecs.core.projectconfig.filters.IFilter) ArrayList(java.util.ArrayList)

Example 9 with IFilter

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;
}
Also used : IFilter(net.sf.eclipsecs.core.projectconfig.filters.IFilter) ArrayList(java.util.ArrayList)

Example 10 with IFilter

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;
}
Also used : ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) IFilter(net.sf.eclipsecs.core.projectconfig.filters.IFilter) Element(org.dom4j.Element) Document(org.dom4j.Document)

Aggregations

IFilter (net.sf.eclipsecs.core.projectconfig.filters.IFilter)10 ArrayList (java.util.ArrayList)4 CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)4 Element (org.dom4j.Element)4 ICheckConfiguration (net.sf.eclipsecs.core.config.ICheckConfiguration)2 IProjectConfiguration (net.sf.eclipsecs.core.projectconfig.IProjectConfiguration)2 Document (org.dom4j.Document)2 IProject (org.eclipse.core.resources.IProject)2 CoreException (org.eclipse.core.runtime.CoreException)2 HashMap (java.util.HashMap)1 UnOpenedFilesFilter (net.sf.eclipsecs.core.projectconfig.filters.UnOpenedFilesFilter)1 SAXReader (org.dom4j.io.SAXReader)1 IMarker (org.eclipse.core.resources.IMarker)1 IResource (org.eclipse.core.resources.IResource)1 IResourceDelta (org.eclipse.core.resources.IResourceDelta)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1