Skip to content

Commit f5abe57

Browse files
committed
Merge branch 'pr-41'
2 parents 4344d54 + 51ee34b commit f5abe57

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

ReleaseNotes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Eclipse Update Site:
2626
* [#20](https://github.com/pmd/pmd-eclipse-plugin/issues/20): category.xml maybe broken
2727
* [#29](https://github.com/pmd/pmd-eclipse-plugin/issues/29): Processing errors without cause
2828
* [#32](https://github.com/pmd/pmd-eclipse-plugin/issues/32): Upgrade PMD to 6.2.0
29+
* [#42](https://github.com/pmd/pmd-eclipse-plugin/issues/42): Marker colors not updated in all views after change
2930
* [#43](https://github.com/pmd/pmd-eclipse-plugin/issues/43): Update unit tests to use new ruleset categories
3031

3132
### External Contributions
@@ -35,6 +36,7 @@ Eclipse Update Site:
3536
* [#37](https://github.com/pmd/pmd-eclipse-plugin/pull/37): Global Priority Filter for Violations Overview/Outline - [Phillip Krall](https://github.com/pkrall520)
3637
* [#39](https://github.com/pmd/pmd-eclipse-plugin/pull/39): Show PMD violations overview/outline views when checking code - [Phillip Krall](https://github.com/pkrall520)
3738
* [#40](https://github.com/pmd/pmd-eclipse-plugin/pull/40): Only execute PMD when check on save is enabled - [Phillip Krall](https://github.com/pkrall520)
39+
* [#41](https://github.com/pmd/pmd-eclipse-plugin/pull/41): Update all views after marker color changed - [Phillip Krall](https://github.com/pkrall520)
3840

3941

4042
## 24-June-2017: 4.0.15.v20170624-2134

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/plugin/PMDPlugin.java

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
import org.eclipse.ui.IDecoratorManager;
4646
import org.eclipse.ui.IEditorPart;
4747
import org.eclipse.ui.IEditorReference;
48+
import org.eclipse.ui.IViewPart;
49+
import org.eclipse.ui.IViewReference;
4850
import org.eclipse.ui.IWorkbenchPart;
4951
import org.eclipse.ui.PartInitException;
5052
import org.eclipse.ui.PlatformUI;
@@ -89,12 +91,12 @@ public class PMDPlugin extends AbstractUIPlugin {
8991
private static File pluginFolder;
9092

9193
private FileChangeReviewer changeReviewer;
92-
public static final String VIOLATIONS_OVERVIEW_ID = "net.sourceforge.pmd.eclipse.ui.views.violationOverview";
93-
public static final String VIOLATIONS_OUTLINE_ID = "net.sourceforge.pmd.eclipse.ui.views.violationOutline";
9494

9595
private Map<RGB, Color> coloursByRGB = new HashMap<RGB, Color>();
9696

9797
public static final String PLUGIN_ID = "net.sourceforge.pmd.eclipse.plugin";
98+
public static final String VIOLATIONS_OVERVIEW_ID = "net.sourceforge.pmd.eclipse.ui.views.violationOverview";
99+
public static final String VIOLATIONS_OUTLINE_ID = "net.sourceforge.pmd.eclipse.ui.views.violationOutline";
98100

99101
private static Map<IProject, IJavaProject> javaProjectsByIProject = new HashMap<IProject, IJavaProject>();
100102

@@ -302,6 +304,55 @@ public void fileChangeListenerEnabled(boolean flag) {
302304
}
303305
}
304306
}
307+
308+
/**
309+
* Get a view from the view id.
310+
* @param id id of the view
311+
* @return view
312+
*/
313+
public static IViewPart getView(String id) {
314+
IViewReference[] viewReferences = PlatformUI.getWorkbench()
315+
.getActiveWorkbenchWindow().getActivePage().getViewReferences();
316+
for (int i = 0; i < viewReferences.length; i++) {
317+
if (id.equals(viewReferences[i].getId())) {
318+
return viewReferences[i].getView(false);
319+
}
320+
}
321+
return null;
322+
}
323+
324+
/**
325+
* refresh a view to the id passed in.
326+
*
327+
* @param viewId id of the view
328+
*/
329+
public void refreshView(final String viewId) {
330+
Display.getDefault().asyncExec(new Runnable() {
331+
@Override
332+
public void run() {
333+
try {
334+
IViewPart view = getView(viewId);
335+
if (view == null) {
336+
return;
337+
}
338+
boolean found = false;
339+
IViewPart[] views = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViews();
340+
for (IViewPart activeView: views) {
341+
if (activeView.getTitle().equals(view.getTitle())) {
342+
found = true;
343+
}
344+
}
345+
if (!found) {
346+
return;
347+
}
348+
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(view);
349+
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(viewId);
350+
} catch (PartInitException e) {
351+
LOG.error(e);
352+
}
353+
}
354+
});
355+
}
305356

306357
/*
307358
* (non-Javadoc)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.eclipse.swt.widgets.Spinner;
4343
import org.eclipse.swt.widgets.Table;
4444
import org.eclipse.swt.widgets.Text;
45+
import org.eclipse.ui.IPageLayout;
4546
import org.eclipse.ui.IWorkbench;
4647
import org.eclipse.ui.IWorkbenchPreferencePage;
4748
import org.eclipse.ui.dialogs.PreferencesUtil;
@@ -825,6 +826,13 @@ private void updateMarkerIcons() {
825826
RootRecord root = new RootRecord(ResourcesPlugin.getWorkspace().getRoot());
826827
Set<IFile> files = MarkerUtil.allMarkedFiles(root);
827828
PMDPlugin.getDefault().changedFiles(files);
829+
830+
/* Refresh the views to pick up the marker change */
831+
PMDPlugin.getDefault().refreshView(PMDPlugin.VIOLATIONS_OVERVIEW_ID);
832+
PMDPlugin.getDefault().refreshView(PMDPlugin.VIOLATIONS_OUTLINE_ID);
833+
PMDPlugin.getDefault().refreshView(IPageLayout.ID_PROJECT_EXPLORER);
834+
PMDPlugin.getDefault().refreshView(IPageLayout.ID_OUTLINE);
835+
828836
}
829837

830838
public boolean performCancel() {

0 commit comments

Comments
 (0)