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:
parent
332b8d0f5b
commit
3452cc8395
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue