From 3452cc839538cfa64a3ad84a23ac5051b0b7b4fa Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Thu, 30 Jun 2016 12:47:00 +0000 Subject: [PATCH] fixed bug for hashtag not giving chance to use enter git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/pickitem-widget@129677 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/dialog/PickItemsDialog.java | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/pickitem/client/dialog/PickItemsDialog.java b/src/main/java/org/gcube/portlets/widgets/pickitem/client/dialog/PickItemsDialog.java index e6970a2..9d52d81 100644 --- a/src/main/java/org/gcube/portlets/widgets/pickitem/client/dialog/PickItemsDialog.java +++ b/src/main/java/org/gcube/portlets/widgets/pickitem/client/dialog/PickItemsDialog.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import org.gcube.portlets.widgets.pickitem.client.bundle.CssAndImages; import org.gcube.portlets.widgets.pickitem.client.events.PickedItemEvent; +import org.gcube.portlets.widgets.pickitem.client.events.PickedItemEventHandler; import org.gcube.portlets.widgets.pickitem.client.uibinder.NoPhotoTemplate; import org.gcube.portlets.widgets.pickitem.client.uibinder.SelectableItem; import org.gcube.portlets.widgets.pickitem.client.uibinder.WithPhotoTemplate; @@ -67,7 +68,9 @@ public class PickItemsDialog extends PopupPanel { private Widget first; private boolean hasPhoto; private boolean includeTriggerChar; - + //to explain + private boolean stopListening = true; + static { CssAndImages.INSTANCE.css().ensureInjected(); } @@ -130,6 +133,14 @@ public class PickItemsDialog extends PopupPanel { handleMouseDown(); } }); + + eventBus.addHandler(PickedItemEvent.TYPE, new PickedItemEventHandler() { + @Override + public void onSelectedItem(PickedItemEvent event) { + GWT.log("GOT @ CAZZEVENT! "+ event.getSelectedItem().getAlternativeName()); + stopListening = true; + } + }); } /** * use if you have want to show a photo for the item or not, remember to provide it in {@link ItemBean} instances @@ -160,25 +171,27 @@ public class PickItemsDialog extends PopupPanel { */ public void onKeyPress(int cursorPos, int keyCode, int x, int y, String currText) { char ch = (char) keyCode; - GWT.log("char = " +ch); if (ch == triggerChar) { setPopupPosition(x, y); hide(); handleNonCharKeys = false; + stopListening = false; this.itemCursorIndexStart = cursorPos; } else { + itemCursorIndexEnd = cursorPos; currText = currText.substring(itemCursorIndexStart, cursorPos)+ch; - if (currText.contains(""+triggerChar) && currText.length() > 1) { + + if (currText.contains(""+triggerChar) && currText.length() > 1 && !stopListening) { if (pickingUser(currText.substring(1))) { handleNonCharKeys = true; - } - } else if (!currText.contains(""+triggerChar)) { + } + } else if (!currText.contains(""+triggerChar) || stopListening) { hide(); handleNonCharKeys = false; + GWT.log("stopListening =" +stopListening); } - } } @@ -187,8 +200,13 @@ public class PickItemsDialog extends PopupPanel { * @param keyCode the event keycode */ public void onKeyUp(int keyCode) { - if (handleNonCharKeys) + if (handleNonCharKeys) { handleNonCharKeys(keyCode); + } + if (keyCode == ENTER) { + stopListening = true; + handleNonCharKeys = false; + } } /** @@ -226,6 +244,7 @@ public class PickItemsDialog extends PopupPanel { hide(); break; case ENTER: //selectd with keyboard + GWT.log("Enter selcted"); SelectableItem ut = null; if (mainPanel.getWidgetCount() > 0) { if (displayIndexSelected < 0 || displayIndexSelected >= mainPanel.getWidgetCount()) //when there's only one left sometimes here i get -sth, no time to see why :) @@ -236,6 +255,11 @@ public class PickItemsDialog extends PopupPanel { hide(); select(0); //RESET } + else { + GWT.log("mainPanel.getWidgetCount() non ci entra"); + hide(); + select(0); //RESET + } break; default: break; @@ -266,7 +290,7 @@ public class PickItemsDialog extends PopupPanel { }); } } - + private ItemBean getUserModelBySuggestion(Suggestion suggestion) { for (ItemBean bean : beans) { if (suggestion.getReplacementString().compareTo(bean.getAlternativeName()) ==0)