Hi Daniel, As Robert suggested, you will need an extension of ULCTable to achieve your goal.
Please see the snippet at the end of this mail. Please note that overriding F2's action will stop its default action of toggling edit mode. I hope this helps. Thanks and regards, Janak -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of ulc rbeeger Sent: Thursday, July 13, 2006 2:31 PM To: Daniel Dilitz; [EMAIL PROTECTED] Subject: Re: [ULC-developer] stopCellEditing Hi Daniel, You cannot register listeners for keyboard shortcuts on a ULC component. So you'll need to create an extension anyways. In that extension on the client-side you could extend the action map in the following way: getBasicTable().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMP ONENT).put( KeyEvent.VK_F2, 0, "saveChanges"); getBasicTable().getActionMap().put("saveChanges", new AbstractAction() { public void actionPerformed(final ActionEvent e) { if (getBasicTable().isEditing()) { getBasicTable().getCellEditor().stopCellEditing(); } invokeULC("saveChanges"); } }); I haven't tested this and it's far from complete. You'll need to implement saveChanges in the server side of your extension. F2 is probably not the best idea for the shortcut. Here it toggles the editing mode of the current cell. You probably should post again to the ULC developer list if this doesn't help. Maybe someone else can provide better advice. Cheers, Robert ----- Original Message ----- From: Daniel Dilitz To: 'ulc rbeeger' Sent: Wednesday, July 12, 2006 11:01 AM Subject: RE: [ULC-developer] stopCellEditing Well i can tell you one case where i need stopCellEditing() (or another solution). If the user is currently editing a cell and then presses the shortcut (e.g. "F2") in order to save the changes, the changes he made to the currently editing cell are not written to the model. I found out that you can change some of these settings over the delivery mode: ULCTableModelAdapter.getInstance(table.getModel()).setEventDeliveryMode(UlcE ventCategories.MODEL_UPDATE_CATEGORY, UlcEventConstants.SYNCHRONOUS_MODE); Is there any setting i can change to force the editor to write the current editing value to the server? Otherwise i have to live with your solution. But the problem is the additional client/server roundtrip i produce. Greets Daniel From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of ulc rbeeger Sent: Dienstag, 11. Juli 2006 10:55 To: Daniel Dilitz; [EMAIL PROTECTED] Subject: Re: [ULC-developer] stopCellEditing Hi Daniel, AFAIK something like that cannot be achieved because of how ULC works. The method calls that are send from the server to the client are collected and returned to the client as a response to the request that started your server code - some event in most cases. So even if you write an extension to ULCTable that provides this stopCellEditing method, there is no way to make it synchronous. You'll have to do something like that instead: addCellEditingStoppedListener(new CellEditingStoppedListner() { public void cellEditingStopped() { saveTableData(); } }); stopCellEditing(); You need to create this new listener type and create obligatory bunch of listner related operations (see the ULC Extension guide). stopCellEditing on the client has to trigger the event once it called the stopCellEditiing() method on the table. You should check whether you really need it, though. ULCTable is smarter than the Swing JTable. In some situation where you would need to explicitely stop cell editing with a Swing JTable, ULC stops it by itself - e.g. clicking on a button.. Cheers, Robert ----- Original Message ----- From: Daniel Dilitz To: [EMAIL PROTECTED] Sent: Tuesday, July 11, 2006 9:35 AM Subject: [ULC-developer] stopCellEditing Hi I need a method like stopCellEditing() on my table which forces the table to stop cell editing and call the validation on current editing cell. The problem is, if i enhance my table which such a call (which would call the client and there call the stopCellEditing() on jtable) the call would be asynchronous. But i need a synchronous stopCellEditing() for code like this: public void saveTable(){ stopCellEditing(); saveTableData(); } Can you give me a hint how to achieve this? Thanks in advance Daniel -------------------- import com.ulcjava.base.application.AbstractApplication; import com.ulcjava.base.application.ULCBoxPane; import com.ulcjava.base.application.ULCComponent; import com.ulcjava.base.application.ULCFrame; import com.ulcjava.base.application.ULCScrollPane; import com.ulcjava.base.application.ULCTable; import com.ulcjava.base.application.event.IKeyListener; import com.ulcjava.base.application.table.DefaultTableModel; import com.ulcjava.base.application.table.ITableModel; import com.ulcjava.base.client.UITable; import com.ulcjava.base.development.DevelopmentRunner; import com.ulcjava.base.server.IDispatcher; import javax.swing.AbstractAction; import javax.swing.InputMap; import javax.swing.JTable; import javax.swing.KeyStroke; import java.awt.event.KeyEvent; public class ULCTableSaveOnF2Snippet extends AbstractApplication { protected ULCComponent createContent() { ULCTable table = new MyULCTable(new DefaultTableModel(new Object[][] { { 0, 0 }, { 1, 1 } }, new String[] { "Col1", "Col2" })); return new ULCScrollPane(table); } public void start() { ULCFrame frame = new ULCFrame("ULCTableTabNavigationSnippet"); frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE); ULCBoxPane content = new ULCBoxPane(true); content.add(ULCBoxPane.BOX_EXPAND_EXPAND, createContent()); frame.add(content); frame.setSize(200, 200); frame.setVisible(true); } public static void main(String[] args) { DevelopmentRunner.setApplicationClass(ULCTableSaveOnF2Snippet.class) ; DevelopmentRunner.main(args); } public static class MyULCTable extends ULCTable { @Override protected IDispatcher createDispatcher() { return new MyULCTableDispatcher(); } public MyULCTable(ITableModel model) { super(model); } protected String typeString() { return MyUITable.class.getName(); } protected void saveChanges(int row, int col) { // for the sake of demo - showing the last selected cell System.out.println("Saved changes to cell:" + getModel().getValueAt(row, col)); } protected class MyULCTableDispatcher extends ULCTableDispatcher { public final void saveChanges(int row, int col) { MyULCTable.this.saveChanges(row, col); } } } public static class MyUITable extends UITable { protected void postInitializeState() { super.postInitializeState(); final JTable table = getBasicTable(); KeyStroke keyF2 = KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0); InputMap inputMap = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); inputMap.put(keyF2, "saveChanges"); table.getActionMap().put("saveChanges", new AbstractAction() { public void actionPerformed(java.awt.event.ActionEvent e) { if (getBasicTable().isEditing()) { getBasicTable().getCellEditor().stopCellEditing(); } // for the sake of demo - sending the currently selected if (table.getSelectedRow() != -1 && table.getSelectedColumn() != -1) { invokeULC("saveChanges", new Object[] {new Integer(table.getSelectedRow()), new Integer(table.getSelectedColumn())}); } } }); } } } _______________________________________________ ULC-developer mailing list [email protected] http://lists.canoo.com/mailman/listinfo/ulc-developer
