Modifying the Marking of Validation Errors and Warning

Oxygen general issues.
Chemo
Posts: 19
Joined: Mon Aug 15, 2011 10:57 am

Modifying the Marking of Validation Errors and Warning

Post by Chemo »

Hello.

Is there any way to costumize the way oxygen marks validation errors and warnings in the author view? Maybe there is some stylesheet i can edit?

I'd like to highlight errors, instead of underlining them, for example changing the text background color to light red (or yellow).
Also I like to let oxygen write a note about the error type into the author view directly at the error position, like " [value "text" not allowed for attribute "type"] ".

I'd be happy about every hint,
Thomas.
Radu
Posts: 9057
Joined: Fri Jul 09, 2004 5:18 pm

Re: Modifying the Marking of Validation Errors and Warning

Post by Radu »

Hi Thomas,

Probably in a future version of Oxygen users will have the possibility to customize the style for all highlights used in the Author page (validation, spell checking, find all, etc) in the Preferences page.
This is not possible right now. The error message is right now available as a tooltip when hovering over the problem area.

But there might be a possibility for you to do this using our Java API. This has to be tried though.
Using our Java API you would be able to add custom highlights (with red background for those areas) which also have callouts on the side (for Oxygen 14.0 or newer).
Would you be interested in a more detailed description of this approach?

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Chemo
Posts: 19
Joined: Mon Aug 15, 2011 10:57 am

Re: Modifying the Marking of Validation Errors and Warning

Post by Chemo »

Hi.

I already have implemented a java extension to my project for an other issue. So costumizing the highlighting by using the API is a fine option.

I assume i find needed highlighting api in the "ro.sync.ecss.extensions.api.highlights" package?

Regards,
Thomas.
Radu
Posts: 9057
Joined: Fri Jul 09, 2004 5:18 pm

Re: Modifying the Marking of Validation Errors and Warning

Post by Radu »

Hi Thomas,

I will assume you are using Oxygen 14.0.
In our Plugins SDK:

http://www.oxygenxml.com/oxygen_sdk.htm ... er_Plugins

there is a type of plugin called Workspace.

I tried implementing such a plugin on my side which uses our support for persistent highlights to add callouts where validation errors are found.
Unfortunately our callouts API does not allow adding API for non-persistent highlights so in order not to save the persistent highlights in the document before each save operation they are removed completely.

Here is a screenshot of how I managed to make it work, the colors can be changed from the Java code:

Image

I will post the sample plugin Java code, unfortunately it also uses some new Oxygen 14.1 API called WSTextBasedEditorPage.getStartEndOffsets(DocumentPositionedInfo) to find the location in the Author content where a problem exists. Oxygen 14.1 will probably be released in a week or two.

Right now my plugin's code looks like this:

Code: Select all

