@Test void testCreateTable() { final Set<Pair<String, String>> data = Set.of(new Pair<>("foo(): String", "fooo"), new Pair<>("bar(): int", "1")); final TableView<Pair<String, String>> table = spoonCodeInstrument.createTable(data); assertThat(table).isNotNull(); assertThat(table.getColumns().size()).isEqualTo(2); assertThat(table.getColumns().get(0).getText()).isEqualTo("Name"); assertThat(table.getColumns().get(1).getText()).isEqualTo("Value"); assertThat(table.getItems()).isEqualTo(new ArrayList<>(data)); }
TableView<Pair<String, String>> createTable(final Set<Pair<String, String>> props) { final TableView<Pair<String, String>> table = new TableView<>(); final TableColumn<Pair<String, String>, String> colName = new TableColumn<>("Name"); final TableColumn<Pair<String, String>, String> colValue = new TableColumn<>("Value"); colName.setCellValueFactory(p -> new ReadOnlyObjectWrapper<>(p.getValue().getKey())); colValue.setCellValueFactory(p -> new ReadOnlyObjectWrapper<>(p.getValue().getValue())); table.getColumns().addAll(List.of(colName, colValue)); table.getColumns().forEach(col -> col.prefWidthProperty().bind(table.widthProperty().divide(table.getColumns().size()))); table.getItems().addAll(props); table.setMinHeight(props.size() * 30 + 40); table.setMaxHeight(table.getMinHeight()); table.setPrefHeight(table.getMinHeight()); final KeyCodeCombination keyCodeCopy = new KeyCodeCombination(KeyCode.C, KeyCombination.CONTROL_ANY); table.setOnKeyPressed(event -> { if (keyCodeCopy.match(event) && table.getSelectionModel().getSelectedItem() != null) { final Pair<String, String> item = table.getSelectionModel().getSelectedItem(); final ClipboardContent clipboardContent = new ClipboardContent(); clipboardContent.putString(item.getKey() + ": " + item.getValue()); Clipboard.getSystemClipboard().setContent(clipboardContent); } }); return table; }
SpoonCodeInstrument extends JfxInstrument implements Initializable { TableView<Pair<String, String>> createTable(final Set<Pair<String, String>> props) { final TableView<Pair<String, String>> table = new TableView<>(); final TableColumn<Pair<String, String>, String> colName = new TableColumn<>("Name"); final TableColumn<Pair<String, String>, String> colValue = new TableColumn<>("Value"); colName.setCellValueFactory(p -> new ReadOnlyObjectWrapper<>(p.getValue().getKey())); colValue.setCellValueFactory(p -> new ReadOnlyObjectWrapper<>(p.getValue().getValue())); table.getColumns().addAll(List.of(colName, colValue)); table.getColumns().forEach(col -> col.prefWidthProperty().bind(table.widthProperty().divide(table.getColumns().size()))); table.getItems().addAll(props); table.setMinHeight(props.size() * 30 + 40); table.setMaxHeight(table.getMinHeight()); table.setPrefHeight(table.getMinHeight()); final KeyCodeCombination keyCodeCopy = new KeyCodeCombination(KeyCode.C, KeyCombination.CONTROL_ANY); table.setOnKeyPressed(event -> { if (keyCodeCopy.match(event) && table.getSelectionModel().getSelectedItem() != null) { final Pair<String, String> item = table.getSelectionModel().getSelectedItem(); final ClipboardContent clipboardContent = new ClipboardContent(); clipboardContent.putString(item.getKey() + ": " + item.getValue()); Clipboard.getSystemClipboard().setContent(clipboardContent); } }); return table; } }
SpoonCodeInstrument extends JfxInstrument implements Initializable { TableView<Pair<String, String>> createTable(final Set<Pair<String, String>> props) { final TableView<Pair<String, String>> table = new TableView<>(); final TableColumn<Pair<String, String>, String> colName = new TableColumn<>("Name"); final TableColumn<Pair<String, String>, String> colValue = new TableColumn<>("Value"); colName.setCellValueFactory(p -> new ReadOnlyObjectWrapper<>(p.getValue().getKey())); colValue.setCellValueFactory(p -> new ReadOnlyObjectWrapper<>(p.getValue().getValue())); table.getColumns().addAll(List.of(colName, colValue)); table.getColumns().forEach(col -> col.prefWidthProperty().bind(table.widthProperty().divide(table.getColumns().size()))); table.getItems().addAll(props); table.setMinHeight(props.size() * 30 + 40); table.setMaxHeight(table.getMinHeight()); table.setPrefHeight(table.getMinHeight()); final KeyCodeCombination keyCodeCopy = new KeyCodeCombination(KeyCode.C, KeyCombination.CONTROL_ANY); table.setOnKeyPressed(event -> { if (keyCodeCopy.match(event) && table.getSelectionModel().getSelectedItem() != null) { final Pair<String, String> item = table.getSelectionModel().getSelectedItem(); final ClipboardContent clipboardContent = new ClipboardContent(); clipboardContent.putString(item.getKey() + ": " + item.getValue()); Clipboard.getSystemClipboard().setContent(clipboardContent); } }); return table; }  }
SpoonCodeInstrument extends JfxInstrument implements Initializable { TableView<Pair<String, String>> createTable(final Set<Pair<String, String>> props) { final TableView<Pair<String, String>> table = new TableView<>(); final TableColumn<Pair<String, String>, String> colName = new TableColumn<>("Name"); final TableColumn<Pair<String, String>, String> colValue = new TableColumn<>("Value"); colName.setCellValueFactory(p -> new ReadOnlyObjectWrapper<>(p.getValue().getKey())); colValue.setCellValueFactory(p -> new ReadOnlyObjectWrapper<>(p.getValue().getValue())); table.getColumns().addAll(List.of(colName, colValue)); table.getColumns().forEach(col -> col.prefWidthProperty().bind(table.widthProperty().divide(table.getColumns().size()))); table.getItems().addAll(props); table.setMinHeight(props.size() * 30 + 40); table.setMaxHeight(table.getMinHeight()); table.setPrefHeight(table.getMinHeight()); final KeyCodeCombination keyCodeCopy = new KeyCodeCombination(KeyCode.C, KeyCombination.CONTROL_ANY); table.setOnKeyPressed(event -> { if (keyCodeCopy.match(event) && table.getSelectionModel().getSelectedItem() != null) { final Pair<String, String> item = table.getSelectionModel().getSelectedItem(); final ClipboardContent clipboardContent = new ClipboardContent(); clipboardContent.putString(item.getKey() + ": " + item.getValue()); Clipboard.getSystemClipboard().setContent(clipboardContent); } }); return table; }  @Override void initialize(final URL url, final ResourceBundle res); }
SpoonCodeInstrument extends JfxInstrument implements Initializable { TableView<Pair<String, String>> createTable(final Set<Pair<String, String>> props) { final TableView<Pair<String, String>> table = new TableView<>(); final TableColumn<Pair<String, String>, String> colName = new TableColumn<>("Name"); final TableColumn<Pair<String, String>, String> colValue = new TableColumn<>("Value"); colName.setCellValueFactory(p -> new ReadOnlyObjectWrapper<>(p.getValue().getKey())); colValue.setCellValueFactory(p -> new ReadOnlyObjectWrapper<>(p.getValue().getValue())); table.getColumns().addAll(List.of(colName, colValue)); table.getColumns().forEach(col -> col.prefWidthProperty().bind(table.widthProperty().divide(table.getColumns().size()))); table.getItems().addAll(props); table.setMinHeight(props.size() * 30 + 40); table.setMaxHeight(table.getMinHeight()); table.setPrefHeight(table.getMinHeight()); final KeyCodeCombination keyCodeCopy = new KeyCodeCombination(KeyCode.C, KeyCombination.CONTROL_ANY); table.setOnKeyPressed(event -> { if (keyCodeCopy.match(event) && table.getSelectionModel().getSelectedItem() != null) { final Pair<String, String> item = table.getSelectionModel().getSelectedItem(); final ClipboardContent clipboardContent = new ClipboardContent(); clipboardContent.putString(item.getKey() + ": " + item.getValue()); Clipboard.getSystemClipboard().setContent(clipboardContent); } }); return table; }  @Override void initialize(final URL url, final ResourceBundle res);  }