Kawamoto Takeshi
Kawamoto Takeshi

Reputation: 606

Writing to 'Problems' table or 'Console' from Plug-in

I have created a plug-in and as part of the functionality of the plug-in, I need to write something into the 'Problems' table or 'Console'.

I'm trying to make it quite similar to how Eclipse shows errors/warnings when it builds.

I have the Error Code, Error Message and the Line number. I have successfully created the logic behind this on an SWT application using a table. However, I now need to create a plug-in. So far, I am trying ways to display it on the 'Problems' table of Eclipse.

In a desperate attempt, I tried writing to the console with

System.out.println
System.console().writer().println(),

but it didn't work. I also tried using

StatusManager ab;
IStatus status = new Status(Status.ERROR, "HELLO", "HELLO!");
ab.handle(status, 0);

But it seems I need to initialize ab, but I can't do that with

StatusManager ab = new StatusManager();

I also tried

logger.info("Info!");
logger.severe("Error!");
logger.warning("Warning!");

But they do not work either.

Plugin ab;
ab.getLog().log(new Status(Status.INFO,"Hello", "hehe"));

Doesn't work either cause I need to initialize ab, which

Plugin ab = new Plugin();

I really need a bit of help to push me to the right direction on how to do this.

P.S: The console or the problems table I'm mentioning is the actual Eclipse one.

Upvotes: 0

Views: 34

Answers (1)

greg-449
greg-449

Reputation: 111142

The Problems views shows IMarker objects with a type of Problem.

Marker objects are always associated with an IResource object (or one of its derived interfaces such as IFile and IFolder).

You create a marker with something like:

IFile file = .... get file to mark 

IMarker marker = file.createMarker(IMarker.PROBLEM);

marker.setAttribute(IMarker.LINE_NUMBER, line number);
marker.setAttribute(IMarker.MESSAGE, "error message");
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);

You can use the org.eclipse.core.resources.markers extension point to define your own marker type which will help you distinguish your markers from other plug-in's markers.

Upvotes: 1

Related Questions