I had create a simple keywords highlighting editor, it just wrap a StyledText widget:
public class SQLSegmentEditor extends Composite {
private StyledText st;
public SQLSegmentEditor(Composite parent) {
super(parent, SWT.NONE);
this.setLayout(new FillLayout());
st = new StyledText(this, SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
st.addLineStyleListener(new SQLSegmentLineStyleListener());
}
}
How can I make it can be used in data-binding? I am looking for the proper way, not just one that makes it work.
I want to observer the text content of the inner StyledText.
For example : I can just add a getStyledText method to return the wrapped StyledText widget for using it in databinding. But this will take a risk. In order to keep my editor behavior correctly, I should keep the StyledText widget not visible to client code.
Although I don’t understand your argument of not exposing the wrapped widget to the client, here is a possible solution. The widget can provide a
WritableValuethat can be bound directly via databinding by the client. That means the binding goes over 3 parties: the clients target, the wrapping writable-value and the SWT source. The only drawback is that you have a direct dependency to Databinding in your widget. Here is a snippet.So the client code would look like: