|
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; |
| 51 | +import org.eclipse.ui.PartInitException; |
49 | 52 | import org.eclipse.ui.PlatformUI; |
50 | 53 | import org.eclipse.ui.plugin.AbstractUIPlugin; |
51 | 54 | import org.osgi.framework.Bundle; |
@@ -92,6 +95,8 @@ public class PMDPlugin extends AbstractUIPlugin { |
92 | 95 | private Map<RGB, Color> coloursByRGB = new HashMap<RGB, Color>(); |
93 | 96 |
|
94 | 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"; |
95 | 100 |
|
96 | 101 | private static Map<IProject, IJavaProject> javaProjectsByIProject = new HashMap<IProject, IJavaProject>(); |
97 | 102 |
|
@@ -281,6 +286,55 @@ public void fileChangeListenerEnabled(boolean flag) { |
281 | 286 | } |
282 | 287 | } |
283 | 288 | } |
| 289 | + |
| 290 | + /** |
| 291 | + * Get a view from the view id. |
| 292 | + * @param id id of the view |
| 293 | + * @return view |
| 294 | + */ |
| 295 | + public static IViewPart getView(String id) { |
| 296 | + IViewReference[] viewReferences = PlatformUI.getWorkbench() |
| 297 | + .getActiveWorkbenchWindow().getActivePage().getViewReferences(); |
| 298 | + for (int i = 0; i < viewReferences.length; i++) { |
| 299 | + if (id.equals(viewReferences[i].getId())) { |
| 300 | + return viewReferences[i].getView(false); |
| 301 | + } |
| 302 | + } |
| 303 | + return null; |
| 304 | + } |
| 305 | + |
| 306 | + /** |
| 307 | + * refresh a view to the id passed in. |
| 308 | + * |
| 309 | + * @param viewId id of the view |
| 310 | + */ |
| 311 | + public void refreshView(final String viewId) { |
| 312 | + Display.getDefault().asyncExec(new Runnable() { |
| 313 | + @Override |
| 314 | + public void run() { |
| 315 | + try { |
| 316 | + IViewPart view = getView(viewId); |
| 317 | + if (view == null) { |
| 318 | + return; |
| 319 | + } |
| 320 | + boolean found = false; |
| 321 | + IViewPart[] views = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViews(); |
| 322 | + for (IViewPart activeView: views) { |
| 323 | + if (activeView.getTitle().equals(view.getTitle())) { |
| 324 | + found = true; |
| 325 | + } |
| 326 | + } |
| 327 | + if (!found) { |
| 328 | + return; |
| 329 | + } |
| 330 | + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(view); |
| 331 | + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(viewId); |
| 332 | + } catch (PartInitException e) { |
| 333 | + LOG.error(e); |
| 334 | + } |
| 335 | + } |
| 336 | + }); |
| 337 | + } |
284 | 338 |
|
285 | 339 | /* |
286 | 340 | * (non-Javadoc) |
|
0 commit comments