Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8186904: TableColumnHeader: resize cursor lost on right click
Reviewed-by: aghaisas
  • Loading branch information
Maran23 authored and aghaisas committed May 18, 2021
1 parent 4619cdd commit e76b7b1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -267,13 +267,13 @@ public TableColumnHeader(final TableColumnBase tc) {
};

private static final EventHandler<MouseEvent> mouseReleasedHandler = me -> {
TableColumnHeader header = (TableColumnHeader) me.getSource();
header.getTableHeaderRow().columnDragLock = false;

if (me.isPopupTrigger()) return;
if (me.isConsumed()) return;
me.consume();

TableColumnHeader header = (TableColumnHeader) me.getSource();
header.getTableHeaderRow().columnDragLock = false;

if (header.getTableHeaderRow().isReordering() && header.isColumnReorderingEnabled()) {
header.columnReorderingComplete();
} else if (me.isStillSincePress()) {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -41,6 +41,10 @@ public static int getSortPos(TableColumnHeader header) {
return header.sortPos;
}

public static boolean getTableHeaderRowColumnDragLock(TableColumnHeader header) {
return header.getTableHeaderRow().columnDragLock;
}

public static TableColumnHeader getColumnHeaderFor(TableHeaderRow header, final TableColumnBase<?,?> col) {
return header.getColumnHeaderFor(col);
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -28,19 +28,24 @@
import com.sun.javafx.tk.Toolkit;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.skin.TableColumnHeader;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import org.junit.Before;
import org.junit.After;
import org.junit.Test;
import test.com.sun.javafx.scene.control.infrastructure.MouseEventFirer;
import test.com.sun.javafx.scene.control.infrastructure.StageLoader;
import test.com.sun.javafx.scene.control.infrastructure.VirtualFlowTestUtils;
import test.com.sun.javafx.scene.control.test.Person;
import javafx.scene.control.skin.TableColumnHeaderShim;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class TableColumnHeaderTest {
Expand Down Expand Up @@ -82,6 +87,44 @@ public void after() {
sl.dispose();
}

/**
* When a right click is done on a table column header, the column drag lock should be set to true in the
* pressed handler, but eventually to false again in the released handler.<br>
* By that we guarantee, that the column resizing still works.
*/
@Test
public void testColumnRightClickDoesAllowResizing() {
MouseEventFirer firer = new MouseEventFirer(firstColumnHeader);

assertFalse(TableColumnHeaderShim.getTableHeaderRowColumnDragLock(firstColumnHeader));

firer.fireMousePressed(MouseButton.SECONDARY);
assertTrue(TableColumnHeaderShim.getTableHeaderRowColumnDragLock(firstColumnHeader));

firer.fireMouseReleased(MouseButton.SECONDARY);
assertFalse(TableColumnHeaderShim.getTableHeaderRowColumnDragLock(firstColumnHeader));
}

/**
* When a right click is done on a table column header and consumed by a self added event handler, the column
* drag lock should be set to true in the pressed handler, but still to false again in the released handler.<br>
* By that we guarantee, that the column resizing still works.
*/
@Test
public void testColumnRightClickDoesAllowResizingWhenConsumed() {
firstColumnHeader.addEventHandler(MouseEvent.MOUSE_RELEASED, Event::consume);

MouseEventFirer firer = new MouseEventFirer(firstColumnHeader);

assertFalse(TableColumnHeaderShim.getTableHeaderRowColumnDragLock(firstColumnHeader));

firer.fireMousePressed(MouseButton.SECONDARY);
assertTrue(TableColumnHeaderShim.getTableHeaderRowColumnDragLock(firstColumnHeader));

firer.fireMouseReleased(MouseButton.SECONDARY);
assertFalse(TableColumnHeaderShim.getTableHeaderRowColumnDragLock(firstColumnHeader));
}

/**
* @test
* @bug 8207957
Expand Down

1 comment on commit e76b7b1

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.