Merge remote-tracking branch

'origin/GP-5618-dragonmacher-table-popup-fix--SQUASHED' (Closes #7902)
This commit is contained in:
Ryan Kurtz 2025-04-28 14:14:43 -04:00
commit fb54675cfc
4 changed files with 35 additions and 7 deletions

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -166,6 +166,7 @@ public class DockableComponent extends JPanel implements ContainerListener {
if (e.isPopupTrigger() && withinBounds) { if (e.isPopupTrigger() && withinBounds) {
PopupMenuContext popupContext = new PopupMenuContext(e); PopupMenuContext popupContext = new PopupMenuContext(e);
actionMgr.showPopupMenu(placeholder, popupContext); actionMgr.showPopupMenu(placeholder, popupContext);
e.consume();
} }
} }
@ -328,8 +329,27 @@ public class DockableComponent extends JPanel implements ContainerListener {
} }
if (comp.isFocusable()) { if (comp.isFocusable()) {
comp.removeMouseListener(popupListener); installPopupListenerFirst(comp);
comp.addMouseListener(popupListener); }
}
/**
* Remove and re-add all mouse listeners so our popup listener can go first. This allows our
* popup listener to consume the event, preventing Java UI listeners from changing the table
* selection when the user is performing a Ctrl-Mouse click on the Mac.
*
* @param comp the component
*/
private void installPopupListenerFirst(Component comp) {
comp.removeMouseListener(popupListener);
MouseListener[] listeners = comp.getMouseListeners();
for (MouseListener l : listeners) {
comp.removeMouseListener(l);
}
comp.addMouseListener(popupListener);
for (MouseListener l : listeners) {
comp.addMouseListener(l);
} }
} }

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

View file

@ -104,7 +104,7 @@ public class GTable extends JTable {
private MouseListener selectRowListener = new MouseAdapter() { private MouseListener selectRowListener = new MouseAdapter() {
@Override @Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) { if (e.isPopupTrigger()) {
int row = rowAtPoint(e.getPoint()); int row = rowAtPoint(e.getPoint());
if (row >= 0) { if (row >= 0) {
if (!isRowSelected(row)) { if (!isRowSelected(row)) {

View file

@ -1734,6 +1734,14 @@ public class GTree extends JPanel implements BusyListener {
} }
} }
@Override
public synchronized MouseListener[] getMouseListeners() {
if (mouseListenerDelegate == null) {
return super.getMouseListeners();
}
return mouseListenerDelegate.getMouseListeners();
}
@Override @Override
public void removeSelectionPath(TreePath path) { public void removeSelectionPath(TreePath path) {
// Called by the UI to add/remove selections--mark it as a user event. // Called by the UI to add/remove selections--mark it as a user event.