OTOH, all those setters are called in the
LdifEditorWidget.createWidget() method, when we call
sourceViewer.configure( sourceViewerConfiguration );
That makes me wonder why we don't create all the elements in the
constructor. Any good reason ?
Le 12/03/15 19:23, Emmanuel Lécharny a écrit :
> Ok, another question.
>
> What's the best style : defining the elements like Reconciler,
> contentAssistent, etc, in the constructor, or instanciate them when they
> are requested like what is done in the flollowing code.
>
> public ITextDoubleClickStrategy getDoubleClickStrategy(
> ISourceViewer sourceViewer, String contentType )
> {
> if ( this.doubleClickStrategy == null )
> {
> this.doubleClickStrategy = new LdifDoubleClickStrategy();
> }
>
> return this.doubleClickStrategy;
> }
>
>
> vs
>
> public LdifSourceViewerConfiguration( ILdifEditor editor, boolean
> contentAssistEnabled )
> {
> super();
>
> this.editor = editor;
> this.contentAssistEnabled = contentAssistEnabled;
>
> // Instanciate the DoubleClickingStartegy
> doubleClickStrategy = new LdifDoubleClickStrategy();
> ...
> }
>
>
> public ITextDoubleClickStrategy getDoubleClickStrategy(
> ISourceViewer sourceViewer, String contentType )
> {
> return this.doubleClickStrategy;
> }
>
> My understanding is that the first style will only instanciate the
> elements when there are absolutely necessary (ie, only when they are
> used) vs a style where we create everything at startup, and return the
> element in the getter.
>
> My guts say that I prefer the second style, but my guts also tell me
> that there is a good reason why it's not done this way (like : why
> creating some resource which will never be used ?)
>
> Thanks !