需求如下:
在做一个图形编辑器,在 代码运 行后能够显示那些错误信息,就像运行Eclipse程序后,如果有错误的话,就会在Problems视图中显示出来(如图示)!
首先,需要得到Problems视图窗口:
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewReference problemView = page.findViewReference(IPageLayout.ID_PROBLEM_VIEW);
其次,要向Problem View里写message, 需要创建相应的Marker。
参考代码如下:
/**
* Problem marker id
*/
public static final String PROBLEMS_MARKER_ID = "org.eclipse.core.resources.problemmarker";
public static void addMarker( IResource resource, String message,
int lineNumber, int severity, int priority ) throws CoreException
{
if ( resource != null )
{
IMarker marker = resource.createMarker( PROBLEMS_MARKER_ID );
if ( message != null )
marker.setAttribute( IMarker.MESSAGE, message );
if ( lineNumber >= 0 )
marker.setAttribute( IMarker.LINE_NUMBER, lineNumber );
marker.setAttribute( IMarker.SEVERITY, severity );
marker.setAttribute( IMarker.PRIORITY, priority );
}
}
在做一个图形编辑器,在 代码运 行后能够显示那些错误信息,就像运行Eclipse程序后,如果有错误的话,就会在Problems视图中显示出来(如图示)!
首先,需要得到Problems视图窗口:
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewReference problemView = page.findViewReference(IPageLayout.ID_PROBLEM_VIEW);
其次,要向Problem View里写message, 需要创建相应的Marker。
参考代码如下:
/**
* Problem marker id
*/
public static final String PROBLEMS_MARKER_ID = "org.eclipse.core.resources.problemmarker";
public static void addMarker( IResource resource, String message,
int lineNumber, int severity, int priority ) throws CoreException
{
if ( resource != null )
{
IMarker marker = resource.createMarker( PROBLEMS_MARKER_ID );
if ( message != null )
marker.setAttribute( IMarker.MESSAGE, message );
if ( lineNumber >= 0 )
marker.setAttribute( IMarker.LINE_NUMBER, lineNumber );
marker.setAttribute( IMarker.SEVERITY, severity );
marker.setAttribute( IMarker.PRIORITY, priority );
}
}