use of javafx.scene.control.TablePosition in project Gargoyle by callakrsos.
the class ClipboardKeyEventInstaller method install.
/********************************
* 작성일 : 2016. 9. 3. 작성자 : KYJ
*
*
* @param tb
********************************/
public static void install(TableView<?> tb) {
tb.addEventHandler(KeyEvent.KEY_PRESSED, e -> {
int type = -1;
if (e.isControlDown() && e.getCode() == KeyCode.C) {
if (e.isShiftDown()) {
type = 2;
} else {
type = 1;
}
if (type == -1)
return;
ObservableList<TablePosition> selectedCells = tb.getSelectionModel().getSelectedCells();
TablePosition tablePosition = selectedCells.get(0);
TableColumn tableColumn = tablePosition.getTableColumn();
int row = tablePosition.getRow();
int col = tb.getColumns().indexOf(tableColumn);
switch(type) {
case 1:
StringBuilder sb = new StringBuilder();
for (TablePosition cell : selectedCells) {
if (row != cell.getRow()) {
sb.append("\n");
row++;
} else if (col != tb.getColumns().indexOf(cell.getTableColumn())) {
sb.append("\t");
}
Object cellData = getDisplayText(cell, row);
sb.append(ValueUtil.decode(cellData, cellData, "").toString());
}
FxClipboardUtil.putString(sb.toString());
break;
case 2:
Object cellData = getDisplayText(tableColumn, row);
FxClipboardUtil.putString(ValueUtil.decode(cellData, cellData, "").toString());
break;
}
e.consume();
}
});
}
Aggregations