SourceViewer doCreateViewer(Composite parent, SourceViewerConfiguration viewerConfiguration) { SourceViewer viewer = null; String contentTypeID = ContentTypeIdForXML.ContentTypeID_XML; viewer = new StructuredTextViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); ((StructuredTextViewer) viewer).getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$ IStructuredModel scratchModel = StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(contentTypeID); IDocument document = scratchModel.getStructuredDocument(); viewer.configure(viewerConfiguration); viewer.setDocument(document); return viewer; }
/** * Creates, configures and returns a source viewer to present the template * pattern on the preference page. Clients may override to provide a * custom source viewer featuring e.g. syntax coloring. * * @param parent * the parent control * @return a configured source viewer */ private SourceViewer createViewer(Composite parent) { SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() { StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationXML(); public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { return baseConfiguration.getConfiguredContentTypes(sourceViewer); } public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) { return baseConfiguration.getLineStyleProviders(sourceViewer, partitionType); } }; SourceViewer viewer = new StructuredTextViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); ((StructuredTextViewer) viewer).getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$ IStructuredModel scratchModel = StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML); IDocument document = scratchModel.getStructuredDocument(); viewer.configure(sourceViewerConfiguration); viewer.setDocument(document); return viewer; }