Fix for Bug #320, Users tagging does not work if @ is in the middle of already typed text
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/pickitem-widget@117242 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
1718317ebb
commit
907f72de81
|
@ -1,6 +1,13 @@
|
||||||
<ReleaseNotes>
|
<ReleaseNotes>
|
||||||
<Changeset component="org.gcube.portlets.widgets.pickitem.0-4-0"
|
|
||||||
|
<Changeset component="portlets-widgets.pickitem-widget.1-1-0"
|
||||||
|
date="2015-07-14">
|
||||||
|
<Change>Ported to GWT 2.7.0</Change>
|
||||||
|
<Change>Fix for Bug #320, Users tagging does not work if @ is in the
|
||||||
|
middle of already typed text</Change>
|
||||||
|
</Changeset>
|
||||||
|
<Changeset component="portlets-widgets.pickitem-widget.1-0-0"
|
||||||
date="2013-10-21">
|
date="2013-10-21">
|
||||||
<Change>Refactored and ported to GWT 2.5.1</Change>
|
<Change>First Release</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
</ReleaseNotes>
|
</ReleaseNotes>
|
||||||
|
|
7
pom.xml
7
pom.xml
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
<groupId>org.gcube.portlets.widgets</groupId>
|
<groupId>org.gcube.portlets.widgets</groupId>
|
||||||
<artifactId>pickitem-widget</artifactId>
|
<artifactId>pickitem-widget</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>gCube Pick Item Widget</name>
|
<name>gCube Pick Item Widget</name>
|
||||||
<description>
|
<description>
|
||||||
|
@ -24,9 +24,8 @@
|
||||||
</scm>
|
</scm>
|
||||||
<properties>
|
<properties>
|
||||||
<!-- Convenience property to set the GWT version -->
|
<!-- Convenience property to set the GWT version -->
|
||||||
<gwtVersion>2.5.1</gwtVersion>
|
<gwtVersion>2.7.0</gwtVersion>
|
||||||
<distroDirectory>distro</distroDirectory>
|
<distroDirectory>distro</distroDirectory>
|
||||||
<!-- GWT needs at least java 1.6 -->
|
|
||||||
<maven.compiler.source>1.7</maven.compiler.source>
|
<maven.compiler.source>1.7</maven.compiler.source>
|
||||||
<maven.compiler.target>1.7</maven.compiler.target>
|
<maven.compiler.target>1.7</maven.compiler.target>
|
||||||
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
|
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
|
||||||
|
@ -50,7 +49,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.gwt</groupId>
|
<groupId>com.google.gwt</groupId>
|
||||||
<artifactId>gwt-user</artifactId>
|
<artifactId>gwt-user</artifactId>
|
||||||
<!-- "provided" so that we don't deploy -->
|
<version>${gwtVersion}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class PickItem implements EntryPoint {
|
||||||
tb.addKeyUpHandler(new KeyUpHandler() {
|
tb.addKeyUpHandler(new KeyUpHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onKeyUp(KeyUpEvent event) {
|
public void onKeyUp(KeyUpEvent event) {
|
||||||
pickUserDlg.onKeyUp(event.getNativeKeyCode(), tb.getAbsoluteLeft(), popUpY, tb.getText());
|
pickUserDlg.onKeyPress(-1, event.getNativeKeyCode(), tb.getAbsoluteLeft(), popUpY, tb.getText());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ 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;
|
||||||
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
|
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
|
||||||
|
|
||||||
|
import com.google.gwt.core.shared.GWT;
|
||||||
import com.google.gwt.event.dom.client.KeyCodes;
|
import com.google.gwt.event.dom.client.KeyCodes;
|
||||||
import com.google.gwt.event.dom.client.MouseDownEvent;
|
import com.google.gwt.event.dom.client.MouseDownEvent;
|
||||||
import com.google.gwt.event.dom.client.MouseDownHandler;
|
import com.google.gwt.event.dom.client.MouseDownHandler;
|
||||||
|
@ -17,6 +18,7 @@ import com.google.gwt.event.dom.client.MouseOutHandler;
|
||||||
import com.google.gwt.event.dom.client.MouseOverEvent;
|
import com.google.gwt.event.dom.client.MouseOverEvent;
|
||||||
import com.google.gwt.event.dom.client.MouseOverHandler;
|
import com.google.gwt.event.dom.client.MouseOverHandler;
|
||||||
import com.google.gwt.event.shared.HandlerManager;
|
import com.google.gwt.event.shared.HandlerManager;
|
||||||
|
import com.google.gwt.user.client.Window;
|
||||||
import com.google.gwt.user.client.ui.FocusPanel;
|
import com.google.gwt.user.client.ui.FocusPanel;
|
||||||
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
|
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
|
||||||
import com.google.gwt.user.client.ui.PopupPanel;
|
import com.google.gwt.user.client.ui.PopupPanel;
|
||||||
|
@ -54,7 +56,7 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
|
|
||||||
private FocusPanel focusPanel = new FocusPanel();
|
private FocusPanel focusPanel = new FocusPanel();
|
||||||
private VerticalPanel mainPanel = new VerticalPanel();
|
private VerticalPanel mainPanel = new VerticalPanel();
|
||||||
private String triggerChar;
|
private char triggerChar;
|
||||||
private ArrayList<ItemBean> users;
|
private ArrayList<ItemBean> users;
|
||||||
|
|
||||||
//needed because is selected when it popups
|
//needed because is selected when it popups
|
||||||
|
@ -65,7 +67,7 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
static {
|
static {
|
||||||
CssAndImages.INSTANCE.css().ensureInjected();
|
CssAndImages.INSTANCE.css().ensureInjected();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param triggerChar the 'single char' used to trigger the items list show, e.g. '@', '#' ....
|
* @param triggerChar the 'single char' used to trigger the items list show, e.g. '@', '#' ....
|
||||||
* @param the list of user to pick
|
* @param the list of user to pick
|
||||||
|
@ -80,7 +82,7 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
throw new IllegalArgumentException("width must be greater than 199");
|
throw new IllegalArgumentException("width must be greater than 199");
|
||||||
}
|
}
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
this.triggerChar = ""+triggerChar;
|
this.triggerChar = triggerChar;
|
||||||
this.includeTriggerChar = false;
|
this.includeTriggerChar = false;
|
||||||
this.hasPhoto = false;
|
this.hasPhoto = false;
|
||||||
this.users = users;
|
this.users = users;
|
||||||
|
@ -132,51 +134,68 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
public void withTriggerCharIncluded() {
|
public void withTriggerCharIncluded() {
|
||||||
includeTriggerChar = true;
|
includeTriggerChar = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
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, itemCursorIndexStart, itemCursorIndexEnd));
|
||||||
hide();
|
hide();
|
||||||
select(0); //RESET
|
select(0); //RESET
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private int itemCursorIndexEnd;
|
||||||
|
|
||||||
|
private int itemCursorIndexStart = -1;
|
||||||
|
boolean handleNonCharKeys = false;
|
||||||
/**
|
/**
|
||||||
* called for each keyUp event from the user
|
* called for each onKeyPress event from the user
|
||||||
* @param keyCode the event keycode
|
* @param keyCode the event keycode
|
||||||
* @param x
|
* @param x
|
||||||
* @param y
|
* @param y
|
||||||
* @param currText
|
* @param currText
|
||||||
*/
|
*/
|
||||||
public void onKeyUp(int keyCode, int x, int y, String currText) {
|
public void onKeyPress(int cursorPos, int keyCode, int x, int y, String currText) {
|
||||||
if (currText.endsWith(triggerChar)) { //the only way i found to intercept the triggerChar
|
char ch = (char) keyCode;
|
||||||
|
if (ch == triggerChar) {
|
||||||
setPopupPosition(x, y);
|
setPopupPosition(x, y);
|
||||||
hide();
|
hide();
|
||||||
}
|
handleNonCharKeys = false;
|
||||||
|
this.itemCursorIndexStart = cursorPos;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
String last5 = (currText.length() > 5) ? currText.substring(currText.length()-5): currText;
|
itemCursorIndexEnd = cursorPos;
|
||||||
if (last5.contains(triggerChar)) {
|
currText = currText.substring(itemCursorIndexStart, cursorPos)+ch;
|
||||||
if (pickingUser(currText)) {
|
if (currText.contains(""+triggerChar) && currText.length() > 1) {
|
||||||
handleNonCharKeys(keyCode);
|
if (pickingUser(currText.substring(1))) {
|
||||||
|
handleNonCharKeys = true;
|
||||||
}
|
}
|
||||||
} else if (!last5.contains(triggerChar))
|
} else if (!currText.contains(""+triggerChar)) {
|
||||||
hide();
|
hide();
|
||||||
|
handleNonCharKeys = false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* called for each onKeyUp event from the user
|
||||||
|
* @param keyCode the event keycode
|
||||||
|
*/
|
||||||
|
public void onKeyUp(int keyCode) {
|
||||||
|
if (handleNonCharKeys)
|
||||||
|
handleNonCharKeys(keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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) {
|
||||||
int tPos = currText.lastIndexOf(triggerChar);
|
if (currText.trim().length() > 0) {
|
||||||
String toSplit = currText.substring(tPos);
|
|
||||||
String[] splitted = toSplit.split(triggerChar); //get the interesting part
|
|
||||||
|
|
||||||
if (splitted[1].trim().length() > 0) {
|
|
||||||
if (includeTriggerChar)
|
if (includeTriggerChar)
|
||||||
showSuggestions(triggerChar+splitted[1]);
|
showSuggestions(triggerChar+currText);
|
||||||
else
|
else
|
||||||
showSuggestions(splitted[1]);
|
showSuggestions(currText);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
hide();
|
hide();
|
||||||
|
@ -207,7 +226,7 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
ut = (SelectableItem) mainPanel.getWidget(0);
|
ut = (SelectableItem) mainPanel.getWidget(0);
|
||||||
else
|
else
|
||||||
ut = (SelectableItem) mainPanel.getWidget(displayIndexSelected);
|
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, itemCursorIndexStart, itemCursorIndexEnd));
|
||||||
hide();
|
hide();
|
||||||
select(0); //RESET
|
select(0); //RESET
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,16 @@ public class PickedItemEvent extends GwtEvent<PickedItemEventHandler> {
|
||||||
public static Type<PickedItemEventHandler> TYPE = new Type<PickedItemEventHandler>();
|
public static Type<PickedItemEventHandler> TYPE = new Type<PickedItemEventHandler>();
|
||||||
|
|
||||||
private ItemBean item;
|
private ItemBean item;
|
||||||
private String triggerChar;
|
private char triggerChar;
|
||||||
|
private int itemCursorIndexStart;
|
||||||
public PickedItemEvent(ItemBean item, String triggerChar) {
|
private int itemCursorIndexEnd;
|
||||||
|
|
||||||
|
public PickedItemEvent(ItemBean item, char triggerChar, int itemCursorIndexStart, int itemCursorIndexEnd) {
|
||||||
|
super();
|
||||||
this.item = item;
|
this.item = item;
|
||||||
this.triggerChar = triggerChar;
|
this.triggerChar = triggerChar;
|
||||||
|
this.itemCursorIndexStart = itemCursorIndexStart;
|
||||||
|
this.itemCursorIndexEnd = itemCursorIndexEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,12 +31,20 @@ public class PickedItemEvent extends GwtEvent<PickedItemEventHandler> {
|
||||||
protected void dispatch(PickedItemEventHandler handler) {
|
protected void dispatch(PickedItemEventHandler handler) {
|
||||||
handler.onSelectedItem(this);
|
handler.onSelectedItem(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getItemCursorIndexStart() {
|
||||||
|
return itemCursorIndexStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getItemCursorIndexEnd() {
|
||||||
|
return itemCursorIndexEnd;
|
||||||
|
}
|
||||||
|
|
||||||
public ItemBean getSelectedItem() {
|
public ItemBean getSelectedItem() {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTriggerChar() {
|
public char getTriggerChar() {
|
||||||
return triggerChar;
|
return triggerChar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue