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:
parent
78d1ad33f2
commit
ad3ed59d4f
|
@ -36,7 +36,7 @@ import com.google.gwt.user.client.ui.Widget;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class PickItemsDialog extends PopupPanel {
|
public class PickItemsDialog extends PopupPanel {
|
||||||
|
|
||||||
public final static int ARROW_UP = 38;
|
public final static int ARROW_UP = 38;
|
||||||
public final static int ARROW_DOWN = 40;
|
public final static int ARROW_DOWN = 40;
|
||||||
|
|
||||||
|
@ -108,15 +108,15 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
select(displayIndexSelected);
|
select(displayIndexSelected);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
focusPanel.addMouseDownHandler(new MouseDownHandler() {
|
focusPanel.addMouseDownHandler(new MouseDownHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onMouseDown(MouseDownEvent event) {
|
public void onMouseDown(MouseDownEvent event) {
|
||||||
handleMouseDown();
|
handleMouseDown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleMouseDown() {
|
private void handleMouseDown() {
|
||||||
SelectableItem ut = (SelectableItem) mainPanel.getWidget(displayIndexSelected);
|
SelectableItem ut = (SelectableItem) mainPanel.getWidget(displayIndexSelected);
|
||||||
eventBus.fireEvent(new PickedItemEvent(new ItemBean("id", "username", ut.getItemName(), "thumb"), this.triggerChar));
|
eventBus.fireEvent(new PickedItemEvent(new ItemBean("id", "username", ut.getItemName(), "thumb"), this.triggerChar));
|
||||||
|
@ -132,15 +132,19 @@ 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)) {
|
}
|
||||||
if (pickingUser(currText)) {
|
else {
|
||||||
handleNonCharKeys(keyCode);
|
String last3 = (currText.length() > 3) ? currText.substring(currText.length()-3): currText;
|
||||||
}
|
if (last3.contains(triggerChar)) {
|
||||||
} else if (!currText.contains(triggerChar))
|
if (pickingUser(currText)) {
|
||||||
hide();
|
handleNonCharKeys(keyCode);
|
||||||
|
}
|
||||||
|
} else if (!last3.contains(triggerChar))
|
||||||
|
hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,9 +152,12 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
* @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();
|
||||||
|
@ -214,7 +221,7 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemBean getUserModelBySuggestion(Suggestion suggestion) {
|
private ItemBean getUserModelBySuggestion(Suggestion suggestion) {
|
||||||
for (ItemBean user : users) {
|
for (ItemBean user : users) {
|
||||||
if (suggestion.getReplacementString().compareTo(user.getAlternativeName()) ==0)
|
if (suggestion.getReplacementString().compareTo(user.getAlternativeName()) ==0)
|
||||||
|
@ -225,7 +232,7 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
|
|
||||||
private Widget getUserTemplate(ItemBean user, int displayIndex, boolean hasPhoto) {
|
private Widget getUserTemplate(ItemBean user, int displayIndex, boolean hasPhoto) {
|
||||||
if (hasPhoto)
|
if (hasPhoto)
|
||||||
return new WithPhotoTemplate(this, user, displayIndex);
|
return new WithPhotoTemplate(this, user, displayIndex);
|
||||||
return new NoPhotoTemplate(this, user, displayIndex);
|
return new NoPhotoTemplate(this, user, displayIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue