|
45 | 45 | import org.eclipse.ui.IDecoratorManager; |
46 | 46 | import org.eclipse.ui.IEditorPart; |
47 | 47 | import org.eclipse.ui.IEditorReference; |
| 48 | +import org.eclipse.ui.IViewPart; |
| 49 | +import org.eclipse.ui.IViewReference; |
48 | 50 | import org.eclipse.ui.IWorkbenchPart; |
49 | 51 | import org.eclipse.ui.PartInitException; |
50 | 52 | import org.eclipse.ui.PlatformUI; |
@@ -89,12 +91,12 @@ public class PMDPlugin extends AbstractUIPlugin { |
89 | 91 | private static File pluginFolder; |
90 | 92 |
|
91 | 93 | 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"; |
94 | 94 |
|
95 | 95 | private Map<RGB, Color> coloursByRGB = new HashMap<RGB, Color>(); |
96 | 96 |
|
97 | 97 | 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"; |
98 | 100 |
|
99 | 101 | private static Map<IProject, IJavaProject> javaProjectsByIProject = new HashMap<IProject, IJavaProject>(); |
100 | 102 |
|
@@ -302,6 +304,55 @@ public void fileChangeListenerEnabled(boolean flag) { |
302 | 304 | } |
303 | 305 | } |
304 | 306 | } |
| 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 | + } |
305 | 356 |
|
306 | 357 | /* |
307 | 358 | * (non-Javadoc) |
|
0 commit comments