I got it running. There were a couple issues. First the element wasn't attached when adding the listeners. Second the input id was wrong.
First add the listeners after it's attached to the DOM, then instead of using the id, you can use the element to attache the handlers.
This worked for me.
Code:
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.InputElement;
import com.google.gwt.event.logical.shared.AttachEvent;
import com.google.gwt.event.logical.shared.AttachEvent.Handler;
import com.google.gwt.user.client.Event;
import com.sencha.gxt.core.client.Style.Side;
import com.sencha.gxt.widget.core.client.form.TextField;
import com.sencha.gxt.widget.core.client.tips.ToolTipConfig;
import com.sencha.gxt.widget.core.client.toolbar.LabelToolItem;
public class TextBox extends TextField implements MandatoryComponent, LabelComponent {
private boolean rightAligned = false;
private boolean mandatory;
private LabelToolItem label = null;
public TextBox(TextBoxMetaData textBoxMetaData) {
super();
setData(AbstractMetaData.ID, textBoxMetaData);
setValidateOnBlur(false);
if (textBoxMetaData.getMaxLength() > -1) {
InputElement inputElement = getInputEl().cast();
inputElement.setId("input1");
inputElement.setMaxLength(textBoxMetaData.getMaxLength());
}
if (textBoxMetaData.isUpperCase())
getInputEl().applyStyles("textTransform:uppercase");
if (textBoxMetaData.isAbsolutePosition())
setStyleName("position-absolute");
else
setStyleName("position-relative");
addAttachHandler(new Handler() {
@Override
public void onAttachOrDetach(AttachEvent event) {
if (isAttached()) {
addPasteListener(getInputEl());
}
}
});
}
@Override
public void onBrowserEvent(Event event) {
super.onBrowserEvent(event);
System.out.println("event=" + event.getType());
}
private native void addPasteListener(Element el)
/*-{
$wnd.$(function() {
$wnd.$(el).pastableNonInputable();
$wnd.$(el)
.on('paste', function(ev, data) {
alert('Here we paste');
})
.on('pasteImage', function(ev, data){
alert('Here we paste');
})
.on('pasteImageError', function(ev, data){
alert('pasteImageError');
})
.on('pasteText', function(ev, data){
alert("text pasted");
})
});
}-*/;
@Override
public boolean isEnabled() {
return !isReadOnly();
}
@Override
public boolean isMandatory() {
return mandatory;
}
@Override
public void setMandatory(boolean mandatory, boolean changeStyles) {
this.mandatory = mandatory;
// if (changeStyles && isEnabled())
// Utilities.setInputElementBackgroundColor(getInputEl(), true, mandatory);
}
@Override
public void setPosition(int x, int y) {
if (label == null) {
super.setPosition(x, y);
return;
}
TextBoxMetaData textBoxMetaData = getData(AbstractMetaData.ID);
Integer labelWidth = textBoxMetaData.getLabelWidth();
if (labelWidth == null)
labelWidth = 0;
if (textBoxMetaData.isLabelLeft()) {
super.setPosition(x + labelWidth, y);
if (isRightAligned())
label.setPosition(x - 6, y + 4);
else
label.setPosition(x, y + 4);
}
else {
super.setPosition(x, y + LabelComponent.LABEL_HEIGHT);
label.setPosition(x, y - 3);
}
}
@Override
public void setLabel(LabelToolItem label) {
this.label = label;
}
public void updateLabelText(String newText) {
TextBoxMetaData textBoxMetaData = getData(AbstractMetaData.ID);
if (textBoxMetaData.isLabelLeft() && isRightAligned() && newText != null && !newText.substring(0, 5).equals("<div "))
newText = "<div align=\"right\">" + newText + "</div>";
this.label.setLabel(newText);
}
public void setColor(String color) {
if (color == null)
return;
// Utilities.setInputElementBackgroundColor(getInputEl(), color);
}
@Override
public void setText(String text) {
super.setText(text);
if (text == null || text.length() == 0)
setToolTip(null);
}
@Override
public void setToolTip(String tooltip) {
if (tooltip == null || tooltip.length() == 0) {
removeToolTip();
return;
}
ToolTipConfig ttConfig = new ToolTipConfig(tooltip);
ttConfig.setAnchor(Side.LEFT);
super.setToolTipConfig(ttConfig);
}
@Override
public void setRightAligned(boolean isRightAligned) {
this.rightAligned = isRightAligned;
}
@Override
public boolean isRightAligned() {
return this.rightAligned;
}
@Override
public void setVisible(boolean visible) {
AbstractMetaData amd = getData(AbstractMetaData.ID);
boolean showDenied = amd.isShowDenied();
if (showDenied && visible)
return;
super.setVisible(visible);
if (label != null)
label.setVisible(visible);
}
@Override
public void setEnabled(boolean enabled) {
AbstractMetaData amd = getData(AbstractMetaData.ID);
boolean editDenied = amd.isEditDenied();
if (editDenied && enabled)
return;
setReadOnly(!enabled);
// Utilities.setInputElementBackgroundColor(getInputEl(), enabled, mandatory);
}
}