jorge vasquez <jorgevasquezang@...> writes:

> 
> 
> Hi Christian Pelster ,I watched your code , because I need implement some 
similar and I could solved your problem , you should modify the method 
updateViewData
>  some like this:
> 
>  private String updateViewData(final Context context, final Element 
parent, final ViewData viewData,
>           final boolean isEditing, final NativeEvent event) {
>     deleteLastPopup ();
>     //final InputElement input = (InputElement) parent.getFirstChild();
>     final InputElement input = getInputElement(parent);
>     final String value = input.getValue();
>     viewData.setText(value);
>     viewData.setEditing(isEditing);
>     
>     SuggestBox suggestBox = suggestBoxes.get(getKeyFromKontext(context));
>     //suggestBox.removeFromParent();
>     if (suggestBox != null) {
>       suggestBox.setText(value);
>       
>       textBox = new MyTextBox(input);
>       suggestBox = new SuggestBox(suggestBox.getSuggestOracle(), textBox);
>       
>       implementarEstilos(suggestBox);
>       DomEvent.fireNativeEvent(event, textBox);
>       
>       
>     }
>     suggestBox.setFocus(true);
>     return value;
>   }
> you should call a new  textBox = new MyTextBox(input); because with this 
he can found the coordenates where will show the results, also you should 
add a method deleteLastPopup which delete the last popup of results showed.
> this is the method :
> 
> 
> private void deleteLastPopup () {
>     Element popupEmpresaServicio =
(Element)Document.get().getBody().getLastChild();
>     String classNameLastChild=popupEmpresaServicio.getClassName();
>     if(popupStyleName.equals(classNameLastChild)) {
>       
Document.get().getBody().removeChild(Document.get().getBody().getLastChild()
);
>     }
>   }
> 
> always the popup is created in the last part of the code generated there 
we can found (in my case i can found for the classname) and delete , then 
the new result will be show
> 
> I found other thing which need solve , for show the suggestbox better , if 
you found others fix or solutions for solve you can put here for improve the 
code :D
> regards,
> 
> Jorge Vasquez
> 
> 
> 

Hello, I know this is an old post, but it helped me and I was able to 
improve so I thought I'd share my findings.

Jorge you're fix for the placement does work, but it opens up a new issue 
with the multiple popups. That issue I wasn't able to solve, because the 
SuggestBox is trying to do this cleanup itself and we're fighting each 
other, so I had to backtrack a bit and find a new fix for the placement 
issue.

Creating a new suggest box is what's causing the multiple popups to appear. 
Just by taking this part out, it fixes the multiple popups.

Now is the issue of placement.

To handle this I simply created a new suggest box each time the edit method 
is called, regardless if one exists in the map.

This way the suggest box always has a TextBox so it can place it's menus 
correctly, and we never create more than one SuggestBox so we never get 
duplicate menu's.


My edit method looks like below.

        protected void edit(Context context, Element parent, String value) {
                setValue(context, parent, value);
                InputElement input = getInputElement(parent);

                input.focus();
                input.select();
                
                // Always create a new SuggestBox so it opens at the correct 
place.
                // Never create more than one SuggestBox, otherwise you will 
end up with multiple pop up menus.
                TextBox textBox = new MyTextBox(input);
                parent.replaceChild(input, 
textBox.getElement()).getOwnerDocument();
                SuggestBox suggestBox = getNewSuggestBox(context, 
getSuggestOracle(), textBox);
                suggestBoxes.put(getKeyFromContext(context), suggestBox);
                
        }


In addition one big thing I had to do was handling the commits.

There is a bit of a conflict here, because a commit will be performed when 
selecting a suggestion (blur). So to handle this part I save the commit 
data, let the cell commit as normal in onBrowserEvent, then on the 
SuggestBox select event I call the commit again with the saved data and the 
selected value. Below is my SuggestBox handler which performs this.

                suggestBox.addSelectionHandler(new 
SelectionHandler<Suggestion>() {
                        @Override
                        public void onSelection(SelectionEvent<Suggestion> 
event) {
                                
                                CommitParameters cp = 
SuggestCell.this.commitParameters.get(getKeyFromContext(context));
                                
                                // A commit is always performed on blur,
                                // the selected text was inserted, but then 
lost by the blur commit (this is needed in case a selection isn't made).
                                // Re-insert it so the commit can be 
performed using the selection text.
                                InputElement input = 
getInputElement(cp.parent);
                                
input.setValue(event.getSelectedItem().getReplacementString());
                                
                                SuggestCell.this.commit(cp.context, 
cp.parent, cp.viewData, cp.valueUpdater, cp.event);
                        }
                });


-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" 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 http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to