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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 9b61484935 Make the window title editable. When user double-clicks on 
a row, move the referenced window to front.
9b61484935 is described below

commit 9b6148493571c7b805be8afd3d8e1945427276f7
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Sat Jun 4 19:25:33 2022 +0200

    Make the window title editable.
    When user double-clicks on a row, move the referenced window to front.
---
 .../apache/sis/gui/coverage/CoverageStyling.java   |  1 +
 .../internal/gui/control/ColorColumnHandler.java   |  2 -
 .../sis/internal/gui/control/SyncWindowList.java   | 46 +++++++++++++++++++---
 .../sis/internal/gui/control/TabularWidget.java    | 19 +++++++++
 4 files changed, 60 insertions(+), 8 deletions(-)

diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageStyling.java
 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageStyling.java
index 392f4b3341..7ffdc2f703 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageStyling.java
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageStyling.java
@@ -207,6 +207,7 @@ final class CoverageStyling extends 
ColorColumnHandler<Category> implements Func
         final MenuItem reset = new 
MenuItem(resources.getString(Resources.Keys.ClearAll));
         reset.setOnAction((e) -> clear(table.getItems()));
         table.setContextMenu(new ContextMenu(reset));
+        table.setEditable(true);
         return table;
     }
 
diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/control/ColorColumnHandler.java
 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/control/ColorColumnHandler.java
index 60b6c90016..7454bebb6d 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/control/ColorColumnHandler.java
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/control/ColorColumnHandler.java
@@ -105,7 +105,6 @@ public abstract class ColorColumnHandler<S> implements 
Callback<TableColumn.Cell
 
     /**
      * Adds a colors column to the specified table.
-     * This method also modifies the table configuration.
      *
      * @param  table   the table where to add a colors column.
      * @param  header  column title to show in header row. This is typically 
"Color" or "Colors".
@@ -142,6 +141,5 @@ public abstract class ColorColumnHandler<S> implements 
Callback<TableColumn.Cell
             }
         });
         table.getColumns().add(colors);
-        table.setEditable(true);
     }
 }
diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/control/SyncWindowList.java
 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/control/SyncWindowList.java
index dfc5c6a281..f909394c9f 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/control/SyncWindowList.java
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/control/SyncWindowList.java
@@ -22,8 +22,9 @@ import javafx.beans.property.SimpleBooleanProperty;
 import javafx.collections.ListChangeListener;
 import javafx.collections.ObservableList;
 import javafx.scene.control.Button;
-import javafx.scene.control.TableColumn;
+import javafx.scene.control.TableRow;
 import javafx.scene.control.TableView;
+import javafx.scene.input.MouseEvent;
 import javafx.scene.layout.Priority;
 import javafx.scene.layout.Region;
 import javafx.scene.layout.VBox;
@@ -123,13 +124,12 @@ public final class SyncWindowList extends TabularWidget 
implements ListChangeLis
         newWindow.setMaxWidth(Double.MAX_VALUE);
         /*
          * The first column contains a checkbox for choosing whether the 
window should be followed or not.
-         * Header text is 🔗 (link symbol).
          */
-        final TableColumn<Link,Boolean> linked = 
newBooleanColumn("\uD83D\uDD17", (cell) -> cell.getValue().linked);
-        final TableColumn<Link,String> name = new 
TableColumn<>(vocabulary.getString(Vocabulary.Keys.Title));
-        name.setCellValueFactory((cell) -> cell.getValue().view.title);
-        table.getColumns().setAll(linked, name);
+        table.getColumns().setAll(
+                newBooleanColumn(/* 🔗 (link symbol) */  "\uD83D\uDD17",      
(cell) -> cell.getValue().linked),
+                newStringColumn (vocabulary.getString(Vocabulary.Keys.Title), 
(cell) -> cell.getValue().view.title));
         table.getItems().setAll(Link.wrap(owner.manager.windows, owner));
+        table.setRowFactory(SyncWindowList::newRow);
         /*
          * Build all other widget controls.
          */
@@ -144,6 +144,40 @@ public final class SyncWindowList extends TabularWidget 
implements ListChangeLis
         owner.manager.windows.addListener(this);
     }
 
+    /**
+     * Invoked when `TableView` needs to create a new row for rendering 
purpose.
+     * This is the place where to configure each {@code TableRow} instances.
+     *
+     * @param  table  the table which needs a new row.
+     * @return the new row.
+     */
+    private static TableRow<Link> newRow(final TableView<Link> table) {
+        TableRow<Link> row = new TableRow<>();
+        row.addEventFilter(MouseEvent.MOUSE_CLICKED, 
SyncWindowList::onMouseClicked);
+        return row;
+    }
+
+    /**
+     * Invoked when the user clicked on a cell of the row. We register this 
listener as a filter,
+     * e.g. this is invoked before the table row see the event, so we can 
prevent the event to be
+     * forwarded to the cell if desired.
+     */
+    private static void onMouseClicked(final MouseEvent event) {
+        if (event.getClickCount() == 2) {
+            final TableRow<?> row = (TableRow<?>) event.getSource();
+            final Link item = (Link) row.getItem();
+            item.view.show();
+            event.consume();
+            /*
+             * If the cell was already selected, the first click caused the 
cell to enter in editing mode
+             * before the second click is detected. We want to cancel the 
edition since we moved focus to
+             * another window. The javadoc for the following method said: 
"Note: This method will cancel
+             * editing if the given row value is less than zero and the given 
column is null."
+             */
+            row.getTableView().edit(-1, null);
+        }
+    }
+
     /**
      * Returns the encapsulated JavaFX component to add in a scene graph for 
making the table visible.
      * The {@code Region} subclass is implementation dependent and may change 
in any future SIS version.
diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/control/TabularWidget.java
 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/control/TabularWidget.java
index 1b204f5f8e..57b6b1a44c 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/control/TabularWidget.java
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/control/TabularWidget.java
@@ -22,6 +22,7 @@ import javafx.scene.control.TableColumn;
 import javafx.scene.control.TableColumn.CellDataFeatures;
 import javafx.scene.control.TableView;
 import javafx.scene.control.cell.CheckBoxTableCell;
+import javafx.scene.control.cell.TextFieldTableCell;
 import org.apache.sis.gui.Widget;
 
 
@@ -54,6 +55,7 @@ abstract class TabularWidget extends Widget {
     static <S> TableView<S> newTable() {
         TableView<S> table = new TableView<>();
         table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
+        table.setEditable(true);
         return table;
     }
 
@@ -77,4 +79,21 @@ abstract class TabularWidget extends Widget {
         c.setMaxWidth(CHECKBOX_WIDTH);
         return c;
     }
+
+    /**
+     * Creates a new column for a string value in a text field.
+     *
+     * @param  <S>      the type of objects contained within the {@link 
TableView} items list.
+     * @param  header   column header.
+     * @param  factory  link to the string property.
+     * @return a column for text field.
+     */
+    static <S> TableColumn<S,String> newStringColumn(final String header,
+            final Callback<CellDataFeatures<S,String>, 
ObservableValue<String>> factory)
+    {
+        final TableColumn<S,String> c = new TableColumn<>(header);
+        c.setCellFactory(TextFieldTableCell.forTableColumn());
+        c.setCellValueFactory(factory);
+        return c;
+    }
 }

Reply via email to