revised the way to capture the trigger char

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/pickitem-widget@100398 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2014-10-02 17:44:49 +00:00
parent 78d1ad33f2
commit ad3ed59d4f
1 changed files with 23 additions and 16 deletions

View File

@ -132,25 +132,32 @@ public class PickItemsDialog extends PopupPanel {
* @param currText * @param currText
*/ */
public void onKeyUp(int keyCode, int x, int y, String currText) { public void onKeyUp(int keyCode, int x, int y, String currText) {
if (currText.endsWith(triggerChar)) { //the only way i found to intercept @ if (currText.endsWith(triggerChar)) { //the only way i found to intercept the triggerChar
setPopupPosition(x, y); setPopupPosition(x, y);
hide(); hide();
} else if (currText.contains(triggerChar)) { }
else {
String last3 = (currText.length() > 3) ? currText.substring(currText.length()-3): currText;
if (last3.contains(triggerChar)) {
if (pickingUser(currText)) { if (pickingUser(currText)) {
handleNonCharKeys(keyCode); handleNonCharKeys(keyCode);
} }
} else if (!currText.contains(triggerChar)) } else if (!last3.contains(triggerChar))
hide(); hide();
} }
}
/** /**
* split the text and keeps listening for user keyboard events * split the text and keeps listening for user keyboard events
* @param currText the text being typed * @param currText the text being typed
*/ */
private boolean pickingUser(String currText) { private boolean pickingUser(String currText) {
String[] toSplit = currText.split(triggerChar); //get the interesting part int tPos = currText.lastIndexOf(triggerChar);
if (toSplit[1].trim().length() > 0) { String toSplit = currText.substring(tPos);
showSuggestions(toSplit[1]); String[] splitted = toSplit.split(triggerChar); //get the interesting part
if (splitted[1].trim().length() > 0) {
showSuggestions(splitted[1]);
return true; return true;
} }
hide(); hide();