Java 类javafx.scene.control.TableView.TableViewSelectionModel 实例源码
项目:marathonv5
文件:JavaFXElementPropertyAccessor.java
@SuppressWarnings("unchecked") public void selectCells(TableView<?> tableView, String value) {
@SuppressWarnings("rawtypes")
TableViewSelectionModel selectionModel = tableView.getSelectionModel();
selectionModel.clearSelection();
JSONObject cells = new JSONObject(value);
JSONArray object = (JSONArray) cells.get("cells");
for (int i = 0; i < object.length(); i++) {
JSONArray jsonArray = object.getJSONArray(i);
int rowIndex = Integer.parseInt(jsonArray.getString(0));
int columnIndex = getColumnIndex(jsonArray.getString(1));
@SuppressWarnings("rawtypes")
TableColumn column = tableView.getColumns().get(columnIndex);
if (getVisibleCellAt(tableView, rowIndex, columnIndex) == null) {
tableView.scrollTo(rowIndex);
tableView.scrollToColumn(column);
}
selectionModel.select(rowIndex, column);
}
}
项目:Gargoyle
文件:SqlMultiplePane.java
private void tableSelectCell() {
int starRowtIndex = startRowIndexProperty.get();
int endRowIndex = endRowIndexProperty.get();
int starColtIndex = startColIndexProperty.get();
int endColIndex = endColIndexProperty.get();
selectedTabAction(tbResult -> {
TableViewSelectionModel<Map<String, Object>> selectionModel = tbResult.getSelectionModel();
selectionModel.clearSelection();
if (starColtIndex == 0) {
selectionModel.selectRange(starRowtIndex, tbResult.getColumns().get(0), endRowIndex,
tbResult.getColumns().get(tbResult.getColumns().size() - 1));
} else {
selectionModel.selectRange(starRowtIndex, tbResult.getColumns().get(starColtIndex), endRowIndex,
tbResult.getColumns().get(endColIndex));
}
});
}
项目:Gargoyle
文件:SqlPane.java
private void tableSelectCell() {
int starRowtIndex = startRowIndexProperty.get();
int endRowIndex = endRowIndexProperty.get();
int starColtIndex = startColIndexProperty.get();
int endColIndex = endColIndexProperty.get();
TableViewSelectionModel<Map<String, Object>> selectionModel = tbResult.getSelectionModel();
selectionModel.clearSelection();
if (starColtIndex == 0) {
selectionModel.selectRange(starRowtIndex, tbResult.getColumns().get(0), endRowIndex,
tbResult.getColumns().get(tbResult.getColumns().size() - 1));
} else {
selectionModel.selectRange(starRowtIndex, tbResult.getColumns().get(starColtIndex), endRowIndex,
tbResult.getColumns().get(endColIndex));
}
}
项目:marathonv5
文件:ImagePanel.java
private static TextArea createTextArea(TableCell<Annotation, String> cell) {
TextArea textArea = new TextArea(cell.getItem() == null ? "" : cell.getItem());
textArea.setPrefRowCount(1);
textArea.setWrapText(true);
textArea.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override public void changed(ObservableValue<? extends Boolean> arg0, Boolean arg1, Boolean arg2) {
if (!textArea.isFocused() && cell.getItem() != null && cell.isEditing()) {
cell.commitEdit(textArea.getText());
}
cell.getTableView().getItems().get(cell.getIndex()).setText(textArea.getText());
}
});
textArea.addEventFilter(MouseEvent.MOUSE_CLICKED, (event) -> {
if (event.getClickCount() > 1) {
cell.getTableView().edit(cell.getTableRow().getIndex(), cell.getTableColumn());
} else {
TableViewSelectionModel<Annotation> selectionModel = cell.getTableView().getSelectionModel();
if (event.isControlDown()) {
if (selectionModel.isSelected(cell.getIndex())) {
selectionModel.clearSelection(cell.getIndex());
} else {
selectionModel.select(cell.getIndex());
}
} else {
selectionModel.clearAndSelect(cell.getIndex());
}
}
});
textArea.addEventFilter(KeyEvent.KEY_PRESSED, (event) -> {
if (event.getCode() == KeyCode.ENTER && event.isShiftDown() && cell.isEditing()) {
cell.commitEdit(textArea.getText());
cell.getTableView().getItems().get(cell.getIndex()).setText(textArea.getText());
event.consume();
}
if (event.getCode() == KeyCode.F2) {
cell.getTableView().edit(cell.getTableRow().getIndex(), cell.getTableColumn());
}
});
return textArea;
}
项目:marathonv5
文件:JavaFXTableViewElement.java
@Override public boolean marathon_select(String value) {
TableView<?> tableView = (TableView<?>) node;
TableViewSelectionModel<?> selectionModel = tableView.getSelectionModel();
if ("".equals(value)) {
selectionModel.clearSelection();
return true;
} else if (value.equals("all")) {
int rowSize = tableView.getItems().size();
for (int i = 0; i < rowSize; i++) {
selectionModel.select(i);
}
return true;
} else if (selectionModel.isCellSelectionEnabled()) {
selectCells(tableView, value);
return true;
} else {
int[] selectedRows = getSelectedRows(value);
selectionModel.clearSelection();
for (int rowIndex : selectedRows) {
if (getVisibleCellAt(tableView, rowIndex, tableView.getColumns().size() - 1) == null) {
tableView.scrollTo(rowIndex);
}
selectionModel.select(rowIndex);
}
return true;
}
}
项目:Gargoyle
文件:SqlPane.java
/**
*
* 새로운 로우를 추가하지만 선택된 행에 대산 값들도 복사한다.
*
*
* #### #### 값을 새롭게 추가한다음에 그 값에대한 값을 변경하는 형태로 로직구성이되야한다.
*
* @작성자 : KYJ
* @작성일 : 2017. 7. 16.
* @param e
*/
public void rowCopyOnAction(ActionEvent e) {
TableViewSelectionModel<Map<ColumnExpression, ObjectProperty<ValueExpression>>> selectionModel = this.editableComposite
.getSelectionModel();
Map<ColumnExpression, ObjectProperty<ValueExpression>> selectedItem = selectionModel.getSelectedItem();
if (selectedItem != null && !selectedItem.isEmpty()) {
Map<ColumnExpression, ObjectProperty<ValueExpression>> newVal = new HashMap<>();
// 값을 새롭게 추가한다음에 그 값에대한 값을 변경하는 형태로 로직구성이되야한다.
this.editableComposite.getItems().add(newVal);
// 값 복사
{
for (ObjectProperty<ValueExpression> value : selectedItem.values()) {
try {
ValueExpression cloneValueExp = value.get().clone();
cloneValueExp.setNew(true);
newVal.put(cloneValueExp.getColumnExpression(), new SimpleObjectProperty<>(cloneValueExp));
} catch (CloneNotSupportedException e1) {
e1.printStackTrace();
}
}
}
}
}
项目:WhoWhatWhere
文件:WatchdogUI.java
/**
* @param movementDirection - enum to specify if the row movement is up or down
* @return an EventHandler for the row movement buttons
*/
private EventHandler<ActionEvent> generateRowMovementButtonHandlers(RowMovementDirection movementDirection)
{
int moveToPosition = movementDirection == RowMovementDirection.UP ? -1 : 1;
return event ->
{
ObservableList<PacketTypeToMatch> items = table.getItems();
TableViewSelectionModel<PacketTypeToMatch> selectionModel = table.getSelectionModel();
List<Integer> modifiableIndices = new ArrayList<>(selectionModel.getSelectedIndices());
int[] reSelectRows = new int[modifiableIndices.size()];
int i = 0;
if (movementDirection == RowMovementDirection.DOWN) //if we are moving down, we should start from the last index and go backwards
Collections.reverse(modifiableIndices);
for (Integer selectedIndex : modifiableIndices)
{
if (selectedIndex == (movementDirection == RowMovementDirection.UP ? 0 : items.size() - 1)) //if it's the first or last row (depending on movement direction), don't do anything
{
reSelectRows[i++] = selectedIndex;
continue;
}
PacketTypeToMatch itemToReplace = items.set(selectedIndex + moveToPosition, items.get(selectedIndex));
items.set(selectedIndex, itemToReplace);
reSelectRows[i++] = selectedIndex + moveToPosition;
}
selectionModel.clearSelection();
selectionModel.selectIndices(reSelectRows[0], reSelectRows);
table.refresh();
};
}
项目:marathonv5
文件:JavaFXElementPropertyAccessor.java
public String getSelection(TableView<?> tableView) {
TableViewSelectionModel<?> selectionModel = tableView.getSelectionModel();
if (!selectionModel.isCellSelectionEnabled()) {
ObservableList<Integer> selectedIndices = selectionModel.getSelectedIndices();
if (tableView.getItems().size() == selectedIndices.size()) {
return "all";
}
if (selectedIndices.size() == 0) {
return "";
}
return getRowSelectionText(selectedIndices);
}
@SuppressWarnings("rawtypes")
ObservableList<TablePosition> selectedCells = selectionModel.getSelectedCells();
int[] rows = new int[selectedCells.size()];
int[] columns = new int[selectedCells.size()];
int rowCount = tableView.getItems().size();
int columnCount = tableView.getColumns().size();
if (selectedCells.size() == rowCount * columnCount) {
return "all";
}
if (selectedCells.size() == 0) {
return "";
}
JSONObject cells = new JSONObject();
JSONArray value = new JSONArray();
for (int i = 0; i < selectedCells.size(); i++) {
TablePosition<?, ?> cell = selectedCells.get(i);
rows[i] = cell.getRow();
columns[i] = cell.getColumn();
List<String> cellValue = new ArrayList<>();
cellValue.add(cell.getRow() + "");
cellValue.add(getColumnName(tableView, cell.getColumn()));
value.put(cellValue);
}
cells.put("cells", value);
return cells.toString();
}
项目:ExtremeGuiMakeover
文件:MovieViewSkin.java
private void addTableAndListView() {
FilteredList<Movie> filteredList = new FilteredList<>(database.getMovies());
filteredList.predicateProperty().bind(getSkinnable().filterPredicateProperty());
SortedList<Movie> tableViewSortedList = new SortedList<>(filteredList);
TableView<Movie> tableView = new MovieTableView();
tableViewSortedList.comparatorProperty().bind(tableView.comparatorProperty());
tableView.setItems(tableViewSortedList);
TableViewSelectionModel<Movie> tableViewSelectionModel = tableView.getSelectionModel();
tableViewSelectionModel.selectedItemProperty().addListener(it -> getSkinnable().setSelectedMovie(tableViewSelectionModel.getSelectedItem()));
PrettyListView<Movie> listView = new PrettyListView<>();
listView.setItems(filteredList);
MultipleSelectionModel<Movie> listViewSelectionModel = listView.getSelectionModel();
listViewSelectionModel.selectedItemProperty().addListener(it -> getSkinnable().setSelectedMovie(listViewSelectionModel.getSelectedItem()));
listView.setOnMouseClicked(evt -> {
if (evt.getButton() == MouseButton.PRIMARY && evt.getClickCount() == 2) {
showTrailer();
}
});
getSkinnable().useListViewCellFactoryProperty().addListener(it -> {
if (getSkinnable().isUseListViewCellFactory()) {
listView.setCellFactory(view -> new MovieCell(getSkinnable()));
} else {
listView.setCellFactory(view -> new ListCell<Movie>() {
@Override
protected void updateItem(Movie item, boolean empty) {
super.updateItem(item, empty);
if (item != null) {
setText(item.toString());
}
}
});
}
});
getSkinnable().selectedMovieProperty().addListener(it -> {
tableViewSelectionModel.select(getSkinnable().getSelectedMovie());
listViewSelectionModel.select(getSkinnable().getSelectedMovie());
});
FlipPanel flipPanel = new FlipPanel();
flipPanel.setFlipDirection(Orientation.HORIZONTAL);
flipPanel.getFront().getChildren().add(tableView);
flipPanel.getBack().getChildren().add(listView);
getSkinnable().useListViewProperty().addListener(it -> {
if (getSkinnable().isUseListView()) {
flipPanel.flipToBack();
if (getSkinnable().isUseListViewCellFactory()) {
listView.setCellFactory(view -> new MovieCell(getSkinnable()));
}
} else {
flipPanel.flipToFront();
}
});
GridPane.setVgrow(flipPanel, Priority.ALWAYS);
container.add(flipPanel, 1, 2);
}
项目:WebtoonDownloadManager
文件:NaverWebtoonSelectController.java
@SuppressWarnings("rawtypes")
public void showWebtoonListDialog(ObservableList<NaverWebtoonSelectService> data) {
try {
// cell init
cellMonday.setCellValueFactory(new PropertyValueFactory<NaverWebtoonSelectService, String>("monday"));
cellTuesday.setCellValueFactory(new PropertyValueFactory<NaverWebtoonSelectService, String>("tuesday"));
cellWednesday.setCellValueFactory(new PropertyValueFactory<NaverWebtoonSelectService, String>("wednesday"));
cellThursday.setCellValueFactory(new PropertyValueFactory<NaverWebtoonSelectService, String>("thursday"));
cellFriday.setCellValueFactory(new PropertyValueFactory<NaverWebtoonSelectService, String>("friday"));
cellSaturday.setCellValueFactory(new PropertyValueFactory<NaverWebtoonSelectService, String>("saturday"));
cellSunday.setCellValueFactory(new PropertyValueFactory<NaverWebtoonSelectService, String>("sunday"));
// selection for single cells instead of single
table.getSelectionModel().setCellSelectionEnabled(true);
table.setItems(data);
// 셀 추적
final ObservableList<TablePosition> selectedCells = table.getSelectionModel().getSelectedCells();
TableViewSelectionModel<NaverWebtoonSelectService> selectionModel = table.getSelectionModel();
// 셀 체인지 이벤트
selectedCells.addListener(new ListChangeListener<TablePosition>() {
@Override
public void onChanged(Change change) {
for (TablePosition pos : selectedCells) {
switch (pos.getColumn()) {
case 0: // 월
cellValue.setText(selectionModel.getSelectedItem().getMonday());
break;
case 1: // 화
cellValue.setText(selectionModel.getSelectedItem().getTuesday());
break;
case 2: // 수
cellValue.setText(selectionModel.getSelectedItem().getWednesday());
break;
case 3: // 목
cellValue.setText(selectionModel.getSelectedItem().getThursday());
break;
case 4: // 금
cellValue.setText(selectionModel.getSelectedItem().getFriday());
break;
case 5: // 토
cellValue.setText(selectionModel.getSelectedItem().getSaturday());
break;
case 6: // 일
cellValue.setText(selectionModel.getSelectedItem().getSunday());
break;
}
}
};
});
// 동적 셀 리스트 변환
ObservableList<NaverWebtoonSelectService> data1 = table.getItems();
filterField.textProperty()
.addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
if (oldValue != null && (newValue.length() < oldValue.length())) {
table.setItems(data1);
}
String value = newValue.toLowerCase();
ObservableList<NaverWebtoonSelectService> subentries = FXCollections.observableArrayList();
long count = table.getColumns().stream().count();
for (int i = 0; i < table.getItems().size(); i++) {
for (int j = 0; j < count; j++) {
String entry = "" + table.getColumns().get(j).getCellData(i);
String parseTitle = entry.split("-")[0];
if (replaceStrAll(parseTitle).toLowerCase().contains(replaceStrAll(value))) {
subentries.add(table.getItems().get(i));
break;
}
}
}
table.setItems(subentries);
});
} catch (Exception e) {
e.printStackTrace();
}
}
项目:FxEditor
文件:FxTable.java
public TableViewSelectionModel<T> getSelectionModel()
{
return table.getSelectionModel();
}
项目:Gargoyle
文件:EditableTableViewComposite.java
public TableViewSelectionModel<Map<ColumnExpression, ObjectProperty<ValueExpression>>> getSelectionModel() {
return this.editableTableView.getSelectionModel();
}
项目:Gargoyle
文件:TableViewSearchComposite.java
private boolean find(String findWord, Function<SearchResultVO, SearchResultVO> function, ObservableList<TableColumn<T, ?>> columns,
int size, int index, Predicate<SearchResultVO> isBreak) {
for (TableColumn<T, ?> c : columns) {
String content = FxUtil.getDisplayText(c, index, this.customConverter).toString();
int startIdx = content.indexOf(findWord);
if (startIdx >= 0) {
int endIdx = startIdx + findWord.length();
SearchResultVO value = new SearchResultVO();
value.setSearchText(findWord);
value.setStartIndex(startIdx);
value.setEndIndex(endIdx);
if (function != null)
value = function.apply(value);
searchResultVOProperty.set(value);
int nextIdx = index;
if (rbDirDown.isSelected()) {
if (size - 1 > nextIdx)
nextIdx++;
} else {
if (nextIdx > 0)
nextIdx--;
}
slidingStartRowIndexProperty.set(nextIdx);
this.tbContent.scrollTo(index);
TableViewSelectionModel<T> selectionModel = this.tbContent.getSelectionModel();
if (selectionModel.isCellSelectionEnabled()) {
selectionModel.select(index, c);
} else {
selectionModel.select(index);
}
if (isBreak.test(value)) {
return true;
}
}
// else {
// slidingStartRowIndexProperty.set(0);
// }
}
return false;
}
项目:ReqTraq
文件:FxTable.java
public TableViewSelectionModel<T> getSelectionModel()
{
return table.getSelectionModel();
}
项目:FxDock
文件:FxTable.java
public TableViewSelectionModel<T> getSelectionModel()
{
return table.getSelectionModel();
}
项目:qupath
文件:SummaryMeasurementTableCommand.java
private void synchronizeSelectionModelToTable(final PathObjectHierarchy hierarchy, final ListChangeListener.Change<? extends PathObject> change, final TableView<PathObject> table) {
if (synchronizingTableToModel || hierarchy == null)
return;
boolean ownsChanges = !synchronizingModelToTable;
try {
// System.out.println(change);
synchronizingModelToTable = true;
PathObjectSelectionModel model = hierarchy.getSelectionModel();
if (model == null) {
return;
}
// Check - was anything removed?
boolean removed = false;
while (change.next())
removed = removed | change.wasRemoved();
TableViewSelectionModel<PathObject> tableModel = table.getSelectionModel();
List<PathObject> selectedItems = tableModel.getSelectedItems();
// If we just have no selected items, and something was removed, then clear the selection
if (selectedItems.isEmpty() && removed) {
model.clearSelection();
return;
}
// If we just have one selected item, and also items were removed from the selection, then only select the one item we have
if (selectedItems.size() == 1 && removed) {
model.setSelectedObject(selectedItems.get(0), false);
return;
}
// If we have multiple selected items, we need to ensure that everything in the tree matches with everything in the selection model
Set<PathObject> currentSelections = model.getSelectedObjects();
Set<PathObject> toDeselect = new HashSet<>();
Set<PathObject> toSelect = new HashSet<>();
int n = table.getItems().size();
for (int i = 0; i < n; i++) {
PathObject temp = table.getItems().get(i);
if (tableModel.isSelected(i)) {
if (!currentSelections.contains(temp))
toSelect.add(temp);
} else {
if (currentSelections.contains(temp))
toDeselect.add(temp);
}
}
model.deselectObjects(toDeselect);
model.selectObjects(toSelect);
// Ensure that we have the main selected object
PathObject mainSelection = table.getFocusModel().getFocusedItem();
if (mainSelection != null && model.isSelected(mainSelection))
model.setSelectedObject(mainSelection, true);
} finally {
if (ownsChanges)
synchronizingModelToTable = false;
}
}
项目:qupath
文件:SummaryMeasurementTableCommand.java
private void synchronizeTableToSelectionModel(final PathObjectHierarchy hierarchy, final TableView<PathObject> table) {
if (synchronizingModelToTable || hierarchy == null)
return;
boolean ownsChanges = !synchronizingTableToModel;
try {
synchronizingTableToModel = true;
PathObjectSelectionModel model = hierarchy.getSelectionModel();
TableViewSelectionModel<PathObject> tableModel = table.getSelectionModel();
if (model == null || model.noSelection()) {
tableModel.clearSelection();
return;
}
if (model.singleSelection()) {
int ind = table.getItems().indexOf(model.getSelectedObject());
if (ind >= 0) {
tableModel.clearAndSelect(ind);
table.scrollTo(ind);
}
else
tableModel.clearSelection();
return;
}
// Loop through all possible selections, and select them if they should be selected (and not if they shouldn't)
// For performance reasons, we need to do this using arrays - otherwise way too many events may be fired
int n = table.getItems().size();
PathObject mainSelectedObject = model.getSelectedObject();
int mainObjectInd = -1;
int[] indsToSelect = new int[table.getItems().size()];
int count = 0;
for (int i = 0; i < n; i++) {
PathObject temp = table.getItems().get(i);
if (temp == mainSelectedObject)
mainObjectInd = i;
if (model.isSelected(temp)) {
indsToSelect[count] = i;
count++;
}
}
tableModel.clearSelection();
if (count > 0)
tableModel.selectIndices(indsToSelect[0], Arrays.copyOfRange(indsToSelect, 1, count));
// for (int i = 0; i < n; i++) {
// PathObject temp = table.getItems().get(i);
// if (temp == mainSelectedObject)
// mainObjectInd = i;
// if (model.isSelected(temp)) {
// // Only select if necessary, or if this is the main selected object
// if (!tableModel.isSelected(i))
// tableModel.select(i);
// }
// else
// tableModel.clearSelection(i);
// }
// Ensure that the main object is focussed & its node expanded
if (mainObjectInd >= 0 && model.singleSelection()) {
tableModel.select(mainObjectInd);
table.scrollTo(mainObjectInd);
}
} finally {
if (ownsChanges)
synchronizingTableToModel = false;
}
}
项目:Gargoyle
文件:CrudBaseGridView.java
/**
* Selection Model 리턴
*
* @작성자 : KYJ
* @작성일 : 2015. 11. 18.
* @return
*/
public TableViewSelectionModel<T> getSelectionModel() {
return gridview.getSelectionModel();
}
项目:jutility-javafx
文件:TableDataViewWrapper.java
/**
* The SelectionModel provides the API through which it is possible to
* select single or multiple items within a TableView, as well as inspect
* which items have been selected by the user. Note that it has a generic
* type that must match the type of the TableView itself.
*
*
* @return the selection model property.
*/
public final ObjectProperty<TableViewSelectionModel<List<T>>> selectionModelProperty() {
return this.getWrappedControl().selectionModelProperty();
}
项目:jutility-javafx
文件:TableDataViewWrapper.java
/**
* Gets the value of the selection model property.
*
* @return the value of the selection model property.
*/
public final TableViewSelectionModel<List<T>> getTableSelectionModel() {
return this.getWrappedControl().getSelectionModel();
}
项目:jutility-javafx
文件:TableDataViewWrapper.java
/**
* Sets the value of the selection model property.
*
* @param value
* the value of the selection model property.
*/
public final void setTableSelectionModel(TableViewSelectionModel<List<T>> value) {
this.getWrappedControl().setSelectionModel(value);
}