public void registerF9KeyToTableTextField(){
ULCTableColumn tableColumn = existingPromotionsTable.getColumn("Description");
final ULCTextFieldExtension f9TextField = new ULCTextFieldExtension(12);
F9Listener f9listener = new F9Listener();
KeyStroke F9 = KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0);
f9TextField.registerKeyboardAction(f9listener,F9,0);
tableColumn.setCellEditor(new ITableCellEditor(){
public IEditorComponent getTableCellEditorComponent(ULCTable table, Object value, int row) {
// TODO Auto-generated method stub
return f9TextField;
}});
}
public class F9Listener implements IActionListener{
public void actionPerformed(ActionEvent event) {
System.out.println(" u clicked f9 key");
}
}
public class ULCTextFieldExtension extends ULCTextField {
private List keyboardActionCopyList = new ArrayList();
public ULCTextFieldExtension() {
super();
}
public ULCTextFieldExtension(int columns) {
super(columns);
}
public ULCTextFieldExtension(String text, int columns) {
super(text, columns);
}
public ULCTextFieldExtension(String text) {
super(text);
}
public void registerKeyboardAction(IActionListener action, String command, KeyStroke keyStroke, int condition) {
super.registerKeyboardAction(action, command, keyStroke, condition);
keyboardActionCopyList.add
(new Object[] { action, command, keyStroke, new Integer(condition) });
}
public void copyAttributes(ICellComponent source) {
super.copyAttributes(source);
ULCTextFieldExtension sourceTextField = (ULCTextFieldExtension)source;
Iterator iterator = sourceTextField.keyboardActionCopyList.iterator
();
while (iterator.hasNext()) {
Object[] args = (Object[]) iterator.next();
super.registerKeyboardAction((IActionListener) args[0], (String) args[1], (KeyStroke) args[2], ((Integer)args[3]).intValue());
}
}
}
Hi Prashanth,
what you are trying to accomplish is not possible because
ULC treats components used as in the context of cell renderers
and cell editors of table in a special way.
ULC performs optimizations so that it does not create as many
cell renderer and cell editor proxy objects as there are cells
in a table, because otherwise there would be far too much server
client traffic and far too many proxy objects on the server.
In this context ULC replaces your f9TextField by another one
which does not hold listener that you initially registered at the f9TextField.
I added a Jira report for this issue (UBA-6925).
In the mean time I can offer you a little "extension" for ULCTextField which
fixes the problem (see code below). Just use an instance of ULCTextFieldExtension
in your cell editor and it should work fine. E.g. with respect to your original sample:
final ULCTextFieldExtension f9TextField = new ULCTextFieldExtension(12);
F9Listener f9listener = new F9Listener();
KeyStroke F9 = KeyStroke.getKeyStroke (KeyEvent.VK_F9, 0);
f9TextField.registerKeyboardAction(f9listener, F9, 0);
tableColumn.setCellEditor(new ITableCellEditor() {
public IEditorComponent getTableCellEditorComponent(ULCTable table, Object value, int row) {
System.out.println("u pressed F9 !!!!!!!!!!");
return (IEditorComponent)f9TextField;
}
});
Here is the code of the related ULCTextFieldExtension:
public class ULCTextFieldExtension extends ULCTextField {
private List keyboardActionCopyList = new ArrayList();
public ULCTextFieldExtension() {
super();
}
public ULCTextFieldExtension(int columns) {
super(columns);
}
public ULCTextFieldExtension(String text, int columns) {
super(text, columns);
}
public ULCTextFieldExtension(String text) {
super(text);
}
public void registerKeyboardAction(IActionListener action, String command, KeyStroke keyStroke, int condition) {
super.registerKeyboardAction(action, command, keyStroke, condition);
keyboardActionCopyList.add (new Object[] { action, command, keyStroke, new Integer(condition) });
}
public void copyAttributes(ICellComponent source) {
super.copyAttributes(source);
ULCTextFieldExtension sourceTextField = (ULCTextFieldExtension)source;
Iterator iterator = sourceTextField.keyboardActionCopyList.iterator();
while (iterator.hasNext()) {
Object[] args = (Object[]) iterator.next();
super.registerKeyboardAction ((IActionListener) args[0], (String) args[1], (KeyStroke) args[2], ((Integer)args[3]).intValue());
}
}
}
Greetings,
Daniel
PS: Please send you request via [email protected]
-----Original Message-----
From: prashanth tr [mailto:[EMAIL PROTECTED]]
Sent: Donnerstag, 18. Mai 2006 18:27
To: Daniel Pfeifer
Subject: Re: [ULC-developer] In table cell ( ie textfield) on press of F9 Funtion Key, I need to do some action. How can I accomplish this in ulc.
Hi Daniel,
thanks for reply
i tried the following code for a particular column named "Description".
But it didnt work.
Can you help me out like where I am wrong.
public void registerF9KeyToTableTextField(){
//WHEN_FOCUSED
ULCTableColumn tableColumn = existingPromotionsTable.getColumn("Description");
final ULCTextField f9TextField = new ULCTextField(12);
F9Listener f9listener = new F9Listener();
KeyStroke F9 = KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0);
f9TextField.registerKeyboardAction(f9listener,F9,0);
tableColumn.setCellEditor(new ITableCellEditor(){
public IEditorComponent getTableCellEditorComponent(ULCTable table, Object value, int row) {
// TODO Auto-generated method stub
System.out.println ("u pressed F9 !!!!!!!!!!");
return (IEditorComponent) f9TextField;
}});
}
public class F9Listener implements IActionListener{
public void actionPerformed(ActionEvent event) {
System.out.println (" u clicked f9 key");
}
}
On 5/18/06, Daniel Pfeifer <[EMAIL PROTECTED]> wrote:
Hi,
here is a simple example on how to register a keyboard action listener for a certain key
(it works for me):
ULCTable table = new ULCTable(new Object[][] { {"a", "b"}, {"c", "d"}}, new String[] {"x", "y"});
table.registerKeyboardAction (new IActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.out.println("z pressed");
};
}, KeyStroke.getKeyStroke('z'), ULCComponent.WHEN_FOCUSED );
ULCRootPane frame = createRootPane();
frame.add(table);
frame.setVisible(true);
In this case an event is only sent to the server, if the table has the focus and the key 'z'
is pressed.
Greetings,
Daniel
-----Original Message-----
From: [EMAIL PROTECTED] [mailto: [EMAIL PROTECTED]]On Behalf Of prashanth tr
Sent: Donnerstag, 18. Mai 2006 15:21
To: [email protected]
Subject: [ULC-developer] In table cell ( ie textfield) on press of F9 Funtion Key, I need to do some action. How can I accomplish this in ulc.
I swing table i am not facing any problem. i just registered F9 key to the desired table column and it worked fine using registerKeyboardAction() method.
But it didnt work in ulc table.
Well I didnt try with keymap.
If there is any way then let me know.
--
Thanks
Prashanth
--
Thanks
Prashanth
--
Thanks
Prashanth
