use of javafx.scene.control.TableView 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;
}
}
});
}
use of javafx.scene.control.TableView in project Gargoyle by callakrsos.
the class PivotTableViewExam method start.
/*
* (non-Javadoc)
*
* @see javafx.application.Application#start(javafx.stage.Stage)
*/
@Override
public void start(Stage primaryStage) throws Exception {
// TableView<VocStA001DVO> root = new TableView<VocStA001DVO>();
TableView<Map<String, Object>> root = new TableView<>();
root.setOnMouseClicked(event -> {
System.out.println(root.getSelectionModel().getSelectedItem());
});
// 샘플데이터
List<VocStA001DVO> arrayList = new ArrayList<VocStA001DVO>();
arrayList.add(getSample("HQ", "11", "등록", "2016W1", 6));
arrayList.add(getSample("HQ", "12", "로컬접수", "2016W1", 1));
arrayList.add(getSample("HQ", "13", "HQ접수", "2016W1", 0));
arrayList.add(getSample("HQ", "14", "PI리더", "2016W1", 4));
arrayList.add(getSample("HQ", "15", "PI실무", "2016W1", 6));
arrayList.add(getSample("HQ", "11", "등록", "2016W2", 23));
arrayList.add(getSample("HQ", "12", "로컬접수", "2016W2", 32));
arrayList.add(getSample("HQ", "13", "HQ접수", "2016W2", 1));
arrayList.add(getSample("HQ", "14", "PI리더", "2016W2", 5));
arrayList.add(getSample("HQ", "15", "PI실무", "2016W2", 9));
arrayList.add(getSample("HQ", "11", "등록", "2016W3", 50));
arrayList.add(getSample("HQ", "12", "로컬접수", "2016W3", 1));
arrayList.add(getSample("HQ", "13", "HQ접수", "2016W3", 3));
arrayList.add(getSample("HQ", "14", "PI리더", "2016W3", 1));
arrayList.add(getSample("HQ", "15", "PI실무", "2016W3", 8));
arrayList.add(getSample("SEDA", "11", "등록", "2016W1", 12));
arrayList.add(getSample("SEDA", "12", "로컬접수", "2016W1", 2));
arrayList.add(getSample("SEDA", "13", "HQ접수", "2016W1", 1));
arrayList.add(getSample("SEDA", "14", "PI리더", "2016W1", 8));
arrayList.add(getSample("SEDA", "15", "PI실무", "2016W1", 12));
arrayList.add(getSample("SEDA", "11", "등록", "2016W2", 46));
arrayList.add(getSample("SEDA", "12", "로컬접수", "2016W2", 64));
arrayList.add(getSample("SEDA", "13", "HQ접수", "2016W2", 2));
arrayList.add(getSample("SEDA", "14", "PI리더", "2016W2", 10));
arrayList.add(getSample("SEDA", "15", "PI실무", "2016W2", 18));
arrayList.add(getSample("SEDA", "11", "등록", "2016W3", 100));
arrayList.add(getSample("SEDA", "12", "로컬접수", "2016W3", 2));
arrayList.add(getSample("SEDA", "13", "HQ접수", "2016W3", 6));
arrayList.add(getSample("SEDA", "14", "PI리더", "2016W3", 2));
arrayList.add(getSample("SEDA", "15", "PI실무", "2016W3", 16));
primaryStage.setScene(new Scene(root));
primaryStage.show();
Header header = new Header(Arrays.asList(new Header("vocStatusNm", "vocStatusNm")), "week", "week");
GroupingSet headerData = new GroupingSet("cnt", "sysCode");
header.setGroupingSet(headerData);
List<Map<String, Object>> groupBy = groupBy(header, arrayList);
List<TableColumn<Map<String, Object>, Object>> groupByColumns = groupByColumn(header, arrayList);
// List<TableColumn<Map<String, Object>, Object>> collect =
// groupBy.get(0).keySet().stream().map(k -> createColumn(k))
// .collect(Collectors.toList());
root.getColumns().addAll(groupByColumns);
root.getItems().addAll(groupBy);
// List<TableColumn<VocStA001DVO, String>> columns =
// createTableColumns(header, arrayList);
// root.getColumns().addAll(columns);
// root.getItems().addAll(arrayList);
}
use of javafx.scene.control.TableView in project Gargoyle by callakrsos.
the class TableInfoTab method supplyNode.
@Override
public BorderPane supplyNode() {
try {
return FxUtil.loadAndControllerAction(TableInfoController.class, (TableInfoController c) -> {
c.setBorTableDefine(new DatabaseTableView());
TableView<Object> tbDefined = new TableView<>();
c.setBorTableCollect(tbDefined);
});
} catch (Exception e) {
LOGGER.error(ValueUtil.toString(e));
}
return new DatabaseTableView();
}
use of javafx.scene.control.TableView in project blue by kunstmusik.
the class LineView method editPoints.
private void editPoints() {
TableView<LinePoint> table = new TableView<>();
TableColumn<LinePoint, Double> xCol = new TableColumn<>("x");
TableColumn<LinePoint, Double> yCol = new TableColumn<>("y");
table.getColumns().setAll(xCol, yCol);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
table.setItems(getSelectedLine().getObservableList());
table.setEditable(true);
xCol.setCellValueFactory(new PropertyValueFactory<LinePoint, Double>("x"));
xCol.setCellFactory(TextFieldTableCell.forTableColumn(new DoubleStringConverter()));
xCol.setOnEditCommit(te -> {
LinePoint lp = te.getRowValue();
if (getSelectedLine().getLinePoint(0) == lp || getSelectedLine().getLinePoint(getSelectedLine().size() - 1) == lp) {
return;
}
lp.setX(Utils.clamp(0.0, te.getNewValue(), 1.0));
});
xCol.setEditable(true);
yCol.setCellValueFactory(new PropertyValueFactory<LinePoint, Double>("y"));
yCol.setCellFactory(TextFieldTableCell.forTableColumn(new DoubleStringConverter()));
yCol.setOnEditCommit(te -> {
te.getRowValue().setY(Utils.clamp(getSelectedLine().getMin(), te.getNewValue(), getSelectedLine().getMax()));
});
yCol.setEditable(true);
Dialog<ButtonType> d = new Dialog<>();
d.initOwner(getScene().getWindow());
d.initModality(Modality.APPLICATION_MODAL);
d.getDialogPane().setContent(new ScrollPane(table));
d.getDialogPane().getStylesheets().add(BlueFX.getBlueFxCss());
d.getDialogPane().getButtonTypes().setAll(ButtonType.OK);
d.setTitle("Edit Points");
TableModelListener tml = tme -> {
repaint();
};
getSelectedLine().addTableModelListener(tml);
Optional<ButtonType> res = d.showAndWait();
getSelectedLine().removeTableModelListener(tml);
}
use of javafx.scene.control.TableView in project org.csstudio.display.builder by kasemir.
the class RulesDialog method createExpressionsTable.
/**
* @return Node for UI elements that edit the expressions
*/
private HBox createExpressionsTable() {
// Create table with editable rule 'bool expression' column
final TableColumn<ExprItem<?>, String> bool_exp_col = new TableColumn<>(Messages.RulesDialog_ColBoolExp);
bool_exp_col.setSortable(false);
bool_exp_col.setCellValueFactory(new PropertyValueFactory<ExprItem<?>, String>("boolExp"));
bool_exp_col.setCellFactory(tableColumn -> new TextFieldTableCell<ExprItem<?>, String>(new DefaultStringConverter()) {
private final ChangeListener<? super Boolean> focusedListener = (ob, o, n) -> {
if (!n)
cancelEdit();
};
/* Instance initializer. */
{
setAlignment(Pos.CENTER_LEFT);
}
@Override
public void cancelEdit() {
((TextField) getGraphic()).focusedProperty().removeListener(focusedListener);
super.cancelEdit();
}
@Override
public void commitEdit(final String newValue) {
((TextField) getGraphic()).focusedProperty().removeListener(focusedListener);
super.commitEdit(newValue);
}
@Override
public void startEdit() {
super.startEdit();
((TextField) getGraphic()).focusedProperty().addListener(focusedListener);
}
});
// Create table with editable rule 'value expression' column
final TableColumn<ExprItem<?>, Node> val_exp_col = new TableColumn<>(Messages.RulesDialog_ColValExp);
// This statement requires "val_exp_col" be defined.
bool_exp_col.setOnEditCommit(event -> {
final int row = event.getTablePosition().getRow();
expression_items.get(row).boolExpProperty().set(event.getNewValue());
ModelThreadPool.getTimer().schedule(() -> {
Platform.runLater(() -> val_exp_col.getCellData(row).requestFocus());
}, 123, TimeUnit.MILLISECONDS);
});
val_exp_col.setSortable(false);
val_exp_col.setCellValueFactory(new PropertyValueFactory<ExprItem<?>, Node>("field"));
val_exp_col.setCellFactory(tableColumn -> new TableCell<ExprItem<?>, Node>() {
@Override
protected void updateItem(final Node item, final boolean empty) {
// calling super here is very important - don't skip this!
super.updateItem(item, empty);
setGraphic(item);
}
});
val_exp_col.setOnEditCommit(event -> {
final int row = event.getTablePosition().getRow();
expression_items.get(row).fieldProperty().set(event.getNewValue());
event.consume();
ModelThreadPool.getTimer().schedule(() -> {
Platform.runLater(() -> btn_add_exp.requestFocus());
}, 1230, TimeUnit.MILLISECONDS);
});
expressions_table = new TableView<>(expression_items);
expressions_table.getColumns().add(bool_exp_col);
expressions_table.getColumns().add(val_exp_col);
expressions_table.setEditable(true);
expressions_table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
expressions_table.setTooltip(new Tooltip(Messages.RulesDialog_ExpressionsTT));
expressions_table.setPlaceholder(new Label(Messages.RulesDialog_NoExpressions));
// Buttons
btn_add_exp = new Button(Messages.Add, JFXUtil.getIcon("add.png"));
btn_add_exp.setMaxWidth(Double.MAX_VALUE);
btn_add_exp.setAlignment(Pos.CENTER_LEFT);
btn_add_exp.setOnAction(event -> {
selected_rule_item.addNewExpr(undo);
expression_items.setAll(selected_rule_item.expressions);
expressions_table.getSelectionModel().select(expression_items.size() - 1);
final int newRow = expression_items.size() - 1;
ModelThreadPool.getTimer().schedule(() -> {
Platform.runLater(() -> expressions_table.edit(newRow, bool_exp_col));
}, 123, TimeUnit.MILLISECONDS);
});
btn_rm_exp = new Button(Messages.Remove, JFXUtil.getIcon("delete.png"));
btn_rm_exp.setMaxWidth(Double.MAX_VALUE);
btn_rm_exp.setMinWidth(96);
btn_rm_exp.setAlignment(Pos.CENTER_LEFT);
btn_rm_exp.setDisable(true);
btn_rm_exp.setOnAction(event -> {
final int sel = expressions_table.getSelectionModel().getSelectedIndex();
if (sel >= 0)
expression_items.remove(sel);
});
btn_move_exp_up = new Button(Messages.MoveUp, JFXUtil.getIcon("up.png"));
btn_move_exp_up.setMaxWidth(Double.MAX_VALUE);
btn_move_exp_up.setAlignment(Pos.CENTER_LEFT);
btn_move_exp_up.setDisable(true);
btn_move_exp_up.setOnAction(event -> TableHelper.move_item_up(expressions_table, expression_items));
btn_move_exp_down = new Button(Messages.MoveDown, JFXUtil.getIcon("down.png"));
btn_move_exp_down.setMaxWidth(Double.MAX_VALUE);
btn_move_exp_down.setAlignment(Pos.CENTER_LEFT);
btn_move_exp_down.setDisable(true);
btn_move_exp_down.setOnAction(event -> TableHelper.move_item_down(expressions_table, expression_items));
final VBox buttons = new VBox(10, btn_add_exp, btn_rm_exp, btn_move_exp_up, btn_move_exp_down);
final HBox content = new HBox(10, expressions_table, buttons);
HBox.setHgrow(expressions_table, Priority.ALWAYS);
HBox.setHgrow(buttons, Priority.NEVER);
content.setDisable(true);
return content;
}
Aggregations