/**
* Plugin extension - workspace access extension.
*/
public class CustomWorkspaceAccessPluginExtension implements WorkspaceAccessPluginExtension {

/**
* @see ro.sync.exml.plugin.workspace.WorkspaceAccessPluginExtension#applicationStarted(ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace)
*/
public void applicationStarted(final StandalonePluginWorkspace pluginWorkspaceAccess) {
pluginWorkspaceAccess.addEditorChangeListener(new WSEditorChangeListener() {
/**
* @see ro.sync.exml.workspace.api.listeners.WSEditorChangeListener#editorOpened(java.net.URL)
*/
@Override
public void editorOpened(URL editorLocation) {
final WSEditor currentEditor = pluginWorkspaceAccess.getEditorAccess(editorLocation, StandalonePluginWorkspace.MAIN_EDITING_AREA);
WSEditorPage currentPage = currentEditor.getCurrentPage();
if(currentPage instanceof WSAuthorEditorPage) {
final WSAuthorEditorPage currentAuthorPage = (WSAuthorEditorPage)currentPage;
currentAuthorPage.getPersistentHighlighter().setHighlightRenderer(new PersistentHighlightRenderer() {
@Override
public String getTooltip(AuthorPersistentHighlight highlight) {
return highlight.getClonedProperties().get("message");
}
@Override
public HighlightPainter getHighlightPainter(AuthorPersistentHighlight highlight) {
//Depending on severity could have different color.
ColorHighlightPainter painter = new ColorHighlightPainter(Color.COLOR_RED, -1, -1);
painter.setBgColor(Color.COLOR_RED);
return painter;
}
});
currentAuthorPage.getReviewController()
.getAuthorCalloutsController().setCalloutsRenderingInformationProvider(
new CalloutsRenderingInformationProvider() {
@Override
public boolean shouldRenderAsCallout(AuthorPersistentHighlight highlight) {
//All custom highlights are ours
return true;
}
@Override
public AuthorCalloutRenderingInformation getCalloutRenderingInformation(
final AuthorPersistentHighlight highlight) {
return new AuthorCalloutRenderingInformation() {
@Override
public long getTimestamp() {
//Not interesting
return -1;
}
@Override
public String getContentFromTarget(int limit) {
return "";
}
@Override
public String getComment(int limit) {
return highlight.getClonedProperties().get("message");
}
@Override
public Color getColor() {
return Color.COLOR_RED;
}
@Override
public String getCalloutType() {
return "Problem";
}
@Override
public String getAuthor() {
return "";
}
@Override
public Map<String, String> getAdditionalData() {
return null;
}
};
}
});
currentEditor.addValidationProblemsFilter(new ValidationProblemsFilter() {
List<int[]> lastStartEndOffsets = new ArrayList<int[]>();
/**
* @see ro.sync.exml.workspace.api.editor.validation.ValidationProblemsFilter#filterValidationProblems(ro.sync.exml.workspace.api.editor.validation.ValidationProblems)
*/
@Override
public void filterValidationProblems(ValidationProblems validationProblems) {
List<int[]> startEndOffsets = new ArrayList<int[]>();
List<DocumentPositionedInfo> problemsList = validationProblems.getProblemsList();
if(problemsList != null) {
for (int i = 0; i < problemsList.size(); i++) {
try {
startEndOffsets.add(currentAuthorPage.getStartEndOffsets(problemsList.get(i)));
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
if(lastStartEndOffsets.size() != startEndOffsets.size()) {
//Continue
} else {
boolean equal = true;
for (int i = 0; i < startEndOffsets.size(); i++) {
int[] o1 = startEndOffsets.get(i);
int[] o2 = lastStartEndOffsets.get(i);
if(o1 == null && o2 == null) {
//Continue
} else if(o1 != null && o2 != null
&& o1[0] == o2[0] && o1[1] == o2[1]){
//Continue
} else {
equal = false;
break;
}
}
if(equal) {
//Same list of problems already displayed.
return;
}
}
//Keep last used offsets.
lastStartEndOffsets = startEndOffsets;
try {
if(! SwingUtilities.isEventDispatchThread()) {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
//First remove all custom highlights.
currentAuthorPage.getPersistentHighlighter().removeAllHighlights();
}
});
}
} catch (InterruptedException e1) {
e1.printStackTrace();
} catch (InvocationTargetException e1) {
e1.printStackTrace();
}
if(problemsList != null) {
for (int i = 0; i < problemsList.size(); i++) {
//A reported problem (could be warning, could be error).
DocumentPositionedInfo dpi = problemsList.get(i);
try {
final int[] currentOffsets = startEndOffsets.get(i);
if(currentOffsets != null) {
//These are offsets in the Author content.
final LinkedHashMap<String, String> highlightProps = new LinkedHashMap<String, String>();
highlightProps.put("message", dpi.getMessage());
highlightProps.put("severity", dpi.getSeverityAsString());
if(! SwingUtilities.isEventDispatchThread()) {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
currentAuthorPage.getPersistentHighlighter().addHighlight(
currentOffsets[0], currentOffsets[1] - 1, highlightProps);
}
});
}
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
});
currentEditor.addEditorListener(new WSEditorListener() {
/**
* @see ro.sync.exml.workspace.api.listeners.WSEditorListener#editorAboutToBeSavedVeto(int)
*/
@Override
public boolean editorAboutToBeSavedVeto(int operationType) {
try {
if(! SwingUtilities.isEventDispatchThread()) {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
//Remove all persistent highlights before saving
currentAuthorPage.getPersistentHighlighter().removeAllHighlights();
}
});
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return true;
}
});
}
}
}, StandalonePluginWorkspace.MAIN_EDITING_AREA);
}


/**
* @see ro.sync.exml.plugin.workspace.WorkspaceAccessPluginExtension#applicationClosing()
*/
public boolean applicationClosing() {
return true;
}
}
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Chemo
Posts: 19
Joined: Mon Aug 15, 2011 10:57 am

Re: Modifying the Marking of Validation Errors and Warning

Post by Chemo »

Thank you for the sample code.
This will help me!
Post Reply