Skip to content

Commit e51cc96

Browse files
committed
Rework PriorityFilter:
* Move singleton of PriorityFilter inside PriorityFilter * Deprecate PriorityUtil * Use PriorityFilter singleton for ViolationOutline as well
1 parent c7a9906 commit e51cc96

File tree

5 files changed

+40
-25
lines changed

5 files changed

+40
-25
lines changed

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/views/PriorityFilter.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.eclipse.jface.viewers.Viewer;
1313
import org.eclipse.jface.viewers.ViewerFilter;
1414

15+
import net.sourceforge.pmd.RulePriority;
1516
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
1617
import net.sourceforge.pmd.eclipse.plugin.UISettings;
1718
import net.sourceforge.pmd.eclipse.ui.PMDUiConstants;
@@ -23,26 +24,32 @@
2324
import net.sourceforge.pmd.eclipse.ui.nls.StringKeys;
2425

2526
/**
26-
* The ViewerFilter for Priorities
27+
* The ViewerFilter for Priorities.
28+
* This is used for both Violation Outline and Violation Overview.
2729
*
2830
* @author SebastianRaffel ( 17.05.2005 )
2931
*/
3032
public class PriorityFilter extends ViewerFilter {
3133

3234
private List<Integer> priorityList;
3335

36+
private static final PriorityFilter INSTANCE = new PriorityFilter();
37+
3438
/**
3539
* Constructor
3640
*
3741
* @author SebastianRaffel ( 29.06.2005 )
42+
* @deprecated will be made private in the future.
3843
*/
44+
@Deprecated
3945
public PriorityFilter() {
40-
super();
41-
// priorityList = new
42-
// ArrayList<Integer>(Arrays.asList(PMDPlugin.getDefault().getPriorityValues()));
4346
priorityList = UISettings.getPriorityIntValues();
4447
}
4548

49+
public static PriorityFilter getInstance() {
50+
return INSTANCE;
51+
}
52+
4653
/*
4754
* @see
4855
* org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.
@@ -70,12 +77,7 @@ public boolean select(Viewer viewer, Object parentElement, Object element) {
7077
} else if (element instanceof MarkerRecord) {
7178
// ViolationOverview
7279
final MarkerRecord markerRec = (MarkerRecord) element;
73-
for (Integer priority : priorityList) {
74-
if (markerRec.getPriority() == priority.intValue()) {
75-
select = true;
76-
break;
77-
}
78-
}
80+
select = isPriorityEnabled(markerRec.getPriority());
7981
} else if (element instanceof FileToMarkerRecord) {
8082
select = true;
8183
}
@@ -96,6 +98,10 @@ private boolean isPriorityEnabled(Integer markerPrio) {
9698
return isEnabled;
9799
}
98100

101+
public boolean isPriorityEnabled(RulePriority priority) {
102+
return isPriorityEnabled(priority.getPriority());
103+
}
104+
99105
private boolean hasMarkersToShow(AbstractPMDRecord record) {
100106
boolean hasMarkers = false;
101107
for (Integer priority : priorityList) {

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/views/ViolationOutline.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected String mementoFileId() {
7878
public void init(IViewSite site) throws PartInitException {
7979
super.init(site);
8080

81-
priorityFilter = new PriorityFilter();
81+
priorityFilter = PriorityFilter.getInstance();
8282

8383
List<Integer> priorityList = getIntegerList(PRIORITY_LIST);
8484
if (!priorityList.isEmpty()) {

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/views/ViolationOverview.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import net.sourceforge.pmd.eclipse.ui.model.PackageRecord;
4444
import net.sourceforge.pmd.eclipse.ui.model.RootRecord;
4545
import net.sourceforge.pmd.eclipse.ui.nls.StringKeys;
46-
import net.sourceforge.pmd.eclipse.util.PriorityUtil;
4746
import net.sourceforge.pmd.util.NumericConstants;
4847

4948
/**
@@ -96,7 +95,7 @@ public void init(IViewSite site) throws PartInitException {
9695
root = (RootRecord) getInitialInput();
9796
contentProvider = new ViolationOverviewContentProvider(this);
9897
labelProvider = new ViolationOverviewLabelProvider(this);
99-
priorityFilter = PriorityUtil.getPriorityFilter();
98+
priorityFilter = PriorityFilter.getInstance();
10099
projectFilter = new ProjectFilter();
101100
doubleClickListener = new ViolationOverviewDoubleClickListener(this);
102101
menuManager = new ViolationOverviewMenuManager(this);
@@ -106,7 +105,7 @@ public void init(IViewSite site) throws PartInitException {
106105
// we can load the Memento here
107106
memento = new ViewMemento(PMDUiConstants.MEMENTO_OVERVIEW_FILE);
108107
if (memento != null) {
109-
rememberFilterSettings();
108+
restoreFilterSettings();
110109
}
111110
}
112111

@@ -141,7 +140,7 @@ public void createPartControl(Composite parent) {
141140

142141
// load the State from a Memento into the View if there is one
143142
if (memento != null) {
144-
rememberTreeSettings();
143+
restoreTreeSettings();
145144
}
146145
}
147146

@@ -458,7 +457,7 @@ private String getString(String key) {
458457
* must be sure memento is not null.
459458
*
460459
*/
461-
private void rememberFilterSettings() {
460+
private void restoreFilterSettings() {
462461

463462
// Provide the Filters with their last State
464463
List<Integer> priorityList = memento.getIntegerList(PRIORITY_LIST);
@@ -491,7 +490,7 @@ private void rememberFilterSettings() {
491490
* one must be sure memento is not null.
492491
*
493492
*/
494-
private void rememberTreeSettings() {
493+
private void restoreTreeSettings() {
495494

496495
// the Memento sets the Widths of Columns
497496
List<Integer> widthList = memento.getIntegerList(COLUMN_WIDTHS);

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/views/ViolationOverviewMenuManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import net.sourceforge.pmd.eclipse.ui.views.actions.PriorityFilterAction;
2828
import net.sourceforge.pmd.eclipse.ui.views.actions.ProjectFilterAction;
2929
import net.sourceforge.pmd.eclipse.ui.views.actions.ViolationPresentationTypeAction;
30-
import net.sourceforge.pmd.eclipse.util.PriorityUtil;
3130

3231
/**
3332
*
@@ -54,7 +53,7 @@ public void setupActions() {
5453
// create the Actions for the PriorityFilter
5554
for (int i = 0; i < priorities.length; i++) {
5655
priorityActions[i] = new PriorityFilterAction(priorities[i], overview); // NOPMD by Herlin on 09/10/06 15:02
57-
priorityActions[i].setChecked(PriorityUtil.isPriorityActive(priorities[i]));
56+
priorityActions[i].setChecked(PriorityFilter.getInstance().isPriorityEnabled(priorities[i]));
5857
}
5958
}
6059

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/util/PriorityUtil.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
*
1818
* @author Phillip Krall
1919
*
20+
* @deprecated use directly {@link PriorityFilter} instead.
2021
*/
22+
@Deprecated
2123
public class PriorityUtil {
2224

23-
private static PriorityFilter priorityFilter = new PriorityFilter();
24-
2525
private PriorityUtil() {
2626
}
2727

@@ -30,32 +30,43 @@ private PriorityUtil() {
3030
*
3131
* @param priority
3232
* @return
33+
* @deprecated use {@link PriorityFilter#isPriorityEnabled(RulePriority)} instead.
3334
*/
35+
@Deprecated
3436
public static boolean isPriorityActive(RulePriority priority) {
35-
return getActivePriorites().contains(priority);
37+
return PriorityFilter.getInstance().isPriorityEnabled(priority);
3638
}
3739

3840
/**
3941
* Get all the priorities that are turned on right now.
4042
*
4143
* @return
44+
* @deprecated not needed, will be removed.
4245
*/
46+
@Deprecated
4347
public static List<RulePriority> getActivePriorites() {
4448
List<RulePriority> active = new ArrayList<RulePriority>();
4549
for (RulePriority priority : UISettings.currentPriorities(true)) {
46-
if (priorityFilter.getPriorityFilterList().contains(priority.getPriority())) {
50+
if (PriorityFilter.getInstance().getPriorityFilterList().contains(priority.getPriority())) {
4751
active.add(priority);
4852
}
4953
}
5054
return active;
5155
}
5256

57+
/**
58+
* @deprecated use {@link PriorityFilter#getInstance()} instead.
59+
*/
60+
@Deprecated
5361
public static PriorityFilter getPriorityFilter() {
54-
return priorityFilter;
62+
return PriorityFilter.getInstance();
5563
}
5664

65+
/**
66+
* @deprecated to be removed without replacement.
67+
*/
68+
@Deprecated
5769
public static void setPriorityFilter(PriorityFilter priorityFilter) {
58-
PriorityUtil.priorityFilter = priorityFilter;
5970
}
6071

6172
}

0 commit comments

Comments
 (0)