Some Oxygen trigger removes StyledText highlighting

Oxygen general issues.
yury.eroshenkov
Posts: 34
Joined: Mon Jun 03, 2013 2:17 pm

Some Oxygen trigger removes StyledText highlighting

Post by yury.eroshenkov »

Hi,
We are building a plug-in for Eclipse(3.5) and Oxygen Eclipse Editor(com.oxygenxml.author 13.2) and integrating some text highlighting logic into the Editor. In the Author mode everything work fine - we are using an Oxygen API to crate text ranges. In the text mode we are using Styled Text widget to create highlighted ranges directly, becouse we not found a way to highlight some part of text inside the xml tag using Oxygen API in the text mode (only whole tag). All ranges are highlighted well, but when a user is modifying text, all highlightings at the current line are removing by some Oxygen trigger.
We tried to remove all listeners from the StyledText widget but without a success.
How should we solve this problem?
Radu
Posts: 9445
Joined: Fri Jul 09, 2004 5:18 pm

Re: Some Oxygen trigger removes StyledText highlighting

Post by Radu »

Hi Yuri,

How exactly are you adding the highlights? Maybe you could give me a small sample code of how you work with the StyledText.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
yury.eroshenkov
Posts: 34
Joined: Mon Jun 03, 2013 2:17 pm

Re: Some Oxygen trigger removes StyledText highlighting

Post by yury.eroshenkov »

For example, adding the ranges:

Code: Select all


    public void add(Key key, AbsoluteRange range, MarkingColor color, MarkingType markingType)
{
StyleRange styleRange = new StyleRange();
styleRange.background = Colors.toSwtColor(color);
styleRange.start = range.getBegin();
styleRange.length = range.getLength();
styleRange.data = key;
styledText.setStyleRange(styleRange);
}
Radu
Posts: 9445
Joined: Fri Jul 09, 2004 5:18 pm

Re: Some Oxygen trigger removes StyledText highlighting

Post by Radu »

Hi Yuri,

We use StyleRange to provide syntax highlight for the XML content in the Text mode. So the ranges on each line are updated as it is modified.
You should probably try to add annotations instead. Here's an example based on our spell check annotations:

Something like:

Code: Select all

if(workbenchPart instanceof MultiPageEditorPart) {
MultiPageEditorPart mPart = (MultiPageEditorPart) workbenchPart;
Object selectedPage = mPart.getSelectedPage();
if(selectedPage instanceof TextEditor) {
TextEditor textModePart = ((TextEditor)selectedPage);
IAnnotationModel annotationModel = textModePart.getDocumentProvider().getAnnotationModel(textModePart.getEditorInput());
annotationModel.addAnnotation(new SpellCheckingAnnotation("TEXT", additionalCheckData), new Position(10, 10));
}
}
Where the acrolinx annotation could be something like:

Code: Select all

public class SpellCheckingAnnotation extends Annotation {

/**
* Contains additional information for the spell check annotation.
*/
private final CheckData checkData;

/**
* Spell Check Annotation constructor.
*
* @param text The text of the annotation.
* @param checkData Contains additional information for the spell check annotation.
*/
public SpellCheckingAnnotation(String text, CheckData checkData) {
super("com.oxygenxml.editor.AcrolinxSpellCheckAnnotation", false, text);
this.checkData = checkData;
}

/**
* @return Returns the additional information for the spell check annotation.
*/
public CheckData getSpellCheckData() {
return checkData;
}
}
Then in your plugin.xml you define a new annotation like:

Code: Select all

<extension id="spell-check-annotation" 
point="org.eclipse.ui.editors.markerAnnotationSpecification">
<specification annotationType="com.oxygenxml.editor.AcrolinxSpellCheckAnnotation"
colorPreferenceKey="spell.ColorKey"
colorPreferenceValue="245,132,76"
contributesToHeader="false"
highlightPreferenceKey="spell.highlightKey"
highlightPreferenceValue="false"
includeOnPreferencePage="true"
label="%specification.label.1"
overviewRulerPreferenceKey="spell.overviewRuler"
overviewRulerPreferenceValue="false"
presentationLayer="1"
textPreferenceKey="spell.textKey"
textPreferenceValue="true"
textStylePreferenceKey="spell.styleKey"
textStylePreferenceValue="UNDERLINE"
verticalRulerPreferenceKey="spell.verticalRuller"
verticalRulerPreferenceValue="false"/>
</extension>
You can look in our plugin.xml to find more annotation examples.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
yury.eroshenkov
Posts: 34
Joined: Mon Jun 03, 2013 2:17 pm

Re: Some Oxygen trigger removes StyledText highlighting

Post by yury.eroshenkov »

Thank you.
Acctually, we tried to use annotations first, but couldn't access to the annotation model.
We will try this.
yury.eroshenkov
Posts: 34
Joined: Mon Jun 03, 2013 2:17 pm

Re: Some Oxygen trigger removes StyledText highlighting

Post by yury.eroshenkov »

Thank you for your help much!
The annotations are working perfectly! Thanks.
Post Reply