On Friday, September 9, 2016 at 9:31:27 AM UTC+2, Eddy wrote:
>
> Thank you for your first help Thomas !
>
> What I had tried is to write a get method from the view/display interface, 
> which return the suggestBox object and which I had called from the 
> presenter on the onBind or revealDisplay :
> => I could redefine as the same the requestSuggestions() into the 
> presenter but then I didn't know how to transmit it to the view / how to 
> instanciate the visible SuggestBox object for showing it into the view 
> (regarding the new SuggestBox(oracle) line).
>

Something like:
in the presenter:
    public void getSuggestions(SuggestOracle.Request req, 
SuggestOracle.Callback callback) {
      service.getSuggestions(req, callback);
    }

in the view:
    SuggestOracleCustom oracle = new SuggestOracleCustom() { 
        @Override
        public void requestSuggestions(SuggestOracle.Request req, 
SuggestOracle.Callback callback) {
            presenter.getSuggestions(req, new 
SuggestOracleCallbackCustom(req, callback));
        }
    };
    SuggestBox suggestBox = new SuggestBox(oracle);
    this.add(suggestBox);

(put the SuggestOracleCallbackCustom where it needs to go, either presenter 
or view, depends on what it does)
 

> Excuses-me but I am not familiar enough by making my own proxy / 
> "delegating" etc. Can you give me some sample please ?
>

Something like:
    private SuggestOracle realOracle; // set by the presenter
    …
    SuggestBox suggestBox = new SuggestBox(new SuggestOracle() {
        @Override
        public boolean isDisplayStringHTML() {
            return realOracle.isDisplayStringHTML();
        }
        @Override
        public void requestDefaultSuggestions(SuggestOracle.Request 
request, SuggestOracle.Callback callback) {
            realOracle.requestDefaultSuggestions(request, callback);
        }
        @Override
        public void requestSuggestions(SuggestOracle.Request req, 
SuggestOracle.Callback callback) {
            realOracle.requestSuggestions(req, callback);
        }
    });
    this.add(suggestBox);

That way, the realOracle can be replaced at any time, without the need to 
re-build the SuggestBox.
The anonymous SuggestOracle passed to the SuggestBox acts as a proxy 
(façade) to the 'realOracle' (which is then the proxy's "delegate").
If you need that pattern many times in your application, then create a 
DelegatingSuggestOracle similar to the anonymous one but with the 
realOracle as a field of the DelegatingSuggestOracle, with getter and 
setter. Your view would then read:

    private final SuggestOracle oracle = new DelegatingSuggestOracle();
    …
    SuggestBox suggestBox = new SuggestBox(oracle);
    this.add(suggestBox);
    …
    public void setSuggestOracle(SuggestOracle oracle) { // called by the 
presenter
      this.oracle.setDelegate(oracle);
    }

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Reply via email to