Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » ComboBoxCellEditor events on mac(ComboBoxCellEditor )
ComboBoxCellEditor events on mac [message #1840926] Thu, 29 April 2021 02:27 Go to next message
Jonathan Menzies is currently offline Jonathan MenziesFriend
Messages: 9
Registered: May 2020
Junior Member
Hey,

I'm having an issue with the ComboBoxCellEditor on Mac, if I set it to useCheckbox and single select. What happens is the mouse up listener fires and commits but the selection listener hasn't fired so nothing gets selected. If I override the mouse up listener to do nothing then it selects but then it essentially becomes a multi select.

I can't figure out a way to set the selection in the mouse listener so that before it tries to commit it atleast sets the internal map to have the correct item selected.

Cheers
Jonny
Re: ComboBoxCellEditor events on mac [message #1840928 is a reply to message #1840926] Thu, 29 April 2021 03:29 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2814
Registered: July 2012
Senior Member
Single select and checkboxes are currently not working

https://www.eclipse.org/forums/index.php/t/1107565/
Re: ComboBoxCellEditor events on mac [message #1841187 is a reply to message #1840928] Thu, 06 May 2021 00:12 Go to previous messageGo to next message
Jonathan Menzies is currently offline Jonathan MenziesFriend
Messages: 9
Registered: May 2020
Junior Member
Dirk Fauth wrote on Thu, 29 April 2021 03:29
Single select and checkboxes are currently not working

https://www.eclipse.org/forums/index.php/t/1107565/


Hi Dirk,

Funnily enough the forum post you link to was from my colleague.

We have found a way to get these to work on Mac without causing any issues on windows. So I thought I would get back to you with our solution incase it helps.

The problem we found in nattable 1.5 was that the mouse up listener in the ComboBoxCellEditor gets hit before the selection listener in NatCombo specifically on mac. Which results in the commit happening before anything was selected. To fix this we called the mouse up from the selection listener and customized the mouse up to ignore certain scenarios unless the data variable is set in the event.

NatCombo Overriden selection listener
this.dropdownTable.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(final SelectionEvent e) {
        boolean selected = e.detail != SWT.CHECK;
        boolean isCtrlPressed = (e.stateMask & SWT.MODIFIER_MASK) == SWT.CTRL;
        TableItem chosenItem = (TableItem) e.item;

        // Given the ability to filter we need to find the item's
        // table index which may not match the index in the itemList
        int itemTableIndex = AdvocateNatCombo.this.dropdownTable.indexOf(chosenItem);

        // This case handles check actions
        if (!selected) {
          if (!chosenItem.getChecked()) {
            AdvocateNatCombo.this.selectionStateMap.put(chosenItem.getText(), Boolean.FALSE);
          } else {
            if (!AdvocateNatCombo.this.multiselect) {
              for (String key : selectionStateMap.keySet()) {
                AdvocateNatCombo.this.selectionStateMap.put(key, Boolean.FALSE);
              }
            }
            AdvocateNatCombo.this.selectionStateMap.put(chosenItem.getText(), Boolean.TRUE);
          }
        } else if (!AdvocateNatCombo.this.useCheckbox) {
          if (AdvocateNatCombo.this.multiselect && isCtrlPressed) {
            boolean isSelected = AdvocateNatCombo.this.dropdownTable.isSelected(itemTableIndex);
            AdvocateNatCombo.this.selectionStateMap.put(chosenItem.getText(), isSelected);
          } else {
            // A single item was selected. Clear all previous state
            for (String item : AdvocateNatCombo.this.itemList) {
              AdvocateNatCombo.this.selectionStateMap.put(item, Boolean.FALSE);
            }

            // Set the state for the selected item
            AdvocateNatCombo.this.selectionStateMap.put(chosenItem.getText(), Boolean.TRUE);
          }
        } else if (selected) {
          if (!chosenItem.getChecked()) {
            AdvocateNatCombo.this.selectionStateMap.put(chosenItem.getText(), Boolean.FALSE);
          }
        }

        // Mouse up and Selection Events get fired the wrong way around on iOS
        // This change makes sure that the Mouse up event gets fired again after the selection event
        if (!AdvocateNatCombo.this.multiselect && AdvocateNatCombo.this.useCheckbox) {
          Event event = new Event();
          event.widget = AdvocateNatCombo.this;
          event.display = AdvocateNatCombo.this.getDisplay();
          event.type = SWT.MouseUp;
          event.data = chosenItem;
          AdvocateNatCombo.this.notifyListeners(SWT.MouseUp, event);
        }

        updateTextControl(false);
      }
    });


ComboBoxCellEditor Overriden Mouse Lisener
combo.addMouseListener(new MouseAdapter() {
      @Override
      public void mouseUp(final MouseEvent e) {
        if (!AdvocateNatTableComboBoxCellEditor.this.multiselect && e.data != null) {
          commit(MoveDirectionEnum.NONE,
              !AdvocateNatTableComboBoxCellEditor.this.multiselect && AdvocateNatTableComboBoxCellEditor.this.editMode == EditModeEnum.INLINE);
          if (!AdvocateNatTableComboBoxCellEditor.this.multiselect && AdvocateNatTableComboBoxCellEditor.this.editMode == EditModeEnum.DIALOG) {
            // hide the dropdown after a value was selected in the combo
            // in a dialog
            combo.hideDropdownControl();
          }
        }
      }
    });
Re: ComboBoxCellEditor events on mac [message #1841189 is a reply to message #1841187] Thu, 06 May 2021 04:40 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2814
Registered: July 2012
Senior Member
Thanks for the update. IIRC the issue only occurs on Mac with a ComboBoxCellEditor that is configured for single-selection with a checkbox. And it only happens if the checkbox is selected and not the element. Is that correct?

Actually your modification breaks the single selection without a checkbox. As in that case no selection event with data is fired, the editor never commits.

And I get a "Widget is disposed" SWTException on updateTextControl() as it is executed after the selection event is triggered.

I made some slight modifications to your solution:

1. move the updateTextControl(false) call before programmatically fire the mouseUp event
2. extended the added if-clause to check also the useCheckbox flag, so the conditions are the same in NatCombo and the ComboBoxCellEditor

        combo.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseUp(MouseEvent e) {
                // Mouse up and Selection Events get fired in the wrong order
                // on iOS when clicking the checkbox. In this scenario the
                // NatCombo will fire a Mouse up event programmatically with set
                // data, to ensure that the processing is done in the correct
                // order.
                boolean isSingleSelectWithCheckbox = !ComboBoxCellEditor.this.multiselect && ComboBoxCellEditor.this.useCheckbox;
                if (!isSingleSelectWithCheckbox || e.data != null) {

                    commit(MoveDirectionEnum.NONE,
                            (!ComboBoxCellEditor.this.multiselect && ComboBoxCellEditor.this.editMode == EditModeEnum.INLINE));
                    if (!ComboBoxCellEditor.this.multiselect && ComboBoxCellEditor.this.editMode == EditModeEnum.DIALOG) {
                        // hide the dropdown after a value was selected in the
                        // combo in a dialog
                        combo.hideDropdownControl();
                    }
                }
            }
        });


I have created a patch here: https://git.eclipse.org/r/c/nattable/org.eclipse.nebula.widgets.nattable/+/180274

I know you are on a quite old NatTable version (1.5 from 2017) but maybe you could verify if that change works on Mac? Let me know if you could verify using the sources and the examples locally or if I should merge first.
Previous Topic:Possible Bug Report for Single Select + Use Checkbox Combobox Cell Editors
Next Topic:Filter Not working when column cell value contains "*"
Goto Forum:
  


Current Time: Mon Jun 14 22:38:51 GMT 2021

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

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

Back to the top