Hi
Here is code for a pjc for autofilling a combo box in oracle forms. It uses most of the regular features of the normal oracle combo box(for example it gets populated like normal), but it adds the autofill feature which is pretty cool. My problem is, for some reason I cannot get the complete value thats in the combo box after I get off the field and go to another item. Debugging it just shows the field blank even though its displaying a value. If I drill down with my mouse and select a value from the list it works fine. Its just when I type the value. Is there any code (set_custom_property or get_custom_property) that can be added so I can get the value thats in the combo box? Or am I missing some java code to spit out the values.
any help would be greatly appreciated.
thanks
here is the code:
package smartbox;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import oracle.ewt.lwAWT.lwText.LWTextField;
import oracle.forms.ui.VComboBox;
public class mycombo extends VComboBox
{
- Sandid Resources LLC Powered by Mambo Generated: 25 March, 2008, 16:16
//private String[] m_origItems;
private char m_keyChar = 0;
private final String CLASSNAME = this.getDefaultName();
/**
* Constructor for the mycombo PJC
*/
public mycombo() {
super();
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
void predict(KeyEvent e)
{
// get the textfield component of ComboBox
LWTextField tf = this.getLWTextField();
// list search flag
boolean found = false;
// found/selected index
int selected = 0;
// replace currently selected characters with acharacter that user has just typed
tf.replaceRange(String.valueOf(m_keyChar),tf.getSelectionStart(),tf.getSelectionEnd());
String currval = tf.getText();
// get array of list items
String[] origItems = this.getItems();
// compare current text in the textfield to the list items,
// find the first occurrence of an item that starts with what userhas typed
for (int i = 0; i < origItems.length; i++)
{
//if (m_origItems.toUpperCase().startsWith(currval.toUpperCase())) {
found = origItems.toUpperCase().startsWith(currval.toUpperCase());
if (found) {selected = i; break;}
}
if (found)
{
this.select(selected);
tf.select(currval.length(),100);
}
e.consume();
}
private void jbInit() throws Exception {
// Hook into the keyboard
addKeyListener(new KeyPressAdapter());
}
/**
* Private class to intercept the keyboard actions and store the keystrokes away.
*/
class KeyPressAdapter extends KeyAdapter
{
public void keyPressed(KeyEvent e)
{
}
/**
* KeyTyped is where we do the work
- Sandid Resources LLC Powered by Mambo Generated: 25 March, 2008, 16:16
*/
public void keyTyped(KeyEvent e)
{
// we are only interested in keystrokes that result in a Unicode character;
// other keystrokes will go default route
int id = e.getID();
if (id == KeyEvent.KEY_TYPED) {
if (e.getKeyChar() != KeyEvent.VK_BACK_SPACE &&
e.getKeyChar() != KeyEvent.VK_ENTER &&
e.getKeyChar() != KeyEvent.VK_TAB) {
m_keyChar = e.getKeyChar();
predict(e);
}
}
}
}
/**
* Utility function to print out a debug message to the Java Console.
* @param msg string to display, this will be prefixed with the classname of the PJC
*/
public void log(String msg)
{
System.out.println(CLASSNAME + ": " + msg);
}
}
Here is code for a pjc for autofilling a combo box in oracle forms. It uses most of the regular features of the normal oracle combo box(for example it gets populated like normal), but it adds the autofill feature which is pretty cool. My problem is, for some reason I cannot get the complete value thats in the combo box after I get off the field and go to another item. Debugging it just shows the field blank even though its displaying a value. If I drill down with my mouse and select a value from the list it works fine. Its just when I type the value. Is there any code (set_custom_property or get_custom_property) that can be added so I can get the value thats in the combo box? Or am I missing some java code to spit out the values.
any help would be greatly appreciated.
thanks
here is the code:
package smartbox;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import oracle.ewt.lwAWT.lwText.LWTextField;
import oracle.forms.ui.VComboBox;
public class mycombo extends VComboBox
{
- Sandid Resources LLC Powered by Mambo Generated: 25 March, 2008, 16:16
//private String[] m_origItems;
private char m_keyChar = 0;
private final String CLASSNAME = this.getDefaultName();
/**
* Constructor for the mycombo PJC
*/
public mycombo() {
super();
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
void predict(KeyEvent e)
{
// get the textfield component of ComboBox
LWTextField tf = this.getLWTextField();
// list search flag
boolean found = false;
// found/selected index
int selected = 0;
// replace currently selected characters with acharacter that user has just typed
tf.replaceRange(String.valueOf(m_keyChar),tf.getSelectionStart(),tf.getSelectionEnd());
String currval = tf.getText();
// get array of list items
String[] origItems = this.getItems();
// compare current text in the textfield to the list items,
// find the first occurrence of an item that starts with what userhas typed
for (int i = 0; i < origItems.length; i++)
{
//if (m_origItems.toUpperCase().startsWith(currval.toUpperCase())) {
found = origItems.toUpperCase().startsWith(currval.toUpperCase());
if (found) {selected = i; break;}
}
if (found)
{
this.select(selected);
tf.select(currval.length(),100);
}
e.consume();
}
private void jbInit() throws Exception {
// Hook into the keyboard
addKeyListener(new KeyPressAdapter());
}
/**
* Private class to intercept the keyboard actions and store the keystrokes away.
*/
class KeyPressAdapter extends KeyAdapter
{
public void keyPressed(KeyEvent e)
{
}
/**
* KeyTyped is where we do the work
- Sandid Resources LLC Powered by Mambo Generated: 25 March, 2008, 16:16
*/
public void keyTyped(KeyEvent e)
{
// we are only interested in keystrokes that result in a Unicode character;
// other keystrokes will go default route
int id = e.getID();
if (id == KeyEvent.KEY_TYPED) {
if (e.getKeyChar() != KeyEvent.VK_BACK_SPACE &&
e.getKeyChar() != KeyEvent.VK_ENTER &&
e.getKeyChar() != KeyEvent.VK_TAB) {
m_keyChar = e.getKeyChar();
predict(e);
}
}
}
}
/**
* Utility function to print out a debug message to the Java Console.
* @param msg string to display, this will be prefixed with the classname of the PJC
*/
public void log(String msg)
{
System.out.println(CLASSNAME + ": " + msg);
}
}