Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SpreadsheetView code to JavaFX 17 #1463

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f7eaf8f
Release v8.40.18
abhinayagarwal Nov 1, 2020
dc02f72
Upgrade version to 8.40.19-SNAPSHOT
Nov 1, 2020
cce2063
Remove VirtualFlow reflection methods in gridViewSkin
Maxoudela Feb 9, 2021
d292e6e
Update license, remove unused imports and jvm args
abhinayagarwal Feb 14, 2021
5f49d3f
Merge branch 'controlsfx:jfx-13' into jfx-13
Maxoudela May 28, 2021
e9e568c
Merge branch 'controlsfx:jfx-13' into jfx-13
Maxoudela Jul 9, 2021
7020100
Merge branch 'controlsfx:jfx-13' into jfx-13
Maxoudela Jul 22, 2021
ae18992
- Update code to be similar to OpenJFX 17 one.
Maxoudela Jul 26, 2021
246d898
Use WeakEventHandler for ContextMenu onShowing and onAction to avoid …
Maxoudela Aug 2, 2021
2595a4c
Rename scrollTo to scrollToTop in order to see rows that are scrolled…
Maxoudela Aug 2, 2021
8761dee
Re-activate resizing of several columns at once.
Maxoudela Aug 3, 2021
a6885c6
Merge branch 'master' of https://github.com/controlsfx/controlsfx int…
Maxoudela Aug 17, 2021
8eaf545
Key pressed to trigger edition is considered for first time edition.
Maxoudela Aug 17, 2021
c94d7b3
Apply CSS to cell before loading style in browser
Maxoudela Aug 18, 2021
949ad65
Refactor HorizontalPicker to avoid infinite loop by trying to reuse p…
Maxoudela Aug 20, 2021
c10e53f
Refactor VerticalHeader to avoid infinite loop by trying to reuse pic…
Maxoudela Sep 8, 2021
6faf618
Remove useless requestLayout methods
Maxoudela Sep 8, 2021
dc5d79f
Fix autofit for columns to use the GridViewSkin algorithm
Maxoudela Sep 22, 2021
0c1fce6
Update SpreadsheetView selection model in order to only scroll to sel…
Maxoudela Sep 24, 2021
991b6b2
Remove useless mouse click handler since key released is doing the tr…
Maxoudela Sep 24, 2021
94cd06b
Use a ConcurrentHashMap instead of a normal HashMap to avoid concurre…
Maxoudela Sep 27, 2021
51b7eef
Force the css to be applied before computing the height of a cell tha…
Maxoudela Sep 27, 2021
f78a63a
Register arrow movement instead of all keys for more precision for sc…
Maxoudela Oct 6, 2021
77655a6
Remove class selectors as they are not working anymore (the reason is…
Maxoudela Oct 20, 2021
ca52840
Using visibility instead of children size for retrieving the top row
Maxoudela Oct 20, 2021
7278780
Reduce the size of scrollBars inside Cell's TextArea with big fonts
Maxoudela Nov 5, 2021
ac77e88
Merge pull request #3 from controlsfx/jfx-13
Maxoudela Jan 14, 2022
179d723
Avoid NPE that can happen somehow on extreme case in GridRowSkin.
Maxoudela Jan 14, 2022
09eb1e7
Authorize to add a filter on a spanned cell (in column) (only one fi…
Maxoudela Jan 25, 2022
217189a
Refresh the TableView when resizing rows to update the scrollBars acc…
Maxoudela Jan 26, 2022
ae3d83c
Preventing tab and enter to be inserted in textArea editor when press…
Maxoudela Jan 27, 2022
06e3e43
Remove unnecessary left padding for JDK 17.
Maxoudela Jan 28, 2022
07b5638
Fix code for activate in GridVieBehavior: activate is allowed if no e…
Maxoudela Feb 4, 2022
a5e7dbd
Preventing memory leak in GridRow by using a weakMapListener.
Maxoudela Apr 5, 2022
be95200
Preventing constant layout in VirtualFlow when zooming.
Maxoudela Apr 5, 2022
25e97fa
Merge branch 'controlsfx:master' into sam-update-code-to-jfx17
Maxoudela May 3, 2022
dbc36be
Merge branch 'master' into sam-update-code-to-jfx17
Groostav Sep 20, 2022
8c0ac3c
Update gradle deps to jfx17
Groostav Sep 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2013, 2019 ControlsFX
* Copyright (c) 2013, 2021 ControlsFX
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -300,6 +300,8 @@ protected void layoutChildren() {
if (dirtyStyle && getItem().isCellGraphic()) {
CellGraphicFactory browserImpl = handle.getView().getCellGraphicFactory();
if (browserImpl != null) {
// When cell is re-used, the style does not seemed to be updated so we force it.
super.applyCss();
//Send the graphic only if it's the right type, otherwise send null.
Node node = getGraphic() != null && browserImpl.getType().isAssignableFrom(getGraphic().getClass()) ? getGraphic() : null;
browserImpl.loadStyle(node, getItem(), getFont(), getTextFill(), getAlignment(), getBackground());
Expand Down
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2013, 2015 ControlsFX
* Copyright (c) 2013, 2021 ControlsFX
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -190,6 +190,10 @@ void startEdit() {

if (editor != null) {
viewCell.setGraphic(editor);
// If the Control has not its skin, we force it. Otherwise the pressed key that triggers edition is not considered
if (editor.getSkin() == null) {
editor.applyCss();
}
editor.setMaxHeight(maxHeight);
editor.setPrefWidth(viewCell.getWidth());
}
Expand Down
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2013, 2016 ControlsFX
* Copyright (c) 2013, 2022 ControlsFX
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -33,6 +33,7 @@
import javafx.beans.property.SimpleDoubleProperty;
import javafx.collections.MapChangeListener;
import javafx.collections.ObservableList;
import javafx.collections.WeakMapChangeListener;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.event.WeakEventHandler;
Expand Down Expand Up @@ -82,17 +83,7 @@ public GridRow(SpreadsheetHandle handle) {
/**
* When the height is changing elsewhere, we need to update ourself if necessary.
*/
handle.getCellsViewSkin().rowHeightMap.addListener(new MapChangeListener<Integer, Double>() {

@Override
public void onChanged(MapChangeListener.Change<? extends Integer, ? extends Double> change) {
if (change.wasAdded() && change.getKey() == handle.getView().getModelRow(getIndex())) {
setRowHeight(change.getValueAdded());
} else if (change.wasRemoved() && change.getKey() == handle.getView().getModelRow(getIndex())) {
setRowHeight(computePrefHeight(-1));
}
}
});
handle.getCellsViewSkin().rowHeightMap.addListener(weakRowHeightListener);
/**
* When we are adding deported cells (fixed in columns) into a row via
* addCell. The cell is not receiving the DRAG_DETECTED eventHandler
Expand Down Expand Up @@ -131,7 +122,20 @@ protected double computeMinHeight(double width) {
protected Skin<?> createDefaultSkin() {
return new GridRowSkin(handle, this);
}


private final MapChangeListener<Integer, Double> rowHeightListener = new MapChangeListener<Integer, Double>() {

@Override
public void onChanged(MapChangeListener.Change<? extends Integer, ? extends Double> change) {
if (change.wasAdded() && change.getKey() == handle.getView().getModelRow(getIndex())) {
setRowHeight(change.getValueAdded());
} else if (change.wasRemoved() && change.getKey() == handle.getView().getModelRow(getIndex())) {
setRowHeight(computePrefHeight(-1));
}
}
};
private final WeakMapChangeListener weakRowHeightListener = new WeakMapChangeListener<>(rowHeightListener);

private final InvalidationListener setPrefHeightListener = new InvalidationListener() {

@Override
Expand Down
295 changes: 139 additions & 156 deletions controlsfx/src/main/java/impl/org/controlsfx/spreadsheet/GridRowSkin.java

Large diffs are not rendered by default.

@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015 ControlsFX All rights reserved.
* Copyright (c) 2015, 2022 ControlsFX All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: *
Expand Down Expand Up @@ -33,6 +33,8 @@
import javafx.scene.control.TablePositionBase;
import javafx.scene.control.TableSelectionModel;
import javafx.scene.control.TableView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.util.Pair;
import org.controlsfx.control.spreadsheet.SpreadsheetCell;

Expand Down Expand Up @@ -494,6 +496,14 @@ private int findPreviousColumn(TablePositionBase focusedCell, SpreadsheetCell ce
return 0;
}

@Override
protected void activate(KeyEvent e) {
// If we are currently editing, do not trigger another edition (for enter, cell below will start edition otherwise)
if (!KeyCode.ENTER.equals(e.getCode()) && skin.getSkinnable().getEditingCell() == null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I this PR is compatible with JDK 13/11, this code needs to be checked because I don't know if that behavior was specific to JDK 17 or not.

Copy link
Author

@Groostav Groostav Oct 11, 2022

Choose a reason for hiding this comment

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

I compiled the library with java 17 targeting java 11, and than ran it under java 11. I opened the speadsheet view, edited some cells, used the enter and tab keys.

Given:
this method is called through the KeyMapping's specified in TableViewBehaviorBase

enterKeyActivateMapping = new KeyMapping(ENTER, this::activate),
new KeyMapping(SPACE, this::activate),
new KeyMapping(F2, this::activate),

two test paths:

  • activate key event:
    1. select an editable cell (without beginning an edit and triggering the creation of a custom editable control. To do this i clicked on an uneditable column title and used the arrow keys to select control's FX's employee count)
    2. press f2
      • on java 11: event is passed to super; text is highlighted
      • on java 17: exact same behaviour
  • filtered key event:
    1. double click an editable cell, type new value
    2. hit enter
      • on java 11: event is filtered from super; value is committed and subseuent column cell is selected
      • on java 17: exact same behaviour

super.activate(e);
}
}

/**
* Cell is empty if there's nothing in it or if we have a NaN instead of a
* proper Double.
Expand Down