Explorar el Código

Minor changes

TableSelectionModel: removed useless clearSelection call.

MFXComboBoxSkin: fixed popup not closing on double click.

MFXTableViewSkin: refactored updateSelection method.
Signed-off-by: PAlex404 <alessandro.parisi406@gmail.com>
PAlex404 hace 4 años
padre
commit
952a59dd7c

+ 0 - 1
materialfx/src/main/java/io/github/palexdev/materialfx/selection/TableSelectionModel.java

@@ -55,7 +55,6 @@ public class TableSelectionModel<T> implements ITableSelectionModel<T> {
     @SuppressWarnings("unchecked")
     protected void select(MFXTableRow<T> item) {
         if (!allowsMultipleSelection) {
-            clearSelection();
             selectedItems.setAll(item);
         } else {
             selectedItems.add(item);

+ 5 - 0
materialfx/src/main/java/io/github/palexdev/materialfx/skins/MFXComboBoxSkin.java

@@ -175,6 +175,11 @@ public class MFXComboBoxSkin<T> extends SkinBase<MFXComboBox<T>> {
                 return;
             }
             if (event.getClickCount() >= 2 && event.getClickCount() % 2 == 0) {
+                if (popup.isShowing()) {
+                    icon.getRippleGenerator().createRipple();
+                    popup.hide();
+                    return;
+                }
                 NodeUtils.fireDummyEvent(icon);
             }
         });

+ 16 - 9
materialfx/src/main/java/io/github/palexdev/materialfx/skins/MFXTableViewSkin.java

@@ -28,6 +28,7 @@ import io.github.palexdev.materialfx.effects.RippleGenerator;
 import io.github.palexdev.materialfx.filter.IFilterable;
 import io.github.palexdev.materialfx.filter.MFXFilterDialog;
 import io.github.palexdev.materialfx.font.MFXFontIcon;
+import io.github.palexdev.materialfx.selection.ITableSelectionModel;
 import io.github.palexdev.materialfx.utils.DragResizer;
 import io.github.palexdev.materialfx.utils.NodeUtils;
 import javafx.animation.KeyFrame;
@@ -498,28 +499,34 @@ public class MFXTableViewSkin<T> extends SkinBase<MFXTableView<T>> {
     }
 
     /**
-     * Gets the selected rows from the selection model, gets the selected items from that list,
-     * gets the row nodes in the rowsContainer, if the selected items contains the row item
+     * Gets the selected items from that list, gets the row nodes in the rowsContainer,
+     * if the selected items contains the row item
      * them the reference in the model is updated.
      */
     @SuppressWarnings("unchecked")
     private void updateSelection() {
         MFXTableView<T> tableView = getSkinnable();
+        ITableSelectionModel<T> selectionModel = tableView.getSelectionModel();
 
-        List<MFXTableRow<T>> selectedRows = tableView.getSelectionModel().getSelectedRows();
-        List<T> selectedItems = selectedRows.stream().map(MFXTableRow::getItem).collect(Collectors.toList());
-        List<MFXTableRow<T>> shownRows = rowsContainer.getChildren().stream()
-                .filter(node -> node instanceof MFXTableRow)
-                .map(node -> (MFXTableRow<T>) node)
+        List<T> selectedItems = selectionModel.getSelectedRows().stream()
+                .map(MFXTableRow::getItem)
                 .collect(Collectors.toList());
 
         if (selectedItems.isEmpty()) {
             return;
         }
+
+        List<MFXTableRow<T>> shownRows = rowsContainer.getChildren().stream()
+                .filter(node -> node instanceof MFXTableRow)
+                .map(node -> (MFXTableRow<T>) node)
+                .collect(Collectors.toList());
+
         for (MFXTableRow<T> row : shownRows) {
             if (selectedItems.contains(row.getItem())) {
-                int index = selectedItems.indexOf(row.getItem());
-                tableView.getSelectionModel().getSelectedRows().set(index, row);
+                selectionModel.getSelectedRows().set(
+                        selectedItems.indexOf(row.getItem()),
+                        row
+                );
             }
         }
     }