diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/icons/forbidden.png b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/icons/forbidden.png new file mode 100644 index 0000000000..e66aa3ae64 Binary files /dev/null and b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/icons/forbidden.png differ diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/icons/ok.gif b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/icons/ok.gif new file mode 100644 index 0000000000..cf7b8043a3 Binary files /dev/null and b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/icons/ok.gif differ diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/BasicAccessor.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/BasicAccessor.java index 66e1c65b32..6589b55852 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/BasicAccessor.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/BasicAccessor.java @@ -2,8 +2,13 @@ package net.sourceforge.pmd.eclipse.ui.filters; import net.sourceforge.pmd.eclipse.ui.filters.FilterHolder.Accessor; +/** + * + * @author Brian Remedios + */ class BasicAccessor implements Accessor { public boolean boolValueFor(FilterHolder fh) { return false; } + public String textValueFor(FilterHolder fh) { return null; } } \ No newline at end of file diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/FilterColumnUI.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/FilterColumnUI.java index 5e204d6591..f08fff954a 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/FilterColumnUI.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/FilterColumnUI.java @@ -3,6 +3,7 @@ package net.sourceforge.pmd.eclipse.ui.filters; import net.sourceforge.pmd.eclipse.ui.ItemColumnDescriptor; import net.sourceforge.pmd.eclipse.ui.ItemFieldAccessor; import net.sourceforge.pmd.eclipse.ui.ItemFieldAccessorAdapter; +import net.sourceforge.pmd.eclipse.util.Util; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; @@ -17,15 +18,15 @@ public interface FilterColumnUI { public Image imageFor(FilterHolder holder) { return FilterPreferencesPage.typeIconFor(holder); } }; - ItemFieldAccessor pmdAcc = new ItemFieldAccessorAdapter(null) { + ItemFieldAccessor pmdAcc = new ItemFieldAccessorAdapter(Util.compStr) { public String valueFor(FilterHolder holder) { return holder.forPMD ? "Y" : ""; } }; - ItemFieldAccessor cpdAcc = new ItemFieldAccessorAdapter(null) { + ItemFieldAccessor cpdAcc = new ItemFieldAccessorAdapter(Util.compStr) { public String valueFor(FilterHolder holder) { return holder.forCPD ? "Y" : ""; } }; - ItemFieldAccessor patternAcc = new ItemFieldAccessorAdapter(null) { + ItemFieldAccessor patternAcc = new ItemFieldAccessorAdapter(Util.compStr) { public String valueFor(FilterHolder holder) { return holder.pattern; } }; diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/FilterHolder.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/FilterHolder.java index 6e1ff5810a..8f37c86156 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/FilterHolder.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/FilterHolder.java @@ -29,6 +29,10 @@ class FilterHolder { String textValueFor(FilterHolder fh); } + public static final Accessor ExcludeAccessor = new BasicAccessor() { + public boolean boolValueFor(FilterHolder fh) { return !fh.isInclude; } + }; + public static final Accessor IncludeAccessor = new BasicAccessor() { public boolean boolValueFor(FilterHolder fh) { return fh.isInclude; } }; diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/FilterPreferencesPage.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/FilterPreferencesPage.java index 599183b921..80f6e0b855 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/FilterPreferencesPage.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/FilterPreferencesPage.java @@ -13,8 +13,6 @@ import net.sourceforge.pmd.RuleSet; import net.sourceforge.pmd.eclipse.runtime.preferences.IPreferencesManager; import net.sourceforge.pmd.eclipse.ui.BasicTableLabelProvider; import net.sourceforge.pmd.eclipse.ui.PMDUiConstants; -import net.sourceforge.pmd.eclipse.ui.Shape; -import net.sourceforge.pmd.eclipse.ui.ShapePainter; import net.sourceforge.pmd.eclipse.ui.nls.StringKeys; import net.sourceforge.pmd.eclipse.ui.preferences.br.AbstractPMDPreferencePage; import net.sourceforge.pmd.eclipse.ui.preferences.br.BasicTableManager; @@ -36,13 +34,11 @@ import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.RGB; 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.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; @@ -58,26 +54,33 @@ import org.eclipse.swt.widgets.Text; */ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements ValueChangeListener, SizeChangeListener { - private TableViewer tableViewer; - private Button addButton; - private Button removeButton; + private TableViewer tableViewer; + private Button addButton; + private Button removeButton; - private Button excludeButt; - private Button includeButt; - private Button cpdButt; - private Button pmdButt; - private Text patternField; - private BasicTableManager reportTableMgr; + private Button excludeButt; + private Button includeButt; + private Button cpdButt; + private Button pmdButt; + private Text patternField; + + private BasicTableManager reportTableMgr; private Collection editorWidgets = new ArrayList(); - private static Image IncludeIcon; - private static Image ExcludeIcon; + private static Image IncludeIcon = plugin.getImage("include", "icons/ok.gif"); + private static Image ExcludeIcon = plugin.getImage("exclude", "icons/forbidden.png"); private static final String NewFilterPattern = ""; - private static final RGB ProtoTransparentColour = new RGB(1,1,1); // almost full black, unlikely to be used public static Image typeIconFor(FilterHolder holder) { - return holder.isInclude ? includeIcon() : excludeIcon(); + return holder.isInclude ? IncludeIcon : ExcludeIcon; + } + + private static Label createLabel(Composite panel, String text) { + Label label = new Label(panel, SWT.None); + label.setLayoutData( new GridData()); + label.setText(text); + return label; } private static Button createButton(Composite panel, int type, String label) { @@ -95,38 +98,6 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements return butt; } - private static Image includeIcon() { - - if (IncludeIcon != null) return IncludeIcon; - - IncludeIcon = ShapePainter.newDrawnImage( - Display.getCurrent(), - 16, - 16, - Shape.plus, - ProtoTransparentColour, - new RGB(0,255,0) - ); - - return IncludeIcon; - } - - private static Image excludeIcon() { - - if (ExcludeIcon != null) return ExcludeIcon; - - ExcludeIcon = ShapePainter.newDrawnImage( - Display.getCurrent(), - 16, - 16, - Shape.minus, - ProtoTransparentColour, - new RGB(255,0,0) - ); - - return ExcludeIcon; - } - /** * Create and initialize the controls of the page * @@ -205,7 +176,7 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements }; BasicTableLabelProvider labelProvider = new BasicTableLabelProvider(FilterColumnUI.VisibleColumns); - reportTableMgr = new BasicTableManager("renderers", null, FilterColumnUI.VisibleColumns); + reportTableMgr = new BasicTableManager("renderers", null, FilterColumnUI.VisibleColumns); tableViewer = reportTableMgr.buildTableViewer( parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION | SWT.CHECK @@ -252,6 +223,7 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements private void selectedPatterns(Collection holders) { + setState(holders, excludeButt, FilterHolder.ExcludeAccessor); setState(holders, includeButt, FilterHolder.IncludeAccessor); setState(holders, pmdButt, FilterHolder.PMDAccessor); setState(holders, cpdButt, FilterHolder.CPDAccessor); @@ -310,15 +282,15 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements typeLabel.setText("Type:"); editorWidgets.add(typeLabel); - excludeButt = createButton(editorPanel, SWT.RADIO, excludeIcon(), "Exclude"); + excludeButt = createButton(editorPanel, SWT.RADIO, ExcludeIcon, "Exclude"); excludeButt.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent se) { - setAllInclude(includeButt.getSelection()); + setAllInclude(!includeButt.getSelection()); tableViewer.refresh(); } }); - includeButt = createButton(editorPanel, SWT.RADIO, includeIcon(), "Include"); + includeButt = createButton(editorPanel, SWT.RADIO, IncludeIcon, "Include"); includeButt.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent se) { setAllInclude(includeButt.getSelection()); @@ -329,9 +301,7 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements editorWidgets.add(excludeButt); editorWidgets.add(includeButt); - Label contextLabel = new Label(editorPanel, SWT.None); - contextLabel.setLayoutData( new GridData()); - contextLabel.setText("Applies to:"); + Label contextLabel = createLabel(editorPanel, "Applies to:"); editorWidgets.add(contextLabel); pmdButt = createButton(editorPanel, SWT.CHECK, "PMD"); @@ -353,9 +323,7 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements editorWidgets.add(pmdButt); editorWidgets.add(cpdButt); - Label patternLabel = new Label(editorPanel, SWT.None); - patternLabel.setLayoutData( new GridData()); - patternLabel.setText("Pattern:"); + Label patternLabel = createLabel(editorPanel, "Pattern:"); editorWidgets.add(patternLabel); patternField = new Text(editorPanel, SWT.BORDER); @@ -368,8 +336,7 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements }); editorWidgets.add(patternField); - Label spacer = new Label(editorPanel, SWT.None); - spacer.setLayoutData( new GridData() ); + createLabel(editorPanel, ""); // spacer Label description = new Label(editorPanel, SWT.None); description.setLayoutData( new GridData(GridData.FILL, GridData.BEGINNING, true, false, 2, 1) ); description.setText("name or path pattern (* = any string, ? = any character)"); @@ -637,5 +604,4 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements public void addedRows(int newRowCount) { } public void changed(RuleSelection rule, PropertyDescriptor desc, Object newValue) { } - }