diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings index 60431ca1c588e96c3936b5f1a8105aa80148f0db..56b30adfc28222598e2493e05c234ae0550d6c3f 100644 --- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings @@ -1,8 +1,8 @@ -DynamicTextFieldTreeTableCell.java 7724630c17dada26e8d4063f3491757cdaeb8350 YELLOW +DynamicTextFieldTreeTableCell.java de24117e6f785b328f1ff62383626a0b4b54e8ff YELLOW DynamicTreeContentProviderBase.java 6760a6dc5721175b1dada8f30fd9da05f7bcc4b3 GREEN DynamicTreeItem.java 75dc5534b119ffdb3c10a65810c2a0f330b7955e GREEN DynamicTreeTableUIProviderBase.java f78c0f8b52fbc939166b3f94f7f6006cc0f4d32b GREEN -DynamicTreeTableViewer.java 5e58a31a63f8e56d8c8e69e2c4d095809bc46bf1 GREEN +DynamicTreeTableViewer.java ca3984b2fc404e3b37e409ce11859bcdc61aaf66 YELLOW DynamicTreeUIProviderBase.java e9b68607683de279d0cb8712a28dc131c5c33ece GREEN DynamicTreeViewer.java 725f41f4fb4b6bfa813f010fb9083ab02eea164a GREEN DynamicTreeViewerBase.java a2013538b62d86f6a09efdf2cd78babac2072484 GREEN diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTextFieldTreeTableCell.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTextFieldTreeTableCell.java index 7724630c17dada26e8d4063f3491757cdaeb8350..de24117e6f785b328f1ff62383626a0b4b54e8ff 100644 --- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTextFieldTreeTableCell.java +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTextFieldTreeTableCell.java @@ -57,7 +57,9 @@ public class DynamicTextFieldTreeTableCell<T> extends TextFieldTreeTableCell<T, this.setOnKeyPressed(event -> { if(event.getCode().equals(KeyCode.ESCAPE)) { - escapePressed = true; + if(currentlyEditedElement != null) { + escapePressed = true; + } } }); } diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableViewer.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableViewer.java index 5e58a31a63f8e56d8c8e69e2c4d095809bc46bf1..ca3984b2fc404e3b37e409ce11859bcdc61aaf66 100644 --- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableViewer.java +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableViewer.java @@ -16,8 +16,14 @@ package org.fortiss.tooling.common.ui.javafx.control.treetableview; import static java.lang.Integer.MAX_VALUE; +import static javafx.collections.FXCollections.observableArrayList; +import static javafx.scene.control.cell.ComboBoxTreeTableCell.forTreeTableColumn; + +import java.util.Collection; +import java.util.function.Function; import javafx.beans.property.SimpleObjectProperty; +import javafx.collections.ObservableList; import javafx.scene.control.SelectionMode; import javafx.scene.control.TreeItem; import javafx.scene.control.TreeTableColumn; @@ -165,6 +171,41 @@ public final class DynamicTreeTableViewer<T> extends DynamicTreeViewerBase<T> { return column; } + /** + * Adds a column with Combo editing support to the view. The labels, context menus and + * icons are shown as defined in the {@link DynamicTreeTableUIProviderBase}. + * + * @param headerLabel + * The Label for the column header. + * @param prefWidth + * The preferred width of the new column in px. + * @param comboValueFactory + * A Function, that maps cell elements to choices for the combo box. + * + * @return The newly created an configured column. + */ + public TreeTableColumn<T, String> addComboColumn(String headerLabel, int prefWidth, + Function<T, Collection<String>> comboValueFactory) { + TreeTableColumn<T, String> column = addColumn(headerLabel, prefWidth); + + // The list with the choices to be offered in the combo. + ObservableList<String> items = observableArrayList(); + column.setCellFactory(forTreeTableColumn(items)); + + // Changes the choices of the combo for every editing of every cell dynamically. + column.setOnEditStart(event -> { + TreeItem<T> treeItem = event.getRowValue(); + T rowEntry = treeItem.getValue(); + + Collection<String> comboValues = comboValueFactory.apply(rowEntry); + + items.clear(); + items.addAll(comboValues); + }); + + return column; + } + /** * Adds a column to the table part of the view. The labels, context menus and icons are shown as * defined in the {@link DynamicTreeTableUIProviderBase}.