This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 20e03deec7ffcc8c1dd9c1607c25b86f252124c7
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Fri Jan 15 00:02:47 2021 +0100

    Add a listener on `KeyEvent` for removing selected row.
---
 .../sis/internal/gui/control/ValueColorMapper.java      | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/control/ValueColorMapper.java
 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/control/ValueColorMapper.java
index fa8f611..1973ca3 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/control/ValueColorMapper.java
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/control/ValueColorMapper.java
@@ -27,6 +27,8 @@ import javafx.beans.property.SimpleObjectProperty;
 import javafx.beans.value.ObservableValue;
 import javafx.collections.ObservableList;
 import javafx.scene.paint.Color;
+import javafx.scene.input.KeyCode;
+import javafx.scene.input.KeyEvent;
 import javafx.scene.control.TableView;
 import javafx.scene.control.TableColumn;
 import javafx.scene.control.cell.CheckBoxTableCell;
@@ -327,6 +329,21 @@ public final class ValueColorMapper extends 
ColorColumnHandler<ValueColorMapper.
          */
         table.getItems().add(new Step());
         trigger.registerTo(table);
+        table.setOnKeyPressed(ValueColorMapper::deleteRow);
         return table;
     }
+
+    /**
+     * Invoked when user presses a key. If the key is "delete", then the 
current row is removed.
+     */
+    private static void deleteRow(final KeyEvent event) {
+        final TableView<?> table = (TableView<?>) event.getSource();
+        if (event.getCode() == KeyCode.DELETE) {
+            final int row = table.getSelectionModel().getSelectedIndex();
+            final ObservableList<?> items = table.getItems();
+            if (row >= 0 && row < items.size() - 1) {           // Do not 
delete last row, which is insertion row.
+                items.remove(row);
+            }
+        }
+    }
 }

Reply via email to