eclipsercpe4styledtext

Java StyledText control with IDocument support


My intention is to code a NASTRAN text editor (plain text editor, eclipse pure E4 RCP application). NASTRAN is an engineering structural analysis application. Simplifying, NASTRAN uses text cards of 8-characters-width per field and up to 10 fields per card (line). See figure with the work done so far

NASTRAN EDITOR screen capture

The main feature of this Editor is to show plain text (fixed pitch font) with colored columns background, so it can be easy to distinguish different fields in each row.

I have used a StyledText control which provides methods to change background:

styledText.setBackgroundImage(backgroundImage);

How can I use IDocument interface with StyledText so It can provide me support for: text manipulation positions partitions line information etc...

Other text controls (TextViewer, SourceViewer) provide setDocument(IDocument) method to load and manipulate text data

--org.eclipse.jface.text.TextViewer

  |
--org.eclipse.jface.text.source.SourceViewer

But StyledText extends SWT Canvas and does not provide methods to set the imput documents

   --org.eclipse.swt.custom.StyledText

Alternative approach could be how can I change background in a SourceViewer control so I can have columns of different colors.

Thanks in advance


Solution

  • Thanks greg-449 for your answer, problem solved. I had not a clear understanding of the concept of a class wrapping another class. So I tried first to create a StyledText object. Now it is clear

    I have attached below how I proceeded: creating a SourceViewer control and then, obtaining the StyledText wrapped. So I could set the background image for the control

    public class NastranEditor {
        public StyledText st = null;
        public SourceViewer sv = null;
        private Image backgroundImage;//The image to appear at the backgroud
        //....
        @PostConstruct
        public void postConstruct(Composite parent){
            IVerticalRuler  ruler = new VerticalRuler(20);
            sv = new SourceViewer(parent, ruler, SWT.MULTI | SWT.V_SCROLL);
            st = sv.getTextWidget();
            st.setBackgroundImage(backgroundImage);
            //....
        }
        //....
    }