下面列出了怎么用javafx.scene.control.SelectionMode的API类实例代码及写法,或者点击链接到github查看源代码。
public NameListPane() {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/preference/NameListPane.fxml"), bundle);
loader.setRoot(this);
loader.setController(this);
try {
loader.load();
}
catch (Exception ex) {
LOG.log(Level.SEVERE, "Unable to load FXML", ex);
}
listName.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
listName.setCellFactory(TextFieldListCell.forListView());
listName.setOnEditCommit((EventHandler<ListView.EditEvent<String>>) t -> {
listName.getItems().set(t.getIndex(), t.getNewValue());
listName.getSelectionModel().clearAndSelect(t.getIndex());
});
}
public TableVisualisation(final AbstractTableTranslator<? extends AnalyticResult<?>, C> translator) {
this.translator = translator;
this.tableVisualisation = new VBox();
this.tableFilter = new TextField();
tableFilter.setPromptText("Type here to filter results");
this.table = new TableView<>();
table.setPlaceholder(new Label("No results"));
table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
table.setId("table-visualisation");
table.setPadding(new Insets(5));
tableVisualisation.getChildren().addAll(tableFilter, table);
}
private ListView<Object> createListView(final AttributeData attribute, final ObservableList<Object> listData) {
final ListView<Object> newList = new ListView<>(listData);
newList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
newList.setCellFactory((ListView<Object> p) -> new AttributeValueCell(attribute.getDataType()));
addCopyHandlersToListView(newList, attribute);
newList.addEventFilter(KeyEvent.KEY_PRESSED, (KeyEvent event) -> {
if (event.isShortcutDown() && (event.getCode() == KeyCode.C)) {
copySelectedItems(newList, attribute.getDataType());
event.consume();
} else if (event.isShortcutDown() && (event.getCode() == KeyCode.A)) {
event.consume();
}
});
return newList;
}
public FeatureTableFX() {
// add dummy root
TreeItem<ModularFeatureListRow> root = new TreeItem<>();
root.setExpanded(true);
this.setRoot(root);
this.setShowRoot(false);
this.setTableMenuButtonVisible(true);
this.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
this.getSelectionModel().setCellSelectionEnabled(true);
setTableEditable(true);
/*getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
int io = getRoot().getChildren().indexOf(oldValue);
int in = getRoot().getChildren().indexOf(newValue);
});*/
parameters = MZmineCore.getConfiguration().getModuleParameters(FeatureTableFXModule.class);
rowTypesParameter = parameters.getParameter(FeatureTableFXParameters.showRowTypeColumns);
featureTypesParameter = parameters
.getParameter(FeatureTableFXParameters.showFeatureTypeColumns);
rowItems = FXCollections.observableArrayList();
filteredRowItems = new FilteredList<>(rowItems);
columnMap = new HashMap<>();
}
public void initialize() {
requestName.setText(request.getName());
List<String> collectionNames = getCollectionStrings();
FilteredList<String> filteredList = new FilteredList<String>(FXCollections.observableList(collectionNames));
collectionName.textProperty().addListener(obs-> {
String filter = collectionName.getText();
if(filter == null || filter.length() == 0) {
Platform.runLater(() -> filteredList.setPredicate(s -> true));
}
else {
Platform.runLater(() -> filteredList.setPredicate(s -> StringUtils.containsLettersInOrder(s, filter)));
}
});
collectionList.setItems(filteredList);
collectionList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
collectionList.getSelectionModel().selectedItemProperty().addListener((obs, o, n) -> {
if (n != null && n.length() > 0)
collectionName.setText(n);
});
}
public ElevantoPlanDialog(ElevantoImportDialog importDlg, JSONObject plan) {
importDialog = importDlg;
planJSON = plan;
try {
FXMLLoader loader = new FXMLLoader();
loader.setController(this);
loader.setResources(LabelGrabber.INSTANCE);
Parent root = loader.load(getClass().getResourceAsStream("PlanningCenterOnlinePlanDialog.fxml"));
setCenter(root);
planView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
enablePlanProgressBars(false);
LOGGER.log(Level.INFO, "Initialised dialog, updating view");
updateView();
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Error", e);
}
}
public PlanningCenterOnlinePlanDialog(PlanningCenterOnlineImportDialog importDlg, Plan plan, List<Item> planItems) {
importDialog = importDlg;
this.plan = plan;
this.planItems = planItems;
try {
FXMLLoader loader = new FXMLLoader();
loader.setController(this);
loader.setResources(LabelGrabber.INSTANCE);
Parent root = loader.load(getClass().getResourceAsStream("PlanningCenterOnlinePlanDialog.fxml"));
setCenter(root);
planView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
enablePlanProgressBars(false);
LOGGER.log(Level.INFO, "Initialised dialog, updating view");
updateView();
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Error", e);
}
}
public BattleOfDecksConfigView() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/BattleOfDecksConfigView.fxml"));
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
try {
fxmlLoader.load();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
setupBehaviourBox();
setupNumberOfGamesBox();
selectedDecksListView.setCellFactory(TextFieldListCell.forListView(new DeckStringConverter()));
selectedDecksListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
availableDecksListView.setCellFactory(TextFieldListCell.forListView(new DeckStringConverter()));
availableDecksListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
addButton.setOnAction(this::handleAddButton);
removeButton.setOnAction(this::handleRemoveButton);
backButton.setOnAction(event -> NotificationProxy.sendNotification(GameNotification.MAIN_MENU));
startButton.setOnAction(this::handleStartButton);
}
void loadEpisodes(EpisodeList episodesTmp) {
Platform.runLater(() -> {
episodes.setAll(episodesTmp.episodes());
episodeList = new ListView<>();
episodeList.setItems(episodes);
episodeList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
episodeList.setOnMouseClicked(event -> {
int selSize = episodeList.getSelectionModel().getSelectedIndices().size();
this.setCheckBoxStatus(selSize, episodes.size());
});
});
Platform.runLater(() -> {
VBox.setVgrow(episodeList, Priority.ALWAYS);
episodeBox.getChildren().setAll(episodeList);
});
}
private void createContextMenu()
{
// Publish selected items as PV
final ListChangeListener<PVInfo> sel_changed = change ->
{
final List<ProcessVariable> pvs = change.getList()
.stream()
.map(info -> new ProcessVariable(info.name.get()))
.collect(Collectors.toList());
SelectionService.getInstance().setSelection(PVListApplication.DISPLAY_NAME, pvs);
};
table.getSelectionModel().getSelectedItems().addListener(sel_changed);
table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
// Context menu with selection-based entries, i.e. PV contributions
final ContextMenu menu = new ContextMenu();
table.setOnContextMenuRequested(event ->
{
menu.getItems().clear();
ContextMenuHelper.addSupportedEntries(table, menu);
menu.show(table.getScene().getWindow());
});
table.setContextMenu(menu);
}
public PreferenceTableView() {
getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
setPrefHeight(100);
setEditable(false);
TableColumn<BrowserPreference, String> colName = new TableColumn<>("Name");
colName.setCellValueFactory(new PropertyValueFactory<>("name"));
colName.prefWidthProperty().bind(widthProperty().multiply(0.5));
TableColumn<BrowserPreference, String> colType = new TableColumn<>("Type");
colType.setCellValueFactory(new PropertyValueFactory<>("type"));
colType.prefWidthProperty().bind(widthProperty().multiply(0.20));
TableColumn<BrowserPreference, String> colValue = new TableColumn<>("Value");
colValue.setCellValueFactory(new PropertyValueFactory<>("value"));
colValue.prefWidthProperty().bind(widthProperty().multiply(0.25));
getColumns().add(colName);
getColumns().add(colType);
getColumns().add(colValue);
}
@SuppressWarnings("unchecked")
@Test
public void selectAllCells() {
TreeTableView<?> treeTableNode = (TreeTableView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-table-view");
Platform.runLater(() -> {
TreeTableViewSelectionModel<?> selectionModel = treeTableNode.getSelectionModel();
selectionModel.setCellSelectionEnabled(true);
selectionModel.setSelectionMode(SelectionMode.MULTIPLE);
selectionModel.selectRange(0, getTreeTableColumnAt(treeTableNode, 0), treeTableNode.getExpandedItemCount() - 1,
getTreeTableColumnAt(treeTableNode, 1));
treeTable.marathon_select("all");
});
new Wait("Waiting for all cells to be selected") {
@Override
public boolean until() {
return treeTableNode.getSelectionModel().getSelectedCells().size() == treeTableNode.getExpandedItemCount()
* treeTableNode.getColumns().size();
}
};
}
@Test
public void selectMultipleCells() {
TreeTableView<?> treeTableNode = (TreeTableView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-table-view");
Platform.runLater(() -> {
TreeTableViewSelectionModel<?> selectionModel = treeTableNode.getSelectionModel();
selectionModel.setSelectionMode(SelectionMode.MULTIPLE);
selectionModel.setCellSelectionEnabled(true);
treeTable.marathon_select(
"{\"cells\":[[\"/Sales Department/Ethan Williams\",\"Employee\"],[\"/Sales Department/Michael Brown\",\"Email\"]]}");
});
new Wait("Waiting for cells to be selected") {
@Override
public boolean until() {
return treeTableNode.getSelectionModel().getSelectedCells().size() == 2;
}
};
}
@Test
public void getText() {
TreeTableView<?> treeTableNode = (TreeTableView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-table-view");
List<String> text = new ArrayList<>();
Platform.runLater(() -> {
treeTableNode.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
treeTable.marathon_select("{\"rows\":[\"/Sales Department/Emma Jones\",\"/Sales Department/Anna Black\"]}");
text.add(treeTable.getAttribute("text"));
});
new Wait("Waiting for tree table text.") {
@Override
public boolean until() {
return text.size() > 0;
}
};
AssertJUnit.assertEquals("{\"rows\":[\"/Sales Department/Emma Jones\",\"/Sales Department/Anna Black\"]}", text.get(0));
}
@Test
public void getText() {
TreeTableView<?> treeTableNode = (TreeTableView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-table-view");
List<String> text = new ArrayList<>();
Platform.runLater(() -> {
treeTableNode.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
treeTable.marathon_select("{\"rows\":[\"/Sales Department/Emma Jones\",\"/Sales Department/Anna Black\"]}");
text.add(treeTable.getAttribute("text"));
});
new Wait("Waiting for tree table text.") {
@Override
public boolean until() {
return text.size() > 0;
}
};
AssertJUnit.assertEquals("{\"rows\":[\"/Sales Department/Emma Jones\",\"/Sales Department/Anna Black\"]}", text.get(0));
}
public ListViewCellFactorySample() {
final ListView<Number> listView = new ListView<Number>();
listView.setItems(FXCollections.<Number>observableArrayList(
100.00, -12.34, 33.01, 71.00, 23000.00, -6.00, 0, 42223.00, -12.05, 500.00,
430000.00, 1.00, -4.00, 1922.01, -90.00, 11111.00, 3901349.00, 12.00, -1.00, -2.00,
15.00, 47.50, 12.11
));
listView.setCellFactory(new Callback<ListView<java.lang.Number>, ListCell<java.lang.Number>>() {
@Override public ListCell<Number> call(ListView<java.lang.Number> list) {
return new MoneyFormatCell();
}
});
listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
getChildren().add(listView);
}
@Override
public void initialize(final URL location, final ResourceBundle resources) {
final ObservableList<TableColumn<Throwable, ?>> cols = table.getColumns();
((TableColumn<Throwable, String>) cols.get(0)).setCellValueFactory(cell -> new ReadOnlyStringWrapper(cell.getValue().toString()));
((TableColumn<Throwable, String>) cols.get(1)).setCellValueFactory(cell -> new ReadOnlyStringWrapper(cell.getValue().getMessage()));
((TableColumn<Throwable, String>) cols.get(2)).setCellValueFactory(cell -> {
final StackTraceElement[] stackTrace = cell.getValue().getStackTrace();
final String msg = stackTrace.length > 0 ? stackTrace[0].toString() : "";
return new ReadOnlyStringWrapper(msg);
});
cols.forEach(col -> col.prefWidthProperty().bind(table.widthProperty().divide(3)));
table.itemsProperty().bind(BadaboomCollector.INSTANCE.errorsProperty());
table.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
final Callable<String> converter = () -> {
final Throwable ex = table.getSelectionModel().getSelectedItem();
if(ex == null) {
return "";
}
return Arrays.stream(ex.getStackTrace()).map(Object::toString).collect(Collectors.joining("\n\tat ", ex.toString() + "\n\tat ", "")); //NON-NLS
};
stack.textProperty().bind(Bindings.createStringBinding(converter, table.getSelectionModel().selectedItemProperty()));
}
@Override
public void start(Stage primaryStage) throws Exception {
final ListView<String> listView = new ListView<String>();
listView.setItems(FXCollections.observableArrayList("Row 1", "Row 2", "Long Row 3", "Row 4", "Row 5", "Row 6", "Row 7",
"Row 8", "Row 9", "Row 10", "Row 11", "Row 12", "Row 13", "Row 14", "Row 15", "Row 16", "Row 17", "Row 18",
"Row 19", "Row 20", "Row 21", "Row 22", "Row 23", "Row 24", "Row 25"));
listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
Button button = new Button("Debug");
button.setOnAction((e) -> {
ObservableList<Integer> selectedIndices = listView.getSelectionModel().getSelectedIndices();
for (Integer index : selectedIndices) {
ListCell cellAt = getCellAt(listView, index);
System.out.println("SimpleListViewScrollSample.SimpleListViewScrollSampleApp.start(" + cellAt + ")");
}
});
VBox root = new VBox(listView, button);
primaryStage.setScene(new Scene(root, 300, 400));
primaryStage.show();
}
@Test
public void selectAllRows() {
TreeTableView<?> treeTableView = (TreeTableView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-table-view");
LoggingRecorder lr = new LoggingRecorder();
Platform.runLater(() -> {
treeTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
RFXTreeTableView rfxTreeTableView = new RFXTreeTableView(treeTableView, null, null, lr);
int count = treeTableView.getExpandedItemCount();
for (int i = 0; i < count; i++) {
treeTableView.getSelectionModel().select(i);
}
rfxTreeTableView.focusLost(null);
});
List<Recording> recordings = lr.waitAndGetRecordings(1);
Recording recording = recordings.get(0);
AssertJUnit.assertEquals("recordSelect", recording.getCall());
AssertJUnit.assertEquals("all", recording.getParameters()[0]);
}
@SuppressWarnings("unchecked")
@Test
public void selectAllCells() {
TreeTableView<?> treeTableView = (TreeTableView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-table-view");
LoggingRecorder lr = new LoggingRecorder();
Platform.runLater(() -> {
treeTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
RFXTreeTableView rfxTreeTableView = new RFXTreeTableView(treeTableView, null, null, lr);
int count = treeTableView.getExpandedItemCount();
treeTableView.getSelectionModel().selectRange(0, getTreeTableColumnAt(treeTableView, 0), count - 1,
getTreeTableColumnAt(treeTableView, 1));
rfxTreeTableView.focusLost(null);
});
List<Recording> recordings = lr.waitAndGetRecordings(1);
Recording recording = recordings.get(0);
AssertJUnit.assertEquals("recordSelect", recording.getCall());
AssertJUnit.assertEquals("all", recording.getParameters()[0]);
}
@Test
public void selectMulpitleRows() {
TableView<?> tableView = (TableView<?>) getPrimaryStage().getScene().getRoot().lookup(".table-view");
LoggingRecorder lr = new LoggingRecorder();
Platform.runLater(() -> {
tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
Point2D point = getPoint(tableView, 1, 1);
RFXTableView rfxTableView = new RFXTableView(tableView, null, point, lr);
rfxTableView.focusGained(null);
tableView.getSelectionModel().selectIndices(1, 3);
rfxTableView.focusLost(null);
});
List<Recording> recordings = lr.waitAndGetRecordings(1);
Recording recording = recordings.get(0);
AssertJUnit.assertEquals("recordSelect", recording.getCall());
AssertJUnit.assertEquals("{\"rows\":[1,3]}", recording.getParameters()[0]);
}
@SuppressWarnings("unchecked")
@Test
public void selectMultipleCells() {
TableView<?> tableView = (TableView<?>) getPrimaryStage().getScene().getRoot().lookup(".table-view");
LoggingRecorder lr = new LoggingRecorder();
Platform.runLater(() -> {
tableView.getSelectionModel().setCellSelectionEnabled(true);
tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
Point2D point = getPoint(tableView, 1, 1);
RFXTableView rfxTableView = new RFXTableView(tableView, null, point, lr);
rfxTableView.focusGained(null);
@SuppressWarnings("rawtypes")
TableColumn column = getTableColumnAt(tableView, 1);
tableView.getSelectionModel().select(1, column);
tableView.getSelectionModel().select(2, column);
rfxTableView.focusLost(null);
});
List<Recording> recordings = lr.waitAndGetRecordings(1);
Recording recording = recordings.get(0);
AssertJUnit.assertEquals("recordSelect", recording.getCall());
AssertJUnit.assertEquals("{\"cells\":[[\"1\",\"Last\"],[\"2\",\"Last\"]]}", recording.getParameters()[0]);
}
@SuppressWarnings("unchecked")
@Test
public void selectAllCells() {
TableView<?> tableView = (TableView<?>) getPrimaryStage().getScene().getRoot().lookup(".table-view");
LoggingRecorder lr = new LoggingRecorder();
Platform.runLater(() -> {
tableView.getSelectionModel().setCellSelectionEnabled(true);
tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
Point2D point = getPoint(tableView, 1, 1);
RFXTableView rfxTableView = new RFXTableView(tableView, null, point, lr);
rfxTableView.focusGained(null);
tableView.getSelectionModel().selectRange(0, getTableColumnAt(tableView, 0), 5, getTableColumnAt(tableView, 2));
rfxTableView.focusLost(null);
});
List<Recording> recordings = lr.waitAndGetRecordings(1);
Recording recording = recordings.get(0);
AssertJUnit.assertEquals("recordSelect", recording.getCall());
AssertJUnit.assertEquals("all", recording.getParameters()[0]);
}
@Test
public void getTextForMultipleSelection() {
ListView<?> listView = (ListView<?>) getPrimaryStage().getScene().getRoot().lookup(".list-view");
LoggingRecorder lr = new LoggingRecorder();
List<String> text = new ArrayList<>();
Platform.runLater(new Runnable() {
@Override
public void run() {
MultipleSelectionModel<?> selectionModel = listView.getSelectionModel();
selectionModel.setSelectionMode(SelectionMode.MULTIPLE);
selectionModel.selectIndices(2, 8);
RFXListView rfxListView = new RFXListView(listView, null, null, lr);
rfxListView.focusLost(new RFXListView(null, null, null, lr));
text.add(rfxListView.getAttribute("text"));
}
});
new Wait("Waiting for list text.") {
@Override
public boolean until() {
return text.size() > 0;
}
};
AssertJUnit.assertEquals("[\"Long Row 3\",\"Row 9\"]", text.get(0));
}
@Test
public void selectMultipleItemSelection() {
ListView<?> listView = (ListView<?>) getPrimaryStage().getScene().getRoot().lookup(".list-view");
LoggingRecorder lr = new LoggingRecorder();
Platform.runLater(new Runnable() {
@Override
public void run() {
MultipleSelectionModel<?> selectionModel = listView.getSelectionModel();
selectionModel.setSelectionMode(SelectionMode.MULTIPLE);
selectionModel.selectIndices(2, 6);
RFXListView rfxListView = new RFXListView(listView, null, null, lr);
rfxListView.focusLost(new RFXListView(null, null, null, lr));
}
});
List<Recording> recordings = lr.waitAndGetRecordings(1);
Recording recording = recordings.get(0);
AssertJUnit.assertEquals("recordSelect", recording.getCall());
AssertJUnit.assertEquals("[\"Long Row 3\",\"Row 7\"]", recording.getParameters()[0]);
}
/** @param model Model to represent. Must <u>not</u> be running, yet */
public AlarmTreeView(final AlarmClient model)
{
if (model.isRunning())
throw new IllegalStateException();
changing.setTextFill(Color.WHITE);
changing.setBackground(new Background(new BackgroundFill(Color.BLUE, CornerRadii.EMPTY, Insets.EMPTY)));
this.model = model;
tree_view.setShowRoot(false);
tree_view.setCellFactory(view -> new AlarmTreeViewCell());
tree_view.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
setTop(createToolbar());
setCenter(tree_view);
tree_view.setRoot(createViewItem(model.getRoot()));
model.addListener(this);
createContextMenu();
addClickSupport();
addDragSupport();
}
public TableViewPane(final TableViewTopComponent parent) {
this.parent = parent;
this.columnIndex = new CopyOnWriteArrayList<>();
this.elementIdToRowIndex = new HashMap<>();
this.rowToElementIdIndex = new HashMap<>();
this.lastChange = null;
final ToolBar toolbar = initToolbar();
setLeft(toolbar);
this.table = new TableView<>();
table.itemsProperty().addListener((v, o, n) -> table.refresh());
table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
table.setPadding(new Insets(5));
setCenter(table);
// TODO: experiment with caching
table.setCache(false);
this.progress = new BorderPane();
final ProgressIndicator progressIndicator = new ProgressIndicator();
progressIndicator.setMaxSize(50, 50);
progress.setCenter(progressIndicator);
this.tableSelectionListener = (v, o, n) -> {
if (parent.getCurrentState() != null && !parent.getCurrentState().isSelectedOnly()) {
TableViewUtilities.copySelectionToGraph(table, rowToElementIdIndex,
parent.getCurrentState().getElementType(), parent.getCurrentGraph());
}
};
this.selectedProperty = table.getSelectionModel().selectedItemProperty();
selectedProperty.addListener(tableSelectionListener);
this.scheduledExecutorService = Executors.newScheduledThreadPool(1);
}
public FilesList()
{
files.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
files.setCellFactory(list -> new FileCell());
final Node buttons = createButtons();
setSpacing(5);
getChildren().setAll(new Label(Messages.AttachedFiles), files, buttons);
setPadding(new Insets(5));
}
@Override
@FxThread
protected void createContent(@NotNull final GridPane root) {
super.createContent(root);
nodeTree = new ModelNodeTree(this::processSelect, null, SelectionMode.SINGLE);
nodeTree.prefHeightProperty().bind(heightProperty());
nodeTree.prefWidthProperty().bind(widthProperty());
root.add(nodeTree, 0, 0);
FXUtils.addClassTo(root, CssClasses.NODE_SELECTOR_DIALOG);
}
public ChartMeasurementSelector(final ParameterMeasurements plugin, final AbstractChartMeasurement dataSetMeasurement, final int requiredNumberOfChartMeasurements) {
super();
if (plugin == null) {
throw new IllegalArgumentException("plugin must not be null");
}
final Label label = new Label("Selected Measurement: ");
GridPane.setConstraints(label, 0, 0);
chartMeasurementListView = new ListView<>(plugin.getChartMeasurements().filtered(t -> !t.equals(dataSetMeasurement)));
GridPane.setConstraints(chartMeasurementListView, 1, 0);
chartMeasurementListView.setOrientation(Orientation.VERTICAL);
chartMeasurementListView.setPrefSize(-1, DEFAULT_SELECTOR_HEIGHT);
chartMeasurementListView.setCellFactory(list -> new ChartMeasurementLabel());
chartMeasurementListView.setPrefHeight(Math.max(2, plugin.getChartMeasurements().size()) * ROW_HEIGHT + 2.0);
MultipleSelectionModel<AbstractChartMeasurement> selModel = chartMeasurementListView.getSelectionModel();
if (requiredNumberOfChartMeasurements == 1) {
selModel.setSelectionMode(SelectionMode.SINGLE);
} else if (requiredNumberOfChartMeasurements >= 2) {
selModel.setSelectionMode(SelectionMode.MULTIPLE);
}
// add default initially selected ChartMeasurements
if (selModel.getSelectedIndices().isEmpty() && plugin.getChartMeasurements().size() >= requiredNumberOfChartMeasurements) {
for (int i = 0; i < requiredNumberOfChartMeasurements; i++) {
selModel.select(i);
}
}
if (selModel.getSelectedIndices().size() < requiredNumberOfChartMeasurements && LOGGER.isWarnEnabled()) {
LOGGER.atWarn().addArgument(plugin.getChartMeasurements().size()).addArgument(requiredNumberOfChartMeasurements).log("could not add default selection: required {} vs. selected {}");
}
if (requiredNumberOfChartMeasurements >= 1) {
getChildren().addAll(label, chartMeasurementListView);
}
}