protected void _processEnterEditing(final char firstKeyForEditing) {
DeferredCommand.addCommand(new Command() {
public void execute() {
final TextArea ta = new TextArea();
String text = contents.getText().trim();
if ( firstKeyForEditing != 0 ) {
text += firstKeyForEditing;
}
ta.setText(text);
int ww = focusPanel.getOffsetWidth();
int hh = (int) (1.3 * focusPanel.getOffsetHeight());
hh = Math.max(hh, 40);
ww = Math.max(ww, 100);
// ta.setHeight(hh+ "px");
ta.setSize(ww+ "px", hh+ "px");
// ta.setCharacterWidth(text.length());
ta.addFocusListener(new FocusListener() {
public void onFocus(Widget sender) {
}
public void onLostFocus(Widget sender) {
RootPanel.get().remove(ta);
focusPanel.setFocus(true);
}
});
ta.addKeyboardListener(new KeyboardListenerAdapter() {
public void onKeyPress(Widget sender, char keyCode, int modifiers) {
String text = ta.getText();
Orr.log("onKeyPress: keyCode=" +keyCode+ ", modifiers=" +modifiers+ " text=[" +text+ "]");
if ( keyCode == KEY_ENTER || keyCode == KEY_TAB ) {
if ( keyCode == KEY_ENTER ) {
ta.cancelKey();
}
contents.setText(text);
if ( text.length() > 0 ) {
contents.setSize("100%", "100%");
}
RootPanel.get().remove(ta);
// add new row automatically if we are in the last row:
if ( actualRow == flexTable.getRowCount() -1
&& actualCol == flexTable.getCellCount(actualRow) -1
) {
addRow(flexTable.getCellCount(actualRow) - 1);
Widget widget = flexTable.getWidget(actualRow +1, FIRST_REGULAR_COL);
// Orr.log("widget= " +widget.getClass().getName());
if ( widget instanceof TableCell ) {
((TableCell) widget).setFocus(true);
}
}
else {
focusPanel.setFocus(true);
}
return;
}
if ( keyCode == KEY_ESCAPE ) {
RootPanel.get().remove(ta);
ta.cancelKey();
focusPanel.setFocus(true);
return;
}
}
});
int left = focusPanel.getAbsoluteLeft();
int top = focusPanel.getAbsoluteTop();
RootPanel.get().add(ta, left, top);
ta.setFocus(true);
ta.setCursorPos(text.length());
}
});
}