Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » table cell editor does not deactivate and commit the value when save command is invoked
table cell editor does not deactivate and commit the value when save command is invoked [message #709123] Wed, 03 August 2011 14:20 Go to next message
Henno Vermeulen is currently offline Henno VermeulenFriend
Messages: 126
Registered: July 2009
Senior Member
I have a TableViewer inside an Eclipse editor. When I am editing a cell and press the save button in the main toolbar or press ctrl-S, the cell editing does not deactivate so that the new value is not yet written to the model when I try to save my model which confuses the user.

The weird thing is that if I click any other cell, or any control inside the editor itself, the cell seems to lose focus and cell editing does get deactivated and the new value is written to the model. I also have the same TableViewer inside a preference page and the apply/ok buttons do not give this problem.

It seems that no focus lost event occurs when you click something in the main toolbar but it does occur when you click anything in the same editor window even another toolbar.

Is there any way to solve this problem, preferably without having to change my save command handler?



Some details which may be of importance:

I have set some cell editor/traversal strategies with code that I found in a JFace snippet. I know that this at least enables tab traversal/single click activation where I want it.


...
    ColumnViewerEditorActivationStrategy actSupport =
        new ColumnViewerEditorActivationStrategy(viewer) {

          protected boolean isEditorActivationEvent(
              ColumnViewerEditorActivationEvent event) {
            ViewerColumn viewerColumn =
                columns[((ViewerCell) event.getSource())
                    .getColumnIndex()];

            return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
                || (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION && !doubleClickActivationMap
                    .get(viewerColumn))
                || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
                // This doesn't seem to work
                || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && (event.keyCode == SWT.CR || event.keyCode == SWT.F2))
                || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
          }
        };

    TableViewerEditor.create(viewer, actSupport,
        ColumnViewerEditor.TABBING_HORIZONTAL
            | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
            | ColumnViewerEditor.TABBING_VERTICAL
            | ColumnViewerEditor.KEYBOARD_ACTIVATION);

...

Re: table cell editor does not deactivate and commit the value when save command is invoked [message #1002452 is a reply to message #709123] Fri, 18 January 2013 16:02 Go to previous message
Henno Vermeulen is currently offline Henno VermeulenFriend
Messages: 126
Registered: July 2009
Senior Member
The problem is caused by not receiving focus lost in the cell editor. Ideal (but hard because you need to adjust all cell editors) solution would be to use databinding to write to the model as you type.

I solved this issue by creating a utility method that applies the cell value for the currently active table viewer. I call this utility from the save handler. To prevent a user from closing a dirty editor that is not yet marked dirty because of the current cell edit, I also call it from an overridden EditorPart.isSaveOnCloseNeeded().

Unfortunately the implementation of the utility is rather ugly. The idea is that you check the ancestors of the focus control of the display until you find a table. Then use a little hack with Eclipse internals to get to the table viewer and then use reflection to call applyEditorValue. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=242231

Hack with Eclipse internals (WARNING may change!): get the first table column widget then get the ViewerColumn through columnWidget.getData(Policy.JFACE + ".columnViewer") and ask for its ColumnViewer.
Previous Topic:How to view sources of internal plugins
Next Topic:Customizing Eclipse Wizards
Goto Forum:
  


Current Time: Sat Apr 27 05:18:02 GMT 2024

Powered by FUDForum. Page generated in 0.03038 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top