/**
* Implement the interface for validating and converting to internal object.
* Null is a valid successful return, so errors are indicated only by
* existance or not of a message in the messageBuffer.
*/
public Object validateAndConvert(String value, Object originalValue, StringBuffer messageBuffer) {
// handle null, which is shown as the special string "<null>"
if (value.equals("<null>") || value.equals(""))
return null;
// Do the conversion into the object in a safe manner
try {
Object obj = new [[#variable18c207c0]](value);
return obj;
}
catch (Exception
e) {
messageBuffer.append(e.toString() + "\n");
//?? do we need the message also, or is it automatically part of the toString()?
//messageBuffer.append(e.getMessage());
return null;
}
}
/**
* If true, this tells the PopupEditableIOPanel to use the
* binary editing panel rather than a pure text panel.
* The binary editing panel assumes the data is an array of bytes,
* converts it into text form, allows the user to change how that
* data is displayed (e.g. Hex, Decimal, etc.), and converts
* the data back from text to bytes when the user editing is completed.
* If this returns false, this DataType class must
* convert the internal data into a text string that
* can be displayed (and edited, if allowed) in a TextField
* or TextArea, and must handle all
* user key strokes related to editing of that data.
*/
public boolean useBinaryEditingPanel() {
return false;
}
/*
* Now the functions for the Popup-related operations.
*/
/**
* Returns true if data type may be edited in the popup,
* false if not.
*/
public boolean isEditableInPopup(Object originalValue) {
return true;
}
/*
* Return a JTextArea usable in the CellPopupDialog
* and fill in the value.
*/
public JTextArea getJTextArea(Object value) {
_textComponent = new RestorableJTextArea();
// value is a simple string representation of the data,
// the same one used in Text and in-cell operations.
((RestorableJTextArea) _textComponent).setText(renderObject(value));
// special handling of operations while editing this data type
((RestorableJTextArea) _textComponent).addKeyListener(new KeyTextHandler());
return (RestorableJTextArea) _textComponent;
}
/**
* Validating and converting in Popup is identical to cell-related operation.
*/
public Object validateAndConvertInPopup(String value, Object originalValue, StringBuffer messageBuffer) {
return validateAndConvert(value, originalValue, messageBuffer);
}
/*
* The following is used in both cell and popup operations.
*/
/*
* Internal class for handling key events during editing
* of both JTextField and JTextArea.
*/
private class KeyTextHandler extends BaseKeyTextHandler {
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
// as a coding convenience, create a reference to the text component
// that is typecast to JTextComponent. this is not essential, as we
// could typecast every reference, but this makes the code cleaner
JTextComponent _theComponent = (JTextComponent) [[#variable18c11300]].this._textComponent;
String text = _theComponent.getText();
// look for illegal chars
if ( ! [[#variable18c11300]].this._isSigned && c == '-') {
// cannot use '-' when unsigned
_beepHelper.beep(_theComponent);
e.consume();
}
// tabs and newlines get put into the text before this check,
// so remove them
// This only applies to Popup editing since these chars are
// not passed to this level by the in-cell editor.
if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER) {
// remove all instances of the offending char
int index = text.indexOf(c);
if (index != -1) {
if (index == text.length() - 1) {
text = text.substring(0, text.length() - 1); // truncate string
}
else {
text = text.substring(0, index) + text.substring(index + 1);
}
((IRestorableTextComponent) _theComponent).updateText(text);
_beepHelper.beep(_theComponent);
}
e.consume();
}
if ( !(Character.isDigit(c) || (c == '-') || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))) {
_beepHelper.beep(_theComponent);
e.consume();
}
// check for max size reached (only works when DB provides non-zero scale info
if ( [[#variable18c11300]].this._scale > 0 && text.length() == [[#variable18c11300]].this._scale && c != KeyEvent.VK_BACK_SPACE && c != KeyEvent.VK_DELETE) {
// max size reached
e.consume();
_beepHelper.beep(_theComponent);
}
// handle cases of null
// The processing is different when nulls are allowed and when they are not.
//
if ( [[#variable18c11300]].this._isNullable) {
// user enters something when field is null
if (text.equals("<null>")) {
if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
[[#variable18c11300]].this._textComponent.restoreText();
e.consume();
}
else {
[[#variable18c11300]].this._textComponent.updateText("");
// fall through to normal processing of this key stroke
}
}
else {
// check for user deletes last thing in field
if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
if (text.length() <= 1) {
[[#variable18c11300]].this._textComponent.updateText("<null>");
e.consume();
}
}
}
}
else {
// field is not nullable
//
handleNotNullableField(text, c, e, _textComponent);
}
}
}
|