@Override public void commitEdit(T item) { if (!isEditing() && !item.equals(getItem())) { TableView<S> table = getTableView(); if (table != null) { TableColumn<S, T> column = getTableColumn(); // S dvo = getTableView().getItems().get(getIndex()); // if (!CommonConst._STATUS_CREATE.equals(dvo.get_status())) { // dvo.set_status(CommonConst._STATUS_UPDATE); // } // ObservableValue<T> ov = column.getCellObservableValue(dvo); // if (ov instanceof WritableValue) { // ((WritableValue) ov).setValue(item); // } CellEditEvent<S, T> event = new CellEditEvent<>(table, new TablePosition<S, T>(table, getIndex(), column), TableColumn.editCommitEvent(), item); Event.fireEvent(column, event); } } super.commitEdit(item); getTableView().refresh(); }
/** * Copy the text content of selected table cells to the clipboard. * * Note #1: This only works for continuous selections, i.e. single selected * cells, or multiple cells arranged in a full rectangular grid. * * Note #2: This method assumes that TableSelectionModel.getSelectedCells() returns * table rows and columns returned with valid indices >= 0. * No provision is made for indices of -1 used to indicate the selection of * an entire row or column. * * @param table * @param warnIfDiscontinuous If true, a warning is shown if a discontinous selection is made. */ private static void copySelectedCellsToClipboard(final TableView<?> table, final boolean warnIfDiscontinuous) { List<TablePosition> positions = table.getSelectionModel().getSelectedCells(); if (positions.isEmpty()) return; int[] rows = positions.stream().mapToInt(tp -> tp.getRow()).sorted().toArray(); int[] cols = positions.stream().mapToInt(tp -> tp.getColumn()).sorted().toArray(); boolean isContinuous = (rows[rows.length-1] - rows[0] + 1) * (cols[cols.length-1] - cols[0] + 1) == positions.size(); if (!isContinuous) { if (warnIfDiscontinuous) DisplayHelpers.showWarningNotification("Copy table selection", "Cannot copy discontinous selection, sorry"); return; } copyToClipboard(positions); }
private static void pasteClipboardContentsToTable(TableView<?> table) { String s = Clipboard.getSystemClipboard().getString(); if (s == null) { logger.warn("No text on clipboard"); return; } List<TablePosition> positions = table.getSelectionModel().getSelectedCells(); if (positions.isEmpty()) { logger.warn("No table cells selected"); return; } if (s.contains("\n") || s.contains("\t")) { DisplayHelpers.showWarningNotification("Paste contents", "Cannot paste clipboard contents - only simple, single-cell text supported"); return; } setTextForSelectedCells(positions, s); table.refresh(); }
private static void setTextForSelectedCells(final List<TablePosition> positions, final String text) { boolean containsImageNameColumns = false; for (TablePosition<?,?> tp : positions) { boolean isImageNameColumn = IMAGE_NAME.equals(tp.getTableColumn().getText()); if (isImageNameColumn) { containsImageNameColumns = true; continue; } ImageEntryWrapper wrapper = (ImageEntryWrapper)tp.getTableView().getItems().get(tp.getRow()); String key = tp.getTableColumn().getText(); if (text == null) wrapper.removeMetadataValue(key); else wrapper.putMetadataValue(key, text); } if (containsImageNameColumns) { DisplayHelpers.showWarningNotification("Project metadata table", "The image name cannot be changed"); } }
@Override public void initialize(URL url, ResourceBundle resourceBundle) { // Store a pointer to this controller in the main node of the JFX GUI node // strucutre. mainNode.getProperties().put("controller", this); if (table != null) { table.getSelectionModel().setCellSelectionEnabled(true); // Start editing the selected cell if a key is pressed. table.setOnKeyPressed(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { if (!event.getCode().isDigitKey() && !event.getCode().isLetterKey()) { return; } ObservableList<TablePosition> selectedCells = table.getSelectionModel().getSelectedCells(); if (selectedCells.size() != 1) { return; } TablePosition selectedCell = selectedCells.get(0); table.edit(selectedCell.getRow(), selectedCell.getTableColumn()); } }); } }
/** Listener to table selection */ private void selectionChanged(final Observable what) { final StringTableListener copy = listener; if (copy == null) return; @SuppressWarnings("rawtypes") final ObservableList<TablePosition> cells = table.getSelectionModel().getSelectedCells(); int num = cells.size(); // Don't select the magic last row if (num > 0 && data.get(cells.get(num-1).getRow()) == MAGIC_LAST_ROW) --num; final int[] rows = new int[num], cols = new int[num]; for (int i=0; i<num; ++i) { rows[i] = cells.get(i).getRow(); cols[i] = cells.get(i).getColumn(); } copy.selectionChanged(this, rows, cols); }
private void cleanTable(VBox v) { TableView<MyDomain> table = (TableView<MyDomain>) v.getChildren().get(2); table.getFocusModel().focus(null); Class tcbClass = TableCellBehavior.class; try { Method anchorMethod = tcbClass.getDeclaredMethod("setAnchor", TableView.class, TablePosition.class); anchorMethod.setAccessible(true); anchorMethod.invoke(null, table, null); } catch (Throwable t) { throw new RuntimeException(); } table.setOnMouseClicked(null); // table.getSelectionModel().getSelectedIndices().removeListener(listener); table.setSelectionModel(null); table.getColumns().clear(); v.getChildren().clear(); table.setItems(FXCollections.<MyDomain> observableArrayList()); table = null; }
@Override public void commitEdit(String item) { // This block is necessary to support commit on losing focus, because the baked-in mechanism // sets our editing state to false before we can intercept the loss of focus. // The default commitEdit(...) method simply bails if we are not editing... if (!isEditing() && !item.equals(getItem())) { TableView<SelectionTableRowData> table = getTableView(); if (table != null) { TableColumn<SelectionTableRowData, String> column = getTableColumn(); CellEditEvent<SelectionTableRowData, String> event = new CellEditEvent<>(table, new TablePosition<>(table, getIndex(), column), TableColumn.editCommitEvent(), item); Event.fireEvent(column, event); } } super.commitEdit(item); setContentDisplay(ContentDisplay.TEXT_ONLY); }
public RFXTableView(Node source, JSONOMapConfig omapConfig, Point2D point, IJSONRecorder recorder) { super(source, omapConfig, point, recorder); TableView<?> table = (TableView<?>) source; if (source == null) { return; } if (table.getEditingCell() != null) { TablePosition<?, ?> editingCell = table.getEditingCell(); row = editingCell.getRow(); column = editingCell.getColumn(); } else { if (point != null && point.getX() > 0 && point.getY() > 0) { column = getColumnAt(table, point); row = getRowAt(table, point); } else { @SuppressWarnings("rawtypes") ObservableList<TablePosition> selectedCells = table.getSelectionModel().getSelectedCells(); for (TablePosition<?, ?> tablePosition : selectedCells) { column = tablePosition.getColumn(); row = tablePosition.getRow(); } } } cellInfo = getTableCellText((TableView<?>) node, row, column); if (row == -1 || column == -1) { row = column = -1; } }
@Override public void handle(MouseEvent event) { //noinspection unchecked TablePosition<T, ?> tablePosition = tableView.focusModelProperty() .get() .focusedCellProperty() .get(); tableView.edit(tablePosition.getRow(), tablePosition.getTableColumn()); }
@Override public void run() { Clipboard clipboard = Clipboard.getSystemClipboard(); ClipboardContent content = new ClipboardContent(); int row = tableView.getSelectionModel().getSelectedIndex(); ObservableList<TablePosition> selectedCells = tableView.getSelectionModel().getSelectedCells(); if (!selectedCells.isEmpty()) { TablePosition tablePosition = selectedCells.get(0); Object cellData = tablePosition.getTableColumn().getCellData(row); content.putString(Objects.toString(cellData)); clipboard.setContent(content); } }
/** * 붙여넣기 * * @param pastString */ public void paste(String pastString) { TablePosition<?, ?> focusedCell = ssv.getSelectionModel().getFocusedCell(); int row = focusedCell.getRow(); int column = focusedCell.getColumn(); paste(pastString, row, column); }
@FXML private void getRefundInfo() { Refund refund = (Refund)refundTable.getSelectionModel().getSelectedItem(); TablePosition pos = refundTable.getFocusModel().getFocusedCell(); int column = pos.getColumn(); if (column == 5) { info.setText("refund " + refund.getPatientID()); Stage stage = new Stage(); PopupAskController popup = new PopupAskController(info,cashier,this); popup.message(" Make the Refund?"); Scene scene = new Scene(popup); stage.setScene( scene ); Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds(); //set Stage boundaries to visible bounds of the main screen stage.setX(primaryScreenBounds.getMinX()); stage.setY(primaryScreenBounds.getMinY()); stage.setWidth(primaryScreenBounds.getWidth()); stage.setHeight(primaryScreenBounds.getHeight()); stage.initStyle(StageStyle.UNDECORATED); scene.setFill(null); stage.initStyle(StageStyle.TRANSPARENT); stage.show(); } if (info.getText().equals("1")) { System.out.println("Yes!"); } System.out.println(info.getText()); }
public void actionPerformed(ActionEvent event) { final SamplesViewer viewer = (SamplesViewer) getViewer(); final ObservableList selectedCells = viewer.getSamplesTable().getSpreadsheetView().getSelectionModel().getSelectedCells(); if (selectedCells.size() == 1) { Object obj = selectedCells.get(0); int row = ((TablePosition) obj).getRow(); int col = ((TablePosition) obj).getColumn(); final String attribute = viewer.getSamplesTable().getDataGrid().getColumnName(col); final String value = viewer.getSamplesTable().getDataGrid().getValue(row, col); executeImmediately("select similar name='" + attribute + "' value='" + value + "';"); } }
/** * Copy the contents of an entire table to the clipboard. * * This should adapt to sorted rows as required. * * @param table */ private static void copyEntireTableToClipboard(final TableView<?> table) { List<TablePosition> positions = new ArrayList<>(); for (TableColumn<?, ?> column : table.getColumns()) { for (int row = 0; row < table.getItems().size(); row++) { positions.add(new TablePosition(table, row, column)); } } copyToClipboard(positions); }
TableSelectionSaver(TableView<T> table) { this.table = table; if (table.getSelectionModel().getSelectedCells().size() > 0) { TablePosition selectedCell = table.getSelectionModel().getSelectedCells().get(0); selectedColumn = selectedCell.getTableColumn(); selectedEntityId = table.getItems().get(selectedCell.getRow()).getId(); selectedRow = selectedCell.getRow(); } }
/** * Starts the edit at the currently selected position. */ public void edit() { @SuppressWarnings("unchecked") TablePosition<IDataRow, ?> focusedCell = getFocusModel().getFocusedCell(); if (focusedCell != null) { edit(focusedCell.getRow(), focusedCell.getTableColumn()); } }
/** * Updates the selection of this table with the one from the backing * {@link #dataBook}. */ private void updateSelectionFromDataBook() { if (!ignoreSelectionEvents) { ignoreSelectionEvents = true; try { int rowIndex = dataBook.get().getSelectedRow(); if (rowIndex >= 0 && !getSelectionModel().isSelected(rowIndex)) { @SuppressWarnings("unchecked") TablePosition<IDataRow, ?> focusedPosition = getFocusModel().getFocusedCell(); if (focusedPosition != null && focusedPosition.getTableColumn() != null) { getSelectionModel().clearAndSelect(rowIndex, focusedPosition.getTableColumn()); } else if (!getColumns().isEmpty()) { getSelectionModel().clearAndSelect(rowIndex, getColumns().get(0)); } else { getSelectionModel().clearAndSelect(rowIndex); } } } catch (ModelException e) { ExceptionHandler.raise(e); } finally { ignoreSelectionEvents = false; } } }
/** @return Currently selected table column or -1 */ private int getSelectedColumn() { @SuppressWarnings("rawtypes") final ObservableList<TablePosition> cells = table.getSelectionModel().getSelectedCells(); if (cells.isEmpty()) return -1; return cells.get(0).getColumn(); }
public void onMouseClicked(javafx.scene.input.MouseEvent event) { if (rowMenuItems!=null) { TableViewSelectionModel selectionModel = getSelectionModel(); ObservableList selectedCells = selectionModel.getSelectedCells(); TablePosition tablePosition = (TablePosition) selectedCells.get(0); TableColumn tableColumn = tablePosition.getTableColumn(); TableRow<?> row = getRow(tablePosition.getRow()); Bounds rowBounds = row.boundsInParentProperty().get(); System.out.println(rowBounds); //TODO Work on this some more!!! e.g. showRowPopUp(x,y), also for keyboard space or enter } }
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(); }
@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(); } }
public static <T> void installDoubleClickPopup(Window _owner, POPUP_STYLE style, TableView<T> tbMetadata) { tbMetadata.addEventHandler(MouseEvent.MOUSE_CLICKED, ev -> { Window owner = _owner; if (MouseButton.PRIMARY == ev.getButton() && ev.getClickCount() == 2) { if (ev.isConsumed()) return; ObservableList<TablePosition> selectedCells = tbMetadata.getSelectionModel().getSelectedCells(); if (selectedCells == null || selectedCells.isEmpty()) return; TablePosition tablePosition = selectedCells.get(0); int column = tablePosition.getColumn(); int row = tablePosition.getRow(); if (column == -1) return; if (row == -1) return; // tablePosition.getTableColumn(). Object valueByConverter = FxTableViewUtil.getValue(tbMetadata, column, row); String value = ""; if (ValueUtil.isNotEmpty(valueByConverter)) { value = valueByConverter.toString(); } /** * @최초생성일 2016. 11. 28. */ final double WIDTH = 500d; final double HEIGHT = 400d; switch (style) { case POP_OVER: JavaTextArea createJavaTextArea = createJavaTextArea(value); createJavaTextArea.setPrefSize(WIDTH, HEIGHT); FxUtil.showPopOver(tbMetadata, createJavaTextArea); break; case POPUP: createSimpleTextAreaAndShow(value, stage -> { stage.setTitle("Show Value"); stage.setWidth(WIDTH); stage.setHeight(HEIGHT); stage.initStyle(StageStyle.UTILITY); stage.initOwner(owner); stage.focusedProperty().addListener((oba, o, n) -> { if (!n) stage.close(); }); stage.getScene().addEventHandler(KeyEvent.KEY_PRESSED, event -> { if (KeyCode.ESCAPE == event.getCode()) { if (!event.isConsumed()) { stage.close(); } } }); }); break; } } }); }
private static Object getDisplayText(TablePosition cell, int row) { return getDisplayText(cell.getTableColumn(), row); }
@Override public ObservableList<TablePosition> getSelectedCells() { return FXCollections.emptyObservableList(); }
private TextField getTextField() { final TextField textField = new TextField(getItemText()); textField.setOnAction(new EventHandler < ActionEvent > () { @Override public void handle(ActionEvent event) { System.out.println("hi"); } }); // Use onAction here rather than onKeyReleased (with check for Enter), textField.setOnAction(event -> { if (getConverter() == null) { throw new IllegalStateException("StringConverter is null."); } this.commitEdit(getConverter().fromString(textField.getText())); event.consume(); }); textField.focusedProperty().addListener(new ChangeListener < Boolean > () { @Override public void changed(ObservableValue < ? extends Boolean > observable, Boolean oldValue, Boolean newValue) { if (!newValue) { commitEdit(getConverter().fromString(textField.getText())); } } }); textField.setOnKeyPressed(t -> { if (t.getCode() == KeyCode.ESCAPE) escapePressed = true; else escapePressed = false; }); textField.setOnKeyReleased(t -> { if (t.getCode() == KeyCode.ESCAPE) { throw new IllegalArgumentException( "did not expect esc key releases here."); } }); textField.addEventFilter(KeyEvent.KEY_PRESSED, event -> { if (event.getCode() == KeyCode.ESCAPE) { textField.setText(getConverter().toString(getItem())); cancelEdit(); event.consume(); } else if (event.getCode() == KeyCode.TAB) { getTableView().getSelectionModel().selectNext(); @SuppressWarnings("unchecked") final TablePosition < S, ? > focusedCell = getTableView() .focusModelProperty().get().focusedCellProperty().get(); getTableView().edit(focusedCell.getRow(), focusedCell.getTableColumn()); event.consume(); }else if (event.getCode() == KeyCode.UP) { getTableView().getSelectionModel().selectAboveCell(); event.consume(); } else if (event.getCode() == KeyCode.DOWN) { getTableView().getSelectionModel().selectBelowCell(); event.consume(); } }); return textField; }
static <T, S> T getObjectAtEvent(CellEditEvent<T, S> evt) { TableView<T> tableView = evt.getTableView(); ObservableList<T> items = tableView.getItems(); TablePosition<T,S> tablePosition = evt.getTablePosition(); int rowId = tablePosition.getRow(); T obj = items.get(rowId); return obj; }
/** * Represents the current cell being edited, or {@code null} if there is no * cell being edited. * * @see #getEditingCell() * @return the current cell being edited, or {@code null} if there is no * cell being edited. * */ public final ReadOnlyObjectProperty<TablePosition<List<T>, ?>> editingCellProperty() { return this.getWrappedControl().editingCellProperty(); }
/** * Gets the value of the property editingCell. * * @return the value of the property editingCell. */ public final TablePosition<List<T>, ?> getEditingCell() { return this.getWrappedControl().getEditingCell(); }
/** * Represents the current cell being edited, or {@code null} if there is no * cell being edited. * * @see TableViewWrapper#getEditingCell() * @return the current cell being edited, or {@code null} if there is no * cell being edited. * */ public final ReadOnlyObjectProperty<TablePosition<T, ?>> editingCellProperty() { return this.getWrappedControl().editingCellProperty(); }
/** * Gets the value of the property editingCell. * * @return the value of the property editingCell. */ public final TablePosition<T, ?> getEditingCell() { return this.getWrappedControl().getEditingCell(); }