use of org.eclipse.jface.text.source.AnnotationModel in project xtext-eclipse by eclipse.
the class EmbeddedEditorModelAccess method setModel.
protected void setModel(XtextDocument document, String prefix, String editablePart, String suffix) {
if (this.insertLineBreaks) {
String delimiter = document.getDefaultLineDelimiter();
prefix = prefix + delimiter;
suffix = delimiter + suffix;
}
String model = prefix + editablePart + suffix;
document.set(model);
XtextResource resource = createResource(model);
document.setInput(resource);
AnnotationModel annotationModel = new AnnotationModel();
if (document instanceof ISynchronizable) {
Object lock = ((ISynchronizable) document).getLockObject();
if (lock == null) {
lock = new Object();
((ISynchronizable) document).setLockObject(lock);
}
((ISynchronizable) annotationModel).setLockObject(lock);
}
this.viewer.setDocument(document, annotationModel, prefix.length(), editablePart.length());
}
use of org.eclipse.jface.text.source.AnnotationModel in project mylyn.docs by eclipse.
the class HtmlViewer method parse.
protected ParseResult parse(String htmlText) {
initPainter();
ParseResult result = new ParseResult();
result.textPresentation = new TextPresentation();
HtmlTextPresentationParser parser = new HtmlTextPresentationParser();
if (stylesheet != null) {
parser.setStylesheet(stylesheet);
}
if (displayImages) {
parser.setImageCache(imageCache);
parser.setEnableImages(displayImages);
}
parser.setPresentation(result.textPresentation);
parser.setDefaultFont(getTextWidget().getFont());
parser.setDefaultMonospaceFont(defaultMonospaceFont);
result.annotationModel = new AnnotationModel();
parser.setAnnotationModel(result.annotationModel);
GC gc = new GC(getTextWidget());
try {
parser.setGC(gc);
parser.parse(htmlText);
} catch (SAXException e) {
throw new IllegalStateException(e);
} catch (IOException e) {
throw new IllegalStateException(e);
} finally {
gc.dispose();
}
result.text = parser.getText();
return result;
}
use of org.eclipse.jface.text.source.AnnotationModel in project eclipse-integration-commons by spring-projects.
the class EditorToolkit method createTextEditor.
public TextViewer createTextEditor(Composite composite, String text, boolean spellCheck, int style) {
AnnotationModel annotationModel = new AnnotationModel();
final SourceViewer textViewer = new SourceViewer(composite, null, null, true, style);
textViewer.showAnnotations(false);
textViewer.showAnnotationsOverview(false);
IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();
final SourceViewerDecorationSupport support = new SourceViewerDecorationSupport(textViewer, null, annotationAccess, EditorsUI.getSharedTextColors());
@SuppressWarnings("unchecked") Iterator e = new MarkerAnnotationPreferences().getAnnotationPreferences().iterator();
while (e.hasNext()) {
support.setAnnotationPreference((AnnotationPreference) e.next());
}
support.install(EditorsUI.getPreferenceStore());
textViewer.getTextWidget().setIndent(2);
textViewer.getTextWidget().addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
support.uninstall();
}
});
IThemeManager themeManager = editorSite.getWorkbenchWindow().getWorkbench().getThemeManager();
textViewer.getTextWidget().setFont(themeManager.getCurrentTheme().getFontRegistry().get(CommonThemes.FONT_EDITOR_COMMENT));
final ActionContributorProxy actionContributor = getContributor();
if (actionContributor.getSelectionChangedListener() != null) {
textViewer.addSelectionChangedListener(actionContributor.getSelectionChangedListener());
}
textViewer.getTextWidget().addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
actionContributor.updateSelectableActions(textViewer.getSelection());
}
public void focusLost(FocusEvent e) {
StyledText st = (StyledText) e.widget;
st.setSelectionRange(st.getCaretOffset(), 0);
actionContributor.forceActionsEnabled();
}
});
textViewer.addTextListener(new ITextListener() {
public void textChanged(TextEvent event) {
actionContributor.updateSelectableActions(textViewer.getSelection());
}
});
Document document = new Document(text);
StsTextViewerConfiguration viewerConfig = new StsTextViewerConfiguration(spellCheck, false);
textViewer.configure(viewerConfig);
textViewer.setDocument(document, annotationModel);
EditorUtil.setTextViewer(textViewer.getControl(), textViewer);
configureContextMenuManager(textViewer.getControl());
return textViewer;
}
use of org.eclipse.jface.text.source.AnnotationModel in project eclipse.platform.text by eclipse.
the class LineNumberColumn method ensureQuickDiffProvider.
/**
* Ensures that quick diff information is displayed and the quick diff provider is the one with
* the specified id. If a different quick diff provider is in use, the user may be asked whether
* he wants to switch.
*
* @param diffProviderId the quick diff provider id to use
* @return <code>true</code> if quick diff could be enabled for the given id,
* <code>false</code> otherwise
*/
private boolean ensureQuickDiffProvider(String diffProviderId) {
if (!isShowingChangeInformation())
// FIXME pass provider id
installChangeRulerModel(fDelegate);
IAnnotationModel annotationModel = fViewer.getAnnotationModel();
IAnnotationModel oldDiffer = getDiffer();
if (oldDiffer == null && annotationModel != null)
// quick diff is enabled, but no differ? not working for whatever reason
return false;
if (annotationModel == null)
annotationModel = new AnnotationModel();
if (!(annotationModel instanceof IAnnotationModelExtension))
return false;
QuickDiff util = new QuickDiff();
Object oldDifferId = util.getConfiguredQuickDiffProvider(oldDiffer);
if (oldDifferId.equals(diffProviderId)) {
if (oldDiffer instanceof ILineDifferExtension)
((ILineDifferExtension) oldDiffer).resume();
return true;
}
// Check whether the desired provider is available at all
IAnnotationModel newDiffer = util.createQuickDiffAnnotationModel(getEditor(), diffProviderId);
if (util.getConfiguredQuickDiffProvider(newDiffer).equals(oldDifferId)) {
if (oldDiffer instanceof ILineDifferExtension)
((ILineDifferExtension) oldDiffer).resume();
return true;
}
// quick diff is showing with the wrong provider - ask the user whether he wants to switch
IPreferenceStore store = EditorsUI.getPreferenceStore();
if (oldDiffer != null && !store.getString(REVISION_ASK_BEFORE_QUICKDIFF_SWITCH_KEY).equals(MessageDialogWithToggle.ALWAYS)) {
MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openOkCancelConfirm(fViewer.getTextWidget().getShell(), RulerMessages.AbstractDecoratedTextEditor_revision_quickdiff_switch_title, RulerMessages.AbstractDecoratedTextEditor_revision_quickdiff_switch_message, RulerMessages.AbstractDecoratedTextEditor_revision_quickdiff_switch_rememberquestion, true, store, REVISION_ASK_BEFORE_QUICKDIFF_SWITCH_KEY);
if (toggleDialog.getReturnCode() != Window.OK)
return false;
}
IAnnotationModelExtension modelExtension = (IAnnotationModelExtension) annotationModel;
modelExtension.removeAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID);
modelExtension.addAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID, newDiffer);
if (fDelegate instanceof IChangeRulerColumn)
// picks up the new model attachment
((IChangeRulerColumn) fDelegate).setModel(annotationModel);
return true;
}
use of org.eclipse.jface.text.source.AnnotationModel in project eclipse.platform.text by eclipse.
the class AnnotationModelStressTest method setUp.
@Before
public void setUp() throws Exception {
fDocument = new Document(RANDOM_CONTENT);
fAnnotationModel = new AnnotationModel();
fInnerModel1 = new AnnotationModel();
fAnnotationModel.addAnnotationModel("model1", fInnerModel1);
fInnerModel2 = new AnnotationModel();
fAnnotationModel.addAnnotationModel("model2", fInnerModel2);
fAnnotationModel.connect(fDocument);
}
Aggregations