Need to "link" table cell editor with its table - java

I need to customise the selection behaviour of the cells inside a JTable descendant. I have a custom cell editor using a JTextField descendant as the editorComponent; there's a focus listener registered on it which manages the desired selection behaviour.
I need different behaviour when tabbing around the table than when another window or application comes to the front and then goes away again.
This is currently not possible, because the cell editor's editorComponent seems to have no off-the-shelf way of knowing (or telling it) that it's the editor for a table cell, so it doesn't know that it's "inside" the table, so my focusGained() and focusLost() think focus is moving between different windows even if I'm just tabbing around in the table.
SwingUtilities.windowForComponent() returns null for the editorComponent.
Before I roll my own solution, is there an accepted way of dealing with this issue? I can't be the first person to need to do this...

Related

Save doesn't get enabled on SWT EditorPart when cell is modified in TableViewer

I'm using a TableViewer in my class which extends EditorPart, TableViewer has one
editable column which has ComboBoxCellEditor. When I modify the column to select a value from ComboBoxCellEditor, the save button doesn't get enabled until a tab key is pressed, or when the focus is moved to a different item. Is there any way that I can get the save to be enabled when I modify the value of ComboBoxCellEditor. I'm extending EditingSupport class to make the column editable. The overridden medthods from this class are not called until the focus is shifted away from this column. Is there any way that I can get this work?
That is how ComboBoxCellEditor is designed to work. The internal method applyEditorValueAndDeactivate is only called on Tab, Enter, and focus lost.
None of this behavior looks easy to modify other than by writing your own version of the class (which is not large).

How would a dev make a JTable LOOK editable

I'm writing an application that has a JTable, and an edit button that sets the current selected row to be editable. Then once the user is done altering the data, they can click the edit button again (with text that now says "Save") to save the data.
The problem is though, when I set a row to be editable, there isn't a visible difference. I could add some code to the renderer to draw the editable cells a little differently, but I don't know what the proper way to make a cell look editable is. Change the color? Make it look like a JTextField? What's the standard method?
Thanks!
Really this is a user interface design question, not a programming one.
To do what you want you need to supply an appropriate cell renderer with the changes you desire but you will need to decide on your own settings. One option might just be to look at the difference between an editable and non-editable text area and apply those to all the cells on the table. This may be as simple as setting the renderers to disabled for any read-only rows.

Changing current selection in JXTable doesn't work?

I have a JXTable where the users need to introduce data, then save it. Only the thing is, the user has to deselect the last edited cell before saving it. If they don't, the data of that cell isn't saved.
The only thing I thought of is to change the current selection automatically just before saving. This is what i tried :
table.getSelectionModel().setSelectionInterval(0, 0);
table.getColumnModel().getSelectionModel().setSelectionInterval(0, 0);
OR
table.getSelectionModel().setLeadSelectionIndex(0);
table.getColumnModel().getSelectionModel().setLeadSelectionIndex(0);
None of both seem to work yet these are the only two methods I found to do this.
Can anyone please tell me how to do this properly or propose an alternative to also let it save the data from that last cell?
I am assuming the user clicks on another component (JButton) when he wishes to save data. If you have a reference to the JXTable when that event happens you could add the following piece of code there:
if (table.isEditing()) {
table.getCellEditor().stopCellEditing();
}
The stopCellEditing() should save the state of the model and allow you to save all the contents, including the currently selected / edited cell.
EDIT: As kleopatra pointed out, the default (and better!) way to handle this is through the client property of JTable component:
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
For JXTable this should already be set though, which indicates that the way your UI handling of the save functionality works does not include moving the focus away from the table. So in essence you'd be better off changing the focus when your 'save' event is being fired.

Eclipse plugin - is TableViewer suitable when multiple tables required

I'm writing an Eclipse plugin for a screen definition editor. The preview page will have multiple tables of different rows/columns definitions, the contents of each cell is effectively a control definition (i.e. Label, TextBox, etc). Some basic requirements of the preview are:
User selection on any cell publishes the control properties to another view.
The cell styling is applied depending upon the control type.
Currently using JFace TableViewers but have the following issues:
1. Only one TableViewer can be registered as a selection provider via the getSite().setSelectionProvider(). How to listen for selection changes on all my tables?
2. TableViewer does not appear to allow for cell styling.
3. Cell selection programatically handling with a TableCursor, but the cell in a previous table is still highlighted when I select another cell in another table.
Are there more suitable layouts to use than TableViewer for my purposes?
Regarding point #2, cell styling, TableViewers do allow for customization of the display of cell data. Take a look here for some ideas on how to get started with that.
You can use this approach for supporting selection in multiple tables with some modification (add listener to each of your table viewers so if one of them is selected it automatically becomes the delegate).

JTable Header Focus Query?

This Scenario may sound silly... but this was the observation...
When a mouse click on the the JTable cell...
Cell is gets into the editor mode, while in the editor and a invalid entry is made (JTextFeild Component is installed in each cell), the focus is restricted in the editor mode by returning false instead of super.return stopCellEditing(); while validation and test field is painted red.
In the false mode, if user clicks anywhere on the table or outside the table the focus is not lost, but when the user clicks on the JTable header the focus is lost from the cell... I need to restrict this... How can this be achieved
Thank You in Advance...
just to make sure: the editing is canceled in that case (though not exactly on click but on any mouse gesture which might be interpreted as starting a column move/resize, if I remember correctly), right?
If so, it's
a long standing bug, table silently removes editors on receiving change notifications from the column model
even if fixed, (arguably, of course) not the best user experience to not allow moving out
You might look at #camickr's TablePopupEditor, which uses a modal dialog to edit.
This can actually be possible by disabling
table.getTableHeader().setReorderingAllowed(false);
table.getTableHeader().setResizingAllowed(false);
Currently its working, but don't know under what circumstances it may fail.
Thank You

Categories

Resources