funziona quasi bene il pick user
git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/share-updates@73363 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
110bb620a2
commit
e121cff500
|
@ -4,8 +4,9 @@ import java.util.ArrayList;
|
|||
import java.util.Date;
|
||||
|
||||
import org.gcube.portal.databook.shared.Like;
|
||||
import org.gcube.portlets.user.shareupdates.client.events.PickedUserEvent;
|
||||
import org.gcube.portlets.user.shareupdates.client.form.SingleUserTemplate;
|
||||
import org.glite.security.voms.admin.operations.groups.AddMemberOperation;
|
||||
import org.gcube.portlets.user.shareupdates.shared.PickingUser;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.dom.client.KeyCodes;
|
||||
|
@ -15,13 +16,11 @@ import com.google.gwt.event.dom.client.MouseOutEvent;
|
|||
import com.google.gwt.event.dom.client.MouseOutHandler;
|
||||
import com.google.gwt.event.dom.client.MouseOverEvent;
|
||||
import com.google.gwt.event.dom.client.MouseOverHandler;
|
||||
import com.google.gwt.event.shared.HandlerManager;
|
||||
import com.google.gwt.user.client.Event;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.ui.FocusPanel;
|
||||
import com.google.gwt.user.client.ui.KeyboardListener;
|
||||
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
|
||||
import com.google.gwt.user.client.ui.PopupPanel;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
import com.google.gwt.user.client.ui.SuggestOracle.Callback;
|
||||
import com.google.gwt.user.client.ui.SuggestOracle.Request;
|
||||
import com.google.gwt.user.client.ui.SuggestOracle.Response;
|
||||
|
@ -36,6 +35,9 @@ public class PickUsersDialog extends PopupPanel {
|
|||
public final static int DELETE = KeyCodes.KEY_DELETE;
|
||||
public final static int ENTER = KeyCodes.KEY_ENTER;
|
||||
public final static int ESCAPE = KeyCodes.KEY_ESCAPE;
|
||||
public final static int TAB = KeyCodes.KEY_TAB;
|
||||
|
||||
private HandlerManager eventBus;
|
||||
|
||||
private int limit = 10;
|
||||
|
||||
|
@ -50,8 +52,9 @@ public class PickUsersDialog extends PopupPanel {
|
|||
//needed because is selected when it popups
|
||||
private SingleUserTemplate first;
|
||||
|
||||
public PickUsersDialog() {
|
||||
public PickUsersDialog(HandlerManager eventBus) {
|
||||
super(true, false);
|
||||
this.eventBus = eventBus;
|
||||
focusPanel.setWidth("525px");
|
||||
mainPanel.setWidth("525px");
|
||||
setWidth("525px");
|
||||
|
@ -81,16 +84,7 @@ public class PickUsersDialog extends PopupPanel {
|
|||
public void onMouseOut(MouseOutEvent event) {
|
||||
select(displayIndexSelected);
|
||||
}
|
||||
});
|
||||
|
||||
focusPanel.addKeyDownHandler(new KeyDownHandler() {
|
||||
|
||||
@Override
|
||||
public void onKeyDown(KeyDownEvent event) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,18 +126,22 @@ public class PickUsersDialog extends PopupPanel {
|
|||
private void handleNonCharKeys(Event event) {
|
||||
switch (event.getKeyCode()) {
|
||||
case ARROW_UP:
|
||||
if (displayIndexSelected > 0) {
|
||||
if (displayIndexSelected > 0)
|
||||
select(--displayIndexSelected);
|
||||
}
|
||||
break;
|
||||
case ARROW_DOWN:
|
||||
if (displayIndexSelected < mainPanel.getWidgetCount()) {
|
||||
select(++displayIndexSelected);
|
||||
}
|
||||
case TAB:
|
||||
if (displayIndexSelected+1 < mainPanel.getWidgetCount())
|
||||
select(displayIndexSelected+1);
|
||||
break;
|
||||
case ESCAPE:
|
||||
case DELETE:
|
||||
hide();
|
||||
|
||||
case ENTER: //selectd with keyboard
|
||||
SingleUserTemplate ut = (SingleUserTemplate) mainPanel.getWidget(displayIndexSelected);
|
||||
eventBus.fireEvent(new PickedUserEvent(new PickingUser("id", "username", ut.getFullName(), "thumb")));
|
||||
hide();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -157,12 +155,12 @@ public class PickUsersDialog extends PopupPanel {
|
|||
int i = 0;
|
||||
for (Suggestion s : response.getSuggestions()) {
|
||||
if (i == 0) {
|
||||
first = getUserTemplate(new Like("", "", new Date(), "", s.getDisplayString(), ""), i);
|
||||
first = getUserTemplate(new PickingUser("", "", s.getDisplayString(), ""), i);
|
||||
first.addStyleName("pickperson-selected");
|
||||
mainPanel.add(first);
|
||||
}
|
||||
else
|
||||
mainPanel.add(getUserTemplate(new Like("", "", new Date(), "", s.getDisplayString(), ""), i));
|
||||
mainPanel.add(getUserTemplate(new PickingUser("", "", s.getDisplayString(), ""), i));
|
||||
i++;
|
||||
}
|
||||
if (i > 0)
|
||||
|
@ -172,8 +170,8 @@ public class PickUsersDialog extends PopupPanel {
|
|||
}
|
||||
}
|
||||
|
||||
private SingleUserTemplate getUserTemplate(Like like, int displayIndex) {
|
||||
return new SingleUserTemplate(this, new Like("", "", new Date(), "", like.getFullName(), ""), displayIndex);
|
||||
private SingleUserTemplate getUserTemplate(PickingUser user, int displayIndex) {
|
||||
return new SingleUserTemplate(this, user, displayIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -186,11 +184,10 @@ public class PickUsersDialog extends PopupPanel {
|
|||
if (i == displayIndex) {
|
||||
ut.addStyleName("pickperson-selected");
|
||||
displayIndexSelected = i;
|
||||
GWT.log("Selected: "+ut.getFullName());
|
||||
//GWT.log("Selected: "+ut.getFullName());
|
||||
}
|
||||
else
|
||||
ut.removeStyleName("pickperson-selected");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.gcube.portlets.user.shareupdates.client.elements;
|
||||
|
||||
import com.google.gwt.user.client.DOM;
|
||||
import com.google.gwt.user.client.Element;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.HasText;
|
||||
|
||||
|
@ -11,18 +12,42 @@ import com.google.gwt.user.client.ui.HasText;
|
|||
*/
|
||||
public class Div extends HTML implements HasText {
|
||||
|
||||
public Div() {
|
||||
super(DOM.createElement("div"));
|
||||
//important to make it act like a textarea
|
||||
DOM.setElementAttribute(getElement(), "contentEditable", "true");
|
||||
}
|
||||
public Div() {
|
||||
super(DOM.createElement("div"));
|
||||
//important to make it act like a textarea
|
||||
DOM.setElementAttribute(getElement(), "contentEditable", "true");
|
||||
DOM.setElementAttribute(getElement(), "id", "mycontentEditableElement");
|
||||
}
|
||||
|
||||
public Div(String text) {
|
||||
this();
|
||||
setText(text);
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
DOM.setElementPropertyBoolean(getElement(), "disabled", !enabled);
|
||||
}
|
||||
public Div(String text) {
|
||||
this();
|
||||
setText(text);
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
DOM.setElementPropertyBoolean(getElement(), "disabled", !enabled);
|
||||
}
|
||||
|
||||
|
||||
public static native void setEndOfContenteditable() /*-{
|
||||
var contentEditableElement = $doc.getElementById("mycontentEditableElement");
|
||||
//alert(contentEditableElement.innerHTML);
|
||||
var range,selection;
|
||||
if($doc.createRange)//Firefox, Chrome, Opera, Safari, IE 9+
|
||||
{
|
||||
range = $doc.createRange();//Create a range (a range is a like the selection but invisible)
|
||||
range.selectNodeContents(contentEditableElement);//Select the entire contents of the element with the range
|
||||
range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
|
||||
selection = $wnd.getSelection();//get the selection object (allows you to change selection)
|
||||
selection.removeAllRanges();//remove any selections already made
|
||||
selection.addRange(range);//make the range you have just created the visible selection
|
||||
}
|
||||
else if($doc.selection)//IE 8 and lower
|
||||
{
|
||||
range = $doc.body.createTextRange();//Create a range (a range is a like the selection but invisible)
|
||||
range.moveToElementText(contentEditableElement);//Select the entire contents of the element with the range
|
||||
range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
|
||||
range.select();//Select the range (make it the visible selection
|
||||
}
|
||||
}-*/;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package org.gcube.portlets.user.shareupdates.client.events;
|
||||
|
||||
import org.gcube.portlets.user.shareupdates.shared.PickingUser;
|
||||
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
|
||||
|
||||
public class PickedUserEvent extends GwtEvent<PickedUserEventHandler> {
|
||||
public static Type<PickedUserEventHandler> TYPE = new Type<PickedUserEventHandler>();
|
||||
|
||||
private PickingUser user;
|
||||
|
||||
|
||||
public PickingUser getSelectedUser() {
|
||||
return user;
|
||||
}
|
||||
public PickedUserEvent(PickingUser user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type<PickedUserEventHandler> getAssociatedType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatch(PickedUserEventHandler handler) {
|
||||
handler.onSelectedUser(this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package org.gcube.portlets.user.shareupdates.client.events;
|
||||
|
||||
import com.google.gwt.event.shared.EventHandler;
|
||||
|
||||
public interface PickedUserEventHandler extends EventHandler {
|
||||
void onSelectedUser(PickedUserEvent event);
|
||||
}
|
|
@ -5,9 +5,12 @@ package org.gcube.portlets.user.shareupdates.client.form;
|
|||
|
||||
import org.gcube.portlets.user.shareupdates.client.dialog.PickUsersDialog;
|
||||
import org.gcube.portlets.user.shareupdates.client.elements.Div;
|
||||
import org.gcube.portlets.user.shareupdates.client.events.PickedUserEvent;
|
||||
import org.gcube.portlets.user.shareupdates.client.events.PickedUserEventHandler;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.dom.client.KeyCodes;
|
||||
import com.google.gwt.event.shared.HandlerManager;
|
||||
import com.google.gwt.user.client.DOM;
|
||||
import com.google.gwt.user.client.Event;
|
||||
import com.google.gwt.user.client.Timer;
|
||||
|
@ -17,20 +20,36 @@ import com.google.gwt.user.client.Timer;
|
|||
*
|
||||
*/
|
||||
public class MyTextArea extends Div {
|
||||
private final HandlerManager eventBus = new HandlerManager(null);
|
||||
|
||||
public final static int ARROW_UP = 38;
|
||||
public final static int ARROW_DOWN = 40;
|
||||
PickUsersDialog pickUserDlg = new PickUsersDialog();
|
||||
PickUsersDialog pickUserDlg = new PickUsersDialog(eventBus);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public MyTextArea() {
|
||||
bind();
|
||||
sinkEvents(Event.ONPASTE);
|
||||
sinkEvents(Event.ONCONTEXTMENU);
|
||||
sinkEvents(Event.ONKEYUP);
|
||||
sinkEvents(Event.ONKEYDOWN);
|
||||
sinkEvents(Event.ONKEYPRESS);
|
||||
sinkEvents(Event.ONKEYPRESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* events binder
|
||||
*/
|
||||
private void bind() {
|
||||
eventBus.addHandler(PickedUserEvent.TYPE, new PickedUserEventHandler() {
|
||||
@Override
|
||||
public void onSelectedUser(PickedUserEvent event) {
|
||||
String[] toSplit = getText().split("@"); //get the interesting part
|
||||
setText(toSplit[0] + event.getSelectedUser().getFullName());
|
||||
setEndOfContenteditable();
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* paste event overridden
|
||||
*/
|
||||
|
@ -58,11 +77,10 @@ public class MyTextArea extends Div {
|
|||
pickUserDlg.onKeyUp(event, this.getAbsoluteLeft(), this.getAbsoluteTop()+65, getText());
|
||||
break;
|
||||
}
|
||||
case Event.ONKEYDOWN: {
|
||||
if (event.getKeyCode() == ARROW_UP) {
|
||||
case Event.ONKEYDOWN: { //avoid the arrow up to move the cursor at the beginning of the textbox and the TAB to move around inputs
|
||||
if (event.getKeyCode() == ARROW_UP || event.getKeyCode() == KeyCodes.KEY_TAB) {
|
||||
DOM.eventCancelBubble(event, true);
|
||||
DOM.eventPreventDefault(event);
|
||||
GWT.log("Cancelled");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.gcube.portlets.user.shareupdates.client.form;
|
||||
|
||||
import org.gcube.portal.databook.shared.Like;
|
||||
import org.gcube.portlets.user.shareupdates.client.dialog.PickUsersDialog;
|
||||
import org.gcube.portlets.user.shareupdates.shared.PickingUser;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.dom.client.MouseOverEvent;
|
||||
|
@ -31,15 +31,15 @@ public class SingleUserTemplate extends Composite {
|
|||
@UiField
|
||||
HTML contentArea;
|
||||
|
||||
public SingleUserTemplate(PickUsersDialog owner, Like like, int displayIndex) {
|
||||
public SingleUserTemplate(PickUsersDialog owner, PickingUser user, int displayIndex) {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
this.owner = owner;
|
||||
currDisplayIndex = displayIndex;
|
||||
if (like.getThumbnailURL() != null)
|
||||
avatarImage.setUrl(like.getThumbnailURL());
|
||||
if (user.getThumbnailURL() != null)
|
||||
avatarImage.setUrl(user.getThumbnailURL());
|
||||
|
||||
avatarImage.setPixelSize(30, 30);
|
||||
contentArea.setHTML(like.getFullName());
|
||||
contentArea.setHTML(user.getFullName());
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package org.gcube.portlets.user.shareupdates.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class PickingUser implements Serializable {
|
||||
private String id;
|
||||
private String username;
|
||||
private String fullName;
|
||||
private String thumbnailURL;
|
||||
|
||||
public PickingUser() {
|
||||
super();
|
||||
}
|
||||
public PickingUser(String id, String username, String fullName, String thumbnailURL) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
this.fullName = fullName;
|
||||
this.thumbnailURL = thumbnailURL;
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
public String getFullName() {
|
||||
return fullName;
|
||||
}
|
||||
public void setFullName(String fullName) {
|
||||
this.fullName = fullName;
|
||||
}
|
||||
|
||||
public String getThumbnailURL() {
|
||||
return thumbnailURL;
|
||||
}
|
||||
public void setThumbnailURL(String thumbnailURL) {
|
||||
this.thumbnailURL = thumbnailURL;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PickingUser [id=" + id + ", username=" + username
|
||||
+ ", fullName=" + fullName + ", thumbnailURL=" + thumbnailURL
|
||||
+ "]";
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue