KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > markers > MarkerViewUtil


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.views.markers;
13
14 import org.eclipse.core.resources.IMarker;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.jface.viewers.StructuredSelection;
17 import org.eclipse.ui.IPageLayout;
18 import org.eclipse.ui.IViewPart;
19 import org.eclipse.ui.IWorkbenchPage;
20 import org.eclipse.ui.views.markers.internal.MarkerView;
21
22 /**
23  * Utility class for showing markers in the marker views.
24  */

25 public class MarkerViewUtil {
26     
27     /**
28      * The PATH_ATTRIBUTE is the tag for the attribute on a marker
29      * that can be used to supply the String for the path rather than
30      * using the path of the underlying resource.
31      * @see IMarker#getAttribute(java.lang.String)
32      * @since 3.2
33      */

34     public static final String JavaDoc PATH_ATTRIBUTE = "org.eclipse.ui.views.markers.path";//$NON-NLS-1$
35

36     /**
37      * The NAME_ATTRIBUTE is the tag for the attribute on a marker
38      * that can be used to supply the String for the name rather than
39      * using the name of the underlying resource.
40      * @see IMarker#getAttribute(java.lang.String)
41      * @since 3.2
42      */

43     public static final String JavaDoc NAME_ATTRIBUTE = "org.eclipse.ui.views.markers.name";//$NON-NLS-1$
44

45     /**
46      * Returns the id of the view used to show markers of the
47      * same type as the given marker.
48      *
49      * @param marker the marker
50      * @return the view id or <code>null</code> if no appropriate view could be determined
51      * @throws CoreException if an exception occurs testing the type of the marker
52      */

53     public static String JavaDoc getViewId(IMarker marker) throws CoreException {
54         if (marker.isSubtypeOf(IMarker.TASK)) {
55             return IPageLayout.ID_TASK_LIST;
56         } else if (marker.isSubtypeOf(IMarker.PROBLEM)) {
57             return IPageLayout.ID_PROBLEM_VIEW;
58         } else if (marker.isSubtypeOf(IMarker.BOOKMARK)) {
59             return IPageLayout.ID_BOOKMARKS;
60         }
61         return null;
62     }
63
64     /**
65      * Shows the given marker in the appropriate view in the given page.
66      * This must be called from the UI thread.
67      *
68      * @param page the workbench page in which to show the marker
69      * @param marker the marker to show
70      * @param showView <code>true</code> if the view should be shown first
71      * <code>false</code> to only show the marker if the view is already showing
72      * @return <code>true</code> if the marker was successfully shown,
73      * <code>false</code> if not
74      *
75      */

76     public static boolean showMarker(IWorkbenchPage page, IMarker marker,
77             boolean showView) {
78         try {
79             String JavaDoc viewId = getViewId(marker);
80             if (viewId != null) {
81                 IViewPart view = showView ? page.showView(viewId) : page
82                         .findView(viewId);
83                 if (view instanceof MarkerView) {
84                     StructuredSelection selection = new StructuredSelection(
85                             marker);
86                     MarkerView markerView = (MarkerView) view;
87                     markerView.setSelection(selection, true);
88                     return true;
89
90                     //return markerView.getSelection().equals(selection);
91
}
92             }
93         } catch (CoreException e) {
94             // ignore
95
}
96         return false;
97     }
98
99 }
100
Popular Tags