use of javafx.scene.control.TableColumn in project jgnash by ccavanaugh.
the class ImportPageTwoController method buildTableView.
private void buildTableView() {
final TableColumn<ImportTransaction, ImportState> stateColumn = new TableColumn<>();
stateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getState()));
stateColumn.setCellFactory(param -> {
TableCell<ImportTransaction, ImportState> cell = new ImportStateTableCell();
cell.addEventFilter(MouseEvent.MOUSE_CLICKED, event -> {
if (event.getClickCount() > 1) {
final ImportTransaction t = tableView.getItems().get(((TableCell<?, ?>) event.getSource()).getTableRow().getIndex());
if (t.getState() == ImportState.EQUAL) {
t.setState(ImportState.NOT_EQUAL);
} else if (t.getState() == ImportState.NOT_EQUAL) {
t.setState(ImportState.EQUAL);
} else if (t.getState() == ImportState.NEW) {
t.setState(ImportState.IGNORE);
} else if (t.getState() == ImportState.IGNORE) {
t.setState(ImportState.NEW);
}
Platform.runLater(tableView::refresh);
}
});
return cell;
});
tableView.getColumns().add(stateColumn);
final TableColumn<ImportTransaction, LocalDate> dateColumn = new TableColumn<>(resources.getString("Column.Date"));
dateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDatePosted()));
dateColumn.setCellFactory(param -> new ShortDateTableCell<>());
tableView.getColumns().add(dateColumn);
final TableColumn<ImportTransaction, String> numberColumn = new TableColumn<>(resources.getString("Column.Num"));
numberColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getCheckNumber()));
tableView.getColumns().add(numberColumn);
final TableColumn<ImportTransaction, String> payeeColumn = new TableColumn<>(resources.getString("Column.Payee"));
payeeColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getPayee()));
tableView.getColumns().add(payeeColumn);
final TableColumn<ImportTransaction, String> memoColumn = new TableColumn<>(resources.getString("Column.Memo"));
memoColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getMemo()));
tableView.getColumns().add(memoColumn);
final TableColumn<ImportTransaction, Account> accountColumn = new TableColumn<>(resources.getString("Column.Account"));
accountColumn.setCellValueFactory(param -> {
if (param.getValue() != null && param.getValue().getAccount() != null) {
return new SimpleObjectProperty<>(param.getValue().getAccount());
}
return null;
});
accountColumn.setCellFactory(param -> new AccountComboBoxTableCell<>());
accountColumn.setEditable(true);
accountColumn.setOnEditCommit(event -> {
event.getTableView().getItems().get(event.getTablePosition().getRow()).setAccount(event.getNewValue());
lastAccount = event.getNewValue();
Platform.runLater(tableViewManager::packTable);
});
tableView.getColumns().add(accountColumn);
incomeAccountColumn = new TableColumn<>(resources.getString("Column.Income"));
incomeAccountColumn.setCellValueFactory(param -> {
if (param.getValue() != null && param.getValue().getGainsAccount() != null) {
return new SimpleObjectProperty<>(param.getValue().getGainsAccount());
}
return null;
});
incomeAccountColumn.setCellFactory(param -> new IncomeAccountComboBoxTableCell<>());
incomeAccountColumn.setEditable(true);
incomeAccountColumn.setOnEditCommit(event -> {
event.getTableView().getItems().get(event.getTablePosition().getRow()).setGainsAccount(event.getNewValue());
lastGainsAccount = event.getNewValue();
Platform.runLater(tableViewManager::packTable);
});
tableView.getColumns().add(incomeAccountColumn);
expenseAccountColumn = new TableColumn<>(resources.getString("Column.Expense"));
expenseAccountColumn.setCellValueFactory(param -> {
if (param.getValue() != null && param.getValue().getFeesAccount() != null) {
if (param.getValue().getFees().compareTo(BigDecimal.ZERO) != 0) {
return new SimpleObjectProperty<>(param.getValue().getFeesAccount());
} else {
return new SimpleObjectProperty<>(NOP_EXPENSE_ACCOUNT);
}
}
return null;
});
expenseAccountColumn.setCellFactory(param -> new ExpenseAccountComboBoxTableCell<>());
expenseAccountColumn.setEditable(true);
expenseAccountColumn.setOnEditCommit(event -> {
event.getTableView().getItems().get(event.getTablePosition().getRow()).setFeesAccount(event.getNewValue());
Platform.runLater(tableViewManager::packTable);
});
tableView.getColumns().add(expenseAccountColumn);
final TableColumn<ImportTransaction, BigDecimal> amountColumn = new TableColumn<>(resources.getString("Column.Amount"));
amountColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getAmount()));
amountColumn.setCellFactory(param -> new BigDecimalTableCell<>(numberFormat));
amountColumn.setCellFactory(param -> {
final TableCell<ImportTransaction, BigDecimal> cell = new BigDecimalTableCell<>(numberFormat);
cell.indexProperty().addListener((observable, oldValue, newValue) -> {
final int index = newValue.intValue();
if (index >= 0 && index < tableView.itemsProperty().get().size()) {
cell.setTooltip(new Tooltip(tableView.itemsProperty().get().get(index).getToolTip()));
}
});
return cell;
});
tableView.getColumns().add(amountColumn);
typeColumn = new TableColumn<>(resources.getString("Column.Type"));
typeColumn.setCellValueFactory(param -> {
TransactionType transactionType = TransactionType.SINGLENTRY;
if (param.getValue().isInvestmentTransaction()) {
transactionType = param.getValue().getTransactionType();
} else if (!param.getValue().getAccount().equals(baseAccount)) {
transactionType = TransactionType.DOUBLEENTRY;
}
return new SimpleStringProperty(transactionType.toString());
});
tableView.getColumns().add(typeColumn);
}
use of javafx.scene.control.TableColumn in project jgnash by ccavanaugh.
the class BasicRegisterTableController method buildTable.
@Override
protected void buildTable() {
final String[] columnNames = RegisterFactory.getColumnNames(accountProperty().get().getAccountType());
final TableColumn<Transaction, LocalDate> dateColumn = new TableColumn<>(columnNames[0]);
dateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getLocalDate()));
dateColumn.setCellFactory(cell -> new TransactionDateTableCell());
tableView.getColumns().add(dateColumn);
final TableColumn<Transaction, LocalDateTime> dateTimeColumn = new TableColumn<>(columnNames[1]);
dateTimeColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getTimestamp()));
dateTimeColumn.setCellFactory(cell -> new TransactionDateTimeTableCell());
tableView.getColumns().add(dateTimeColumn);
final TableColumn<Transaction, String> numberColumn = new TableColumn<>(columnNames[2]);
numberColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getNumber()));
numberColumn.setCellFactory(cell -> new TransactionStringTableCell());
tableView.getColumns().add(numberColumn);
final TableColumn<Transaction, String> payeeColumn = new TableColumn<>(columnNames[3]);
payeeColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getPayee()));
payeeColumn.setCellFactory(cell -> new TransactionStringTableCell());
tableView.getColumns().add(payeeColumn);
final TableColumn<Transaction, String> memoColumn = new TableColumn<>(columnNames[4]);
memoColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getMemo()));
memoColumn.setCellFactory(cell -> new TransactionStringTableCell());
tableView.getColumns().add(memoColumn);
final TableColumn<Transaction, String> accountColumn = new TableColumn<>(columnNames[5]);
accountColumn.setCellValueFactory(param -> new AccountNameWrapper(param.getValue()));
accountColumn.setCellFactory(cell -> new TransactionStringTableCell());
tableView.getColumns().add(accountColumn);
final TableColumn<Transaction, String> reconciledColumn = new TableColumn<>(columnNames[6]);
reconciledColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getReconciled(account.get()).toString()));
reconciledColumn.setCellFactory(cell -> new TransactionStringTableCell());
tableView.getColumns().add(reconciledColumn);
final TableColumn<Transaction, BigDecimal> increaseColumn = new TableColumn<>(columnNames[7]);
increaseColumn.setCellValueFactory(param -> new IncreaseAmountProperty(param.getValue().getAmount(accountProperty().getValue())));
increaseColumn.setCellFactory(cell -> new TransactionCommodityFormatTableCell(CommodityFormat.getShortNumberFormat(account.get().getCurrencyNode())));
tableView.getColumns().add(increaseColumn);
final TableColumn<Transaction, BigDecimal> decreaseColumn = new TableColumn<>(columnNames[8]);
decreaseColumn.setCellValueFactory(param -> new DecreaseAmountProperty(param.getValue().getAmount(accountProperty().getValue())));
decreaseColumn.setCellFactory(cell -> new TransactionCommodityFormatTableCell(CommodityFormat.getShortNumberFormat(account.get().getCurrencyNode())));
tableView.getColumns().add(decreaseColumn);
final TableColumn<Transaction, BigDecimal> balanceColumn = new TableColumn<>(columnNames[9]);
balanceColumn.setCellValueFactory(param -> {
final AccountType accountType = accountProperty().getValue().getAccountType();
return new SimpleObjectProperty<>(AccountBalanceDisplayManager.convertToSelectedBalanceMode(accountType, getBalanceAt(param.getValue())));
});
balanceColumn.setCellFactory(cell -> new TransactionCommodityFormatTableCell(CommodityFormat.getFullNumberFormat(account.get().getCurrencyNode())));
// do not allow a sort on the balance
balanceColumn.setSortable(false);
tableView.getColumns().add(balanceColumn);
tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
tableViewManager.setColumnFormatFactory(param -> {
if (param == balanceColumn) {
return CommodityFormat.getFullNumberFormat(accountProperty().getValue().getCurrencyNode());
} else if (param == increaseColumn || param == decreaseColumn) {
return CommodityFormat.getShortNumberFormat(accountProperty().getValue().getCurrencyNode());
} else if (param == dateColumn) {
return DateUtils.getShortDateFormatter().toFormat();
} else if (param == dateTimeColumn) {
return DateUtils.getShortDateTimeFormatter().toFormat();
}
return null;
});
}
use of javafx.scene.control.TableColumn in project jgnash by ccavanaugh.
the class InvestmentRegisterTableController method buildTable.
@Override
protected void buildTable() {
final String[] columnNames = RegisterFactory.getColumnNames(accountProperty().get().getAccountType());
final TableColumn<Transaction, LocalDate> dateColumn = new TableColumn<>(columnNames[0]);
dateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getLocalDate()));
dateColumn.setCellFactory(cell -> new TransactionDateTableCell());
tableView.getColumns().add(dateColumn);
final TableColumn<Transaction, LocalDateTime> dateTimeColumn = new TableColumn<>(columnNames[1]);
dateTimeColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getTimestamp()));
dateTimeColumn.setCellFactory(cell -> new TransactionDateTimeTableCell());
tableView.getColumns().add(dateTimeColumn);
final TableColumn<Transaction, String> typeColumn = new TableColumn<>(columnNames[2]);
typeColumn.setCellValueFactory(param -> new TransactionTypeWrapper(param.getValue()));
typeColumn.setCellFactory(cell -> new TransactionStringTableCell());
tableView.getColumns().add(typeColumn);
final TableColumn<Transaction, String> investmentColumn = new TableColumn<>(columnNames[3]);
investmentColumn.setCellValueFactory(param -> new TransactionSymbolWrapper(param.getValue()));
investmentColumn.setCellFactory(cell -> new TransactionStringTableCell());
tableView.getColumns().add(investmentColumn);
final TableColumn<Transaction, String> memoColumn = new TableColumn<>(columnNames[4]);
memoColumn.setCellValueFactory(param -> new MemoWrapper(param.getValue()));
memoColumn.setCellFactory(cell -> new TransactionStringTableCell());
tableView.getColumns().add(memoColumn);
final TableColumn<Transaction, String> reconciledColumn = new TableColumn<>(columnNames[5]);
reconciledColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getReconciled(account.getValue()).toString()));
reconciledColumn.setCellFactory(cell -> new TransactionStringTableCell());
tableView.getColumns().add(reconciledColumn);
final TableColumn<Transaction, BigDecimal> quantityColumn = new TableColumn<>(columnNames[6]);
quantityColumn.setCellValueFactory(param -> new QuantityProperty(param.getValue()));
quantityColumn.setCellFactory(cell -> new InvestmentTransactionQuantityTableCell());
tableView.getColumns().add(quantityColumn);
final TableColumn<Transaction, BigDecimal> priceColumn = new TableColumn<>(columnNames[7]);
priceColumn.setCellValueFactory(param -> new PriceProperty(param.getValue()));
priceColumn.setCellFactory(cell -> new TransactionCommodityFormatTableCell(CommodityFormat.getShortNumberFormat(account.get().getCurrencyNode())));
tableView.getColumns().add(priceColumn);
final TableColumn<Transaction, BigDecimal> netColumn = new TableColumn<>(columnNames[8]);
netColumn.setCellValueFactory(param -> new AmountProperty(param.getValue()));
netColumn.setCellFactory(cell -> new TransactionCommodityFormatTableCell(CommodityFormat.getShortNumberFormat(account.get().getCurrencyNode())));
tableView.getColumns().add(netColumn);
tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
tableViewManager.setColumnFormatFactory(param -> {
if (param == netColumn) {
return CommodityFormat.getFullNumberFormat(accountProperty().getValue().getCurrencyNode());
} else if (param == quantityColumn) {
return getQuantityColumnFormat();
} else if (param == priceColumn) {
return CommodityFormat.getShortNumberFormat(accountProperty().getValue().getCurrencyNode());
} else if (param == dateColumn) {
return DateUtils.getShortDateFormatter().toFormat();
} else if (param == dateTimeColumn) {
return DateUtils.getShortDateTimeFormatter().toFormat();
}
return null;
});
}
use of javafx.scene.control.TableColumn 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.TableColumn in project Gargoyle by callakrsos.
the class EditableTableView method readByTableName.
private void readByTableName(String sql, String tableName, boolean appendHist) throws Exception {
LOGGER.debug(sql);
getColumns().clear();
getItems().clear();
removedList.clear();
columnMap.clear();
try (Connection connection = connectionSupplier.get()) {
List<String> pks = DbUtil.pks(connection, tableName);
Map<String, Boolean> columnsToMap = DbUtil.columnsToMap(connection, tableName, rs -> {
try {
return rs.getString(4);
} catch (Exception e) {
return null;
}
}, rs -> {
try {
return Boolean.valueOf("YES".equals(rs.getString(18)));
} catch (Exception e) {
return false;
}
});
LOGGER.debug("nullable columns ? {} ", columnsToMap);
DbUtil.select(connection, sql, FETCH_COUNT, LIMIT_ROW_COUNT, new BiFunction<ResultSetMetaData, ResultSet, List<Map<String, Object>>>() {
@Override
public List<Map<String, Object>> apply(ResultSetMetaData t, ResultSet u) {
try {
int columnCount = t.getColumnCount();
for (int i = 1; i <= columnCount; i++) {
String columnName = t.getColumnName(i);
ColumnExpression columnExp = new ColumnExpression(columnName);
columnExp.isPrimaryColumn = pks.contains(columnName);
columnExp.isNullableColumn = columnsToMap.containsKey(columnName) && (columnsToMap.get(columnName) == true);
columnExp.setColumnType(t.getColumnType(i));
TableColumn<Map<ColumnExpression, ObjectProperty<ValueExpression>>, ValueExpression> e = new TableColumn<>(columnName);
e.setUserData(columnExp);
e.setCellValueFactory(DynamicCallback.fromTableColumn(columnExp));
e.setCellFactory(DEFAULT_CELL_FACTORY);
e.setEditable(true);
columnMap.put(columnName, columnExp);
getColumns().add(e);
}
while (u.next()) {
Map<ColumnExpression, ObjectProperty<ValueExpression>> hashMap = new HashMap<>();
for (int i = 1; i <= columnCount; i++) {
String columnName = t.getColumnName(i);
//new ColumnExpression(columnName);
ColumnExpression columnExp = columnMap.get(columnName);
ValueExpression valueExp = new ValueExpression();
valueExp.displayText.set(u.getString(columnName));
valueExp.isPrimaryKey = pks.contains(columnName);
valueExp.realValue.set(u.getObject(columnName));
valueExp.setColumnExpression(columnExp);
hashMap.put(columnExp, new SimpleObjectProperty<>(valueExp));
}
getItems().removeListener(itemChangeListener);
getItems().add(hashMap);
getItems().addListener(itemChangeListener);
}
} catch (SQLException e) {
LOGGER.error(ValueUtil.toString(e));
}
return null;
}
});
if (appendHist) {
if (history.size() >= HISTORY_LIMITED_SIZE) {
history.removeFirst();
}
history.add(sql);
}
this.tableName.set(tableName);
}
}
Aggregations