javafx.scene.control.TablePosition Java Examples
The following examples show how to use
javafx.scene.control.TablePosition.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TooltippedTextFieldTableCell.java From pdfsam with GNU Affero General Public License v3.0 | 6 votes |
@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); }
Example #2
Source File: StatisticalQueryGroupAndSortController.java From arcgis-runtime-samples-java with Apache License 2.0 | 6 votes |
/** * Initializes the Order By table view. Configures the table columns to show the correct field values and allow the * sort order of each field to be changed with a ComboBox. */ private void initializeOrderByTableView() { // make the table columns stretch to fill the width of the table orderByTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); // show the field name and sort order values in the column cells orderByFieldNameTableColumn.setCellValueFactory(cellData -> cellData.getValue().fieldNameProperty()); orderBySortOrderTableColumn.setCellValueFactory(cellData -> cellData.getValue().sortOrderProperty()); // show an editable ComboBox in the sort order column cells to change the sort order orderBySortOrderTableColumn.setCellFactory(col -> { ComboBoxTableCell<OrderByField, QueryParameters.SortOrder> ct = new ComboBoxTableCell<>(); ct.getItems().addAll(QueryParameters.SortOrder.values()); ct.setEditable(true); return ct; }); // switch to edit mode when the user selects the Sort Order column orderByTableView.getSelectionModel().selectedItemProperty().addListener(e -> { List<TablePosition> tablePositions = orderByTableView.getSelectionModel().getSelectedCells(); if (!tablePositions.isEmpty()) { tablePositions.forEach(tp -> orderByTableView.edit(tp.getRow(), orderBySortOrderTableColumn)); } }); }
Example #3
Source File: TableAutoCommitCell.java From MyBox with Apache License 2.0 | 6 votes |
@Override public void commitEdit(final T valNew) { if (isEditing()) { super.commitEdit(valNew); } else { final TableView<S> tbl = getTableView(); if (tbl != null) { final TablePosition<S, T> pos = new TablePosition<>(tbl, getTableRow().getIndex(), getTableColumn()); // instead of tbl.getEditingCell() final CellEditEvent<S, T> ev = new CellEditEvent<>(tbl, pos, TableColumn.editCommitEvent(), valNew); Event.fireEvent(getTableColumn(), ev); } updateItem(valNew, false); if (tbl != null) { tbl.edit(-1, null); } // TODO ControlUtils.requestFocusOnControlOnlyIfCurrentFocusOwnerIsChild(tbl); } }
Example #4
Source File: StringTable.java From phoebus with Eclipse Public License 1.0 | 6 votes |
/** 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); }
Example #5
Source File: StringTable.java From phoebus with Eclipse Public License 1.0 | 5 votes |
/** Handle key pressed on the table * * <p>Ignores keystrokes while editing a cell. * * @param event Key pressed */ private void handleKey(final KeyEvent event) { if (! editing) { // Toggle toolbar on Ctrl/Command T if (event.getCode() == KeyCode.T && event.isShortcutDown()) { showToolbar(! isToolbarVisible()); event.consume(); return; } // Switch to edit mode on keypress if (event.getCode().isLetterKey() || event.getCode().isDigitKey()) { @SuppressWarnings("unchecked") final TablePosition<List<ObservableCellValue>, ?> pos = table.getFocusModel().getFocusedCell(); table.edit(pos.getRow(), pos.getTableColumn()); // TODO If the cell had been edited before, i.e. the editor already exists, // that editor will be shown and it will receive the key. // But if the editor needed to be created for a new cell, // it won't receive the key?! // Attempts to re-send the event via a delayed // Event.fireEvent(table, event.copyFor(event.getSource(), table)); // failed to have any effect. } } }
Example #6
Source File: SamplesTableView.java From megan-ce with GNU General Public License v3.0 | 5 votes |
private void setColorForSelected(Color color) { if (tableView != null) { for (TablePosition position : tableView.getSelectedCells()) { final String attribute = tableView.getColName(position.getColumn()); final String value = tableView.getValue(position.getRow(), position.getColumn()); samplesViewer.getDocument().getChartColorManager().setAttributeStateColor(attribute, value, FXSwingUtilities.getColorAWT(color)); } } }
Example #7
Source File: RefundController.java From HealthPlus with Apache License 2.0 | 5 votes |
@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()); }
Example #8
Source File: StringTable.java From phoebus with Eclipse Public License 1.0 | 5 votes |
/** @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(); }
Example #9
Source File: CObjectArray.java From Open-Lowcode with Eclipse Public License 2.0 | 5 votes |
@Override public void handle(MouseEvent event) { MouseButton button = event.getButton(); if (button == MouseButton.PRIMARY) { if (event.getClickCount() == 1 && (!event.isShiftDown())) { if (thisobjectarray.thistable.getEditingCell() == null) { @SuppressWarnings("unchecked") TablePosition< ObjectTableRow, ?> focusedCellPosition = thisobjectarray.thistable.getFocusModel().getFocusedCell(); thisobjectarray.thistable.edit(focusedCellPosition.getRow(), focusedCellPosition.getTableColumn()); } } // checking that something is actually selecting when double-clicking. if (event.getClickCount() > 1) if (thisobjectarray.thistable.getSelectionModel().getSelectedItem() != null) { // trigger the action on double click only if updatemode is not active if (!thisobjectarray.updatemodeactive) { mouseeventlistener.handle(event); } } } else { } }
Example #10
Source File: DirectChoiceBoxTableCell.java From phoebus with Eclipse Public License 1.0 | 5 votes |
@Override protected void updateItem(final T value, final boolean empty) { super.updateItem(value, empty); if (empty) setGraphic(null); else { choicebox.setValue(value); setGraphic(choicebox); choicebox.setOnAction(event -> { // 'onAction' is invoked from setValue as called above, // but also when table updates its cells. // Ignore those. // Also ignore dummy updates to null which happen // when the list of choices changes if (! choicebox.isShowing() || choicebox.getValue() == null) return; final TableRow<S> row = getTableRow(); if (row == null) return; // Fire 'onEditCommit' final TableView<S> table = getTableView(); final TableColumn<S, T> col = getTableColumn(); final TablePosition<S, T> pos = new TablePosition<>(table, row.getIndex(), col); Objects.requireNonNull(col.getOnEditCommit(), "Must define onEditCommit handler") .handle(new CellEditEvent<>(table, pos, TableColumn.editCommitEvent(), choicebox.getValue())); }); } }
Example #11
Source File: GUI.java From phoebus with Eclipse Public License 1.0 | 5 votes |
private void createContextMenu() { // Create menu with dummy entry (otherwise it won't show up) final ContextMenu menu = new ContextMenu(new MenuItem()); // Update menu based on selection menu.setOnShowing(event -> { // Get selected Cells and their PV names final List<Cell> cells = new ArrayList<>(); final List<ProcessVariable> pvnames = new ArrayList<>(); final List<Instance> rows = table.getItems(); for (TablePosition<?, ?> sel : table.getSelectionModel().getSelectedCells()) { final Cell cell = rows.get(sel.getRow()).getCell(sel.getColumn()-1); cells.add(cell); pvnames.add(new ProcessVariable(cell.getName())); } // Update menu final ObservableList<MenuItem> items = menu.getItems(); items.clear(); items.add(new RestoreCellValues(cells)); items.add(new SetCellValues(table, cells)); // Add PV name entries if (pvnames.size() > 0) { items.add(new SeparatorMenuItem()); SelectionService.getInstance().setSelection("AlarmUI", pvnames); ContextMenuHelper.addSupportedEntries(table, menu); } }); table.setContextMenu(menu); }
Example #12
Source File: RFXTableView.java From marathonv5 with Apache License 2.0 | 5 votes |
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; } }
Example #13
Source File: TableUtils.java From kafka-message-tool with MIT License | 5 votes |
private static void copySelectionToClipboard(TableView<?> table) { StringBuilder clipboardString = new StringBuilder(); ObservableList<TablePosition> positionList = table.getSelectionModel().getSelectedCells(); if (positionList.size() == 0) { return; } if (positionList.size() > 1) { Logger.error("Invalid selection: should be selected only one cell, but is " + positionList.size()); return; } TablePosition position = positionList.get(0); int row = position.getRow(); int col = position.getColumn(); Object cell = table.getColumns().get(col).getCellData(row); if (cell == null) { return; } clipboardString.append(cell.toString()); final ClipboardContent clipboardContent = new ClipboardContent(); clipboardContent.putString(clipboardString.toString()); Clipboard.getSystemClipboard().setContent(clipboardContent); }
Example #14
Source File: CGrid.java From Open-Lowcode with Eclipse Public License 2.0 | 5 votes |
@Override public void handle(MouseEvent event) { MouseButton button = event.getButton(); if (button == MouseButton.PRIMARY) { if (event.getClickCount() == 1 && (event.isShiftDown())) { if (thisobjectgrid.isinlineupdate) if (!thisobjectgrid.updatemodeactive) { // currently, table in read mode, move to logger.fine("moving tableview " + thisobjectgrid.name + " to update mode"); thisobjectgrid.tableview.setEditable(true); thisobjectgrid.tableview.getSelectionModel().setCellSelectionEnabled(true); thisobjectgrid.updatemodeactive = true; thisobjectgrid.startupdate.setDisable(true); thisobjectgrid.commitupdate.setDisable(false); return; } } if (thisobjectgrid.isinlineupdate) if (thisobjectgrid.updatemodeactive) if (event.getClickCount() == 1) { if (thisobjectgrid.tableview.getEditingCell() == null) { @SuppressWarnings("unchecked") TablePosition<CObjectGridLine<String>, ?> focusedCellPosition = thisobjectgrid.tableview .getFocusModel().getFocusedCell(); thisobjectgrid.tableview.edit(focusedCellPosition.getRow(), focusedCellPosition.getTableColumn()); } } if (thisobjectgrid.iscellaction) if (event.getClickCount() > 1) { // trigger the action on double click only if updatemode is not active if (!thisobjectgrid.updatemodeactive) { logger.info("Single action click detected"); pageactionmanager.getMouseHandler().handle(event); } } } }
Example #15
Source File: CObjectArray.java From Open-Lowcode with Eclipse Public License 2.0 | 5 votes |
public void commitOngoingEdition() { TablePosition<ObjectTableRow, ?> editingcell = thistable.getEditingCell(); if (editingcell != null) { updatemodeactive = false; thistable.setEditable(false); thistable.getSelectionModel().setCellSelectionEnabled(false); startupdate.setDisable(false); commitupdate.setDisable(true); } }
Example #16
Source File: JavaFXElementPropertyAccessor.java From marathonv5 with Apache License 2.0 | 4 votes |
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(); }
Example #17
Source File: SamplesTableView.java From megan-ce with GNU General Public License v3.0 | 4 votes |
/** * pastes lines into table guided by an attribute * * @param attribute * @throws IOException */ public void pasteClipboardByAttribute(String attribute) throws IOException { if (tableView != null && tableView.getSelectedCells().size() > 0) { ensureFXThread(() -> { final Clipboard clipboard = Clipboard.getSystemClipboard(); final BitSet rows = new BitSet(); for (TablePosition position : tableView.getSelectedCells()) { rows.set(position.getRow()); } String contents = clipboard.getString().trim().replaceAll("\r\n", "\n").replaceAll("\r", "\n"); String[] lines = contents.split("\n"); if (lines.length > 0) { final int guideCol = tableView.getColIndex(attribute); final Map<String, String> attributeValue2Line = new HashMap<>(); int inputLineNumber = 0; String[] toPaste = new String[tableView.getSelectedRows().size()]; int expandedLineNumber = 0; for (int row = rows.nextSetBit(1); row != -1; row = rows.nextSetBit(row + 1)) { String value = tableView.getValue(row, guideCol); if (!attributeValue2Line.containsKey(value)) { if (inputLineNumber == lines.length) break; toPaste[expandedLineNumber++] = lines[inputLineNumber]; attributeValue2Line.put(value, lines[inputLineNumber++]); } else { if (expandedLineNumber == toPaste.length) break; toPaste[expandedLineNumber++] = attributeValue2Line.get(value); } } if (attributeValue2Line.size() != lines.length) { System.err.println("Mismatch between number of lines pasted (" + lines.length + ") and number of attribute values (" + attributeValue2Line.size() + ")"); return; } paste(toPaste); } }); } }
Example #18
Source File: BigTableController.java From examples-javafx-repos1 with Apache License 2.0 | 3 votes |
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; }