Re: Problem with SuggextBox as table cell

136 views
Skip to first unread message

jorge vasquez

unread,
Dec 18, 2012, 11:11:05 AM12/18/12
to google-we...@googlegroups.com
Hi Ande , sorry i forgot put this method but i can explain you, the method implementarEstilos(suggestBox); set a styleName to the object suggestBox  ,
and the popupStyleName is a constant  with the name that you put to suggestBox popup (because is the unique way how we can found the popup hidden in the code generated), you must evaluate that the last child popupStyleName is called equal to the popup that you showed and then delete when close the popup
this is the method 
// popupStyleName is necesary for show and delete popup
 private void implementarEstilos(final SuggestBox suggestBox) {
    if (!styleName.isEmpty()) {
      suggestBox.setStyleName(styleName);
    }
    if (!popupStyleName.isEmpty()) {
      suggestBox.setPopupStyleName(popupStyleName);
    }
  }

if you have another question, ask me.

I hope I can clear your doubts.

Jorge Vasquez.

El miércoles, 12 de diciembre de 2012 10:40:27 UTC-5, Ande escribió:
Hi Jorge Vasquez,

I tried to follow your solution, but I can not figure out what this method does:

      implementarEstilos(suggestBox);
 
Also I have no idea where you retrieve the popupStyleName in this line:

    if(popupStyleName.equals(classNameLastChild)) {


greetings
Ande
 

Timothy Gonzalez

unread,
Sep 27, 2013, 6:26:43 PM9/27/13
to Google-We...@googlegroups.com
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);
}
});


Reply all
Reply to author
Forward
0 new messages