use of javafx.scene.control.TableColumn in project Gargoyle by callakrsos.
the class CheckBoxTableCellExam method start.
/*
* (non-Javadoc)
*
* @see javafx.application.Application#start(javafx.stage.Stage)
*/
@Override
public void start(Stage primaryStage) throws Exception {
TableView<SampleVO> center = new TableView<>();
center.setEditable(true);
TableColumn<SampleVO, Boolean> e = new TableColumn<SampleVO, Boolean>();
e.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<SampleVO, Boolean>, ObservableValue<Boolean>>() {
@Override
public ObservableValue<Boolean> call(CellDataFeatures<SampleVO, Boolean> param) {
return param.getValue().checked;
}
});
e.setCellFactory(new Callback<TableColumn<SampleVO, Boolean>, TableCell<SampleVO, Boolean>>() {
@Override
public TableCell<SampleVO, Boolean> call(TableColumn<SampleVO, Boolean> param) {
return new CheckBoxTableCell<SampleVO, Boolean>() {
/*
* (non-Javadoc)
*
* @see
* javafx.scene.control.cell.CheckBoxTableCell#updateItem(
* java.lang.Object, boolean)
*/
@Override
public void updateItem(Boolean item, boolean empty) {
super.updateItem(item, empty);
}
/*
* (non-Javadoc)
*
* @see
* javafx.scene.control.Cell#isItemChanged(java.lang.Object,
* java.lang.Object)
*/
@Override
protected boolean isItemChanged(Boolean oldItem, Boolean newItem) {
System.out.println(oldItem + " : " + newItem);
return super.isItemChanged(oldItem, newItem);
}
};
}
});
e.setEditable(true);
TableColumn<SampleVO, String> e2 = new TableColumn<SampleVO, String>();
e2.setCellValueFactory(new PropertyValueFactory<SampleVO, String>("name"));
center.getColumns().add(e);
center.getColumns().add(e2);
center.getItems().add(new SampleVO(true, "kim"));
center.getItems().add(new SampleVO(true, "young"));
BorderPane borderPane = new BorderPane(center);
primaryStage.setScene(new Scene(borderPane));
primaryStage.show();
}
use of javafx.scene.control.TableColumn in project Gargoyle by callakrsos.
the class FilterTableExample method start.
@Override
public void start(Stage primaryStage) throws Exception {
TableView<DataItem> tableView = new TableView<>();
FxUtil.installClipboardKeyEvent(tableView);
tableView.setItems(FXCollections.observableArrayList());
IntStream.range(0, 20000).mapToObj(i -> new DataItem()).forEach(d -> tableView.getItems().add(d));
TableColumn<DataItem, Integer> smallInt = new TableColumn<>("Small Int");
smallInt.setCellValueFactory(cb -> new ReadOnlyObjectWrapper<>(cb.getValue().getSmallIntValue()));
TableColumn<DataItem, Integer> largeInt = new TableColumn<>("Large Int");
largeInt.setCellValueFactory(cb -> new ReadOnlyObjectWrapper<>(cb.getValue().getLargeIntValue()));
TableColumn<DataItem, String> randomLetter = new TableColumn<>("Letter");
randomLetter.setCellValueFactory(cb -> new ReadOnlyObjectWrapper<>(cb.getValue().getRandomLetter()));
TableColumn<DataItem, String> randomString1 = new TableColumn<>("AlphaNum 1");
randomString1.setCellValueFactory(cb -> new ReadOnlyObjectWrapper<>(cb.getValue().getRandomStr1()));
TableColumn<DataItem, String> randomString2 = new TableColumn<>("AlphaNum 2");
randomString1.setCellValueFactory(cb -> new ReadOnlyObjectWrapper<>(cb.getValue().getRandomStr2()));
tableView.getColumns().addAll(smallInt, largeInt, randomLetter, randomString1, randomString2);
Platform.runLater(() -> new TableFilter<>(tableView));
GridPane grp = new GridPane();
GridPane.setFillHeight(tableView, true);
GridPane.setFillWidth(tableView, true);
GridPane.setHgrow(tableView, Priority.ALWAYS);
GridPane.setVgrow(tableView, Priority.ALWAYS);
grp.getChildren().add(tableView);
Scene scene = new Scene(grp);
primaryStage.setScene(scene);
primaryStage.show();
}
use of javafx.scene.control.TableColumn 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();
}
});
}
use of javafx.scene.control.TableColumn in project Gargoyle by callakrsos.
the class TableViewWithVisibleRowCountExam method start.
/* (non-Javadoc)
* @see javafx.application.Application#start(javafx.stage.Stage)
*/
@Override
public void start(Stage primaryStage) throws Exception {
TableViewWithVisibleRowCount<Object> center = new TableViewWithVisibleRowCount<>();
TableColumn<Object, Object> e = new TableColumn<>();
e.setCellValueFactory(new PropertyValueFactory<>("name"));
center.getColumns().add(e);
center.getItems().add(new Person("ssss"));
center.getItems().add(new Person("ssss"));
center.getItems().add(new Person("ssss"));
center.getItems().add(new Person("ssss"));
center.getItems().add(new Person("ssss"));
center.getItems().add(new Person("ssss"));
primaryStage.setScene(new Scene(new BorderPane(center), 300, 400));
primaryStage.show();
Platform.runLater(() -> {
System.out.println(center.getVisibleRowCount());
});
}
use of javafx.scene.control.TableColumn in project Gargoyle by callakrsos.
the class FxTableViewUtil method installCopyHandler.
@SuppressWarnings("rawtypes")
public static void installCopyHandler(TableView<?> table) {
table.addEventHandler(KeyEvent.KEY_PRESSED, e -> {
if (e.isConsumed())
return;
int type = -1;
if (e.isControlDown() && e.getCode() == KeyCode.C) {
if (e.isShiftDown()) {
type = 2;
} else {
type = 1;
}
}
if (type == -1)
return;
TableViewSelectionModel<?> selectionModel = table.getSelectionModel();
SelectionMode selectionMode = selectionModel.getSelectionMode();
boolean cellSelectionEnabled = selectionModel.isCellSelectionEnabled();
if (!cellSelectionEnabled) {
Object selectedItem = table.getSelectionModel().getSelectedItem();
ObservableList<?> columns = table.getColumns();
Optional<String> reduce = columns.stream().filter(ob -> ob instanceof TableColumn).map(obj -> (TableColumn) obj).map(tc -> tc.getCellData(selectedItem)).filter(v -> v != null).map(v -> v.toString()).reduce((o1, o2) -> o1.toString().concat("\t").concat(o2.toString()));
reduce.ifPresent(str -> {
FxClipboardUtil.putString(str);
e.consume();
});
} else if (cellSelectionEnabled) {
ObservableList<TablePosition> selectedCells = selectionModel.getSelectedCells();
TablePosition tablePosition = selectedCells.get(0);
TableColumn tableColumn = tablePosition.getTableColumn();
int row = tablePosition.getRow();
int col = table.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 != table.getColumns().indexOf(cell.getTableColumn())) {
sb.append("\t");
}
Object cellData = cell.getTableColumn().getCellData(cell.getRow());
sb.append(ValueUtil.decode(cellData, cellData, "").toString());
}
FxClipboardUtil.putString(sb.toString());
e.consume();
break;
case 2:
Object cellData = tableColumn.getCellData(row);
FxClipboardUtil.putString(ValueUtil.decode(cellData, cellData, "").toString());
e.consume();
break;
}
}
});
}
Aggregations