|
|
Re: ComboBoxCellEditor events on mac [message #1841187 is a reply to message #1840928] |
Thu, 06 May 2021 00:12 |
Jonathan Menzies Messages: 60 Registered: May 2020 Location: California |
Member |
|
|
Dirk Fauth wrote on Thu, 29 April 2021 03:29Single 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();
}
}
}
});
|
|
|
|
Powered by
FUDForum. Page generated in 0.03569 seconds