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
This commit is contained in:
Massimiliano Assante 2016-06-30 12:47:00 +00:00
parent 332b8d0f5b
commit 3452cc8395
1 changed files with 32 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import org.gcube.portlets.widgets.pickitem.client.bundle.CssAndImages; 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.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.NoPhotoTemplate;
import org.gcube.portlets.widgets.pickitem.client.uibinder.SelectableItem; import org.gcube.portlets.widgets.pickitem.client.uibinder.SelectableItem;
import org.gcube.portlets.widgets.pickitem.client.uibinder.WithPhotoTemplate; import org.gcube.portlets.widgets.pickitem.client.uibinder.WithPhotoTemplate;
@ -67,7 +68,9 @@ public class PickItemsDialog extends PopupPanel {
private Widget first; private Widget first;
private boolean hasPhoto; private boolean hasPhoto;
private boolean includeTriggerChar; private boolean includeTriggerChar;
//to explain
private boolean stopListening = true;
static { static {
CssAndImages.INSTANCE.css().ensureInjected(); CssAndImages.INSTANCE.css().ensureInjected();
} }
@ -130,6 +133,14 @@ public class PickItemsDialog extends PopupPanel {
handleMouseDown(); 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 * 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) { public void onKeyPress(int cursorPos, int keyCode, int x, int y, String currText) {
char ch = (char) keyCode; char ch = (char) keyCode;
GWT.log("char = " +ch);
if (ch == triggerChar) { if (ch == triggerChar) {
setPopupPosition(x, y); setPopupPosition(x, y);
hide(); hide();
handleNonCharKeys = false; handleNonCharKeys = false;
stopListening = false;
this.itemCursorIndexStart = cursorPos; this.itemCursorIndexStart = cursorPos;
} }
else { else {
itemCursorIndexEnd = cursorPos; itemCursorIndexEnd = cursorPos;
currText = currText.substring(itemCursorIndexStart, cursorPos)+ch; 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))) { if (pickingUser(currText.substring(1))) {
handleNonCharKeys = true; handleNonCharKeys = true;
} }
} else if (!currText.contains(""+triggerChar)) { } else if (!currText.contains(""+triggerChar) || stopListening) {
hide(); hide();
handleNonCharKeys = false; handleNonCharKeys = false;
GWT.log("stopListening =" +stopListening);
} }
} }
} }
@ -187,8 +200,13 @@ public class PickItemsDialog extends PopupPanel {
* @param keyCode the event keycode * @param keyCode the event keycode
*/ */
public void onKeyUp(int keyCode) { public void onKeyUp(int keyCode) {
if (handleNonCharKeys) if (handleNonCharKeys) {
handleNonCharKeys(keyCode); handleNonCharKeys(keyCode);
}
if (keyCode == ENTER) {
stopListening = true;
handleNonCharKeys = false;
}
} }
/** /**
@ -226,6 +244,7 @@ public class PickItemsDialog extends PopupPanel {
hide(); hide();
break; break;
case ENTER: //selectd with keyboard case ENTER: //selectd with keyboard
GWT.log("Enter selcted");
SelectableItem ut = null; SelectableItem ut = null;
if (mainPanel.getWidgetCount() > 0) { 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 :) 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(); hide();
select(0); //RESET select(0); //RESET
} }
else {
GWT.log("mainPanel.getWidgetCount() non ci entra");
hide();
select(0); //RESET
}
break; break;
default: default:
break; break;
@ -266,7 +290,7 @@ public class PickItemsDialog extends PopupPanel {
}); });
} }
} }
private ItemBean getUserModelBySuggestion(Suggestion suggestion) { private ItemBean getUserModelBySuggestion(Suggestion suggestion) {
for (ItemBean bean : beans) { for (ItemBean bean : beans) {
if (suggestion.getReplacementString().compareTo(bean.getAlternativeName()) ==0) if (suggestion.getReplacementString().compareTo(bean.getAlternativeName()) ==0)