Skip to content

Commit 344c681

Browse files
committed
Merge branch 'pr-107'
2 parents 1e2bded + f7ff85c commit 344c681

File tree

7 files changed

+226
-26
lines changed

7 files changed

+226
-26
lines changed

ReleaseNotes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ This is a minor release.
1717
marker properties which shows more information from the rule violation and rule itself.
1818
For more information, see [Marker Property Page (wiki)](https://github.com/pmd/pmd-eclipse-plugin/wiki/Marker-Property-Page).
1919

20+
* Marker Icons: Instead of the geometrical figures, the old icons for the PMD markers can
21+
be selected again:
22+
![Screenshot of PMD Marker Property Page](https://raw.githubusercontent.com/wiki/pmd/pmd-eclipse-plugin/images/PMDMarkerPriorityIcons.png)
23+
2024
### Fixed Issues
2125

26+
* [#82](https://github.com/pmd/pmd-eclipse-plugin/issues/82): Support old PMD icons
2227
* [#84](https://github.com/pmd/pmd-eclipse-plugin/issues/84): Rule Name in Tooltip
2328

2429
### API Changes

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/preferences/impl/PreferencesManagerImpl.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,16 @@ private void loadRulePriorityDescriptors() {
368368

369369
if (STORE_KEYS_BY_PRIORITY != null) {
370370
for (Map.Entry<RulePriority, String> entry : STORE_KEYS_BY_PRIORITY.entrySet()) {
371-
PriorityDescriptor desc = defaultDescriptorFor(entry.getKey());
372-
loadPreferencesStore.setDefault(entry.getValue(), desc.storeString());
371+
PriorityDescriptor defaultPriorityDescriptor = defaultDescriptorFor(entry.getKey());
372+
loadPreferencesStore.setDefault(entry.getValue(), defaultPriorityDescriptor.storeString());
373373
String storeKey = STORE_KEYS_BY_PRIORITY.get(entry.getKey());
374-
preferences.setPriorityDescriptor(entry.getKey(),
375-
PriorityDescriptor.from(loadPreferencesStore.getString(storeKey)));
374+
PriorityDescriptor loadedPriorityDescriptor = PriorityDescriptor.from(loadPreferencesStore.getString(storeKey));
375+
if (loadedPriorityDescriptor != null) {
376+
preferences.setPriorityDescriptor(entry.getKey(), loadedPriorityDescriptor);
377+
} else {
378+
loadPreferencesStore.setValue(entry.getValue(), defaultPriorityDescriptor.storeString());
379+
preferences.setPriorityDescriptor(entry.getKey(), defaultPriorityDescriptor);
380+
}
376381
}
377382
}
378383
}

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/ShapePicker.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ private void selectionChanged() {
144144
if (listeners == null) {
145145
return;
146146
}
147-
IStructuredSelection selection = new StructuredSelection(new Object[] { selectedItem });
147+
IStructuredSelection selection = StructuredSelection.EMPTY;
148+
if (selectedItem != null) {
149+
selection = new StructuredSelection(new Object[] { selectedItem });
150+
}
148151
SelectionChangedEvent event = new SelectionChangedEvent(this, selection);
149152
for (ISelectionChangedListener listener : listeners) {
150153
listener.selectionChanged(event);
@@ -302,9 +305,11 @@ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
302305
}
303306

304307
public void setSelection(ISelection selection) {
305-
306308
setSelection((T) ((StructuredSelection) selection).getFirstElement());
309+
}
307310

311+
public void removeSelection() {
312+
setSelection((T) null);
308313
}
309314

310315
// public void setTooltipMap(Map<T, String> theTooltips) {

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/GeneralPreferencesPage.java

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import net.sourceforge.pmd.eclipse.ui.priority.PriorityColumnUI;
6767
import net.sourceforge.pmd.eclipse.ui.priority.PriorityDescriptor;
6868
import net.sourceforge.pmd.eclipse.ui.priority.PriorityDescriptorCache;
69+
import net.sourceforge.pmd.eclipse.ui.priority.PriorityDescriptorIcon;
6970
import net.sourceforge.pmd.util.StringUtil;
7071

7172
/**
@@ -282,31 +283,31 @@ public Object[] getElements(Object inputElement) {
282283
// for (TableColumn column : columns) column.pack();
283284

284285
Composite editorPanel = new Composite(group, SWT.None);
285-
editorPanel.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true));
286-
editorPanel.setLayout(new GridLayout(6, false));
286+
editorPanel.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true, 2, 1));
287+
editorPanel.setLayout(new GridLayout(3, false));
287288

288289
Label shapeLabel = new Label(editorPanel, SWT.None);
289290
shapeLabel.setLayoutData(new GridData());
290-
shapeLabel.setText("Shape:");
291+
shapeLabel.setText("Shape and Color:");
291292

292293
final ShapePicker<Shape> ssc = new ShapePicker<Shape>(editorPanel, SWT.None, 14);
293294
ssc.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
294295
ssc.setSize(280, 30);
295296
ssc.setShapeMap(UISettings.shapeSet(SHAPE_COLOR, 10));
296297
ssc.setItems(UISettings.allShapes());
297298

298-
Label colourLabel = new Label(editorPanel, SWT.None);
299-
colourLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 1, 1));
300-
colourLabel.setText("Color:");
301-
302299
final ColorSelector colorPicker = new ColorSelector(editorPanel);
303300

304-
Label nameLabel = new Label(editorPanel, SWT.None);
301+
new Label(editorPanel, SWT.NONE).setText("Icon:");
302+
final IconSelector iconSelector = new IconSelector(editorPanel);
303+
iconSelector.setLayoutData(new GridData(SWT.LEFT, GridData.CENTER, true, true, 2, 1));
304+
305+
Label nameLabel = new Label(editorPanel, SWT.NONE);
305306
nameLabel.setLayoutData(new GridData());
306307
nameLabel.setText("Name:");
307308

308309
final Text priorityName = new Text(editorPanel, SWT.BORDER);
309-
priorityName.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true));
310+
priorityName.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true, 2, 1));
310311

311312
nameFields = new Control[] { nameLabel, priorityName };
312313

@@ -322,14 +323,31 @@ public Object[] getElements(Object inputElement) {
322323
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
323324
public void selectionChanged(SelectionChangedEvent event) {
324325
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
325-
selectedPriorities(selection.toList(), ssc, colorPicker, priorityName);
326+
selectedPriorities(selection.toList(), ssc, colorPicker, priorityName, iconSelector);
326327
}
327328
});
328329

329330
ssc.addSelectionChangedListener(new ISelectionChangedListener() {
330331
public void selectionChanged(SelectionChangedEvent event) {
331332
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
332-
setShape((Shape) selection.getFirstElement());
333+
if (!selection.isEmpty()) {
334+
setShape((Shape) selection.getFirstElement());
335+
iconSelector.setSelectedIcon(null);
336+
}
337+
}
338+
});
339+
340+
iconSelector.addListener(new IPropertyChangeListener() {
341+
@Override
342+
public void propertyChange(PropertyChangeEvent event) {
343+
if (event.getNewValue() != null) {
344+
ssc.removeSelection();
345+
for (PriorityDescriptor pd : selectedDescriptors()) {
346+
pd.iconId = ((PriorityDescriptorIcon) event.getNewValue()).getIconId();
347+
}
348+
349+
tableViewer.refresh();
350+
}
333351
}
334352
});
335353

@@ -359,10 +377,9 @@ private void setShape(Shape shape) {
359377

360378
for (PriorityDescriptor pd : selectedDescriptors()) {
361379
pd.shape.shape = shape;
380+
pd.iconId = null;
362381
}
363382

364-
// PriorityDescriptorCache.instance.dump(System.out);
365-
366383
tableViewer.refresh();
367384
}
368385

@@ -396,7 +413,7 @@ private PriorityDescriptor[] selectedDescriptors() {
396413
}
397414

398415
private static void selectedPriorities(List<RulePriority> items, ShapePicker<Shape> ssc, ColorSelector colorPicker,
399-
Text nameField) {
416+
Text nameField, IconSelector iconSelector) {
400417

401418
if (items.size() != 1) {
402419
ssc.setSelection((Shape) null);
@@ -407,9 +424,14 @@ private static void selectedPriorities(List<RulePriority> items, ShapePicker<Sha
407424
RulePriority priority = items.get(0);
408425
PriorityDescriptor desc = PriorityDescriptorCache.INSTANCE.descriptorFor(priority);
409426

410-
ssc.setSelection(desc.shape.shape);
411427
nameField.setText(desc.label);
412428
colorPicker.setColorValue(desc.shape.rgbColor);
429+
if (desc.iconId == null) {
430+
ssc.setSelection(desc.shape.shape);
431+
} else {
432+
ssc.removeSelection();
433+
}
434+
iconSelector.setSelectedIcon(PriorityDescriptorIcon.getById(desc.iconId));
413435
}
414436

415437
/**
@@ -757,6 +779,7 @@ protected void performDefaults() {
757779
descriptor.shape.shape = defaultDescriptor.shape.shape;
758780
descriptor.shape.rgbColor = defaultDescriptor.shape.rgbColor;
759781
descriptor.label = defaultDescriptor.label;
782+
descriptor.iconId = defaultDescriptor.iconId;
760783
}
761784
tableViewer.refresh();
762785

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3+
*/
4+
5+
package net.sourceforge.pmd.eclipse.ui.preferences;
6+
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
10+
import org.eclipse.core.runtime.ListenerList;
11+
import org.eclipse.jface.util.IPropertyChangeListener;
12+
import org.eclipse.jface.util.PropertyChangeEvent;
13+
import org.eclipse.swt.SWT;
14+
import org.eclipse.swt.events.SelectionAdapter;
15+
import org.eclipse.swt.events.SelectionEvent;
16+
import org.eclipse.swt.layout.FillLayout;
17+
import org.eclipse.swt.widgets.Button;
18+
import org.eclipse.swt.widgets.Composite;
19+
20+
import net.sourceforge.pmd.eclipse.ui.priority.PriorityDescriptorIcon;
21+
22+
public class IconSelector {
23+
private Composite composite;
24+
private ListenerList listeners = new ListenerList();
25+
private PriorityDescriptorIcon selectedIcon;
26+
27+
public IconSelector(Composite parent) {
28+
composite = new Composite(parent, SWT.FILL);
29+
composite.setLayout(new FillLayout());
30+
31+
final List<Button> buttonGroup = new ArrayList<>();
32+
for (PriorityDescriptorIcon icon : PriorityDescriptorIcon.ICONS) {
33+
Button button = new Button(composite, SWT.TOGGLE);
34+
button.setImage(icon.getImage());
35+
button.setData(icon);
36+
button.addSelectionListener(new SelectionAdapter() {
37+
@Override
38+
public void widgetSelected(SelectionEvent e) {
39+
Button btn = (Button) e.widget;
40+
if (btn.getSelection()) {
41+
for (Button otherButton : buttonGroup) {
42+
if (otherButton != btn) {
43+
otherButton.setSelection(false);
44+
}
45+
}
46+
setSelectedIcon((PriorityDescriptorIcon) btn.getData());
47+
} else {
48+
btn.setSelection(true);
49+
}
50+
}
51+
});
52+
buttonGroup.add(button);
53+
}
54+
55+
addListener(new IPropertyChangeListener() {
56+
@Override
57+
public void propertyChange(PropertyChangeEvent event) {
58+
PriorityDescriptorIcon icon = (PriorityDescriptorIcon) event.getNewValue();
59+
for (Button btn : buttonGroup) {
60+
btn.setSelection(btn.getData() == icon);
61+
}
62+
}
63+
});
64+
}
65+
66+
public void setLayoutData(Object layoutData) {
67+
composite.setLayoutData(layoutData);
68+
}
69+
70+
public void setSelectedIcon(PriorityDescriptorIcon icon) {
71+
PropertyChangeEvent event = new PropertyChangeEvent(this, "selectedIcon", this.selectedIcon, icon);
72+
this.selectedIcon = icon;
73+
74+
for (Object listener : listeners.getListeners()) {
75+
((IPropertyChangeListener) listener).propertyChange(event);
76+
}
77+
}
78+
79+
public PriorityDescriptorIcon getSelectedIcon() {
80+
return selectedIcon;
81+
}
82+
83+
public void addListener(IPropertyChangeListener listener) {
84+
listeners.add(listener);
85+
}
86+
87+
public void removeListener(IPropertyChangeListener listener) {
88+
listeners.remove(listener);
89+
}
90+
}

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/priority/PriorityDescriptor.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import org.eclipse.jface.resource.ImageDescriptor;
1212
import org.eclipse.swt.graphics.Image;
13+
import org.eclipse.swt.graphics.ImageData;
1314
import org.eclipse.swt.graphics.RGB;
1415
import org.eclipse.swt.widgets.Display;
1516

@@ -53,7 +54,10 @@ public PriorityDescriptor(RulePriority thePriority, String theLabelKey, String t
5354
label = AbstractPMDAction.getString(theLabelKey);
5455
description = "--"; // TODO
5556
filterText = AbstractPMDAction.getString(theFilterTextKey);
56-
iconId = theIconId;
57+
iconId = null;
58+
if (theIconId != null && !theIconId.isEmpty() && !"null".equals(theIconId)) {
59+
iconId = theIconId;
60+
}
5761
shape = theShape;
5862
}
5963

@@ -133,7 +137,10 @@ public void storeOn(StringBuilder sb) {
133137
sb.append(label).append(DELIMITER);
134138
// sb.append(description).append(DELIMITER);
135139
sb.append(filterText).append(DELIMITER);
136-
sb.append(iconId).append(DELIMITER);
140+
if (iconId != null) {
141+
sb.append(iconId);
142+
}
143+
sb.append(DELIMITER);
137144
sb.append(shape.shape.id).append(DELIMITER);
138145
rgbOn(sb, shape.rgbColor);
139146
sb.append(DELIMITER);
@@ -200,9 +207,19 @@ public ImageDescriptor getAnnotationImageDescriptor() {
200207
}
201208

202209
private Image createImage(final int size) {
203-
return ShapePainter.newDrawnImage(Display.getCurrent(), size, size, shape.shape, PROTO_TRANSPARENT_COLOR,
204-
shape.rgbColor // fillColour
205-
);
210+
if (iconId == null || iconId.isEmpty() || "null".equals(iconId)) {
211+
return ShapePainter.newDrawnImage(Display.getCurrent(), size, size, shape.shape, PROTO_TRANSPARENT_COLOR,
212+
shape.rgbColor // fillColour
213+
);
214+
} else {
215+
Image srcImage = PriorityDescriptorIcon.getById(iconId).getImage();
216+
// need to create a copy since the image of the PropertyDescriptor might be disposed
217+
// if the image is changed. See #refreshImages()
218+
// also, we might need to scale the icon.
219+
ImageData imageData = srcImage.getImageData().scaledTo(size, size);
220+
Image copy = new Image(srcImage.getDevice(), imageData);
221+
return copy;
222+
}
206223
}
207224

208225
/**
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3+
*/
4+
5+
package net.sourceforge.pmd.eclipse.ui.priority;
6+
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
10+
import org.eclipse.swt.graphics.Image;
11+
12+
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
13+
14+
public class PriorityDescriptorIcon {
15+
private final String iconId;
16+
private final String imagePath;
17+
18+
private PriorityDescriptorIcon(String iconId, String imagePath) {
19+
this.iconId = iconId;
20+
this.imagePath = imagePath;
21+
}
22+
23+
public String getIconId() {
24+
return iconId;
25+
}
26+
27+
public Image getImage() {
28+
return PMDPlugin.getDefault().getImage(iconId, imagePath);
29+
}
30+
31+
public static final PriorityDescriptorIcon[] ICONS = {
32+
new PriorityDescriptorIcon("icon-prio-1", "icons/prio_1.gif"),
33+
new PriorityDescriptorIcon("icon-prio-2", "icons/prio_2.gif"),
34+
new PriorityDescriptorIcon("icon-prio-3", "icons/prio_3.gif"),
35+
new PriorityDescriptorIcon("icon-prio-4", "icons/prio_4.gif"),
36+
new PriorityDescriptorIcon("icon-prio-5", "icons/prio_5.gif"),
37+
new PriorityDescriptorIcon("icon-pmd", "icons/pmd-icon-16.gif"),
38+
new PriorityDescriptorIcon("icon-error", "icons/error.gif"),
39+
new PriorityDescriptorIcon("icon-warn", "icons/warn.gif"),
40+
new PriorityDescriptorIcon("icon-info", "icons/info.gif"),
41+
};
42+
43+
private static final Map<String, PriorityDescriptorIcon> ICONS_BY_ID;
44+
45+
static {
46+
ICONS_BY_ID = new HashMap<>(ICONS.length);
47+
for (PriorityDescriptorIcon icon : ICONS) {
48+
ICONS_BY_ID.put(icon.getIconId(), icon);
49+
}
50+
}
51+
52+
public static PriorityDescriptorIcon getById(String iconId) {
53+
return ICONS_BY_ID.get(iconId);
54+
}
55+
}

0 commit comments

Comments
 (0)