use of javafx.scene.control.TableCell in project Gargoyle by callakrsos.
the class IExcelScreenHandler method valueMapper.
/**
* 테이블컬럼의 row에 해당하는 데이터가 무엇인지 정의한 값에 따라 엑셀에 표현됨.
*
* StringConverter를 이용한 TableCell인경우 정의된 StringConvert를 이용한 데이터를 Excel의
* Cell에 쓰고, StringConverter를 이용하지않는 UI의 TableCell의 경우 데이터셋에 바인드된 값을 사용하게됨.
*
* 작성된 API내에서 적절한 값이 아니라고 판단되는경우 Ovrride해서 재정의하도록한다.
*
* @작성자 : KYJ
* @작성일 : 2016. 9. 9.
* @param table
* 사용자 화면에 정의된 tableView
* @param column
* 사용자 화면에 정의된 tableColumn
* @param columnIndex
* 사용자 화면에 정의된 tableColumn의 인덱스
* @param rowIndex
* 사용자 화면에 정의된 tableCell의 인덱스
* @return Object 테이블셀에 정의된 데이터를 리턴할 값으로, 리턴해주는 값이 엑셀에 write된다.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public default default <T> Object valueMapper(TableView<?> table, TableColumn<?, ?> column, int columnIndex, int rowIndex) {
Callback cellFactory = column.getCellFactory();
if (cellFactory != null) {
TableCell cell = (TableCell) cellFactory.call(column);
if (cell != null) {
StringConverter converter = null;
if (cell instanceof TextFieldTableCell) {
TextFieldTableCell txtCell = (TextFieldTableCell) cell;
converter = txtCell.getConverter();
} else // }
if (cell instanceof ComboBoxTableCell) {
ComboBoxTableCell txtCell = (ComboBoxTableCell) cell;
converter = txtCell.getConverter();
} else // else if (cell instanceof HyperlinkTableCell) {
// HyperlinkTableCell txtCell = (HyperlinkTableCell) cell;
// converter = txtCell.getConverter();
// }
/* else 기본값. */
{
try {
Method m = cell.getClass().getMethod("converterProperty");
if (m != null) {
Object object = m.invoke(cell);
if (object != null && object instanceof ObjectProperty) {
ObjectProperty<StringConverter> convert = (ObjectProperty<StringConverter>) object;
converter = convert.get();
}
}
} catch (Exception e) {
// Nothing...
}
}
if (converter != null) {
Object cellData = column.getCellData(rowIndex);
return converter.toString(cellData);
}
}
}
return column.getCellData(rowIndex);
}
use of javafx.scene.control.TableCell in project Gargoyle by callakrsos.
the class MacroBaseSkin method start.
/**
* Start 버튼을 클릭하면 결과가 리턴된다. param으로 입력받은 데이터는 textArea에서 적혀져있는 텍스트문자열.
*
* 2016-10-25 Skin클래스안으로 이동처리.
*
* @작성자 : KYJ
* @작성일 : 2016. 10. 25.
* @param tbResult
* @param param
* @throws Exception
*/
public void start(TableView<Map<String, String>> tbResult, String param) throws Exception {
Connection connection = getSkinnable().getConnectionSupplier().get();
tbResult.getItems().clear();
tbResult.getColumns().clear();
// try {
String[] split = param.split(";");
connection.setAutoCommit(false);
try {
for (String sql : split) {
String _sql = sql.trim();
if (_sql.isEmpty())
continue;
boolean dml = DbUtil.isDml(_sql);
if (dml) {
LOGGER.debug("do update : {}", _sql);
DbUtil.update(connection, _sql);
} else {
LOGGER.debug("do select : {}", _sql);
DbUtil.select(connection, _sql, 30, 1000, new BiFunction<ResultSetMetaData, ResultSet, List<Map<String, ObjectProperty<Object>>>>() {
@Override
public List<Map<String, ObjectProperty<Object>>> apply(ResultSetMetaData t, ResultSet rs) {
try {
int columnCount = t.getColumnCount();
for (int i = 1; i <= columnCount; i++) {
String columnName = t.getColumnName(i);
TableColumn<Map<String, String>, String> tbCol = new TableColumn<>(columnName);
tbCol.setCellFactory(new Callback<TableColumn<Map<String, String>, String>, TableCell<Map<String, String>, String>>() {
@Override
public TableCell<Map<String, String>, String> call(TableColumn<Map<String, String>, String> param) {
return new TableCell<Map<String, String>, String>() {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setGraphic(null);
} else {
setGraphic(new Label(item));
}
}
};
}
});
tbCol.setCellValueFactory(param -> {
return new SimpleStringProperty(param.getValue().get(columnName));
});
tbResult.getColumns().add(tbCol);
}
while (rs.next()) {
Map<String, String> hashMap = new HashMap<>();
for (int i = 1; i <= columnCount; i++) {
String columnName = t.getColumnName(i);
String value = rs.getString(columnName);
hashMap.put(columnName, value);
}
tbResult.getItems().add(hashMap);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return Collections.emptyList();
}
});
}
}
connection.commit();
} catch (Exception e) {
connection.rollback();
throw new RuntimeException(e);
} finally {
DbUtil.close(connection);
}
}
use of javafx.scene.control.TableCell in project Gargoyle by callakrsos.
the class FxTableViewUtil method getValue.
/**
* 테이블컬럼의 row에 해당하는 데이터가 무엇인지 정의한 값을 리턴.
*
* StringConverter를 이용한 TableCell인경우 정의된 StringConvert를 이용한 데이터를 Excel의
* Cell에 쓰고, StringConverter를 이용하지않는 UI의 TableCell의 경우 데이터셋에 바인드된 값을 사용하게됨.
*
* 작성된 API내에서 적절한 값이 아니라고 판단되는경우 Ovrride해서 재정의하도록한다.
*
* @작성자 : KYJ
* @작성일 : 2016. 9. 9.
* @param table
* 사용자 화면에 정의된 tableView
* @param column
* 사용자 화면에 정의된 tableColumn
* @param columnIndex
* 사용자 화면에 정의된 tableColumn의 인덱스
* @param rowIndex
* 사용자 화면에 정의된 tableCell의 인덱스
* @return Object 테이블셀에 정의된 데이터를 리턴할 값으로, 리턴해주는 값이 엑셀에 write된다.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Object getValue(TableView<?> table, TableColumn<?, ?> column, int rowIndex) {
Callback cellFactory = column.getCellFactory();
if (cellFactory != null) {
TableCell cell = (TableCell) cellFactory.call(column);
if (cell != null) {
StringConverter converter = null;
if (cell instanceof TextFieldTableCell) {
TextFieldTableCell txtCell = (TextFieldTableCell) cell;
converter = txtCell.getConverter();
} else if (cell instanceof ComboBoxTableCell) {
ComboBoxTableCell txtCell = (ComboBoxTableCell) cell;
converter = txtCell.getConverter();
} else /* else 기본값. */
{
try {
Method m = cell.getClass().getMethod("converterProperty");
if (m != null) {
Object object = m.invoke(cell);
if (object != null && object instanceof ObjectProperty) {
ObjectProperty<StringConverter> convert = (ObjectProperty<StringConverter>) object;
converter = convert.get();
}
}
} catch (Exception e) {
// Nothing...
}
}
if (converter != null) {
Object cellData = column.getCellData(rowIndex);
return converter.toString(cellData);
}
}
}
return column.getCellData(rowIndex);
}
use of javafx.scene.control.TableCell 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.TableCell in project trex-stateless-gui by cisco-system-traffic-generator.
the class CheckBoxTableViewCell method call.
/**
*
* @param p
* @return
*/
@Override
public TableCell call(TableColumn p) {
return new TableCell<Object, Boolean>() {
private final CheckBox checkBox;
{
checkBox = new CheckBox();
checkBox.selectedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
if (checkboxChangeHandler != null) {
checkboxChangeHandler.stateChanged(getTableRow().getIndex(), newValue);
}
});
this.setGraphic(checkBox);
this.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
this.setEditable(true);
}
@Override
public void updateItem(Boolean item, boolean empty) {
super.updateItem(item, empty);
if (!empty) {
checkBox.setSelected(item);
setGraphic(checkBox);
} else {
this.setGraphic(null);
}
}
};
}
Aggregations